ovn-controller: Dynamically reconnect if ovn-remote value changes.
authorRYAN D. MOATS <rmoats@us.ibm.com>
Tue, 12 Apr 2016 13:43:59 +0000 (08:43 -0500)
committerBen Pfaff <blp@ovn.org>
Thu, 14 Apr 2016 21:58:18 +0000 (14:58 -0700)
Allows for auto detection and reconnect if the ovn-remote needs
to change.  Ovn-controller test case updated to include testing
this code.

Signed-off-by: RYAN D. MOATS <rmoats@us.ibm.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
lib/ovsdb-idl.c
lib/ovsdb-idl.h
ovn/controller/ovn-controller.c
tests/ovn-controller.at

index 3ab05a3..a046b6b 100644 (file)
@@ -272,6 +272,18 @@ ovsdb_idl_create(const char *remote, const struct ovsdb_idl_class *class,
     return idl;
 }
 
+/* Changes the remote and creates a new session. */
+void
+ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote,
+                     bool retry)
+{
+    if (idl) {
+        ovs_assert(!idl->txn);
+        idl->session = jsonrpc_session_open(remote, retry);
+        idl->state_seqno = UINT_MAX;
+    }
+}
+
 /* Destroys 'idl' and all of the data structures that it manages. */
 void
 ovsdb_idl_destroy(struct ovsdb_idl *idl)
index e2e2a5e..bad2dc6 100644 (file)
@@ -51,6 +51,7 @@ struct ovsdb_idl *ovsdb_idl_create(const char *remote,
                                    const struct ovsdb_idl_class *,
                                    bool monitor_everything_by_default,
                                    bool retry);
+void ovsdb_idl_set_remote(struct ovsdb_idl *, const char *, bool);
 void ovsdb_idl_destroy(struct ovsdb_idl *);
 
 void ovsdb_idl_run(struct ovsdb_idl *);
index c47492e..f68f842 100644 (file)
@@ -330,6 +330,16 @@ main(int argc, char *argv[])
     /* Main loop. */
     exiting = false;
     while (!exiting) {
+        /* Check OVN SB database. */
+        char *new_ovnsb_remote = get_ovnsb_remote(ovs_idl_loop.idl);
+        if (strcmp(ovnsb_remote, new_ovnsb_remote)) {
+            free(ovnsb_remote);
+            ovnsb_remote = new_ovnsb_remote;
+            ovsdb_idl_set_remote(ovnsb_idl_loop.idl, ovnsb_remote, true);
+        } else {
+            free(new_ovnsb_remote);
+        }
+
         struct controller_ctx ctx = {
             .ovs_idl = ovs_idl_loop.idl,
             .ovs_idl_txn = ovsdb_idl_loop_run(&ovs_idl_loop),
index 4bee3ca..13b3f53 100644 (file)
@@ -120,6 +120,21 @@ check_patches \
     'br-int patch-quux-to-baz patch-baz-to-quux' \
     'br-int patch-baz-to-quux patch-quux-to-baz'
 
+# Create an empty database, serve it and switch to it
+# and verify that the OVS patch ports disappear
+# then put it back and verify that they reappear
+
+on_exit 'kill `cat $ovs_base/ovn-sb/ovsdb-server-2.pid`'
+
+ovsdb-tool create $ovs_base/ovn-sb/ovn-sb1.db "$abs_top_srcdir"/ovn/ovn-sb.ovsschema
+as ovn-sb ovsdb-server --detach --pidfile=$ovs_base/ovn-sb/ovsdb-server-2.pid --remote=punix:$ovs_base/ovn-sb/ovn-sb1.sock $ovs_base/ovn-sb/ovn-sb1.db
+AT_CHECK([ovs-vsctl -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb1.sock])
+check_patches
+AT_CHECK([ovs-vsctl -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock])
+check_patches \
+    'br-int patch-quux-to-baz patch-baz-to-quux' \
+    'br-int patch-baz-to-quux patch-quux-to-baz'
+
 # Change the logical patch ports to VIFs and verify that the OVS patch
 # ports disappear.
 AT_CHECK([ovn-sbctl \
@@ -138,6 +153,7 @@ OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
 
 as ovn-sb
+OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server-2])
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
 
 AT_CLEANUP