From patchwork Tue Jun 29 18:51:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1498532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDtqb2PTdz9sWM for ; Wed, 30 Jun 2021 04:51:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 16CD740401; Tue, 29 Jun 2021 18:51:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y5PboZOW6eg2; Tue, 29 Jun 2021 18:51:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 30F98403EF; Tue, 29 Jun 2021 18:51:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E9023C0010; Tue, 29 Jun 2021 18:51:34 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 66B3EC000E for ; Tue, 29 Jun 2021 18:51:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 48F0D83A4D for ; Tue, 29 Jun 2021 18:51:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tUtvIvA5ZTfz for ; Tue, 29 Jun 2021 18:51:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp1.osuosl.org (Postfix) with ESMTPS id C1DD683A4F for ; Tue, 29 Jun 2021 18:51:31 +0000 (UTC) Received: (Authenticated sender: blp@ovn.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id DF0B0C0009; Tue, 29 Jun 2021 18:51:28 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 29 Jun 2021 11:51:25 -0700 Message-Id: <20210629185125.3327437-1-blp@ovn.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Cc: Ben Pfaff , Dumitru Ceara Subject: [ovs-dev] [PATCH ovn] ovs-sandbox: Allow specifying initial contents for NB and SB database. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This makes it easier to test northd behavior with particular database contents, like the ones that Dumitru posted to the mailing list: https://mail.openvswitch.org/pipermail/ovs-dev/2021-June/384519.html You just do something like this: make sandbox SANDBOXFLAGS="--nbdb-source=$HOME/Downloads/ovnnb_db.db --sbdb-source=$HOME/Downloads/ovnsb_db.db --ddlog" Signed-off-by: Ben Pfaff CC: Dumitru Ceara Acked-by: Dumitru Ceara --- tutorial/ovs-sandbox | 71 +++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/tutorial/ovs-sandbox b/tutorial/ovs-sandbox index 08a3629be7f6..847bff224b2d 100755 --- a/tutorial/ovs-sandbox +++ b/tutorial/ovs-sandbox @@ -74,8 +74,6 @@ built=false ovn=true ddlog=false ddlog_record=true -ovnsb_schema= -ovnnb_schema= ic_sb_schema= ic_nb_schema= ovn_rbac=true @@ -84,8 +82,10 @@ n_ics=1 n_controllers=1 nbdb_model=standalone nbdb_servers=3 +nbdb_source= sbdb_model=backup sbdb_servers=3 +sbdb_source= ic_nb_model=clustered ic_nb_servers=3 ic_sb_model=clustered @@ -152,8 +152,10 @@ OVN options: --n-ics=NUMBER run NUMBER copies of ic (default: 1) --nbdb-model=standalone|backup|clustered northbound database model --nbdb-servers=N number of servers in nbdb cluster (default: 3) + --nbdb-source=FILE database or schema to copy NBDB from --sbdb-model=standalone|backup|clustered southbound database model --sbdb-servers=N number of servers in sbdb cluster (default: 3) + --sbdb-source=FILE database or schema to copy SBDB from --ic-nb-model=standalone|backup|clustered ic-northbound database model --ic-nb-servers=N number of servers in IC NB cluster (default: 3) --ic-sb-model=standalone|backup|clustered ic-southbound database model @@ -265,11 +267,11 @@ EOF --n-controller*) prev=n_controllers ;; - --nbdb-s*=*) + --nbdb-se*=*) nbdb_servers=$optarg nbdb_model=clustered ;; - --nbdb-s*) + --nbdb-se*) prev=nbdb_servers nbdb_model=clustered ;; @@ -279,11 +281,17 @@ EOF --nbdb-m*) prev=nbdb_model ;; - --sbdb-s*=*) + --nbdb-so*=*) + ovnnb_source=$optarg + ;; + --nbdb-so*) + prev=ovnnb_source + ;; + --sbdb-se*=*) sbdb_servers=$optarg sbdb_model=clustered ;; - --sbdb-s*) + --sbdb-se*) prev=sbdb_servers sbdb_model=clustered ;; @@ -293,6 +301,12 @@ EOF --sbdb-m*) prev=sbdb_model ;; + --sbdb-so*=*) + ovnsb_source=$optarg + ;; + --sbdb-so*) + prev=ovnsb_source + ;; --ic-nb-s*=*) ic_nb_servers=$optarg ic_nb_model=clustered @@ -380,15 +394,15 @@ if $built; then exit 1 fi if $ovn; then - ovnsb_schema=$srcdir/ovn-sb.ovsschema - if test ! -e "$ovnsb_schema"; then - echo >&2 'source directory not found, please use --srcdir' - exit 1 + : ${ovnnb_source:=$srcdir/ovn-nb.ovsschema} + if test ! -e "$ovnnb_source"; then + echo >&2 "OVN northbound database source $ovnnb_source not found, please check --srcdir or --ovnnb-source" + exit 1 fi - ovnnb_schema=$srcdir/ovn-nb.ovsschema - if test ! -e "$ovnnb_schema"; then - echo >&2 'source directory not found, please use --srcdir' - exit 1 + : ${ovnsb_source:=$srcdir/ovn-sb.ovsschema} + if test ! -e "$ovnsb_source"; then + echo >&2 "OVN southbound database source $ovnsb_source not found, please check --srcdir or --ovnsb-source" + exit 1 fi ic_sb_schema=$srcdir/ovn-ic-sb.ovsschema if test ! -e "$ic_sb_schema"; then @@ -484,9 +498,18 @@ rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir --pidfile -vcon $ovsdb_server_args ovn_start_db() { - local db=$1 model=$2 servers=$3 schema=$4 + local db=$1 model=$2 servers=$3 source=$4 local DB=$(echo $db | tr a-z A-Z) - local schema_name=$(ovsdb-tool schema-name $schema) + + local schema_name source_type + if schema_name=$(ovsdb-tool schema-name "$source" 2>/dev/null); then + source_type=schema + elif schema_name=$(ovsdb-tool db-name "$source" 2>/dev/null); then + source_type=database + else + echo "$source is not an OVSDB schema or database" >&2 + exit 1 + fi case $model in standalone | backup) ;; @@ -520,13 +543,19 @@ ovn_start_db() { case $model in standalone) - run ovsdb-tool create ${db}1.db "$schema" + case $source_type in + database) run cp "$source" ${db}1.db ;; + schema) run ovsdb-tool create ${db}1.db "$source" ;; + esac ovn_start_ovsdb_server 1 remote=unix:${db}1.ovsdb ;; backup) for i in 1 2; do - run ovsdb-tool create $db$i.db "$schema" + case $source_type in + database) run cp "$source" $db$i.db ;; + schema) run ovsdb-tool create $db$i.db "$source" ;; + esac done ovn_start_ovsdb_server 1 ovn_start_ovsdb_server 2 --sync-from=unix:${db}1.ovsdb @@ -541,7 +570,7 @@ The backup database file is sandbox/${db}2.db clustered) for i in $(seq $servers); do if test $i = 1; then - run ovsdb-tool create-cluster ${db}1.db "$schema" unix:${db}1.raft; + run ovsdb-tool create-cluster ${db}1.db "$source" unix:${db}1.raft; else run ovsdb-tool join-cluster $db$i.db $schema_name unix:$db$i.raft unix:${db}1.raft fi @@ -561,8 +590,8 @@ The backup database file is sandbox/${db}2.db } backup_note= -ovn_start_db nb "$nbdb_model" "$nbdb_servers" "$ovnnb_schema" -ovn_start_db sb "$sbdb_model" "$sbdb_servers" "$ovnsb_schema" +ovn_start_db nb "$nbdb_model" "$nbdb_servers" "$ovnnb_source" +ovn_start_db sb "$sbdb_model" "$sbdb_servers" "$ovnsb_source" ovn_start_db ic_nb "$ic_nb_model" "$ic_nb_servers" "$ic_nb_schema" ovn_start_db ic_sb "$ic_sb_model" "$ic_sb_servers" "$ic_sb_schema"