From: RYAN D. MOATS <rmo...@us.ibm.com> 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 <rmo...@us.ibm.com> --- lib/ovsdb-idl.c | 12 ++++++++++++ lib/ovsdb-idl.h | 1 + ovn/controller/ovn-controller.c | 10 ++++++++++ tests/ovn-controller.at | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 0 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 3ab05a3..a046b6b 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -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) diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h index e2e2a5e..bad2dc6 100644 --- a/lib/ovsdb-idl.h +++ b/lib/ovsdb-idl.h @@ -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 *); diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 6027011..0847da2 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -302,6 +302,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), diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at index 4bee3ca..13b3f53 100644 --- a/tests/ovn-controller.at +++ b/tests/ovn-controller.at @@ -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 -- 1.7.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev