@@ -56,10 +56,13 @@ command line has options, then those options must be separated from
the global options by \fB\-\-\fR.
.
.IP "\fB\-\-db=\fIserver\fR"
-Sets \fIserver\fR as the database server that \fBovn\-sbctl\fR
-contacts to query or modify configuration. The default is
-\fBunix:@RUNDIR@/db.sock\fR. \fIserver\fR must take one of the
-following forms:
+The OVSDB database remote to contact. If the \fBOVN_SB_DB\fR
+environment variable is set, its value is used as the default.
+Otherwise, the default is \fBunix:@RUNDIR@/db.sock\fR, but this
+default is unlikely to be useful outside of single-machine OVN test
+environments.
+.IP
+\fIserver\fR must take one of the following forms:
.RS
.so ovsdb/remote-active.man
.so ovsdb/remote-passive.man
@@ -77,6 +77,7 @@ OVS_NO_RETURN static void sbctl_exit(int status);
static void sbctl_cmd_init(void);
OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[], struct shash *local_options);
+static const char *sbctl_default_db(void);
static void run_prerequisites(struct ctl_command[], size_t n_commands,
struct ovsdb_idl *);
static void do_sbctl(const char *args, struct ctl_command *, size_t n,
@@ -147,6 +148,19 @@ main(int argc, char *argv[])
}
}
+static const char *
+sbctl_default_db(void)
+{
+ static char *def;
+ if (!def) {
+ def = getenv("OVN_SB_DB");
+ if (!def) {
+ def = ctl_default_db();
+ }
+ }
+ return def;
+}
+
static void
parse_options(int argc, char *argv[], struct shash *local_options)
{
@@ -270,7 +284,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
free(short_options);
if (!db) {
- db = ctl_default_db();
+ db = sbctl_default_db();
}
for (i = n_global_long_options; options[i].name; i++) {
@@ -110,8 +110,9 @@ as() {
# ovn_init_db DATABASE
#
-# Creates and initializes the given DATABASE (one of "ovn-sb" or "ovn-nb")
-# and starts its ovsdb-server instance.
+# Creates and initializes the given DATABASE (one of "ovn-sb" or "ovn-nb"),
+# starts its ovsdb-server instance, and sets the appropriate environment
+# variable so that ovn-sbctl or ovn-nbctl uses the database by default.
#
# Usually invoked from ovn_start.
ovn_init_db () {
@@ -121,18 +122,20 @@ ovn_init_db () {
: > "$d"/.$1.db.~lock~
as $1 ovsdb-tool create "$d"/$1.db "$abs_top_srcdir"/ovn/$1.ovsschema
as $1 start_daemon ovsdb-server --remote=punix:"$d"/$1.sock "$d"/$1.db
+ local var=`echo $1_db | tr a-z- A-Z_`
+ AS_VAR_SET([$var], [unix:$ovs_base/$1/$1.sock]); export $var
}
# ovn_start
#
# Creates and initializes ovn-sb and ovn-nb databases and starts their
-# ovsdb-server instance, and starts ovn-northd running against them.
+# ovsdb-server instance, sets appropriate environment variables so that
+# ovn-sbctl and ovn-nbctl use them by default, and starts ovn-northd running
+# against them.
ovn_start () {
ovn_init_db ovn-sb
ovn_init_db ovn-nb
- OVN_NB_DB=unix:$ovs_base/ovn-nb/ovn-nb.sock; export OVN_NB_DB
-
echo "starting ovn-northd"
mkdir "$ovs_base"/northd
as northd start_daemon ovn-northd \
@@ -541,7 +541,7 @@ ovn_populate_arp
# Allow some time for ovn-northd and ovn-controller to catch up.
# XXX This should be more systematic.
sleep 1
-ovn-sbctl --db=unix:`pwd`/ovn-sb/ovn-sb.sock dump-flows -- list multicast_group
+ovn-sbctl dump-flows -- list multicast_group
# test_packet INPORT DST SRC ETHTYPE OUTPORT...
#
@@ -261,11 +261,12 @@ EOF
done
OVN_NB_DB=unix:$sim_base/ovn-nb/ovn-nb.sock; export OVN_NB_DB
+ OVN_SB_DB=unix:$sim_base/ovn-sb/ovn-sb.sock; export OVN_SB_DB
mkdir "$sim_base"/northd
as northd ovn-northd $daemon_opts \
- --ovnnb-db=unix:"$sim_base"/ovn-nb/ovn-nb.sock \
- --ovnsb-db=unix:"$sim_base"/ovn-sb/ovn-sb.sock
+ --ovnnb-db="$OVN_NB_DB" \
+ --ovnsb-db="$OVN_SB_DB"
}
export -f ovn_start
This makes it possible to use ovn-sbctl without always typing the --db option (outside of trivial single-machine OVN deployments). Also modifies the testsuite to use this. Signed-off-by: Ben Pfaff <blp@nicira.com> --- ovn/utilities/ovn-sbctl.8.in | 11 +++++++---- ovn/utilities/ovn-sbctl.c | 16 +++++++++++++++- tests/ofproto-macros.at | 13 ++++++++----- tests/ovn.at | 2 +- utilities/ovs-sim.in | 5 +++-- 5 files changed, 34 insertions(+), 13 deletions(-)