[ovs-dev] [PATCH v2] testsuite: exit gracefully if it fails.

Flavio Leitner fbl at redhat.com
Fri Jun 9 15:58:57 UTC 2017


The daemon is killed leaving resources behind when a test fails.
This fixes to first signal the daemon to exit gracefully.

Fixes: 0f28164be02ac ("netdev-linux: make tap devices persistent")
Suggested-by: Joe Stringer <joe at ovn.org>
Co-authored-by: Ben Pfaff <blp at ovn.org>
Signed-off-by: Flavio Leitner <fbl at redhat.com>
---
 tests/ofproto-macros.at |  2 +-
 tests/ovs-macros.at     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

Changelog:
- V2
  - Using a function instead of a single line as suggested by Ben.

diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at
index faff5b0..30a8b21 100644
--- a/tests/ofproto-macros.at
+++ b/tests/ofproto-macros.at
@@ -322,7 +322,7 @@ m4_define([_OVS_VSWITCHD_START],
    dnl Start ovs-vswitchd.
    AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
    AT_CAPTURE_FILE([ovs-vswitchd.log])
-   on_exit "kill `cat ovs-vswitchd.pid`"
+   on_exit "kill_ovs_vswitchd `cat ovs-vswitchd.pid`"
    AT_CHECK([[sed < stderr '
 /ovs_numa|INFO|Discovered /d
 /vlog|INFO|opened log file/d
diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index 047d0dd..dbce0a5 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -115,6 +115,39 @@ parent_pid () {
     fi
 }
 
+# kill_ovs_vswitchd [PID]
+#
+# Signal the ovs-vswitchd daemon to exit gracefully and wait for it to
+# terminate or kill it if that takes too long.
+#
+# It is used to cleanup all sorts of tests and results. It can't assume
+# any state, including the availability of PID file which can be provided.
+kill_ovs_vswitchd () {
+    # Use provided PID or save the current PID if available.
+    TMPPID=$1
+    if test -z "$TMPPID"; then
+        TMPPID=$(cat $OVS_RUNDIR/ovs-vswitchd.pid 2>/dev/null)
+    fi
+
+    # Tell the daemon to terminate gracefully
+    ovs-appctl --timeout=10 -t ovs-vswitchd exit --cleanup 2>/dev/null
+
+    # Nothing else to be done if there is no PID
+    test -z "$TMPPID" && return
+
+    for i in 1 2 3 4 5 6 7 8 9; do
+        # Check if the daemon is alive.
+        kill -0 $TMPPID 2>/dev/null || return
+
+        # Fallback to whole number since POSIX doesn't require
+        # fractional times to work.
+        sleep 0.1 || sleep 1
+    done
+
+    # Make sure it is terminated.
+    kill $TMPPID
+}
+
 # Normalize the output of 'wc' to match POSIX.
 # POSIX says 'wc' should print "%d %d %d", but GNU prints "%7d %7d %7d".
 # POSIX says 'wc -l' should print "%d %s", but BSD prints "%8d".
-- 
2.9.4



More information about the dev mailing list