hs-test: add option to unconfigure topology

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
diff --git a/extras/hs-test/Makefile b/extras/hs-test/Makefile
index 7460026..a392c14 100644
--- a/extras/hs-test/Makefile
+++ b/extras/hs-test/Makefile
@@ -7,6 +7,10 @@
 PERSIST=false
 endif
 
+ifeq ($(UNCONFIGURE),)
+UNCONFIGURE=false
+endif
+
 ifeq ($(TEST),)
 TEST=all
 endif
@@ -45,7 +49,8 @@
 
 .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
diff --git a/extras/hs-test/hst_suite.go b/extras/hs-test/hst_suite.go
index ff70245..8e52cc4 100644
--- a/extras/hs-test/hst_suite.go
+++ b/extras/hs-test/hst_suite.go
@@ -19,6 +19,7 @@
 
 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 @@
 	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) log(args ...any) {
 	if *IsVerbose {
-                s.T().Helper()
+		s.T().Helper()
 		s.T().Log(args...)
 	}
 }
@@ -223,6 +231,10 @@
 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)
diff --git a/extras/hs-test/suite_no_topo_test.go b/extras/hs-test/suite_no_topo_test.go
index 12b939e..bca1dbf 100644
--- a/extras/hs-test/suite_no_topo_test.go
+++ b/extras/hs-test/suite_no_topo_test.go
@@ -18,6 +18,7 @@
 }
 
 func (s *NoTopoSuite) SetupTest() {
+	s.skipIfUnconfiguring()
 	s.SetupVolumes()
 	s.SetupContainers()
 
diff --git a/extras/hs-test/suite_ns_test.go b/extras/hs-test/suite_ns_test.go
index 5bc45c7..c4a3f42 100644
--- a/extras/hs-test/suite_ns_test.go
+++ b/extras/hs-test/suite_ns_test.go
@@ -17,6 +17,7 @@
 }
 
 func (s *NsSuite) SetupTest() {
+	s.skipIfUnconfiguring()
 	s.SetupVolumes()
 	s.SetupContainers()
 
diff --git a/extras/hs-test/suite_veth_test.go b/extras/hs-test/suite_veth_test.go
index ff79dfa..96af407 100644
--- a/extras/hs-test/suite_veth_test.go
+++ b/extras/hs-test/suite_veth_test.go
@@ -23,6 +23,8 @@
 }
 
 func (s *VethsSuite) SetupTest() {
+	s.skipIfUnconfiguring()
+
 	s.SetupVolumes()
 	s.SetupContainers()
 
diff --git a/extras/hs-test/test b/extras/hs-test/test
index e14f3ee..f02c159 100755
--- a/extras/hs-test/test
+++ b/extras/hs-test/test
@@ -5,6 +5,7 @@
 args=
 single_test=0
 persist_set=0
+unconfigure_set=0
 
 for i in "$@"
 do
@@ -22,6 +23,13 @@
             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 @@
 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