[ovs-dev] [PATCH v3] Introduce ovs-appctl command to monitor HVs sb connection status
Jakub Sitnicki
jkbs at redhat.com
Tue Jul 31 14:19:09 UTC 2018
On Tue, 31 Jul 2018 15:22:38 +0200
Lorenzo Bianconi <lorenzo.bianconi at redhat.com> wrote:
> Add 'connection-status' command to ovs-appctl utility in order to check
> if a given chassis is currently connected to SB db
>
> Acked-by: Mark Michelson <mmichels at redhat.com>
> Co-authored-by: aginwala <aginwala at ebay.com>
> Signed-off-by: aginwala <aginwala at ebay.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>
> ---
> Changes since v2:
> - check idl->session pointer in ovsdb_idl_is_connected routine
>
> Changes since v1:
> - add unit tests for ovs-appctl -t ovn-controller connection-status
> command
> - use jsonrpc_session_is_connected() in ovsdb_idl_is_connected routine
> ---
> lib/ovsdb-idl.c | 6 +++++
> lib/ovsdb-idl.h | 1 +
> ovn/controller/ovn-controller.8.xml | 5 +++++
> ovn/controller/ovn-controller.c | 17 +++++++++++++++
> tests/ovn-controller.at | 34 +++++++++++++++++++++++++++++
> 5 files changed, 63 insertions(+)
>
> diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
> index ae0a55c3a..40c29cbd1 100644
> --- a/lib/ovsdb-idl.c
> +++ b/lib/ovsdb-idl.c
> @@ -922,6 +922,12 @@ ovsdb_idl_is_alive(const struct ovsdb_idl *idl)
> idl->state != IDL_S_ERROR;
> }
>
> +bool
> +ovsdb_idl_is_connected(const struct ovsdb_idl *idl)
> +{
> + return idl->session && jsonrpc_session_is_connected(idl->session);
> +}
> +
> /* Returns the last error reported on a connection by 'idl'. The return value
> * is 0 only if no connection made by 'idl' has ever encountered an error and
> * a negative response to a schema request has never been received. See
> diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
> index ea18b22f5..5f933b628 100644
> --- a/lib/ovsdb-idl.h
> +++ b/lib/ovsdb-idl.h
> @@ -80,6 +80,7 @@ void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
> void ovsdb_idl_verify_write_only(struct ovsdb_idl *);
>
> bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
> +bool ovsdb_idl_is_connected(const struct ovsdb_idl *idl);
> int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
>
> void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int probe_interval);
> diff --git a/ovn/controller/ovn-controller.8.xml b/ovn/controller/ovn-controller.8.xml
> index 2e4e53d6b..8035638b3 100644
> --- a/ovn/controller/ovn-controller.8.xml
> +++ b/ovn/controller/ovn-controller.8.xml
> @@ -398,6 +398,11 @@
> 0x800</code>.
> </p>
> </dd>
> +
> + <dt><code>connection-status</code></dt>
> + <dd>
> + Show OVN SBDB connection status for the chassis.
> + </dd>
> </dl>
> </p>
>
> diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
> index 470e02ae8..bc4e8014b 100644
> --- a/ovn/controller/ovn-controller.c
> +++ b/ovn/controller/ovn-controller.c
> @@ -68,6 +68,7 @@ static unixctl_cb_func ct_zone_list;
> static unixctl_cb_func meter_table_list;
> static unixctl_cb_func group_table_list;
> static unixctl_cb_func inject_pkt;
> +static unixctl_cb_func ovn_controller_conn_show;
>
> #define DEFAULT_BRIDGE_NAME "br-int"
> #define DEFAULT_PROBE_INTERVAL_MSEC 5000
> @@ -594,6 +595,9 @@ main(int argc, char *argv[])
> ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
> ovsdb_idl_set_leader_only(ovnsb_idl_loop.idl, false);
>
> + unixctl_command_register("connection-status", "", 0, 0,
> + ovn_controller_conn_show, ovnsb_idl_loop.idl);
> +
> struct ovsdb_idl_index *sbrec_chassis_by_name
> = chassis_index_create(ovnsb_idl_loop.idl);
> struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath
> @@ -1122,3 +1126,16 @@ update_probe_interval(const struct ovsrec_open_vswitch_table *ovs_table,
>
> ovsdb_idl_set_probe_interval(ovnsb_idl, interval);
> }
> +
> +static void
> +ovn_controller_conn_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
> + const char *argv[] OVS_UNUSED, void *idl_)
> +{
> + char *result = "not connected";
> + struct ovsdb_idl *idl = idl_;
'result' definitely should be pointing to const data. 'idl' could be
declared as const as well.
> +
> + if (idl && ovsdb_idl_is_connected(idl)) {
It doesn't look like 'idl' can be null or we would be in trouble in
other code paths.
Sorry I didn't notice these the first time.
-Jakub
> + result = "connected";
> + }
> + unixctl_command_reply(conn, result);
> +}
> diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
> index ecc6a50da..13e88a0cc 100644
> --- a/tests/ovn-controller.at
> +++ b/tests/ovn-controller.at
> @@ -228,3 +228,37 @@ as ovn-sb
> OVS_APP_EXIT_AND_WAIT([ovsdb-server])
>
> AT_CLEANUP
> +
> +# Check ovn-controller connection status to Southbound database
> +AT_SETUP([ovn-controller - check sbdb connection])
> +AT_KEYWORDS([ovn])
> +ovn_init_db ovn-sb
> +
> +net_add n1
> +sim_add hv
> +as hv
> +ovs-vsctl \
> + -- add-br br-phys \
> + -- add-br br-eth0 \
> + -- add-br br-eth1 \
> + -- add-br br-eth2
> +ovn_attach n1 br-phys 192.168.0.1
> +
> +check_sbdb_connection () {
> + test "$(ovs-appctl -t ovn-controller connection-status)" = "$1"
> +}
> +
> +OVS_WAIT_UNTIL([check_sbdb_connection connected])
> +
> +ovs-vsctl set open . external_ids:ovn-remote=tcp:192.168.0.10:6642
> +OVS_WAIT_UNTIL([check_sbdb_connection 'not connected'])
> +
> +# reset the remote for clean-up
> +ovs-vsctl set open . external_ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock
> +# Gracefully terminate daemons
> +OVN_CLEANUP_SBOX([hv])
> +OVN_CLEANUP_VSWITCH([main])
> +as ovn-sb
> +OVS_APP_EXIT_AND_WAIT([ovsdb-server])
> +
> +AT_CLEANUP
More information about the dev
mailing list