Skip to content

Commit

Permalink
ovn-controller: Dynamically reconnect if ovn-remote value changes.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
jayhawk87 authored and blp committed Apr 14, 2016
1 parent 7d9d86a commit 1b62572
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/ovsdb-idl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/ovsdb-idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
10 changes: 10 additions & 0 deletions ovn/controller/ovn-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions tests/ovn-controller.at
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

0 comments on commit 1b62572

Please sign in to comment.