hs-test: add option to unconfigure topology 61/38361/2
authorMaros Ondrejicka <mondreji@cisco.com>
Mon, 27 Feb 2023 15:52:57 +0000 (16:52 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 28 Feb 2023 16:36:41 +0000 (16:36 +0000)
Adding `UNCONFIGURE=true` argument when running `make test` will skip
test run and unconfigure existing topology for that test.

Type: test
Signed-off-by: Maros Ondrejicka <mondreji@cisco.com>
Change-Id: I197747a56ca68807f0b2c3f25b6f61c3dcc41ace

extras/hs-test/Makefile
extras/hs-test/hst_suite.go
extras/hs-test/suite_no_topo_test.go
extras/hs-test/suite_ns_test.go
extras/hs-test/suite_veth_test.go
extras/hs-test/test

index 7460026..a392c14 100644 (file)
@@ -7,6 +7,10 @@ ifeq ($(PERSIST),)
 PERSIST=false
 endif
 
+ifeq ($(UNCONFIGURE),)
+UNCONFIGURE=false
+endif
+
 ifeq ($(TEST),)
 TEST=all
 endif
@@ -45,7 +49,8 @@ build-vpp-debug:
 
 .PHONY: test
 test: .deps.ok .build.vpp
-       @bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) --test=$(TEST)
+       @bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
+               --unconfigure=$(UNCONFIGURE) --test=$(TEST)
 
 build-go:
        go build ./tools/http_server
index ff70245..8e52cc4 100644 (file)
@@ -19,6 +19,7 @@ const (
 
 var IsPersistent = flag.Bool("persist", false, "persists topology config")
 var IsVerbose = flag.Bool("verbose", false, "verbose test output")
+var IsUnconfiguring = flag.Bool("unconfigure", false, "remove topology")
 
 type HstSuite struct {
        suite.Suite
@@ -42,7 +43,14 @@ func (s *HstSuite) TearDownTest() {
        s.RemoveVolumes()
 }
 
+func (s *HstSuite) skipIfUnconfiguring() {
+       if *IsUnconfiguring {
+               s.skip("skipping to unconfigure")
+       }
+}
+
 func (s *HstSuite) SetupTest() {
+       s.skipIfUnconfiguring()
        s.SetupVolumes()
        s.SetupContainers()
 }
@@ -111,7 +119,7 @@ func (s *HstSuite) assertNotEmpty(object interface{}, msgAndArgs ...interface{})
 
 func (s *HstSuite) log(args ...any) {
        if *IsVerbose {
-                s.T().Helper()
+               s.T().Helper()
                s.T().Log(args...)
        }
 }
@@ -223,6 +231,10 @@ func (s *HstSuite) loadNetworkTopology(topologyName string) {
 func (s *HstSuite) configureNetworkTopology(topologyName string) {
        s.loadNetworkTopology(topologyName)
 
+       if *IsUnconfiguring {
+               return
+       }
+
        for _, nc := range s.netConfigs {
                if err := nc.Configure(); err != nil {
                        s.T().Fatalf("network config error: %v", err)
index 12b939e..bca1dbf 100644 (file)
@@ -18,6 +18,7 @@ func (s *NoTopoSuite) SetupSuite() {
 }
 
 func (s *NoTopoSuite) SetupTest() {
+       s.skipIfUnconfiguring()
        s.SetupVolumes()
        s.SetupContainers()
 
index 5bc45c7..c4a3f42 100644 (file)
@@ -17,6 +17,7 @@ func (s *NsSuite) SetupSuite() {
 }
 
 func (s *NsSuite) SetupTest() {
+       s.skipIfUnconfiguring()
        s.SetupVolumes()
        s.SetupContainers()
 
index ff79dfa..96af407 100644 (file)
@@ -23,6 +23,8 @@ func (s *VethsSuite) SetupSuite() {
 }
 
 func (s *VethsSuite) SetupTest() {
+       s.skipIfUnconfiguring()
+
        s.SetupVolumes()
        s.SetupContainers()
 
index e14f3ee..f02c159 100755 (executable)
@@ -5,6 +5,7 @@ source vars
 args=
 single_test=0
 persist_set=0
+unconfigure_set=0
 
 for i in "$@"
 do
@@ -22,6 +23,13 @@ case "${i}" in
             args="$args -verbose"
         fi
         ;;
+    --unconfigure=*)
+        unconfigure="${i#*=}"
+        if [ $unconfigure = "true" ]; then
+            args="$args -unconfigure"
+            unconfigure_set=1
+        fi
+        ;;
     --test=*)
         tc_name="${i#*=}"
         if [ $tc_name != "all" ]; then
@@ -32,7 +40,17 @@ esac
 done
 
 if [ $single_test -eq 0 ] && [ $persist_set -eq 1 ]; then
-    echo "persist flag is not supperted while running all tests!"
+    echo "persist flag is not supported while running all tests!"
+    exit 1
+fi
+
+if [ $unconfigure_set -eq 1 ] && [ $single_test -eq 0 ]; then
+    echo "a single test has to be specified when unconfigure is set"
+    exit 1
+fi
+
+if [ $persist_set -eq 1 ] && [ $unconfigure_set -eq 1 ]; then
+    echo "setting persist flag and unconfigure flag is not allowed"
     exit 1
 fi