From patchwork Wed Oct 7 20:57:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 527412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id DD5411402A2 for ; Thu, 8 Oct 2015 07:57:28 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 0DC0810999; Wed, 7 Oct 2015 13:57:27 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 4BF861098C for ; Wed, 7 Oct 2015 13:57:25 -0700 (PDT) Received: from bar4.cudamail.com (bar2 [192.168.15.2]) by mx3v1.cudamail.com (Postfix) with ESMTP id C3537618091 for ; Wed, 7 Oct 2015 14:57:24 -0600 (MDT) X-ASG-Debug-ID: 1444251444-03dc2149b23bab0001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar4.cudamail.com with ESMTP id zC1v4V2ePY0HD3c2 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 07 Oct 2015 14:57:24 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO mail-pa0-f46.google.com) (209.85.220.46) by mx3-pf3.cudamail.com with ESMTPS (RC4-SHA encrypted); 7 Oct 2015 20:57:23 -0000 Received-SPF: unknown (mx3-pf3.cudamail.com: Multiple SPF records returned) X-Barracuda-Apparent-Source-IP: 209.85.220.46 X-Barracuda-RBL-IP: 209.85.220.46 Received: by padhy16 with SMTP id hy16so31522670pad.1 for ; Wed, 07 Oct 2015 13:57:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bg4TqZBXYRnghWrrvlJKqxSB60j2sy1B8q+nn58LvEE=; b=eCTv+tYqnw4hCr+R5eQ+mZ+zD5xq7Drp0w/RAQHx0H64IDhwhvAu/Kwk9f6e79ptgl d8BukIQDm6Mq5NABucCyZQYtQOT5XD7+tFch2SjfkUZZKM8SLQweNzd0X7TnIOukb5Pt b2ECMAopFBkAE+vOB4CK3LVEDa+Lr9/JK+UWI2U3gIc0URiF8chN9wm3wiCuE2sq0KH4 2F06s0ahixi+hEj8ir+M4//JbG4EWX5/qpvK6PGRuNR3BNgaNqG7g4NvDprKvnGPYncF bD5Pjff4BVuKTWmweQdDn0cwmcF5Do0HgozGzt8J8eQAQjlODXn+PK/Y42aESvwhAtFj /NYA== X-Gm-Message-State: ALoCoQmcWRo7Ar+TQr+Ng3gu92dnYYvqlh4stMmh95fAJrMIUvc55kFKGmB35zzxBsxSh1HSQuob X-Received: by 10.67.30.136 with SMTP id ke8mr3462839pad.16.1444251443391; Wed, 07 Oct 2015 13:57:23 -0700 (PDT) Received: from sigabrt.benpfaff.org ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id yh3sm11385375pbb.82.2015.10.07.13.57.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Oct 2015 13:57:22 -0700 (PDT) X-CudaMail-Envelope-Sender: blp@nicira.com From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-1006061428 X-CudaMail-DTE: 100715 X-CudaMail-Originating-IP: 209.85.220.46 Date: Wed, 7 Oct 2015 13:57:15 -0700 X-ASG-Orig-Subj: [##CM-V3-1006061428##][PATCH 2/3] ovn-sbctl: Use environment var OVN_SB_DB to find the database by default. Message-Id: <1444251436-26967-2-git-send-email-blp@nicira.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1444251436-26967-1-git-send-email-blp@nicira.com> References: <1444251436-26967-1-git-send-email-blp@nicira.com> X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1444251444 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 2/3] ovn-sbctl: Use environment var OVN_SB_DB to find the database by default. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 Acked-by: Justin Pettit --- 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(-) diff --git a/ovn/utilities/ovn-sbctl.8.in b/ovn/utilities/ovn-sbctl.8.in index 7e68d68..9c3706d 100644 --- a/ovn/utilities/ovn-sbctl.8.in +++ b/ovn/utilities/ovn-sbctl.8.in @@ -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 diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index f7cb156..29aaf47 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -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++) { diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index a5aee3a..6ca4ab4 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -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 \ diff --git a/tests/ovn.at b/tests/ovn.at index 9bf8022..1eb6d0b 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -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... # diff --git a/utilities/ovs-sim.in b/utilities/ovs-sim.in index 2d9d66d..1702f0e 100755 --- a/utilities/ovs-sim.in +++ b/utilities/ovs-sim.in @@ -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