[ovs-dev] [PATCH 1/2] ovsdb-cluster: Use ovs-vsctl instead of ovn-nbctl and ovn-sbctl.
Han Zhou
zhouhan at gmail.com
Fri Sep 27 21:07:49 UTC 2019
On Fri, Sep 27, 2019 at 12:50 PM Ben Pfaff <blp at ovn.org> wrote:
>
> This removes a dependency on OVN from the tests.
>
> This adds some options to ovs-vsctl to allow it to be used for testing
> the clustering feature. The new options are undocumented because
> they're really just useful for testing clustering.
>
> Signed-off-by: Ben Pfaff <blp at ovn.org>
> ---
> tests/ovsdb-cluster.at | 37 ++++++++++++++++++-------------------
> utilities/ovs-vsctl.c | 27 ++++++++++++++++++++++++++-
> 2 files changed, 44 insertions(+), 20 deletions(-)
>
> diff --git a/tests/ovsdb-cluster.at b/tests/ovsdb-cluster.at
> index de4295a7e60c..24601c887ff0 100644
> --- a/tests/ovsdb-cluster.at
> +++ b/tests/ovsdb-cluster.at
> @@ -249,10 +249,10 @@ ovsdb_cluster_failure_test () {
> new_leader=$5
> fi
>
> - cp $top_srcdir/ovn/ovn-nb.ovsschema schema
> + cp $top_srcdir/vswitchd/vswitch.ovsschema schema
> schema=`ovsdb-tool schema-name schema`
> AT_CHECK([ovsdb-tool '-vPATTERN:console:%c|%p|%m' create-cluster
s1.db schema unix:s1.raft], [0], [], [dnl
> -ovsdb|WARN|schema: changed 2 columns in 'OVN_Northbound' database from
ephemeral to persistent, including 'status' column in 'Connection' table,
because clusters do not support ephemeral columns
> +ovsdb|WARN|schema: changed 30 columns in 'Open_vSwitch' database from
ephemeral to persistent, including 'status' column in 'Manager' table,
because clusters do not support ephemeral columns
> ])
>
> n=3
> @@ -283,7 +283,7 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Northbound' database from ephemeral
> for i in `seq $n`; do start_server $i; done
> for i in `seq $n`; do connect_server $i; done
>
> - export OVN_NB_DB=unix:s$remote_1.ovsdb,unix:s$remote_2.ovsdb
> + db=unix:s$remote_1.ovsdb,unix:s$remote_2.ovsdb
>
> # To ensure $new_leader node the new leader, we delay election timer
for
> # the other follower.
> @@ -296,15 +296,15 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Northbound' database from ephemeral
> AT_CHECK([ovs-appctl -t "`pwd`"/s$delay_election_node
cluster/failure-test delay-election], [0], [ignore])
> fi
> AT_CHECK([ovs-appctl -t "`pwd`"/s$crash_node cluster/failure-test
$crash_command], [0], [ignore])
> - AT_CHECK([ovn-nbctl -v --timeout=10 --no-leader-only
--no-shuffle-remotes create logical_switch name=ls1], [0], [ignore],
[ignore])
> + AT_CHECK([ovs-vsctl -v --timeout=10 --db="$db" --no-leader-only
--no-shuffle-remotes --no-wait create QoS type=x], [0], [ignore], [ignore])
>
> # Make sure that the node really crashed.
> AT_CHECK([ls s$crash_node.ovsdb], [2], [ignore], [ignore])
> # XXX: Client will fail if remotes contains unix socket that doesn't
exist (killed).
> - if test "$remote_1" == "$crash_node"; then
> - export OVN_NB_DB=unix:s$remote_2.ovsdb
> + if test "$remote_1" = "$crash_node"; then
> + db=unix:s$remote_2.ovsdb
> fi
> - AT_CHECK([ovn-nbctl --no-leader-only ls-list | awk '{ print $2 }'],
[0], [(ls1)
> + AT_CHECK([ovs-vsctl --db="$db" --no-leader-only --no-wait
--columns=type --bare list QoS], [0], [x
> ])
> }
> OVS_END_SHELL_HELPERS
> @@ -407,10 +407,10 @@ ovsdb_torture_test () {
> local n=$1 # Number of cluster members
> local victim=$2 # Cluster member to kill or remove
> local variant=$3 # 'kill' and restart or 'remove' and add
> - cp $top_srcdir/ovn/ovn-sb.ovsschema schema
> + cp $top_srcdir/vswitchd/vswitch.ovsschema schema
> schema=`ovsdb-tool schema-name schema`
> AT_CHECK([ovsdb-tool '-vPATTERN:console:%c|%p|%m' create-cluster
s1.db schema unix:s1.raft], [0], [], [dnl
> -ovsdb|WARN|schema: changed 2 columns in 'OVN_Southbound' database from
ephemeral to persistent, including 'status' column in 'Connection' table,
because clusters do not support ephemeral columns
> +ovsdb|WARN|schema: changed 30 columns in 'Open_vSwitch' database from
ephemeral to persistent, including 'status' column in 'Manager' table,
because clusters do not support ephemeral columns
> ])
>
> join_cluster() {
> @@ -442,7 +442,7 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Southbound' database from ephemeral
> remove_server() {
> local i=$1
> printf "\ns$i: removing from cluster\n"
> - AT_CHECK([ovs-appctl --timeout=30 -t "`pwd`"/s$i cluster/leave
OVN_Southbound])
> + AT_CHECK([ovs-appctl --timeout=30 -t "`pwd`"/s$i cluster/leave
Open_vSwitch])
> printf "\ns$i: waiting for removal to complete\n"
> AT_CHECK([ovsdb_client_wait --log-file=remove$i.log
unix:s$i.ovsdb $schema removed])
> stop_server $i
> @@ -462,22 +462,21 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Southbound' database from ephemeral
> for i in `seq $n`; do start_server $i; done
> for i in `seq $n`; do connect_server $i; done
>
> - OVN_SB_DB=unix:s1.ovsdb
> + db=unix:s1.ovsdb
> for i in `seq 2 $n`; do
> - OVN_SB_DB=$OVN_SB_DB,unix:s$i.ovsdb
> + db=$db,unix:s$i.ovsdb
> done
> - export OVN_SB_DB
>
> n1=10 n2=5 n3=50
> - echo "starting $n1*$n2 ovn-sbctl processes..."
> + echo "starting $n1*$n2 ovs-vsctl processes..."
> for i in $(seq 0 $(expr $n1 - 1) ); do
> (for j in $(seq $n2); do
> : > $i-$j.running
> - txn="add SB_Global . external_ids $i-$j=$i-$j"
> + txn="add Open_vSwitch . external_ids $i-$j=$i-$j"
> for k in $(seq $n3); do
> - txn="$txn -- add SB_Global . external_ids
$i-$j-$k=$i-$j-$k"
> + txn="$txn -- add Open_vSwitch . external_ids
$i-$j-$k=$i-$j-$k"
> done
> - run_as "ovn-sbctl($i-$j)" ovn-sbctl
"-vPATTERN:console:ovn-sbctl($i-$j)|%D{%H:%M:%S}|%05N|%c|%p|%m"
--log-file=$i-$j.log -vfile -vsyslog:off -vtimeval:off --timeout=120
--no-leader-only $txn
> + run_as "ovs-vsctl($i-$j)" ovs-vsctl
"-vPATTERN:console:ovs-vsctl($i-$j)|%D{%H:%M:%S}|%05N|%c|%p|%m"
--log-file=$i-$j.log -vfile -vsyslog:off -vtimeval:off --timeout=120
--db="$db" --no-leader-only --no-wait $txn
> status=$?
> if test $status != 0; then
> echo "$i-$j exited with status $status" > $i-$j:$status
> @@ -488,7 +487,7 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Southbound' database from ephemeral
> done
> echo "...done"
>
> - echo "waiting for ovn-sbctl processes to exit..."
> + echo "waiting for ovs-vsctl processes to exit..."
> # Use file instead of var because code inside "while" runs in a
subshell.
> echo 0 > phase
> i=0
> @@ -544,7 +543,7 @@ ovsdb|WARN|schema: changed 2 columns in
'OVN_Southbound' database from ephemeral
> done
> done
> done | sort > expout
> - AT_CHECK([ovn-sbctl --timeout=30 --log-file=finalize.log
-vtimeval:off -vfile -vsyslog:off --bare get SB_Global . external-ids | tr
',' '\n' | sed 's/[[{}"" ]]//g' | sort], [0], [expout])
> + AT_CHECK([ovs-vsctl --timeout=30 --db="$db" --no-wait
--log-file=finalize.log -vtimeval:off -vfile -vsyslog:off --bare get
Open_vSwitch . external-ids | tr ',' '\n' | sed 's/[[{}"" ]]//g' | sort],
[0], [expout])
>
> for i in `seq $n`; do
> if test $i != $victim || test $(cat phase) != 1; then
> diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
> index 43f64d4711f9..7232471e68b9 100644
> --- a/utilities/ovs-vsctl.c
> +++ b/utilities/ovs-vsctl.c
> @@ -83,6 +83,21 @@ static unsigned int timeout;
> * wait. */
> static bool retry;
>
> +/* --leader-only, --no-leader-only: Only accept the leader in a cluster.
> + *
> + * In a real Open vSwitch environment, it doesn't make much sense to
cluster
> + * the Open vSwitch database. This option exists to enable using
ovs-vsctl to
> + * test OVSDB's clustering feature. */
> +static int leader_only = true;
> +
> +/* --shuffle-remotes, --no-shuffle-remotes: Shuffle the order of remotes
that
> + * are specified in the connetion method string.
> + *
> + * In a real Open vSwitch environment, it doesn't make much sense to
cluster
> + * the Open vSwitch database. This option exists to enable using
ovs-vsctl to
> + * test OVSDB's clustering feature. */
> +static int shuffle_remotes = true;
> +
> /* Format for table output. */
> static struct table_style table_style = TABLE_STYLE_DEFAULT;
>
> @@ -161,7 +176,10 @@ main(int argc, char *argv[])
> ctl_timeout_setup(timeout);
>
> /* Initialize IDL. */
> - idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class, false,
retry);
> + idl = the_idl = ovsdb_idl_create_unconnected(&ovsrec_idl_class,
false);
> + ovsdb_idl_set_shuffle_remotes(idl, shuffle_remotes);
> + ovsdb_idl_set_remote(idl, db, retry);
> + ovsdb_idl_set_leader_only(idl, leader_only);
> run_prerequisites(commands, n_commands, idl);
>
> /* Execute the commands.
> @@ -225,6 +243,10 @@ parse_options(int argc, char *argv[], struct shash
*local_options)
> {"help", no_argument, NULL, 'h'},
> {"commands", no_argument, NULL, OPT_COMMANDS},
> {"options", no_argument, NULL, OPT_OPTIONS},
> + {"leader-only", no_argument, &leader_only, true},
> + {"no-leader-only", no_argument, &leader_only, false},
> + {"shuffle-remotes", no_argument, &shuffle_remotes, true},
> + {"no-shuffle-remotes", no_argument, &shuffle_remotes, false},
> {"version", no_argument, NULL, 'V'},
> VLOG_LONG_OPTIONS,
> TABLE_LONG_OPTIONS,
> @@ -336,6 +358,9 @@ parse_options(int argc, char *argv[], struct shash
*local_options)
> case '?':
> exit(EXIT_FAILURE);
>
> + case 0:
> + break;
> +
> default:
> abort();
> }
> --
> 2.21.0
>
Thanks Ben. For the series:
Acked-by: Han Zhou <hzhou8 at ebay.com>
More information about the dev
mailing list