From af5fcbfa713ca3693ee9d28354fe004b76f74d6a Mon Sep 17 00:00:00 2001 From: Adrian Villin Date: Mon, 9 Dec 2024 14:18:31 +0100 Subject: [PATCH] hs-test: replaced container/interface getter func - replaced s.GetContainerByName("xyz") with s.Containers.Xyz in tests and suites - same thing for interfaces - each suite has its own structs with containers/interfaces - structs are initialized in SetupSuite Type: test Change-Id: I5bd99605b40921b7b8c844e8650f6fb0915e9e99 Signed-off-by: Adrian Villin --- extras/hs-test/cpu_pinning_test.go | 4 +- extras/hs-test/echo_test.go | 23 ++-- extras/hs-test/http_test.go | 138 +++++++++---------- extras/hs-test/infra/hst_suite.go | 14 +- extras/hs-test/infra/suite_cpu_pinning.go | 11 +- extras/hs-test/infra/suite_envoy_proxy.go | 72 +++++----- extras/hs-test/infra/suite_iperf_linux.go | 19 ++- extras/hs-test/infra/suite_ldp.go | 52 +++---- extras/hs-test/infra/suite_nginx_proxy.go | 63 ++++----- extras/hs-test/infra/suite_no_topo.go | 44 +++--- extras/hs-test/infra/suite_veth.go | 38 ++--- extras/hs-test/infra/suite_vpp_proxy.go | 70 +++++----- extras/hs-test/infra/suite_vpp_udp_proxy.go | 36 ++--- extras/hs-test/infra/utils.go | 9 +- extras/hs-test/iperf_linux_test.go | 10 +- extras/hs-test/ldp_test.go | 19 +-- extras/hs-test/mem_leak_test.go | 2 +- extras/hs-test/nginx_test.go | 48 +++---- extras/hs-test/proxy_test.go | 35 ++--- extras/hs-test/raw_session_test.go | 13 +- extras/hs-test/topo-containers/vppProxy.yaml | 4 +- extras/hs-test/vcl_test.go | 28 ++-- 22 files changed, 378 insertions(+), 374 deletions(-) diff --git a/extras/hs-test/cpu_pinning_test.go b/extras/hs-test/cpu_pinning_test.go index b8dec65937e..f1f689cc373 100644 --- a/extras/hs-test/cpu_pinning_test.go +++ b/extras/hs-test/cpu_pinning_test.go @@ -11,7 +11,7 @@ func init() { // TODO: Add more CPU configuration tests func DefaultCpuConfigurationTest(s *CpuPinningSuite) { - vpp := s.GetContainerByName(SingleTopoContainerVpp).VppInstance + vpp := s.Containers.Vpp.VppInstance s.AssertNil(vpp.Start()) } @@ -23,7 +23,7 @@ func SkipCoresTest(s *CpuPinningSuite) { SkipCores: 1, } - vpp := s.GetContainerByName(SingleTopoContainerVpp).VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.CpuConfig = skipCoresConfiguration s.AssertNil(vpp.Start()) diff --git a/extras/hs-test/echo_test.go b/extras/hs-test/echo_test.go index 6b4739a5457..f27ad077928 100644 --- a/extras/hs-test/echo_test.go +++ b/extras/hs-test/echo_test.go @@ -10,17 +10,16 @@ func init() { } func EchoBuiltinTest(s *VethsSuite) { - serverVpp := s.GetContainerByName("server-vpp").VppInstance - serverVeth := s.GetInterfaceByName(ServerInterfaceName) + serverVpp := s.Containers.ServerVpp.VppInstance serverVpp.Vppctl("test echo server " + - " uri tcp://" + serverVeth.Ip4AddressString() + "/1234") + " uri tcp://" + s.Interfaces.Server.Ip4AddressString() + "/1234") - clientVpp := s.GetContainerByName("client-vpp").VppInstance + clientVpp := s.Containers.ClientVpp.VppInstance o := clientVpp.Vppctl("test echo client nclients 100 bytes 1 verbose" + " syn-timeout 100 test-timeout 100" + - " uri tcp://" + serverVeth.Ip4AddressString() + "/1234") + " uri tcp://" + s.Interfaces.Server.Ip4AddressString() + "/1234") s.Log(o) s.AssertNotContains(o, "failed:") } @@ -28,28 +27,26 @@ func EchoBuiltinTest(s *VethsSuite) { // unstable with multiple workers func TcpWithLossTest(s *VethsSuite) { s.SkipIfMultiWorker() - serverVpp := s.GetContainerByName("server-vpp").VppInstance + serverVpp := s.Containers.ServerVpp.VppInstance - serverVeth := s.GetInterfaceByName(ServerInterfaceName) serverVpp.Vppctl("test echo server uri tcp://%s/20022", - serverVeth.Ip4AddressString()) + s.Interfaces.Server.Ip4AddressString()) - clientVpp := s.GetContainerByName("client-vpp").VppInstance + clientVpp := s.Containers.ClientVpp.VppInstance // Ensure that VPP doesn't abort itself with NSIM enabled // Warning: Removing this ping will make VPP crash! - clientVpp.Vppctl("ping %s", serverVeth.Ip4AddressString()) + clientVpp.Vppctl("ping %s", s.Interfaces.Server.Ip4AddressString()) // Add loss of packets with Network Delay Simulator clientVpp.Vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit" + " packet-size 1400 packets-per-drop 1000") - name := s.GetInterfaceByName(ClientInterfaceName).Name() - clientVpp.Vppctl("nsim output-feature enable-disable host-" + name) + clientVpp.Vppctl("nsim output-feature enable-disable host-" + s.Interfaces.Server.Name()) // Do echo test from client-vpp container output := clientVpp.Vppctl("test echo client uri tcp://%s/20022 verbose echo-bytes mbytes 50", - serverVeth.Ip4AddressString()) + s.Interfaces.Server.Ip4AddressString()) s.Log(output) s.AssertNotEqual(len(output), 0) s.AssertNotContains(output, "failed", output) diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index a65497054d3..90c3b77b156 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -67,7 +67,7 @@ func HttpGetTpsInterruptModeTest(s *NoTopoSuite) { } func HttpGetTpsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":8080/test_file_10M" @@ -100,7 +100,7 @@ func HttpPostTpsInterruptModeTest(s *NoTopoSuite) { } func HttpPostTpsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":8080/test_file_10M" @@ -112,7 +112,7 @@ func HttpPostTpsTest(s *NoTopoSuite) { func HttpPersistentConnectionTest(s *NoTopoSuite) { // testing url handler app do not support multi-thread s.SkipIfMultiWorker() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) s.Log(vpp.Vppctl("test-url-handler enable")) @@ -177,7 +177,7 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) { func HttpPipeliningTest(s *NoTopoSuite) { // testing url handler app do not support multi-thread s.SkipIfMultiWorker() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) s.Log(vpp.Vppctl("test-url-handler enable")) @@ -210,16 +210,11 @@ func HttpPipeliningTest(s *NoTopoSuite) { } func HttpCliTest(s *VethsSuite) { - serverContainer := s.GetContainerByName("server-vpp") - clientContainer := s.GetContainerByName("client-vpp") + s.Containers.ServerVpp.VppInstance.Vppctl("http cli server") - serverVeth := s.GetInterfaceByName(ServerInterfaceName) + uri := "http://" + s.Interfaces.Server.Ip4AddressString() + "/80" - serverContainer.VppInstance.Vppctl("http cli server") - - uri := "http://" + serverVeth.Ip4AddressString() + "/80" - - o := clientContainer.VppInstance.Vppctl("http cli client" + + o := s.Containers.ClientVpp.VppInstance.Vppctl("http cli client" + " uri " + uri + " query /show/vlib/graph") s.Log(o) @@ -228,12 +223,9 @@ func HttpCliTest(s *VethsSuite) { } func HttpCliConnectErrorTest(s *VethsSuite) { - clientContainer := s.GetContainerByName("client-vpp") - serverVeth := s.GetInterfaceByName(ServerInterfaceName) + uri := "http://" + s.Interfaces.Server.Ip4AddressString() + "/80" - uri := "http://" + serverVeth.Ip4AddressString() + "/80" - - o := clientContainer.VppInstance.Vppctl("http cli client" + + o := s.Containers.ClientVpp.VppInstance.Vppctl("http cli client" + " uri " + uri + " query /show/vlib/graph") s.Log(o) @@ -257,7 +249,7 @@ func HttpClientTest(s *NoTopoSuite) { server.Start() defer server.Close() uri := "http://" + serverAddress + "/80" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance o := vpp.Vppctl("http cli client uri " + uri + " query /test") s.Log(o) @@ -280,7 +272,7 @@ func HttpClientErrRespTest(s *NoTopoSuite) { server.Start() defer server.Close() uri := "http://" + serverAddress + "/80" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance o := vpp.Vppctl("http cli client uri " + uri + " query /test") s.Log(o) @@ -308,7 +300,7 @@ func HttpClientPostFormTest(s *NoTopoSuite) { defer server.Close() uri := "http://" + serverAddress + "/80" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance o := vpp.Vppctl("http client post verbose header Hello:World uri " + uri + " target /test data " + body) s.Log(o) @@ -334,7 +326,7 @@ func HttpClientGetNoResponseBodyTest(s *NoTopoSuite) { func httpClientGet(s *NoTopoSuite, response string, size int) { serverAddress := s.HostAddr() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance server := ghttp.NewUnstartedServer() l, err := net.Listen("tcp", serverAddress+":80") @@ -394,7 +386,7 @@ func HttpClientPostRepeat(s *NoTopoSuite) { func httpClientRepeat(s *NoTopoSuite, requestMethod string) { replyCount := 0 - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.HostAddr() repeatAmount := 10000 server := startSimpleServer(s, &replyCount, serverAddress) @@ -446,7 +438,7 @@ func httpClientRepeat(s *NoTopoSuite, requestMethod string) { func HttpClientGetTimeout(s *NoTopoSuite) { serverAddress := s.HostAddr() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance server := ghttp.NewUnstartedServer() l, err := net.Listen("tcp", serverAddress+":"+s.GetPortFromPpid()) @@ -473,7 +465,7 @@ func HttpClientGetTimeout(s *NoTopoSuite) { func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) { serverAddress := s.HostAddr() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance fileName := "/tmp/test_file.txt" s.Log(vpp.Container.Exec(false, "fallocate -l "+strconv.Itoa(fileSize)+" "+fileName)) s.Log(vpp.Container.Exec(false, "ls -la "+fileName)) @@ -513,7 +505,7 @@ func HttpClientPostFilePtrTest(s *NoTopoSuite) { } func HttpUnitTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance o := vpp.Vppctl("test http all") s.Log(o) s.AssertContains(o, "SUCCESS") @@ -521,7 +513,7 @@ func HttpUnitTest(s *NoTopoSuite) { func HttpStaticPromTest(s *NoTopoSuite) { query := "stats.prom" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) s.Log(vpp.Vppctl("prom enable")) @@ -559,7 +551,7 @@ func promReqWg(s *NoTopoSuite, url string, wg *sync.WaitGroup) { } func PromConcurrentConnectionsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":80/stats.prom" @@ -577,7 +569,7 @@ func PromConcurrentConnectionsTest(s *NoTopoSuite) { } func PromConsecutiveConnectionsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":80/stats.prom" @@ -593,7 +585,7 @@ func PromConsecutiveConnectionsTest(s *NoTopoSuite) { func PromMemLeakTest(s *NoTopoSuite) { s.SkipUnlessLeakCheck() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() url := "http://" + serverAddress + ":80/stats.prom" @@ -628,35 +620,34 @@ func PromMemLeakTest(s *NoTopoSuite) { func HttpClientGetMemLeakTest(s *VethsSuite) { s.SkipUnlessLeakCheck() - serverContainer := s.GetContainerByName("server-vpp").VppInstance - clientContainer := s.GetContainerByName("client-vpp").VppInstance - serverVeth := s.GetInterfaceByName(ServerInterfaceName) + serverVpp := s.Containers.ServerVpp.VppInstance + clientVpp := s.Containers.ClientVpp.VppInstance /* no goVPP less noise */ - clientContainer.Disconnect() + clientVpp.Disconnect() - serverContainer.Vppctl("http cli server") + serverVpp.Vppctl("http cli server") - uri := "http://" + serverVeth.Ip4AddressString() + "/80" + uri := "http://" + s.Interfaces.Server.Ip4AddressString() + "/80" /* warmup request (FIB) */ - clientContainer.Vppctl("http cli client uri " + uri + " query /show/version") + clientVpp.Vppctl("http cli client uri " + uri + " query /show/version") /* let's give it some time to clean up sessions, so local port can be reused and we have less noise */ time.Sleep(time.Second * 12) - clientContainer.EnableMemoryTrace() - traces1, err := clientContainer.GetMemoryTrace() + clientVpp.EnableMemoryTrace() + traces1, err := clientVpp.GetMemoryTrace() s.AssertNil(err, fmt.Sprint(err)) - clientContainer.Vppctl("http cli client uri " + uri + " query /show/vlib/graph") + clientVpp.Vppctl("http cli client uri " + uri + " query /show/vlib/graph") /* let's give it some time to clean up sessions */ time.Sleep(time.Second * 12) - traces2, err := clientContainer.GetMemoryTrace() + traces2, err := clientVpp.GetMemoryTrace() s.AssertNil(err, fmt.Sprint(err)) - clientContainer.MemLeakCheck(traces1, traces2) + clientVpp.MemLeakCheck(traces1, traces2) } func HttpClientPostMemLeakTest(s *NoTopoSuite) { @@ -666,7 +657,7 @@ func HttpClientPostMemLeakTest(s *NoTopoSuite) { body := "field1=value1&field2=value2" uri := "http://" + serverAddress + "/80" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance /* no goVPP less noise */ vpp.Disconnect() @@ -711,7 +702,7 @@ func HttpClientPostMemLeakTest(s *NoTopoSuite) { func HttpInvalidClientRequestMemLeakTest(s *NoTopoSuite) { s.SkipUnlessLeakCheck() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() /* no goVPP less noise */ @@ -746,18 +737,17 @@ func runWrkPerf(s *NoTopoSuite) { nConnections := 1000 serverAddress := s.VppAddr() - wrkCont := s.GetContainerByName("wrk") args := fmt.Sprintf("-c %d -t 2 -d 30s http://%s:80/64B", nConnections, serverAddress) - wrkCont.ExtraRunningArgs = args - wrkCont.Run() + s.Containers.Wrk.ExtraRunningArgs = args + s.Containers.Wrk.Run() s.Log("Please wait for 30s, test is running.") - o, err := wrkCont.GetOutput() + o, err := s.Containers.Wrk.GetOutput() s.Log(o) s.AssertEmpty(err, "err: '%s'", err) } func HttpStaticFileHandlerWrkTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) content := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -768,7 +758,7 @@ func HttpStaticFileHandlerWrkTest(s *NoTopoSuite) { } func HttpStaticUrlHandlerWrkTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers private-segment-size 256m")) s.Log(vpp.Vppctl("test-url-handler enable")) @@ -795,7 +785,7 @@ func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { content := "

Hello

" content2 := "

Page

" - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) err := vpp.Container.CreateFile(wwwRootPath+"/index.html", content) s.AssertNil(err, fmt.Sprint(err)) @@ -851,7 +841,7 @@ func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { } func HttpStaticPathTraversalTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) vpp.Container.Exec(false, "mkdir -p "+"/tmp/secret_folder") err := vpp.Container.CreateFile("/tmp/secret_folder/secret_file.txt", "secret") @@ -873,7 +863,7 @@ func HttpStaticPathTraversalTest(s *NoTopoSuite) { } func HttpStaticMovedTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.Container.Exec(false, "mkdir -p "+wwwRootPath+"/tmp.aaa") err := vpp.Container.CreateFile(wwwRootPath+"/tmp.aaa/index.html", "

Hello

") s.AssertNil(err, fmt.Sprint(err)) @@ -895,7 +885,7 @@ func HttpStaticMovedTest(s *NoTopoSuite) { } func HttpStaticNotFoundTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.Container.Exec(false, "mkdir -p "+wwwRootPath) serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug")) @@ -914,7 +904,7 @@ func HttpStaticNotFoundTest(s *NoTopoSuite) { } func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -932,7 +922,7 @@ func HttpCliMethodNotAllowedTest(s *NoTopoSuite) { } func HttpCliBadRequestTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -949,7 +939,7 @@ func HttpCliBadRequestTest(s *NoTopoSuite) { } func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tls://" + serverAddress + "/80 url-handlers debug")) @@ -973,7 +963,7 @@ func HttpStaticBuildInUrlGetVersionTest(s *NoTopoSuite) { } func HttpStaticBuildInUrlGetVersionVerboseTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) @@ -997,7 +987,7 @@ func HttpStaticBuildInUrlGetVersionVerboseTest(s *NoTopoSuite) { } func HttpStaticBuildInUrlGetIfListTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) @@ -1017,7 +1007,7 @@ func HttpStaticBuildInUrlGetIfListTest(s *NoTopoSuite) { } func HttpStaticBuildInUrlGetIfStatsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) @@ -1045,7 +1035,7 @@ func validatePostInterfaceStats(s *NoTopoSuite, data string) { } func HttpStaticBuildInUrlPostIfStatsTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) body := []byte(s.VppIfName()) @@ -1066,7 +1056,7 @@ func HttpStaticBuildInUrlPostIfStatsTest(s *NoTopoSuite) { } func HttpStaticMacTimeTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) s.Log(vpp.Vppctl("mactime enable-disable " + s.VppIfName())) @@ -1083,7 +1073,7 @@ func HttpStaticMacTimeTest(s *NoTopoSuite) { s.AssertNil(err, fmt.Sprint(err)) s.AssertContains(string(data), "mactime") s.AssertContains(string(data), s.HostAddr()) - s.AssertContains(string(data), s.GetInterfaceByName(TapInterfaceName).HwAddress.String()) + s.AssertContains(string(data), s.Interfaces.Tap.HwAddress.String()) s.AssertHttpHeaderWithValue(resp, "Content-Type", "application/json") parsedTime, err := time.Parse(time.RFC1123, resp.Header.Get("Date")) s.AssertNil(err, fmt.Sprint(err)) @@ -1092,7 +1082,7 @@ func HttpStaticMacTimeTest(s *NoTopoSuite) { } func HttpInvalidRequestLineTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1138,7 +1128,7 @@ func HttpInvalidRequestLineTest(s *NoTopoSuite) { } func HttpRequestLineTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1149,7 +1139,7 @@ func HttpRequestLineTest(s *NoTopoSuite) { } func HttpInvalidTargetSyntaxTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) @@ -1197,7 +1187,7 @@ func HttpInvalidTargetSyntaxTest(s *NoTopoSuite) { } func HttpInvalidContentLengthTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1216,7 +1206,7 @@ func HttpInvalidContentLengthTest(s *NoTopoSuite) { } func HttpContentLengthTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug")) ifName := s.VppIfName() @@ -1238,7 +1228,7 @@ func HttpContentLengthTest(s *NoTopoSuite) { } func HttpMethodNotImplementedTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1255,7 +1245,7 @@ func HttpMethodNotImplementedTest(s *NoTopoSuite) { } func HttpVersionNotSupportedTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1265,7 +1255,7 @@ func HttpVersionNotSupportedTest(s *NoTopoSuite) { } func HttpUriDecodeTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1285,7 +1275,7 @@ func HttpUriDecodeTest(s *NoTopoSuite) { } func HttpHeadersTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1338,7 +1328,7 @@ func HttpHeadersTest(s *NoTopoSuite) { } func HttpInvalidHeadersTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1376,7 +1366,7 @@ func HttpInvalidHeadersTest(s *NoTopoSuite) { } func HeaderServerTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() vpp.Vppctl("http cli server") @@ -1393,7 +1383,7 @@ func HeaderServerTest(s *NoTopoSuite) { } func HttpConnTimeoutTest(s *NoTopoSuite) { - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() s.Log(vpp.Vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers debug keepalive-timeout 2")) diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go index 0cedfc692b0..1e189b62b8f 100644 --- a/extras/hs-test/infra/hst_suite.go +++ b/extras/hs-test/infra/hst_suite.go @@ -47,7 +47,7 @@ var NumaAwareCpuAlloc bool var TestTimeout time.Duration type HstSuite struct { - Containers map[string]*Container + AllContainers map[string]*Container StartedContainers []*Container Volumes []string NetConfigs []NetConfig @@ -240,7 +240,7 @@ func (s *HstSuite) SetupTest() { } func (s *HstSuite) SetupContainers() { - for _, container := range s.Containers { + for _, container := range s.AllContainers { if !container.IsOptional { container.Run() } @@ -527,7 +527,7 @@ func (s *HstSuite) GetInterfaceByName(name string) *NetInterface { } func (s *HstSuite) GetContainerByName(name string) *Container { - return s.Containers[s.ProcessIndex+name+s.Ppid] + return s.AllContainers[s.ProcessIndex+name+s.Ppid] } /* @@ -535,7 +535,7 @@ func (s *HstSuite) GetContainerByName(name string) *Container { * are not able to modify the original container and affect other tests by doing that */ func (s *HstSuite) GetTransientContainerByName(name string) *Container { - containerCopy := *s.Containers[s.ProcessIndex+name+s.Ppid] + containerCopy := *s.AllContainers[s.ProcessIndex+name+s.Ppid] return &containerCopy } @@ -559,7 +559,7 @@ func (s *HstSuite) LoadContainerTopology(topologyName string) { s.Volumes = append(s.Volumes, hostDir) } - s.Containers = make(map[string]*Container) + s.AllContainers = make(map[string]*Container) for _, elem := range yamlTopo.Containers { newContainer, err := newContainer(s, elem) newContainer.Suite = s @@ -567,12 +567,12 @@ func (s *HstSuite) LoadContainerTopology(topologyName string) { if err != nil { Fail("container config error: " + fmt.Sprint(err)) } - s.Containers[newContainer.Name] = newContainer + s.AllContainers[newContainer.Name] = newContainer } if *DryRun { s.Log(Colors.pur + "* Containers used by this suite (some might already be running):" + Colors.rst) - for name := range s.Containers { + for name := range s.AllContainers { s.Log("%sdocker start %s && docker exec -it %s bash%s", Colors.pur, name, name, Colors.rst) } } diff --git a/extras/hs-test/infra/suite_cpu_pinning.go b/extras/hs-test/infra/suite_cpu_pinning.go index 57efbe7f4f0..63ebd8b6ef5 100644 --- a/extras/hs-test/infra/suite_cpu_pinning.go +++ b/extras/hs-test/infra/suite_cpu_pinning.go @@ -15,6 +15,12 @@ var cpuPinningSoloTests = map[string][]func(s *CpuPinningSuite){} type CpuPinningSuite struct { HstSuite previousMaxContainerCount int + Interfaces struct { + Tap *NetInterface + } + Containers struct { + Vpp *Container + } } func RegisterCpuPinningTests(tests ...func(s *CpuPinningSuite)) { @@ -29,6 +35,8 @@ func (s *CpuPinningSuite) SetupSuite() { s.HstSuite.SetupSuite() s.LoadNetworkTopology("tap") s.LoadContainerTopology("singleCpuPinning") + s.Interfaces.Tap = s.GetInterfaceByName("htaphost") + s.Containers.Vpp = s.GetContainerByName("vpp") } func (s *CpuPinningSuite) SetupTest() { @@ -39,8 +47,7 @@ func (s *CpuPinningSuite) SetupTest() { s.SkipIfNotEnoughAvailableCpus() s.HstSuite.SetupTest() - container := s.GetContainerByName(SingleTopoContainerVpp) - vpp, err := container.newVppInstance(container.AllocatedCpus) + vpp, err := s.Containers.Vpp.newVppInstance(s.Containers.Vpp.AllocatedCpus) s.AssertNotNil(vpp, fmt.Sprint(err)) if *DryRun { diff --git a/extras/hs-test/infra/suite_envoy_proxy.go b/extras/hs-test/infra/suite_envoy_proxy.go index 754705d24e0..c20cf291388 100644 --- a/extras/hs-test/infra/suite_envoy_proxy.go +++ b/extras/hs-test/infra/suite_envoy_proxy.go @@ -15,16 +15,21 @@ import ( . "github.com/onsi/ginkgo/v2" ) -const ( - VppContainerName = "vpp" - EnvoyProxyContainerName = "envoy-vcl" -) - type EnvoyProxySuite struct { HstSuite nginxPort uint16 proxyPort uint16 maxTimeout int + Interfaces struct { + Server *NetInterface + Client *NetInterface + } + Containers struct { + EnvoyProxy *Container + NginxServerTransient *Container + Vpp *Container + Curl *Container + } } var envoyProxyTests = map[string][]func(s *EnvoyProxySuite){} @@ -48,6 +53,12 @@ func (s *EnvoyProxySuite) SetupSuite() { } else { s.maxTimeout = 60 } + s.Interfaces.Client = s.GetInterfaceByName("hstcln") + s.Interfaces.Server = s.GetInterfaceByName("hstsrv") + s.Containers.NginxServerTransient = s.GetTransientContainerByName("nginx-server") + s.Containers.Vpp = s.GetContainerByName("vpp") + s.Containers.EnvoyProxy = s.GetContainerByName("envoy-vcl") + s.Containers.Curl = s.GetContainerByName("curl") } func (s *EnvoyProxySuite) SetupTest() { @@ -62,15 +73,11 @@ func (s *EnvoyProxySuite) SetupTest() { Append("evt_qs_memfd_seg"). Append("event-queue-length 100000") - vppContainer := s.GetContainerByName(VppContainerName) - vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus, sessionConfig) + vpp, err := s.Containers.Vpp.newVppInstance(s.Containers.Vpp.AllocatedCpus, sessionConfig) s.AssertNotNil(vpp, fmt.Sprint(err)) - clientInterface := s.GetInterfaceByName(ClientTapInterfaceName) - serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) // nginx HTTP server - nginxContainer := s.GetTransientContainerByName(NginxServerContainerName) - s.AssertNil(nginxContainer.Create()) + s.AssertNil(s.Containers.NginxServerTransient.Create()) s.nginxPort = 80 nginxSettings := struct { LogPrefix string @@ -78,20 +85,19 @@ func (s *EnvoyProxySuite) SetupTest() { Port uint16 Timeout int }{ - LogPrefix: nginxContainer.Name, - Address: serverInterface.Ip4AddressString(), + LogPrefix: s.Containers.NginxServerTransient.Name, + Address: s.Interfaces.Server.Ip4AddressString(), Port: s.nginxPort, Timeout: s.maxTimeout, } - nginxContainer.CreateConfigFromTemplate( + s.Containers.NginxServerTransient.CreateConfigFromTemplate( "/nginx.conf", "./resources/nginx/nginx_server.conf", nginxSettings, ) // Envoy - envoyContainer := s.GetContainerByName(EnvoyProxyContainerName) - s.AssertNil(envoyContainer.Create()) + s.AssertNil(s.Containers.EnvoyProxy.Create()) s.proxyPort = 8080 envoySettings := struct { @@ -100,12 +106,12 @@ func (s *EnvoyProxySuite) SetupTest() { ServerPort uint16 ProxyPort uint16 }{ - LogPrefix: envoyContainer.Name, - ServerAddress: serverInterface.Ip4AddressString(), + LogPrefix: s.Containers.EnvoyProxy.Name, + ServerAddress: s.Interfaces.Server.Ip4AddressString(), ServerPort: s.nginxPort, ProxyPort: s.proxyPort, } - envoyContainer.CreateConfigFromTemplate( + s.Containers.EnvoyProxy.CreateConfigFromTemplate( "/etc/envoy/envoy.yaml", "resources/envoy/proxy.yaml", envoySettings, @@ -114,15 +120,15 @@ func (s *EnvoyProxySuite) SetupTest() { s.AssertNil(vpp.Start()) // wait for VPP to start time.Sleep(time.Second * 1) - s.AssertNil(vpp.CreateTap(clientInterface, 1, 1)) - s.AssertNil(vpp.CreateTap(serverInterface, 1, 2)) - vppContainer.Exec(false, "chmod 777 -R %s", vppContainer.GetContainerWorkDir()) + s.AssertNil(vpp.CreateTap(s.Interfaces.Client, 1, 1)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Server, 1, 2)) + s.Containers.Vpp.Exec(false, "chmod 777 -R %s", s.Containers.Vpp.GetContainerWorkDir()) // Add Ipv4 ARP entry for nginx HTTP server, otherwise first request fail (HTTP error 503) arp := fmt.Sprintf("set ip neighbor %s %s %s", - serverInterface.Peer.Name(), - serverInterface.Ip4AddressString(), - serverInterface.HwAddress) + s.Interfaces.Server.Peer.Name(), + s.Interfaces.Server.Ip4AddressString(), + s.Interfaces.Server.HwAddress) if *DryRun { vpp.AppendToCliConfig(arp) @@ -131,15 +137,15 @@ func (s *EnvoyProxySuite) SetupTest() { s.Skip("Dry run mode = true") } - vppContainer.VppInstance.Vppctl(arp) - s.AssertNil(nginxContainer.Start()) - s.AssertNil(envoyContainer.Start()) + s.Containers.Vpp.VppInstance.Vppctl(arp) + s.AssertNil(s.Containers.NginxServerTransient.Start()) + s.AssertNil(s.Containers.EnvoyProxy.Start()) } func (s *EnvoyProxySuite) TearDownTest() { if CurrentSpecReport().Failed() { - s.CollectNginxLogs(NginxServerContainerName) - s.CollectEnvoyLogs(EnvoyProxyContainerName) + s.CollectNginxLogs(s.Containers.NginxServerTransient) + s.CollectEnvoyLogs(s.Containers.EnvoyProxy) } s.HstSuite.TearDownTest() } @@ -149,12 +155,12 @@ func (s *EnvoyProxySuite) ProxyPort() uint16 { } func (s *EnvoyProxySuite) ProxyAddr() string { - return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString() + return s.Interfaces.Client.Peer.Ip4AddressString() } func (s *EnvoyProxySuite) CurlDownloadResource(uri string) { args := fmt.Sprintf("-w @/tmp/write_out_download --max-time %d --insecure --noproxy '*' --remote-name --output-dir /tmp %s", s.maxTimeout, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "GET response code: 200") s.AssertNotContains(log, "bytes remaining to read") s.AssertNotContains(log, "Operation timed out") @@ -162,7 +168,7 @@ func (s *EnvoyProxySuite) CurlDownloadResource(uri string) { func (s *EnvoyProxySuite) CurlUploadResource(uri, file string) { args := fmt.Sprintf("-w @/tmp/write_out_upload --max-time %d --insecure --noproxy '*' -T %s %s", s.maxTimeout, file, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "PUT response code: 201") s.AssertNotContains(log, "Operation timed out") } diff --git a/extras/hs-test/infra/suite_iperf_linux.go b/extras/hs-test/infra/suite_iperf_linux.go index fb685f9ad96..c957978c7e6 100644 --- a/extras/hs-test/infra/suite_iperf_linux.go +++ b/extras/hs-test/infra/suite_iperf_linux.go @@ -11,15 +11,16 @@ import ( type IperfSuite struct { HstSuite + Interfaces struct { + Server *NetInterface + Client *NetInterface + } + Containers struct { + Server *Container + Client *Container + } } -const ( - ServerIperfContainerName string = "server" - ServerIperfInterfaceName string = "hstsrv" - ClientIperfContainerName string = "client" - ClientIperfInterfaceName string = "hstcln" -) - var iperfTests = map[string][]func(s *IperfSuite){} var iperfSoloTests = map[string][]func(s *IperfSuite){} @@ -35,6 +36,10 @@ func (s *IperfSuite) SetupSuite() { s.HstSuite.SetupSuite() s.ConfigureNetworkTopology("2taps") s.LoadContainerTopology("2containers") + s.Interfaces.Client = s.GetInterfaceByName("hstcln") + s.Interfaces.Server = s.GetInterfaceByName("hstsrv") + s.Containers.Server = s.GetContainerByName("server") + s.Containers.Client = s.GetContainerByName("client") } var _ = Describe("IperfSuite", Ordered, ContinueOnFailure, func() { diff --git a/extras/hs-test/infra/suite_ldp.go b/extras/hs-test/infra/suite_ldp.go index 6294fab0dd6..408fea31325 100644 --- a/extras/hs-test/infra/suite_ldp.go +++ b/extras/hs-test/infra/suite_ldp.go @@ -10,17 +10,21 @@ import ( . "github.com/onsi/ginkgo/v2" ) -// These correspond to names used in yaml config -const ( - ServerLdpInterfaceName = "srv" - ClientLdpInterfaceName = "cln" -) - var ldpTests = map[string][]func(s *LdpSuite){} var ldpSoloTests = map[string][]func(s *LdpSuite){} type LdpSuite struct { HstSuite + Interfaces struct { + Server *NetInterface + Client *NetInterface + } + Containers struct { + ServerVpp *Container + ClientVpp *Container + ServerApp *Container + ClientApp *Container + } } func RegisterLdpTests(tests ...func(s *LdpSuite)) { @@ -35,6 +39,12 @@ func (s *LdpSuite) SetupSuite() { s.HstSuite.SetupSuite() s.ConfigureNetworkTopology("2peerVeth") s.LoadContainerTopology("2peerVethLdp") + s.Interfaces.Client = s.GetInterfaceByName("cln") + s.Interfaces.Server = s.GetInterfaceByName("srv") + s.Containers.ServerVpp = s.GetContainerByName("server-vpp") + s.Containers.ClientVpp = s.GetContainerByName("client-vpp") + s.Containers.ServerApp = s.GetContainerByName("server-app") + s.Containers.ClientApp = s.GetContainerByName("client-app") } func (s *LdpSuite) SetupTest() { @@ -55,19 +65,15 @@ func (s *LdpSuite) SetupTest() { } // ... For server - serverContainer := s.GetContainerByName("server-vpp") - - serverVpp, err := serverContainer.newVppInstance(serverContainer.AllocatedCpus, sessionConfig) + serverVpp, err := s.Containers.ServerVpp.newVppInstance(s.Containers.ServerVpp.AllocatedCpus, sessionConfig) s.AssertNotNil(serverVpp, fmt.Sprint(err)) // ... For client - clientContainer := s.GetContainerByName("client-vpp") - - clientVpp, err := clientContainer.newVppInstance(clientContainer.AllocatedCpus, sessionConfig) + clientVpp, err := s.Containers.ClientVpp.newVppInstance(s.Containers.ClientVpp.AllocatedCpus, sessionConfig) s.AssertNotNil(clientVpp, fmt.Sprint(err)) - serverContainer.AddEnvVar("VCL_CONFIG", serverContainer.GetContainerWorkDir()+"/vcl.conf") - clientContainer.AddEnvVar("VCL_CONFIG", clientContainer.GetContainerWorkDir()+"/vcl.conf") + s.Containers.ServerVpp.AddEnvVar("VCL_CONFIG", s.Containers.ServerVpp.GetContainerWorkDir()+"/vcl.conf") + s.Containers.ClientVpp.AddEnvVar("VCL_CONFIG", s.Containers.ClientVpp.GetContainerWorkDir()+"/vcl.conf") for _, container := range s.StartedContainers { container.AddEnvVar("LD_PRELOAD", "/usr/lib/libvcl_ldpreload.so") @@ -75,17 +81,17 @@ func (s *LdpSuite) SetupTest() { container.AddEnvVar("VCL_DEBUG", "0") } - s.CreateVclConfig(serverContainer) - s.CreateVclConfig(clientContainer) - s.SetupServerVpp(serverContainer) - s.setupClientVpp(clientContainer) + s.CreateVclConfig(s.Containers.ServerVpp) + s.CreateVclConfig(s.Containers.ClientVpp) + s.SetupServerVpp(s.Containers.ServerVpp) + s.setupClientVpp(s.Containers.ClientVpp) if *DryRun { s.LogStartedContainers() s.Log("\n%s* LD_PRELOAD and VCL_CONFIG server/client paths:", Colors.grn) s.Log("LD_PRELOAD=/usr/lib/libvcl_ldpreload.so") - s.Log("VCL_CONFIG=%s/vcl.conf", serverContainer.GetContainerWorkDir()) - s.Log("VCL_CONFIG=%s/vcl.conf%s\n", clientContainer.GetContainerWorkDir(), Colors.rst) + s.Log("VCL_CONFIG=%s/vcl.conf", s.Containers.ServerVpp.GetContainerWorkDir()) + s.Log("VCL_CONFIG=%s/vcl.conf%s\n", s.Containers.ClientVpp.GetContainerWorkDir(), Colors.rst) s.Skip("Dry run mode = true") } } @@ -121,8 +127,7 @@ func (s *LdpSuite) SetupServerVpp(serverContainer *Container) { serverVpp := serverContainer.VppInstance s.AssertNil(serverVpp.Start()) - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - idx, err := serverVpp.createAfPacket(serverVeth) + idx, err := serverVpp.createAfPacket(s.Interfaces.Server) s.AssertNil(err, fmt.Sprint(err)) s.AssertNotEqual(0, idx) } @@ -131,8 +136,7 @@ func (s *LdpSuite) setupClientVpp(clientContainer *Container) { clientVpp := clientContainer.VppInstance s.AssertNil(clientVpp.Start()) - clientVeth := s.GetInterfaceByName(ClientInterfaceName) - idx, err := clientVpp.createAfPacket(clientVeth) + idx, err := clientVpp.createAfPacket(s.Interfaces.Client) s.AssertNil(err, fmt.Sprint(err)) s.AssertNotEqual(0, idx) } diff --git a/extras/hs-test/infra/suite_nginx_proxy.go b/extras/hs-test/infra/suite_nginx_proxy.go index f0c178fc2f8..1b6d9f61aae 100644 --- a/extras/hs-test/infra/suite_nginx_proxy.go +++ b/extras/hs-test/infra/suite_nginx_proxy.go @@ -9,14 +9,6 @@ import ( . "github.com/onsi/ginkgo/v2" ) -// These correspond to names used in yaml config -const ( - NginxProxyContainerName = "nginx-proxy" - NginxServerContainerName = "nginx-server" - MirroringClientInterfaceName = "hstcln" - MirroringServerInterfaceName = "hstsrv" -) - var nginxProxyTests = map[string][]func(s *NginxProxySuite){} var nginxProxySoloTests = map[string][]func(s *NginxProxySuite){} @@ -24,6 +16,16 @@ type NginxProxySuite struct { HstSuite proxyPort uint16 maxTimeout int + Interfaces struct { + Server *NetInterface + Client *NetInterface + } + Containers struct { + NginxProxy *Container + NginxServerTransient *Container + Vpp *Container + Curl *Container + } } func RegisterNginxProxyTests(tests ...func(s *NginxProxySuite)) { @@ -43,6 +45,12 @@ func (s *NginxProxySuite) SetupSuite() { } else { s.maxTimeout = 60 } + s.Interfaces.Client = s.GetInterfaceByName("hstcln") + s.Interfaces.Server = s.GetInterfaceByName("hstsrv") + s.Containers.NginxProxy = s.GetContainerByName("nginx-proxy") + s.Containers.NginxServerTransient = s.GetTransientContainerByName("nginx-server") + s.Containers.Vpp = s.GetContainerByName("vpp") + s.Containers.Curl = s.GetContainerByName("curl") } func (s *NginxProxySuite) SetupTest() { @@ -55,38 +63,33 @@ func (s *NginxProxySuite) SetupTest() { Append("enable"). Append("use-app-socket-api") - vppContainer := s.GetContainerByName(VppContainerName) - vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus, sessionConfig) + vpp, err := s.Containers.Vpp.newVppInstance(s.Containers.Vpp.AllocatedCpus, sessionConfig) s.AssertNotNil(vpp, fmt.Sprint(err)) - clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName) - serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName) // nginx proxy - nginxProxyContainer := s.GetContainerByName(NginxProxyContainerName) - s.AssertNil(nginxProxyContainer.Create()) + s.AssertNil(s.Containers.NginxProxy.Create()) s.proxyPort = 80 // nginx HTTP server - nginxServerContainer := s.GetTransientContainerByName(NginxServerContainerName) - s.AssertNil(nginxServerContainer.Create()) + s.AssertNil(s.Containers.NginxServerTransient.Create()) nginxSettings := struct { LogPrefix string Address string Timeout int }{ - LogPrefix: nginxServerContainer.Name, - Address: serverInterface.Ip4AddressString(), + LogPrefix: s.Containers.NginxServerTransient.Name, + Address: s.Interfaces.Server.Ip4AddressString(), Timeout: s.maxTimeout, } - nginxServerContainer.CreateConfigFromTemplate( + s.Containers.NginxServerTransient.CreateConfigFromTemplate( "/nginx.conf", "./resources/nginx/nginx_server_mirroring.conf", nginxSettings, ) s.AssertNil(vpp.Start()) - s.AssertNil(vpp.CreateTap(clientInterface, 1, 1)) - s.AssertNil(vpp.CreateTap(serverInterface, 1, 2)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Client, 1, 1)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Server, 1, 2)) if *DryRun { s.LogStartedContainers() @@ -94,21 +97,19 @@ func (s *NginxProxySuite) SetupTest() { s.Skip("Dry run mode = true") } - s.AssertNil(nginxProxyContainer.Start()) - s.AssertNil(nginxServerContainer.Start()) + s.AssertNil(s.Containers.NginxProxy.Start()) + s.AssertNil(s.Containers.NginxServerTransient.Start()) } func (s *NginxProxySuite) TearDownTest() { if CurrentSpecReport().Failed() { - s.CollectNginxLogs(NginxServerContainerName) - s.CollectNginxLogs(NginxProxyContainerName) + s.CollectNginxLogs(s.Containers.NginxProxy) + s.CollectNginxLogs(s.Containers.NginxServerTransient) } s.HstSuite.TearDownTest() } func (s *NginxProxySuite) CreateNginxProxyConfig(container *Container, multiThreadWorkers bool) { - clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName) - serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName) var workers uint8 if multiThreadWorkers { workers = 2 @@ -124,8 +125,8 @@ func (s *NginxProxySuite) CreateNginxProxyConfig(container *Container, multiThre }{ Workers: workers, LogPrefix: container.Name, - Proxy: clientInterface.Peer.Ip4AddressString(), - Server: serverInterface.Ip4AddressString(), + Proxy: s.Interfaces.Client.Peer.Ip4AddressString(), + Server: s.Interfaces.Server.Ip4AddressString(), Port: s.proxyPort, } container.CreateConfigFromTemplate( @@ -140,12 +141,12 @@ func (s *NginxProxySuite) ProxyPort() uint16 { } func (s *NginxProxySuite) ProxyAddr() string { - return s.GetInterfaceByName(MirroringClientInterfaceName).Peer.Ip4AddressString() + return s.Interfaces.Client.Peer.Ip4AddressString() } func (s *NginxProxySuite) CurlDownloadResource(uri string) { args := fmt.Sprintf("-w @/tmp/write_out_download --max-time %d --insecure --noproxy '*' --remote-name --output-dir /tmp %s", s.maxTimeout, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "GET response code: 200") s.AssertNotContains(log, "bytes remaining to read") s.AssertNotContains(log, "Operation timed out") diff --git a/extras/hs-test/infra/suite_no_topo.go b/extras/hs-test/infra/suite_no_topo.go index 727789b4deb..1c7b6fe91c3 100644 --- a/extras/hs-test/infra/suite_no_topo.go +++ b/extras/hs-test/infra/suite_no_topo.go @@ -9,18 +9,22 @@ import ( . "github.com/onsi/ginkgo/v2" ) -const ( - SingleTopoContainerVpp = "vpp" - SingleTopoContainerNginx = "nginx" - TapInterfaceName = "htaphost" - NginxHttp3ContainerName = "nginx-http3" -) - var noTopoTests = map[string][]func(s *NoTopoSuite){} var noTopoSoloTests = map[string][]func(s *NoTopoSuite){} type NoTopoSuite struct { HstSuite + Interfaces struct { + Tap *NetInterface + } + Containers struct { + Vpp *Container + Nginx *Container + NginxHttp3 *Container + Wrk *Container + Curl *Container + Ab *Container + } } func RegisterNoTopoTests(tests ...func(s *NoTopoSuite)) { @@ -34,6 +38,13 @@ func (s *NoTopoSuite) SetupSuite() { s.HstSuite.SetupSuite() s.LoadNetworkTopology("tap") s.LoadContainerTopology("single") + s.Interfaces.Tap = s.GetInterfaceByName("htaphost") + s.Containers.Vpp = s.GetContainerByName("vpp") + s.Containers.Nginx = s.GetContainerByName("nginx") + s.Containers.NginxHttp3 = s.GetContainerByName("nginx-http3") + s.Containers.Wrk = s.GetContainerByName("wrk") + s.Containers.Curl = s.GetContainerByName("curl") + s.Containers.Ab = s.GetContainerByName("ab") } func (s *NoTopoSuite) SetupTest() { @@ -53,12 +64,10 @@ func (s *NoTopoSuite) SetupTest() { sessionConfig.Close() } - container := s.GetContainerByName(SingleTopoContainerVpp) - vpp, _ := container.newVppInstance(container.AllocatedCpus, sessionConfig) + vpp, _ := s.Containers.Vpp.newVppInstance(s.Containers.Vpp.AllocatedCpus, sessionConfig) s.AssertNil(vpp.Start()) - tapInterface := s.GetInterfaceByName(TapInterfaceName) - s.AssertNil(vpp.CreateTap(tapInterface, 1, 1), "failed to create tap interface") + s.AssertNil(vpp.CreateTap(s.Interfaces.Tap, 1, 1), "failed to create tap interface") if *DryRun { s.LogStartedContainers() @@ -68,7 +77,7 @@ func (s *NoTopoSuite) SetupTest() { func (s *NoTopoSuite) TearDownTest() { if CurrentSpecReport().Failed() { - s.CollectNginxLogs(NginxHttp3ContainerName) + s.CollectNginxLogs(s.Containers.NginxHttp3) } s.HstSuite.TearDownTest() } @@ -93,10 +102,9 @@ func (s *NoTopoSuite) CreateNginxConfig(container *Container, multiThreadWorkers } func (s *NoTopoSuite) AddNginxVclConfig(multiThreadWorkers bool) { - nginxCont := s.GetContainerByName(SingleTopoContainerNginx) - vclFileName := nginxCont.GetHostWorkDir() + "/vcl.conf" + vclFileName := s.Containers.Nginx.GetHostWorkDir() + "/vcl.conf" appSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default", - nginxCont.GetContainerWorkDir()) + s.Containers.Nginx.GetContainerWorkDir()) var vclConf Stanza vclConf. @@ -118,15 +126,15 @@ func (s *NoTopoSuite) AddNginxVclConfig(multiThreadWorkers bool) { } func (s *NoTopoSuite) VppAddr() string { - return s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() + return s.Interfaces.Tap.Peer.Ip4AddressString() } func (s *NoTopoSuite) VppIfName() string { - return s.GetInterfaceByName(TapInterfaceName).Peer.Name() + return s.Interfaces.Tap.Peer.Name() } func (s *NoTopoSuite) HostAddr() string { - return s.GetInterfaceByName(TapInterfaceName).Ip4AddressString() + return s.Interfaces.Tap.Ip4AddressString() } func (s *NoTopoSuite) CreateNginxHttp3Config(container *Container) { diff --git a/extras/hs-test/infra/suite_veth.go b/extras/hs-test/infra/suite_veth.go index cbbd7ee2694..c13f3e4cdf8 100644 --- a/extras/hs-test/infra/suite_veth.go +++ b/extras/hs-test/infra/suite_veth.go @@ -10,17 +10,21 @@ import ( . "github.com/onsi/ginkgo/v2" ) -// These correspond to names used in yaml config -const ( - ServerInterfaceName = "srv" - ClientInterfaceName = "cln" -) - var vethTests = map[string][]func(s *VethsSuite){} var vethSoloTests = map[string][]func(s *VethsSuite){} type VethsSuite struct { HstSuite + Interfaces struct { + Server *NetInterface + Client *NetInterface + } + Containers struct { + ServerVpp *Container + ClientVpp *Container + ServerApp *Container + ClientApp *Container + } } func RegisterVethTests(tests ...func(s *VethsSuite)) { @@ -35,6 +39,12 @@ func (s *VethsSuite) SetupSuite() { s.HstSuite.SetupSuite() s.ConfigureNetworkTopology("2peerVeth") s.LoadContainerTopology("2peerVeth") + s.Interfaces.Client = s.GetInterfaceByName("cln") + s.Interfaces.Server = s.GetInterfaceByName("srv") + s.Containers.ServerVpp = s.GetContainerByName("server-vpp") + s.Containers.ClientVpp = s.GetContainerByName("client-vpp") + s.Containers.ServerApp = s.GetContainerByName("server-app") + s.Containers.ClientApp = s.GetContainerByName("client-app") } func (s *VethsSuite) SetupTest() { @@ -55,15 +65,11 @@ func (s *VethsSuite) SetupTest() { } // ... For server - serverContainer := s.GetContainerByName("server-vpp") - - serverVpp, err := serverContainer.newVppInstance(serverContainer.AllocatedCpus, sessionConfig) + serverVpp, err := s.Containers.ServerVpp.newVppInstance(s.Containers.ServerVpp.AllocatedCpus, sessionConfig) s.AssertNotNil(serverVpp, fmt.Sprint(err)) // ... For client - clientContainer := s.GetContainerByName("client-vpp") - - clientVpp, err := clientContainer.newVppInstance(clientContainer.AllocatedCpus, sessionConfig) + clientVpp, err := s.Containers.ClientVpp.newVppInstance(s.Containers.ClientVpp.AllocatedCpus, sessionConfig) s.AssertNotNil(clientVpp, fmt.Sprint(err)) s.SetupServerVpp() @@ -75,11 +81,10 @@ func (s *VethsSuite) SetupTest() { } func (s *VethsSuite) SetupServerVpp() { - serverVpp := s.GetContainerByName("server-vpp").VppInstance + serverVpp := s.Containers.ServerVpp.VppInstance s.AssertNil(serverVpp.Start()) - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - idx, err := serverVpp.createAfPacket(serverVeth) + idx, err := serverVpp.createAfPacket(s.Interfaces.Server) s.AssertNil(err, fmt.Sprint(err)) s.AssertNotEqual(0, idx) } @@ -88,8 +93,7 @@ func (s *VethsSuite) setupClientVpp() { clientVpp := s.GetContainerByName("client-vpp").VppInstance s.AssertNil(clientVpp.Start()) - clientVeth := s.GetInterfaceByName(ClientInterfaceName) - idx, err := clientVpp.createAfPacket(clientVeth) + idx, err := clientVpp.createAfPacket(s.Interfaces.Client) s.AssertNil(err, fmt.Sprint(err)) s.AssertNotEqual(0, idx) } diff --git a/extras/hs-test/infra/suite_vpp_proxy.go b/extras/hs-test/infra/suite_vpp_proxy.go index 51beade2d9b..37d251a3a6d 100644 --- a/extras/hs-test/infra/suite_vpp_proxy.go +++ b/extras/hs-test/infra/suite_vpp_proxy.go @@ -14,20 +14,25 @@ import ( . "github.com/onsi/ginkgo/v2" ) -// These correspond to names used in yaml config const ( - VppProxyContainerName = "vpp-proxy" - ClientTapInterfaceName = "hstcln" - ServerTapInterfaceName = "hstsrv" - IperfServerContainerName = "iperfA" - IperfClientContainerName = "iperfB" - CurlContainerTestFile = "/tmp/testFile" + CurlContainerTestFile = "/tmp/testFile" ) type VppProxySuite struct { HstSuite serverPort uint16 maxTimeout int + Interfaces struct { + Client *NetInterface + Server *NetInterface + } + Containers struct { + VppProxy *Container + Curl *Container + NginxServerTransient *Container + IperfS *Container + IperfC *Container + } } var vppProxyTests = map[string][]func(s *VppProxySuite){} @@ -52,22 +57,25 @@ func (s *VppProxySuite) SetupSuite() { } else { s.maxTimeout = 60 } + s.Interfaces.Client = s.GetInterfaceByName("hstcln") + s.Interfaces.Server = s.GetInterfaceByName("hstsrv") + s.Containers.NginxServerTransient = s.GetTransientContainerByName("nginx-server") + s.Containers.VppProxy = s.GetContainerByName("vpp-proxy") + s.Containers.Curl = s.GetContainerByName("curl") + s.Containers.IperfC = s.GetContainerByName("iperfC") + s.Containers.IperfS = s.GetContainerByName("iperfS") } func (s *VppProxySuite) SetupTest() { s.HstSuite.SetupTest() // VPP HTTP connect-proxy - vppContainer := s.GetContainerByName(VppProxyContainerName) - vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus) + vpp, err := s.Containers.VppProxy.newVppInstance(s.Containers.VppProxy.AllocatedCpus) s.AssertNotNil(vpp, fmt.Sprint(err)) - clientInterface := s.GetInterfaceByName(ClientTapInterfaceName) - serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) - s.AssertNil(vpp.Start()) - s.AssertNil(vpp.CreateTap(clientInterface, 1, 1)) - s.AssertNil(vpp.CreateTap(serverInterface, 1, 2)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Client, 1, 1)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Server, 1, 2)) if *DryRun { s.LogStartedContainers() @@ -76,36 +84,34 @@ func (s *VppProxySuite) SetupTest() { } func (s *VppProxySuite) TearDownTest() { - vpp := s.GetContainerByName(VppProxyContainerName).VppInstance + vpp := s.Containers.VppProxy.VppInstance if CurrentSpecReport().Failed() { s.Log(vpp.Vppctl("show session verbose 2")) s.Log(vpp.Vppctl("show error")) - s.CollectNginxLogs(NginxServerContainerName) + s.CollectNginxLogs(s.Containers.NginxServerTransient) } s.HstSuite.TearDownTest() } func (s *VppProxySuite) SetupNginxServer() { - nginxContainer := s.GetTransientContainerByName(NginxServerContainerName) - serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) - s.AssertNil(nginxContainer.Create()) + s.AssertNil(s.Containers.NginxServerTransient.Create()) nginxSettings := struct { LogPrefix string Address string Port uint16 Timeout int }{ - LogPrefix: nginxContainer.Name, - Address: serverInterface.Ip4AddressString(), + LogPrefix: s.Containers.NginxServerTransient.Name, + Address: s.Interfaces.Server.Ip4AddressString(), Port: s.serverPort, Timeout: s.maxTimeout, } - nginxContainer.CreateConfigFromTemplate( + s.Containers.NginxServerTransient.CreateConfigFromTemplate( "/nginx.conf", "./resources/nginx/nginx_server.conf", nginxSettings, ) - s.AssertNil(nginxContainer.Start()) + s.AssertNil(s.Containers.NginxServerTransient.Start()) } func (s *VppProxySuite) ServerPort() uint16 { @@ -113,32 +119,32 @@ func (s *VppProxySuite) ServerPort() uint16 { } func (s *VppProxySuite) ServerAddr() string { - return s.GetInterfaceByName(ServerTapInterfaceName).Ip4AddressString() + return s.Interfaces.Server.Ip4AddressString() } func (s *VppProxySuite) VppProxyAddr() string { - return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString() + return s.Interfaces.Client.Peer.Ip4AddressString() } func (s *VppProxySuite) ClientAddr() string { - return s.GetInterfaceByName(ClientTapInterfaceName).Ip4AddressString() + return s.Interfaces.Client.Ip4AddressString() } func (s *VppProxySuite) CurlRequest(targetUri string) (string, string) { args := fmt.Sprintf("--insecure --noproxy '*' %s", targetUri) - body, log := s.RunCurlContainer(args) + body, log := s.RunCurlContainer(s.Containers.Curl, args) return body, log } func (s *VppProxySuite) CurlRequestViaTunnel(targetUri string, proxyUri string) (string, string) { args := fmt.Sprintf("--max-time %d --insecure -p -x %s %s", s.maxTimeout, proxyUri, targetUri) - body, log := s.RunCurlContainer(args) + body, log := s.RunCurlContainer(s.Containers.Curl, args) return body, log } func (s *VppProxySuite) CurlDownloadResource(uri string) { args := fmt.Sprintf("-w @/tmp/write_out_download --max-time %d --insecure --noproxy '*' --remote-name --output-dir /tmp %s", s.maxTimeout, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "GET response code: 200") s.AssertNotContains(log, "bytes remaining to read") s.AssertNotContains(log, "Operation timed out") @@ -146,14 +152,14 @@ func (s *VppProxySuite) CurlDownloadResource(uri string) { func (s *VppProxySuite) CurlUploadResource(uri, file string) { args := fmt.Sprintf("-w @/tmp/write_out_upload --max-time %d --insecure --noproxy '*' -T %s %s", s.maxTimeout, file, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "PUT response code: 201") s.AssertNotContains(log, "Operation timed out") } func (s *VppProxySuite) CurlDownloadResourceViaTunnel(uri string, proxyUri string) { args := fmt.Sprintf("-w @/tmp/write_out_download_connect --max-time %d --insecure -p -x %s --remote-name --output-dir /tmp %s", s.maxTimeout, proxyUri, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "CONNECT response code: 200") s.AssertContains(writeOut, "GET response code: 200") s.AssertNotContains(log, "bytes remaining to read") @@ -163,7 +169,7 @@ func (s *VppProxySuite) CurlDownloadResourceViaTunnel(uri string, proxyUri strin func (s *VppProxySuite) CurlUploadResourceViaTunnel(uri, proxyUri, file string) { args := fmt.Sprintf("-w @/tmp/write_out_upload_connect --max-time %d --insecure -p -x %s -T %s %s", s.maxTimeout, proxyUri, file, uri) - writeOut, log := s.RunCurlContainer(args) + writeOut, log := s.RunCurlContainer(s.Containers.Curl, args) s.AssertContains(writeOut, "CONNECT response code: 200") s.AssertContains(writeOut, "PUT response code: 201") s.AssertNotContains(log, "Operation timed out") diff --git a/extras/hs-test/infra/suite_vpp_udp_proxy.go b/extras/hs-test/infra/suite_vpp_udp_proxy.go index 84e76d6643a..6a65a0be5ff 100644 --- a/extras/hs-test/infra/suite_vpp_udp_proxy.go +++ b/extras/hs-test/infra/suite_vpp_udp_proxy.go @@ -11,12 +11,17 @@ import ( . "github.com/onsi/ginkgo/v2" ) -const VppUdpProxyContainerName = "vpp" - type VppUdpProxySuite struct { HstSuite proxyPort int serverPort int + Interfaces struct { + Client *NetInterface + Server *NetInterface + } + Containers struct { + VppProxy *Container + } } var vppUdpProxyTests = map[string][]func(s *VppUdpProxySuite){} @@ -34,30 +39,29 @@ func (s *VppUdpProxySuite) SetupSuite() { s.HstSuite.SetupSuite() s.LoadNetworkTopology("2taps") s.LoadContainerTopology("single") + s.Interfaces.Client = s.GetInterfaceByName("hstcln") + s.Interfaces.Server = s.GetInterfaceByName("hstsrv") + s.Containers.VppProxy = s.GetContainerByName("vpp") } func (s *VppUdpProxySuite) SetupTest() { s.HstSuite.SetupTest() // VPP proxy - vppContainer := s.GetContainerByName(VppUdpProxyContainerName) - vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus) + vpp, err := s.Containers.VppProxy.newVppInstance(s.Containers.VppProxy.AllocatedCpus) s.AssertNotNil(vpp, fmt.Sprint(err)) - clientInterface := s.GetInterfaceByName(ClientTapInterfaceName) - serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) - s.AssertNil(vpp.Start()) - s.AssertNil(vpp.CreateTap(clientInterface, 1, 1)) - s.AssertNil(vpp.CreateTap(serverInterface, 1, 2)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Client, 1, 1)) + s.AssertNil(vpp.CreateTap(s.Interfaces.Server, 1, 2)) s.proxyPort = 8080 s.serverPort = 80 arp := fmt.Sprintf("set ip neighbor %s %s %s", - serverInterface.Peer.Name(), - serverInterface.Ip4AddressString(), - serverInterface.HwAddress) + s.Interfaces.Server.Peer.Name(), + s.Interfaces.Server.Ip4AddressString(), + s.Interfaces.Server.HwAddress) vpp.Vppctl(arp) if *DryRun { @@ -67,7 +71,7 @@ func (s *VppUdpProxySuite) SetupTest() { } func (s *VppUdpProxySuite) TearDownTest() { - vpp := s.GetContainerByName(VppUdpProxyContainerName).VppInstance + vpp := s.Containers.VppProxy.VppInstance if CurrentSpecReport().Failed() { s.Log(vpp.Vppctl("show session verbose 2")) s.Log(vpp.Vppctl("show error")) @@ -76,7 +80,7 @@ func (s *VppUdpProxySuite) TearDownTest() { } func (s *VppUdpProxySuite) VppProxyAddr() string { - return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString() + return s.Interfaces.Client.Peer.Ip4AddressString() } func (s *VppUdpProxySuite) ProxyPort() int { @@ -84,7 +88,7 @@ func (s *VppUdpProxySuite) ProxyPort() int { } func (s *VppUdpProxySuite) ServerAddr() string { - return s.GetInterfaceByName(ServerTapInterfaceName).Ip4AddressString() + return s.Interfaces.Server.Ip4AddressString() } func (s *VppUdpProxySuite) ServerPort() int { @@ -92,7 +96,7 @@ func (s *VppUdpProxySuite) ServerPort() int { } func (s *VppUdpProxySuite) ClientAddr() string { - return s.GetInterfaceByName(ClientTapInterfaceName).Ip4AddressString() + return s.Interfaces.Client.Ip4AddressString() } func (s *VppUdpProxySuite) StartEchoServer() *net.UDPConn { diff --git a/extras/hs-test/infra/utils.go b/extras/hs-test/infra/utils.go index a7c2f13625e..b690efc32ca 100644 --- a/extras/hs-test/infra/utils.go +++ b/extras/hs-test/infra/utils.go @@ -174,8 +174,7 @@ RunCurlContainer execute curl command with given args. Container with name "curl" must be available. Curl runs in verbose mode and progress meter switch off by default. */ -func (s *HstSuite) RunCurlContainer(args string) (string, string) { - curlCont := s.GetContainerByName("curl") +func (s *HstSuite) RunCurlContainer(curlCont *Container, args string) (string, string) { cmd := fmt.Sprintf("curl -v -s %s", args) s.Log(cmd) curlCont.ExtraRunningArgs = cmd @@ -195,8 +194,7 @@ Nginx logging need to be set following way: where LogPrefix is set to nginxContainer.Name */ -func (s *HstSuite) CollectNginxLogs(containerName string) { - nginxContainer := s.GetContainerByName(containerName) +func (s *HstSuite) CollectNginxLogs(nginxContainer *Container) { targetDir := nginxContainer.Suite.getLogDirPath() source := nginxContainer.GetHostWorkDir() + "/" + nginxContainer.Name + "-" cmd := exec.Command("cp", "-t", targetDir, source+"error.log", source+"access.log") @@ -213,8 +211,7 @@ Envoy access log path need to be set following way: /{{.LogPrefix}}-access.log where LogPrefix is set to envoyContainer.Name */ -func (s *HstSuite) CollectEnvoyLogs(containerName string) { - envoyContainer := s.GetContainerByName(containerName) +func (s *HstSuite) CollectEnvoyLogs(envoyContainer *Container) { targetDir := envoyContainer.Suite.getLogDirPath() source := envoyContainer.GetHostWorkDir() + "/" + envoyContainer.Name + "-" cmd := exec.Command("cp", "-t", targetDir, source+"access.log") diff --git a/extras/hs-test/iperf_linux_test.go b/extras/hs-test/iperf_linux_test.go index 0a59f6a4e0f..ead9cc81e43 100644 --- a/extras/hs-test/iperf_linux_test.go +++ b/extras/hs-test/iperf_linux_test.go @@ -13,10 +13,8 @@ func init() { } func IperfUdpLinuxTest(s *IperfSuite) { - serverContainer := s.GetContainerByName(ServerIperfContainerName) - serverIpAddress := s.GetInterfaceByName(ServerIperfInterfaceName).Ip4AddressString() - clientContainer := s.GetContainerByName(ClientIperfContainerName) - clientIpAddress := s.GetInterfaceByName(ClientIperfInterfaceName).Ip4AddressString() + serverIpAddress := s.Interfaces.Server.Ip4AddressString() + clientIpAddress := s.Interfaces.Client.Ip4AddressString() clnCh := make(chan error) stopServerCh := make(chan struct{}) @@ -30,7 +28,7 @@ func IperfUdpLinuxTest(s *IperfSuite) { go func() { defer GinkgoRecover() cmd := "iperf3 -4 -s -B " + serverIpAddress + " -p " + s.GetPortFromPpid() - s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh) + s.StartServerApp(s.Containers.Server, "iperf3", cmd, srvCh, stopServerCh) }() err := <-srvCh s.AssertNil(err, fmt.Sprint(err)) @@ -40,7 +38,7 @@ func IperfUdpLinuxTest(s *IperfSuite) { defer GinkgoRecover() cmd := "iperf3 -c " + serverIpAddress + " -B " + clientIpAddress + " -u -l 1460 -b 10g -J -p " + s.GetPortFromPpid() - s.StartClientApp(clientContainer, cmd, clnCh, clnRes) + s.StartClientApp(s.Containers.Client, cmd, clnCh, clnRes) }() s.AssertChannelClosed(time.Minute*3, clnCh) output := <-clnRes diff --git a/extras/hs-test/ldp_test.go b/extras/hs-test/ldp_test.go index 585f4981681..590c7c3826d 100644 --- a/extras/hs-test/ldp_test.go +++ b/extras/hs-test/ldp_test.go @@ -17,7 +17,7 @@ func LdpIperfUdpVppInterruptModeTest(s *LdpSuite) { } func LdpIperfTlsTcpTest(s *LdpSuite) { - for _, c := range s.Containers { + for _, c := range s.StartedContainers { defer delete(c.EnvVars, "LDP_TRANSPARENT_TLS") defer delete(c.EnvVars, "LDP_TLS_CERT_FILE") defer delete(c.EnvVars, "LDP_TLS_KEY_FILE") @@ -42,9 +42,7 @@ func ldPreloadIperfVpp(s *LdpSuite, useUdp bool) { if useUdp { protocol = " -u " } - clientContainer := s.GetContainerByName("client-vpp") - serverContainer := s.GetContainerByName("server-vpp") - serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() stopServerCh := make(chan struct{}, 1) srvCh := make(chan error, 1) clnCh := make(chan error) @@ -57,7 +55,7 @@ func ldPreloadIperfVpp(s *LdpSuite, useUdp bool) { go func() { defer GinkgoRecover() cmd := "iperf3 -4 -s -p " + s.GetPortFromPpid() - s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh) + s.StartServerApp(s.Containers.ServerVpp, "iperf3", cmd, srvCh, stopServerCh) }() err := <-srvCh @@ -66,7 +64,7 @@ func ldPreloadIperfVpp(s *LdpSuite, useUdp bool) { go func() { defer GinkgoRecover() cmd := "iperf3 -c " + serverVethAddress + " -l 1460 -b 10g -J -p " + s.GetPortFromPpid() + protocol - s.StartClientApp(clientContainer, cmd, clnCh, clnRes) + s.StartClientApp(s.Containers.ClientVpp, cmd, clnCh, clnRes) }() s.AssertChannelClosed(time.Minute*3, clnCh) @@ -80,10 +78,7 @@ func RedisBenchmarkTest(s *LdpSuite) { s.SkipIfMultiWorker() s.SkipIfArm() - serverContainer := s.GetContainerByName("server-vpp") - clientContainer := s.GetContainerByName("client-vpp") - - serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() runningSrv := make(chan error) doneSrv := make(chan struct{}) clnCh := make(chan error) @@ -96,7 +91,7 @@ func RedisBenchmarkTest(s *LdpSuite) { go func() { defer GinkgoRecover() cmd := "redis-server --daemonize yes --protected-mode no --bind " + serverVethAddress - s.StartServerApp(serverContainer, "redis-server", cmd, runningSrv, doneSrv) + s.StartServerApp(s.Containers.ServerVpp, "redis-server", cmd, runningSrv, doneSrv) }() err := <-runningSrv @@ -110,7 +105,7 @@ func RedisBenchmarkTest(s *LdpSuite) { } else { cmd = "redis-benchmark --threads " + fmt.Sprint(*NConfiguredCpus) + "-h " + serverVethAddress } - s.StartClientApp(clientContainer, cmd, clnCh, clnRes) + s.StartClientApp(s.Containers.ClientVpp, cmd, clnCh, clnRes) }() diff --git a/extras/hs-test/mem_leak_test.go b/extras/hs-test/mem_leak_test.go index 0d8831d2bbc..75520529392 100644 --- a/extras/hs-test/mem_leak_test.go +++ b/extras/hs-test/mem_leak_test.go @@ -12,7 +12,7 @@ func init() { func MemLeakTest(s *NoTopoSuite) { s.SkipUnlessLeakCheck() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance /* no goVPP less noise */ vpp.Disconnect() vpp.EnableMemoryTrace() diff --git a/extras/hs-test/nginx_test.go b/extras/hs-test/nginx_test.go index 7a6f5b3c182..12aa2487c2d 100644 --- a/extras/hs-test/nginx_test.go +++ b/extras/hs-test/nginx_test.go @@ -17,22 +17,20 @@ func init() { func NginxHttp3Test(s *NoTopoSuite) { query := "index.html" - nginxCont := s.GetContainerByName(NginxHttp3ContainerName) - nginxCont.Create() - s.CreateNginxHttp3Config(nginxCont) - nginxCont.Start() + s.Containers.NginxHttp3.Create() + s.CreateNginxHttp3Config(s.Containers.NginxHttp3) + s.Containers.NginxHttp3.Start() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.WaitForApp("nginx-", 5) serverAddress := s.VppAddr() defer func() { os.Remove(query) }() - curlCont := s.GetContainerByName("curl") args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query) - curlCont.ExtraRunningArgs = args - curlCont.Run() - body, stats := curlCont.GetOutput() + s.Containers.Curl.ExtraRunningArgs = args + s.Containers.Curl.Run() + body, stats := s.Containers.Curl.GetOutput() s.Log(body) s.Log(stats) s.AssertNotContains(stats, "refused") @@ -44,13 +42,12 @@ func NginxAsServerTest(s *NoTopoSuite) { query := "return_ok" finished := make(chan error, 1) - nginxCont := s.GetContainerByName("nginx") - nginxCont.Create() - s.CreateNginxConfig(nginxCont, false) + s.Containers.Nginx.Create() + s.CreateNginxConfig(s.Containers.Nginx, false) s.AddNginxVclConfig(false) - nginxCont.Start() + s.Containers.Nginx.Start() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance vpp.WaitForApp("nginx-", 5) serverAddress := s.VppAddr() @@ -79,17 +76,15 @@ func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string, multiThreadWorkers boo serverAddress := s.VppAddr() - vpp := s.GetContainerByName("vpp").VppInstance + vpp := s.Containers.Vpp.VppInstance - nginxCont := s.GetContainerByName(SingleTopoContainerNginx) - nginxCont.Create() + s.Containers.Nginx.Create() s.AddNginxVclConfig(multiThreadWorkers) - s.CreateNginxConfig(nginxCont, multiThreadWorkers) - nginxCont.Start() + s.CreateNginxConfig(s.Containers.Nginx, multiThreadWorkers) + s.Containers.Nginx.Start() vpp.WaitForApp("nginx-", 5) if ab_or_wrk == "ab" { - abCont := s.GetContainerByName("ab") args := fmt.Sprintf("-n %d -c %d", nRequests, nClients) if mode == "rps" { args += " -k" @@ -99,21 +94,20 @@ func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string, multiThreadWorkers boo // don't exit on socket receive errors args += " -r" args += " http://" + serverAddress + ":80/64B.json" - abCont.ExtraRunningArgs = args + s.Containers.Ab.ExtraRunningArgs = args s.Log("Test might take up to 2 minutes to finish. Please wait") - abCont.Run() - o, err := abCont.GetOutput() + s.Containers.Ab.Run() + o, err := s.Containers.Ab.GetOutput() rps := parseString(o, "Requests per second:") s.Log(rps) s.AssertContains(err, "Finished "+fmt.Sprint(nRequests)) } else { - wrkCont := s.GetContainerByName("wrk") args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients, serverAddress) - wrkCont.ExtraRunningArgs = args - wrkCont.Run() + s.Containers.Wrk.ExtraRunningArgs = args + s.Containers.Wrk.Run() s.Log("Please wait for 30s, test is running.") - o, err := wrkCont.GetOutput() + o, err := s.Containers.Wrk.GetOutput() rps := parseString(o, "requests") s.Log(rps) s.Log(err) diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go index a7f83ab7430..0d1aa3b83cd 100644 --- a/extras/hs-test/proxy_test.go +++ b/extras/hs-test/proxy_test.go @@ -20,7 +20,7 @@ func init() { } func configureVppProxy(s *VppProxySuite, proto string, proxyPort uint16) { - vppProxy := s.GetContainerByName(VppProxyContainerName).VppInstance + vppProxy := s.Containers.VppProxy.VppInstance cmd := fmt.Sprintf("test proxy server fifo-size 512k server-uri %s://%s/%d", proto, s.VppProxyAddr(), proxyPort) if proto != "http" && proto != "udp" { proto = "tcp" @@ -46,23 +46,19 @@ func VppProxyUdpIperfMTTest(s *VppProxySuite) { } func vppProxyIperfMTTest(s *VppProxySuite, proto string) { - iperfServer := s.GetContainerByName(IperfServerContainerName) - iperfClient := s.GetContainerByName(IperfClientContainerName) - iperfServer.Run() - iperfClient.Run() - serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) - clientInterface := s.GetInterfaceByName(ClientTapInterfaceName) - vppProxy := s.GetContainerByName(VppProxyContainerName).VppInstance + s.Containers.IperfC.Run() + s.Containers.IperfS.Run() + vppProxy := s.Containers.VppProxy.VppInstance proxyPort, err := strconv.Atoi(s.GetPortFromPpid()) s.AssertNil(err) // tap interfaces are created on test setup with 1 rx-queue, // need to recreate them with 2 + consistent-qp - s.AssertNil(vppProxy.DeleteTap(serverInterface)) - s.AssertNil(vppProxy.CreateTap(serverInterface, 2, uint32(serverInterface.Peer.Index), Consistent_qp)) + s.AssertNil(vppProxy.DeleteTap(s.Interfaces.Server)) + s.AssertNil(vppProxy.CreateTap(s.Interfaces.Server, 2, uint32(s.Interfaces.Server.Peer.Index), Consistent_qp)) - s.AssertNil(vppProxy.DeleteTap(clientInterface)) - s.AssertNil(vppProxy.CreateTap(clientInterface, 2, uint32(clientInterface.Peer.Index), Consistent_qp)) + s.AssertNil(vppProxy.DeleteTap(s.Interfaces.Client)) + s.AssertNil(vppProxy.CreateTap(s.Interfaces.Client, 2, uint32(s.Interfaces.Client.Peer.Index), Consistent_qp)) configureVppProxy(s, "tcp", uint16(proxyPort)) if proto == "udp" { @@ -84,7 +80,7 @@ func vppProxyIperfMTTest(s *VppProxySuite, proto string) { go func() { defer GinkgoRecover() cmd := fmt.Sprintf("iperf3 -4 -s -B %s -p %s", s.ServerAddr(), fmt.Sprint(s.ServerPort())) - s.StartServerApp(iperfServer, "iperf3", cmd, srvCh, stopServerCh) + s.StartServerApp(s.Containers.IperfS, "iperf3", cmd, srvCh, stopServerCh) }() err = <-srvCh @@ -93,7 +89,7 @@ func vppProxyIperfMTTest(s *VppProxySuite, proto string) { go func() { defer GinkgoRecover() cmd := fmt.Sprintf("iperf3 -c %s -P 4 -l 1460 -b 10g -J -p %d -B %s %s", s.VppProxyAddr(), proxyPort, s.ClientAddr(), proto) - s.StartClientApp(iperfClient, cmd, clnCh, clnRes) + s.StartClientApp(s.Containers.IperfC, cmd, clnCh, clnRes) }() s.AssertChannelClosed(time.Minute*4, clnCh) @@ -157,12 +153,11 @@ func NginxMirroringTest(s *NginxProxySuite) { } func nginxMirroring(s *NginxProxySuite, multiThreadWorkers bool) { - nginxProxyContainer := s.GetContainerByName(NginxProxyContainerName) - vpp := s.GetContainerByName(VppContainerName).VppInstance + vpp := s.Containers.Vpp.VppInstance - s.AddVclConfig(nginxProxyContainer, multiThreadWorkers) - s.CreateNginxProxyConfig(nginxProxyContainer, multiThreadWorkers) - nginxProxyContainer.Start() + s.AddVclConfig(s.Containers.NginxProxy, multiThreadWorkers) + s.CreateNginxProxyConfig(s.Containers.NginxProxy, multiThreadWorkers) + s.Containers.NginxProxy.Start() vpp.WaitForApp("nginx-", 5) uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort()) s.CurlDownloadResource(uri) @@ -192,7 +187,7 @@ func VppProxyUdpTest(s *VppUdpProxySuite) { remoteServerConn := s.StartEchoServer() defer remoteServerConn.Close() - vppProxy := s.GetContainerByName(VppUdpProxyContainerName).VppInstance + vppProxy := s.Containers.VppProxy.VppInstance cmd := fmt.Sprintf("test proxy server fifo-size 512k server-uri udp://%s/%d", s.VppProxyAddr(), s.ProxyPort()) cmd += fmt.Sprintf(" client-uri udp://%s/%d", s.ServerAddr(), s.ServerPort()) s.Log(vppProxy.Vppctl(cmd)) diff --git a/extras/hs-test/raw_session_test.go b/extras/hs-test/raw_session_test.go index 822ee5c68e3..cbf85a54530 100644 --- a/extras/hs-test/raw_session_test.go +++ b/extras/hs-test/raw_session_test.go @@ -20,23 +20,20 @@ func VppEchoTcpTest(s *VethsSuite) { } func testVppEcho(s *VethsSuite, proto string) { - serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() uri := proto + "://" + serverVethAddress + "/12344" - echoSrvContainer := s.GetContainerByName("server-app") serverCommand := "vpp_echo server TX=RX" + - " socket-name " + echoSrvContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/default" + + " socket-name " + s.Containers.ServerApp.GetContainerWorkDir() + "/var/run/app_ns_sockets/default" + " use-app-socket-api" + " uri " + uri s.Log(serverCommand) - echoSrvContainer.ExecServer(true, serverCommand) - - echoClnContainer := s.GetContainerByName("client-app") + s.Containers.ServerApp.ExecServer(true, serverCommand) clientCommand := "vpp_echo client" + - " socket-name " + echoClnContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/default" + + " socket-name " + s.Containers.ClientApp.GetContainerWorkDir() + "/var/run/app_ns_sockets/default" + " use-app-socket-api uri " + uri s.Log(clientCommand) - o := echoClnContainer.Exec(true, clientCommand) + o := s.Containers.ClientApp.Exec(true, clientCommand) s.Log(o) } diff --git a/extras/hs-test/topo-containers/vppProxy.yaml b/extras/hs-test/topo-containers/vppProxy.yaml index 73a02b0031b..557d65d644a 100644 --- a/extras/hs-test/topo-containers/vppProxy.yaml +++ b/extras/hs-test/topo-containers/vppProxy.yaml @@ -9,13 +9,13 @@ containers: - <<: *shared-vol container-dir: "/tmp/vpp" is-default-work-dir: true - - name: "iperfB" + - name: "iperfC" volumes: - <<: *shared-vol container-dir: "/tmp/vpp" is-default-work-dir: true is-optional: true - - name: "iperfA" + - name: "iperfS" volumes: - <<: *shared-vol container-dir: "/tmp/vpp" diff --git a/extras/hs-test/vcl_test.go b/extras/hs-test/vcl_test.go index 68ca9d02097..11e2be1258e 100644 --- a/extras/hs-test/vcl_test.go +++ b/extras/hs-test/vcl_test.go @@ -40,15 +40,14 @@ func XEchoVclClientTcpTest(s *VethsSuite) { func testXEchoVclClient(s *VethsSuite, proto string) { port := "12345" - serverVpp := s.GetContainerByName("server-vpp").VppInstance + serverVpp := s.Containers.ServerVpp.VppInstance - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.Ip4AddressString(), port) + serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, s.Interfaces.Server.Ip4AddressString(), port) echoClnContainer := s.GetTransientContainerByName("client-app") echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer)) - testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.Ip4AddressString() + " " + port + testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + s.Interfaces.Server.Ip4AddressString() + " " + port s.Log(testClientCommand) echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf") o := echoClnContainer.Exec(true, testClientCommand) @@ -66,18 +65,17 @@ func XEchoVclServerTcpTest(s *VethsSuite) { func testXEchoVclServer(s *VethsSuite, proto string) { port := "12345" - srvVppCont := s.GetContainerByName("server-vpp") - srvAppCont := s.GetContainerByName("server-app") + srvVppCont := s.Containers.ServerVpp + srvAppCont := s.Containers.ServerApp srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont)) srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf") vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port) srvAppCont.ExecServer(true, vclSrvCmd) - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - serverVethAddress := serverVeth.Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() - clientVpp := s.GetContainerByName("client-vpp").VppInstance + clientVpp := s.Containers.ClientVpp.VppInstance o := clientVpp.Vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port) s.Log(o) s.AssertContains(o, "Test finished at") @@ -85,15 +83,14 @@ func testXEchoVclServer(s *VethsSuite, proto string) { func testVclEcho(s *VethsSuite, proto string) { port := "12345" - srvVppCont := s.GetContainerByName("server-vpp") - srvAppCont := s.GetContainerByName("server-app") + srvVppCont := s.Containers.ServerVpp + srvAppCont := s.Containers.ServerApp srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont)) srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf") srvAppCont.ExecServer(true, "vcl_test_server -p "+proto+" "+port) - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - serverVethAddress := serverVeth.Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() echoClnContainer := s.GetTransientContainerByName("client-app") echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer)) @@ -123,7 +120,7 @@ func VclRetryAttachTest(s *VethsSuite) { func testRetryAttach(s *VethsSuite, proto string) { srvVppContainer := s.GetTransientContainerByName("server-vpp") - echoSrvContainer := s.GetContainerByName("server-app") + echoSrvContainer := s.Containers.ServerApp echoSrvContainer.CreateFile("/vcl.conf", getVclConfig(echoSrvContainer)) @@ -133,8 +130,7 @@ func testRetryAttach(s *VethsSuite, proto string) { 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.") - serverVeth := s.GetInterfaceByName(ServerInterfaceName) - serverVethAddress := serverVeth.Ip4AddressString() + serverVethAddress := s.Interfaces.Server.Ip4AddressString() echoClnContainer := s.GetTransientContainerByName("client-app") echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))