diff mbox series

[ovs-dev,ovn,v4,11/13] ovn-ctl: Refactor to reduce redundant code.

Message ID 1580327768-36501-12-git-send-email-hzhou@ovn.org
State Accepted
Headers show
Series OVN Interconnection | expand

Commit Message

Han Zhou Jan. 29, 2020, 7:56 p.m. UTC
This patch helps reducing redundant code in next patch for adding
support for interconnection related DBs and daemon.

Signed-off-by: Han Zhou <hzhou@ovn.org>
---
 utilities/ovn-ctl | 61 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 26 deletions(-)

Comments

0-day Robot Jan. 29, 2020, 9:15 p.m. UTC | #1
Bleep bloop.  Greetings Han Zhou, 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 is 83 characters long (recommended limit is 79)
#58 FILE: utilities/ovn-ctl:72:
        echo "$sync_from_proto:$sync_from_addr:$sync_from_port" > $active_conf_file

WARNING: Line is 104 characters long (recommended limit is 79)
#65 FILE: utilities/ovn-ctl:76:
        ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/set-active-ovsdb-server `cat $active_conf_file`

WARNING: Line is 84 characters long (recommended limit is 79)
#66 FILE: utilities/ovn-ctl:77:
        ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/connect-active-ovsdb-server

Lines checked: 115, Warnings: 3, Errors: 0


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

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/utilities/ovn-ctl b/utilities/ovn-ctl
index 576a983..2e4e773 100755
--- a/utilities/ovn-ctl
+++ b/utilities/ovn-ctl
@@ -42,16 +42,18 @@  pidfile_is_running () {
     test -e "$pidfile" && [ -s "$pidfile" ] && pid=`cat "$pidfile"` && pid_exists "$pid"
 } >/dev/null 2>&1
 
-stop_nb_ovsdb() {
-    if pidfile_is_running $DB_NB_PID; then
-        ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl exit
+stop_xx_ovsdb() {
+    if pidfile_is_running $1; then
+        ovn-appctl -t $OVN_RUNDIR/$2 exit
     fi
 }
 
+stop_nb_ovsdb() {
+    stop_xx_ovsdb $DB_NB_PID ovnnb_db.ctl
+}
+
 stop_sb_ovsdb() {
-    if pidfile_is_running $DB_SB_PID; then
-        ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl exit
-    fi
+    stop_xx_ovsdb $DB_SB_PID ovnsb_db.ctl
 }
 
 stop_ovsdb () {
@@ -59,42 +61,49 @@  stop_ovsdb () {
     stop_sb_ovsdb
 }
 
-demote_ovnnb() {
-    if test ! -z "$DB_NB_SYNC_FROM_ADDR"; then
-        echo "$DB_NB_SYNC_FROM_PROTO:$DB_NB_SYNC_FROM_ADDR:$DB_NB_SYNC_FROM_PORT" > $ovnnb_active_conf_file
+demote_xx_ovsdb () {
+    local sync_from_addr=$1
+    local sync_from_proto=$2
+    local sync_from_port=$3
+    local active_conf_file=$4
+    local ctl_file=$5
+
+    if test ! -z "$sync_from_addr"; then
+        echo "$sync_from_proto:$sync_from_addr:$sync_from_port" > $active_conf_file
     fi
 
-    if test -e $ovnnb_active_conf_file; then
-        ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnnb_active_conf_file`
-        ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/connect-active-ovsdb-server
+    if test -e $active_conf_file; then
+        ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/set-active-ovsdb-server `cat $active_conf_file`
+        ovn-appctl -t $OVN_RUNDIR/$ctl_file ovsdb-server/connect-active-ovsdb-server
     else
         echo >&2 "$0: active server details not set"
         exit 1
     fi
 }
 
+demote_ovnnb() {
+    demote_xx_ovsdb $DB_NB_SYNC_FROM_ADDR $DB_NB_SYNC_FROM_PROTO \
+                    $DB_NB_SYNC_FROM_PORT $ovnnb_active_conf_file ovnnb_db.ctl
+}
+
 demote_ovnsb() {
-    if test ! -z "$DB_SB_SYNC_FROM_ADDR"; then
-        echo "$DB_SB_SYNC_FROM_PROTO:$DB_SB_SYNC_FROM_ADDR:$DB_SB_SYNC_FROM_PORT" > $ovnsb_active_conf_file
-    fi
+    demote_xx_ovsdb $DB_SB_SYNC_FROM_ADDR $DB_SB_SYNC_FROM_PROTO \
+                    $DB_SB_SYNC_FROM_PORT $ovnsb_active_conf_file ovnsb_db.ctl
+}
 
-    if test -e $ovnsb_active_conf_file; then
-        ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/set-active-ovsdb-server `cat $ovnsb_active_conf_file`
-        ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/connect-active-ovsdb-server
-    else
-        echo >&2 "$0: active server details not set"
-        exit 1
-    fi
+promote_xx_ovsdb() {
+    local active_conf_file=$1
+    local ctl_file=$2
+    rm -f $active_conf_file
+    ovn-appctl -t $OVN_RUNDIR/$2 ovsdb-server/disconnect-active-ovsdb-server
 }
 
 promote_ovnnb() {
-    rm -f $ovnnb_active_conf_file
-    ovn-appctl -t $OVN_RUNDIR/ovnnb_db.ctl ovsdb-server/disconnect-active-ovsdb-server
+    promote_xx_ovsdb $ovnnb_active_conf_file ovnnb_db.ctl
 }
 
 promote_ovnsb() {
-    rm -f $ovnsb_active_conf_file
-    ovn-appctl -t $OVN_RUNDIR/ovnsb_db.ctl ovsdb-server/disconnect-active-ovsdb-server
+    promote_xx_ovsdb $ovnsb_active_conf_file ovnsb_db.ctl
 }
 
 start_ovsdb__() {