aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorMaros Ondrejicka <maros.ondrejicka@pantheon.tech>2022-12-19 20:35:27 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-12-20 18:49:49 +0000
commit8753180a80e03dd031fa7f470adbcbb4a611d1c9 (patch)
treef524d7f4261b5db5861ee7e83822d99ab63f3262 /extras
parent8c626b41eaab5c74e7e023205f1c6cd655d40f44 (diff)
hs-test: add runtime options
Options "-p" to not remove topology elements after the test finishes "-v" from now on extra output from tests is hidden by default, this will show it again Type: test Signed-off-by: Maros Ondrejicka <maros.ondrejicka@pantheon.tech> Change-Id: I626188561c883534e9004d5130ee2a972d12b4e2
Diffstat (limited to 'extras')
-rw-r--r--extras/hs-test/container.go18
-rwxr-xr-xextras/hs-test/echo_test.go6
-rwxr-xr-xextras/hs-test/framework_test.go47
-rwxr-xr-xextras/hs-test/http_test.go9
-rwxr-xr-xextras/hs-test/ldp_test.go10
-rwxr-xr-xextras/hs-test/linux_iperf_test.go11
-rwxr-xr-xextras/hs-test/proxy_test.go10
-rwxr-xr-xextras/hs-test/test16
-rwxr-xr-xextras/hs-test/utils.go7
-rwxr-xr-xextras/hs-test/vcl_test.go23
10 files changed, 95 insertions, 62 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 1dc65fff308..5aa5e4795e8 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -71,19 +71,23 @@ func NewContainer(yamlInput ContainerConfig) (*Container, error) {
return container, nil
}
-func (c *Container) run() error {
- if c.name == "" {
- return fmt.Errorf("create volume failed: container name is blank")
- }
-
- exechelper.Run(fmt.Sprintf("mkdir -p /tmp/%s/sync", c.name))
+func (c *Container) getRunCommand() string {
syncPath := fmt.Sprintf(" -v %s:/tmp/sync", c.getSyncPath())
cmd := "docker run --cap-add=all -d --privileged --network host --rm"
cmd += syncPath
cmd += c.getVolumesAsCliOption()
cmd += c.getEnvVarsAsCliOption()
cmd += " --name " + c.name + " " + c.image
- fmt.Println(cmd)
+ return cmd
+}
+
+func (c *Container) run() error {
+ if c.name == "" {
+ return fmt.Errorf("run container failed: name is blank")
+ }
+
+ exechelper.Run(fmt.Sprintf("mkdir -p /tmp/%s/sync", c.name))
+ cmd := c.getRunCommand()
err := exechelper.Run(cmd)
if err != nil {
return fmt.Errorf("container run failed: %s", err)
diff --git a/extras/hs-test/echo_test.go b/extras/hs-test/echo_test.go
index 9bc8f76105c..813297cef2a 100755
--- a/extras/hs-test/echo_test.go
+++ b/extras/hs-test/echo_test.go
@@ -1,9 +1,5 @@
package main
-import (
- "fmt"
-)
-
func (s *VethsSuite) TestEchoBuiltin() {
serverContainer := s.getContainerByName("server-vpp")
_, err := serverContainer.execAction("Configure2Veths srv")
@@ -18,5 +14,5 @@ func (s *VethsSuite) TestEchoBuiltin() {
o, err := clientContainer.execAction("RunEchoClnInternal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4")
s.assertNil(err)
- fmt.Println(o)
+ s.log(o)
}
diff --git a/extras/hs-test/framework_test.go b/extras/hs-test/framework_test.go
index a3d46ad0ab9..33bc1f35011 100755
--- a/extras/hs-test/framework_test.go
+++ b/extras/hs-test/framework_test.go
@@ -1,9 +1,9 @@
package main
import (
- "fmt"
"testing"
"io/ioutil"
+ "os"
"github.com/edwarnicke/exechelper"
"github.com/stretchr/testify/assert"
@@ -11,6 +11,20 @@ import (
"gopkg.in/yaml.v3"
)
+func IsPersistent() bool {
+ if os.Getenv("HST_PERSIST") == "1" {
+ return true
+ }
+ return false
+}
+
+func IsVerbose() bool {
+ if os.Getenv("HST_VERBOSE") == "1" {
+ return true
+ }
+ return false
+}
+
type HstSuite struct {
suite.Suite
teardownSuite func()
@@ -23,6 +37,9 @@ func (s *HstSuite) TearDownSuite() {
}
func (s *HstSuite) TearDownTest() {
+ if IsPersistent() {
+ return
+ }
s.ResetContainers()
s.RemoveVolumes()
}
@@ -30,7 +47,7 @@ func (s *HstSuite) TearDownTest() {
func (s *HstSuite) SetupTest() {
for _, volume := range s.volumes {
cmd := "docker volume create --name=" + volume
- fmt.Println(cmd)
+ s.log(cmd)
exechelper.Run(cmd)
}
for _, container := range s.containers {
@@ -80,20 +97,21 @@ func (s *HstSuite) assertNotContains(testString, contains interface{}, msgAndArg
}
}
-func (s *HstSuite) ResetContainers() {
- for _, container := range s.containers {
- container.stop()
+func (s *HstSuite) log(args ...any) {
+ if IsVerbose() {
+ s.T().Log(args...)
}
}
-func (s *HstSuite) NewVolume(name string) error {
- err := exechelper.Run(fmt.Sprintf("docker volume create --name=%s", name))
- if err != nil {
- return err
- }
+func (s *HstSuite) skip(args ...any) {
+ s.log(args...)
+ s.T().SkipNow()
+}
- s.volumes = append(s.volumes, name)
- return nil
+func (s *HstSuite) ResetContainers() {
+ for _, container := range s.containers {
+ container.stop()
+ }
}
func (s *HstSuite) RemoveVolumes() {
@@ -128,6 +146,7 @@ func (s *HstSuite) loadContainerTopology(topologyName string) {
if err != nil {
s.T().Fatalf("config error: %v", err)
}
+ s.log(newContainer.getRunCommand())
s.containers[newContainer.name] = newContainer
}
}
@@ -143,8 +162,10 @@ func setupSuite(s *suite.Suite, topologyName string) func() {
t.Fatalf("failed to configure %s: %v", topologyName, err)
}
- t.Logf("topo %s loaded", topologyName)
return func() {
+ if IsPersistent() {
+ return
+ }
topology.Unconfigure()
}
}
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go
index 1cbddec9e76..ae1c8b82e5a 100755
--- a/extras/hs-test/http_test.go
+++ b/extras/hs-test/http_test.go
@@ -1,14 +1,13 @@
package main
func (s *NsSuite) TestHttpTps() {
- t := s.T()
finished := make(chan error, 1)
server_ip := "10.0.0.2"
port := "8080"
container := s.getContainerByName("vpp")
- t.Log("starting vpp..")
+ s.log("starting vpp..")
// start & configure vpp in the container
_, err := container.execAction("ConfigureHttpTps")
@@ -21,8 +20,6 @@ func (s *NsSuite) TestHttpTps() {
}
func (s *VethsSuite) TestHttpCli() {
- t := s.T()
-
serverContainer := s.getContainerByName("server-vpp")
clientContainer := s.getContainerByName("client-vpp")
@@ -32,12 +29,12 @@ func (s *VethsSuite) TestHttpCli() {
_, err = clientContainer.execAction("Configure2Veths cln")
s.assertNil(err)
- t.Log("configured IPs...")
+ s.log("configured IPs...")
_, err = serverContainer.execAction("RunHttpCliSrv")
s.assertNil(err)
- t.Log("configured http server")
+ s.log("configured http server")
o, err := clientContainer.execAction("RunHttpCliCln /show/version")
s.assertNil(err)
diff --git a/extras/hs-test/ldp_test.go b/extras/hs-test/ldp_test.go
index 9a8b8121e8a..8d81cde56e6 100755
--- a/extras/hs-test/ldp_test.go
+++ b/extras/hs-test/ldp_test.go
@@ -26,7 +26,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
srvCh := make(chan error, 1)
clnCh := make(chan error)
- fmt.Println("starting VPPs")
+ s.log("starting VPPs")
originalWorkDir := serverContainer.workDir
serverContainer.workDir = serverVolume.containerDir
@@ -66,7 +66,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
SaveToFile(srvVcl)
s.assertNil(err)
- fmt.Printf("attaching server to vpp")
+ s.log("attaching server to vpp")
// FIXME
time.Sleep(5 * time.Second)
@@ -77,9 +77,11 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
err = <-srvCh
s.assertNil(err)
- fmt.Println("attaching client to vpp")
+ s.log("attaching client to vpp")
+ var clnRes = make(chan string, 1)
clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clnVcl)
- go StartClientApp(clnEnv, clnCh)
+ go StartClientApp(clnEnv, clnCh, clnRes)
+ s.log(<- clnRes)
// wait for client's result
err = <-clnCh
diff --git a/extras/hs-test/linux_iperf_test.go b/extras/hs-test/linux_iperf_test.go
index bef07fb7d65..38649e5d4f4 100755
--- a/extras/hs-test/linux_iperf_test.go
+++ b/extras/hs-test/linux_iperf_test.go
@@ -1,10 +1,10 @@
package main
func (s *TapSuite) TestLinuxIperf() {
- t := s.T()
clnCh := make(chan error)
stopServerCh := make(chan struct{})
srvCh := make(chan error, 1)
+ clnRes := make(chan string, 1)
defer func() {
stopServerCh <- struct{}{}
}()
@@ -12,10 +12,11 @@ func (s *TapSuite) TestLinuxIperf() {
go StartServerApp(srvCh, stopServerCh, nil)
err := <-srvCh
s.assertNil(err)
- t.Log("server running")
- go StartClientApp(nil, clnCh)
- t.Log("client running")
+ s.log("server running")
+ go StartClientApp(nil, clnCh, clnRes)
+ s.log("client running")
+ s.log(<- clnRes)
err = <-clnCh
s.assertNil(err)
- t.Log("Test completed")
+ s.log("Test completed")
}
diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go
index 952bcc5aa76..745f042a4b6 100755
--- a/extras/hs-test/proxy_test.go
+++ b/extras/hs-test/proxy_test.go
@@ -20,7 +20,7 @@ func testProxyHttpTcp(s *NsSuite, proxySetup func() error) error {
s.assertNil(err, "failed to run truncate command")
defer func() { os.Remove(srcFile) }()
- fmt.Println("Test file created...")
+ s.log("Test file created...")
go startHttpServer(serverRunning, stopServer, ":666", "server")
// TODO better error handling and recovery
@@ -30,7 +30,7 @@ func testProxyHttpTcp(s *NsSuite, proxySetup func() error) error {
stopServer <- struct{}{}
}(stopServer)
- fmt.Println("http server started...")
+ s.log("http server started...")
c := fmt.Sprintf("ip netns exec client wget --retry-connrefused --retry-on-http-error=503 --tries=10 -O %s 10.0.0.2:555/%s", outputFile, srcFile)
_, err = exechelper.CombinedOutput(c)
@@ -49,10 +49,10 @@ func configureVppProxy(s *NsSuite) error {
testVppProxy.setVppProxy()
err := testVppProxy.start()
s.assertNil(err, "failed to start and configure VPP")
- fmt.Println("VPP running and configured...")
+ s.log("VPP running and configured...")
output, err := testVppProxy.vppctl("test proxy server server-uri tcp://10.0.0.2/555 client-uri tcp://10.0.1.1/666")
- fmt.Println("Proxy configured...", string(output))
+ s.log("Proxy configured...", string(output))
return nil
}
@@ -73,7 +73,7 @@ func configureEnvoyProxy(s *NsSuite) error {
envoyContainer := s.getContainerByName("envoy")
envoyContainer.run()
- fmt.Println("VPP running and configured...")
+ s.log("VPP running and configured...")
return nil
}
diff --git a/extras/hs-test/test b/extras/hs-test/test
index 0bccc871711..cd0a6e176f5 100755
--- a/extras/hs-test/test
+++ b/extras/hs-test/test
@@ -1,4 +1,18 @@
#!/usr/bin/env bash
source vars
-sudo -E go test -buildvcs=false -v $@
+
+for ARG in "$@"
+do
+ if [[ "$ARG" = "-p" ]]
+ then
+ export HST_PERSIST=1
+ shift
+ elif [[ "$ARG" = "-v" ]]
+ then
+ export HST_VERBOSE=1
+ shift
+ fi
+done
+
+sudo -E go test -buildvcs=false -v $@
diff --git a/extras/hs-test/utils.go b/extras/hs-test/utils.go
index bec54e8cf50..583dc4aff54 100755
--- a/extras/hs-test/utils.go
+++ b/extras/hs-test/utils.go
@@ -96,7 +96,7 @@ func StartServerApp(running chan error, done chan struct{}, env []string) {
cmd.Process.Kill()
}
-func StartClientApp(env []string, clnCh chan error) {
+func StartClientApp(env []string, clnCh chan error, clnRes chan string) {
defer func() {
clnCh <- nil
}()
@@ -118,7 +118,7 @@ func StartClientApp(env []string, clnCh chan error) {
nTries++
continue
} else {
- fmt.Printf("Client output: %s", o)
+ clnRes <- fmt.Sprintf("Client output: %s", o)
}
break
}
@@ -186,10 +186,9 @@ func startWget(finished chan error, server_ip, port string, netNs string) {
netNs)
o, err := cmd.CombinedOutput()
if err != nil {
- fmt.Printf("wget error: '%s'.\n%s", err, o)
+ finished <- errors.New(fmt.Sprintf("wget error: '%s'.\n%s", err, o))
return
}
- fmt.Printf("Client output: %s", o)
finished <- nil
}
diff --git a/extras/hs-test/vcl_test.go b/extras/hs-test/vcl_test.go
index 80775542712..5a5ba06bebc 100755
--- a/extras/hs-test/vcl_test.go
+++ b/extras/hs-test/vcl_test.go
@@ -1,17 +1,16 @@
package main
import (
- "fmt"
"time"
)
func (s *VethsSuite) TestVclEchoQuic() {
- s.T().Skip("quic test skipping..")
+ s.skip("quic test skipping..")
s.testVclEcho("quic")
}
func (s *VethsSuite) TestVclEchoUdp() {
- s.T().Skip("udp echo currently broken in vpp, skipping..")
+ s.skip("udp echo currently broken in vpp, skipping..")
s.testVclEcho("udp")
}
@@ -41,11 +40,11 @@ func (s *VethsSuite) testVclEcho(proto string) {
o, err := echoClnContainer.execAction("RunEchoClient "+proto)
s.assertNil(err)
- fmt.Println(o)
+ s.log(o)
}
func (s *VethsSuite) TestVclRetryAttach() {
- s.T().Skip()
+ s.skip()
s.testRetryAttach("tcp")
}
@@ -64,12 +63,12 @@ func (s *VethsSuite) testRetryAttach(proto string) {
_, err = echoSrvContainer.execAction("RunVclEchoServer "+proto)
s.assertNil(err)
- fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
- fmt.Println("... Running first echo client test, before disconnect.")
+ s.log("This whole test case can take around 3 minutes to run. Please be patient.")
+ s.log("... Running first echo client test, before disconnect.")
echoClnContainer := s.getContainerByName("client-application")
_, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
s.assertNil(err)
- fmt.Println("... First test ended. Stopping VPP server now.")
+ s.log("... First test ended. Stopping VPP server now.")
// Stop server-vpp-instance, start it again and then run vcl-test-client once more
stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
@@ -82,13 +81,13 @@ func (s *VethsSuite) testRetryAttach(proto string) {
_, err = srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
s.assertNil(err)
- fmt.Println("... VPP server is starting again, so waiting for a bit.")
+ s.log("... VPP server is starting again, so waiting for a bit.")
time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
- fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
+ s.log("... Running second echo client test, after disconnect and re-attachment.")
_, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
s.assertNil(err)
- fmt.Println("Done.")
+ s.log("Done.")
}
func (s *VethsSuite) TestTcpWithLoss() {
@@ -127,5 +126,5 @@ func (s *VethsSuite) TestTcpWithLoss() {
s.assertNil(err)
s.assertEqual(true, len(output) != 0)
s.assertNotContains(output, "failed: timeout")
- fmt.Println(output)
+ s.log(output)
}