diff mbox series

[ovs-dev] ovs-sandbox: Allow specifying initial contents for NB and SB database.

Message ID 20210629185125.3327437-1-blp@ovn.org
State Accepted
Headers show
Series [ovs-dev] ovs-sandbox: Allow specifying initial contents for NB and SB database. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot success github build: passed

Commit Message

Ben Pfaff June 29, 2021, 6:51 p.m. UTC
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 <blp@ovn.org>
CC: Dumitru Ceara <dceara@redhat.com>
---
 tutorial/ovs-sandbox | 71 +++++++++++++++++++++++++++++++-------------
 1 file changed, 50 insertions(+), 21 deletions(-)

Comments

0-day Robot June 29, 2021, 7:05 p.m. UTC | #1
Bleep bloop.  Greetings Ben Pfaff, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line has non-spaces leading whitespace
#73 FILE: tutorial/ovs-sandbox:284:
	--nbdb-so*=*)

WARNING: Line has non-spaces leading whitespace
#74 FILE: tutorial/ovs-sandbox:285:
	    ovnnb_source=$optarg

WARNING: Line has non-spaces leading whitespace
#75 FILE: tutorial/ovs-sandbox:286:
	    ;;

WARNING: Line has non-spaces leading whitespace
#76 FILE: tutorial/ovs-sandbox:287:
	--nbdb-so*)

WARNING: Line has non-spaces leading whitespace
#77 FILE: tutorial/ovs-sandbox:288:
	    prev=ovnnb_source

WARNING: Line has non-spaces leading whitespace
#78 FILE: tutorial/ovs-sandbox:289:
	    ;;

WARNING: Line has non-spaces leading whitespace
#92 FILE: tutorial/ovs-sandbox:304:
	--sbdb-so*=*)

WARNING: Line has non-spaces leading whitespace
#93 FILE: tutorial/ovs-sandbox:305:
	    ovnsb_source=$optarg

WARNING: Line has non-spaces leading whitespace
#94 FILE: tutorial/ovs-sandbox:306:
	    ;;

WARNING: Line has non-spaces leading whitespace
#95 FILE: tutorial/ovs-sandbox:307:
	--sbdb-so*)

WARNING: Line has non-spaces leading whitespace
#96 FILE: tutorial/ovs-sandbox:308:
	    prev=ovnsb_source

WARNING: Line has non-spaces leading whitespace
#97 FILE: tutorial/ovs-sandbox:309:
	    ;;

WARNING: Line has non-spaces leading whitespace
#109 FILE: tutorial/ovs-sandbox:397:
	: ${ovnnb_source:=$srcdir/ovn-nb.ovsschema}

WARNING: Line has non-spaces leading whitespace
#110 FILE: tutorial/ovs-sandbox:398:
	if test ! -e "$ovnnb_source"; then

WARNING: Line is 111 characters long (recommended limit is 79)
WARNING: Line has non-spaces leading whitespace
#111 FILE: tutorial/ovs-sandbox:399:
	    echo >&2 "OVN northbound database source $ovnnb_source not found, please check --srcdir or --ovnnb-source"

WARNING: Line has non-spaces leading whitespace
#112 FILE: tutorial/ovs-sandbox:400:
	    exit 1

WARNING: Line has non-spaces leading whitespace
#118 FILE: tutorial/ovs-sandbox:402:
	: ${ovnsb_source:=$srcdir/ovn-sb.ovsschema}

WARNING: Line has non-spaces leading whitespace
#119 FILE: tutorial/ovs-sandbox:403:
	if test ! -e "$ovnsb_source"; then

WARNING: Line is 111 characters long (recommended limit is 79)
WARNING: Line has non-spaces leading whitespace
#120 FILE: tutorial/ovs-sandbox:404:
	    echo >&2 "OVN southbound database source $ovnsb_source not found, please check --srcdir or --ovnsb-source"

WARNING: Line has non-spaces leading whitespace
#121 FILE: tutorial/ovs-sandbox:405:
	    exit 1

WARNING: Line has non-spaces leading whitespace
#136 FILE: tutorial/ovs-sandbox:506:
	source_type=schema

WARNING: Line has non-spaces leading whitespace
#138 FILE: tutorial/ovs-sandbox:508:
	source_type=database

WARNING: Line has non-spaces leading whitespace
#140 FILE: tutorial/ovs-sandbox:510:
	echo "$source is not an OVSDB schema or database" >&2

WARNING: Line has non-spaces leading whitespace
#141 FILE: tutorial/ovs-sandbox:511:
	exit 1

WARNING: Line has non-spaces leading whitespace
#151 FILE: tutorial/ovs-sandbox:546:
	    case $source_type in

WARNING: Line has non-spaces leading whitespace
#152 FILE: tutorial/ovs-sandbox:547:
		database) run cp "$source" ${db}1.db ;;

WARNING: Line has non-spaces leading whitespace
#153 FILE: tutorial/ovs-sandbox:548:
		schema) run ovsdb-tool create ${db}1.db "$source" ;;

WARNING: Line has non-spaces leading whitespace
#154 FILE: tutorial/ovs-sandbox:549:
	    esac

WARNING: Line has non-spaces leading whitespace
#161 FILE: tutorial/ovs-sandbox:555:
		case $source_type in

WARNING: Line has non-spaces leading whitespace
#162 FILE: tutorial/ovs-sandbox:556:
		    database) run cp "$source" $db$i.db ;;

WARNING: Line has non-spaces leading whitespace
#163 FILE: tutorial/ovs-sandbox:557:
		    schema) run ovsdb-tool create $db$i.db "$source" ;;

WARNING: Line has non-spaces leading whitespace
#164 FILE: tutorial/ovs-sandbox:558:
		esac

WARNING: Line is 87 characters long (recommended limit is 79)
#173 FILE: tutorial/ovs-sandbox:573:
                    run ovsdb-tool create-cluster ${db}1.db "$source" unix:${db}1.raft;

Lines checked: 190, Warnings: 35, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
Dumitru Ceara June 30, 2021, 8:06 a.m. UTC | #2
On 6/29/21 8:51 PM, Ben Pfaff wrote:
> 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 <blp@ovn.org>
> CC: Dumitru Ceara <dceara@redhat.com>
> ---

Hi Ben,

Thanks for this!

Nit: I think the 0-day bot is right about not using tabs in ovs-sandbox.
We currently only use spaces in that file.

With tabs converted to spaces:

Acked-by: Dumitru Ceara <dceara@redhat.com>

Regards,
Dumitru
Ben Pfaff July 2, 2021, 5:35 p.m. UTC | #3
On Wed, Jun 30, 2021 at 10:06:39AM +0200, Dumitru Ceara wrote:
> On 6/29/21 8:51 PM, Ben Pfaff wrote:
> > 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 <blp@ovn.org>
> > CC: Dumitru Ceara <dceara@redhat.com>
> > ---
> 
> Hi Ben,
> 
> Thanks for this!
> 
> Nit: I think the 0-day bot is right about not using tabs in ovs-sandbox.
> We currently only use spaces in that file.

Oops.  Thanks, fixed!

> With tabs converted to spaces:
> 
> Acked-by: Dumitru Ceara <dceara@redhat.com>

I applied this to master.
diff mbox series

Patch

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"