diff options
author | Matus Fabian <matfabia@cisco.com> | 2024-08-14 12:38:20 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-08-22 03:25:19 +0000 |
commit | 8792e5c5c5e8e4f6c514ff81c97a7fb31890d657 (patch) | |
tree | ebb33de76afe10d080969ee6fc9d543935e1564a /extras/hs-test/proxy_test.go | |
parent | 58cb6ba81833a79a877448aa60d7d68604ad6c4e (diff) |
hs-test: proxy testing improvement
- new container topologies and suites for VPP proxy and Envoy proxy
- removed build docker image since it can't be used with CI cache
builder, container builders are designed to be stateless, they
only preserve build-cache, but not images
Type: test
Change-Id: I93e4d079780d18d6aa3b5ce807adc4707b6f2d9b
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'extras/hs-test/proxy_test.go')
-rw-r--r-- | extras/hs-test/proxy_test.go | 117 |
1 files changed, 23 insertions, 94 deletions
diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go index e646a969214..c09fe56b3bc 100644 --- a/extras/hs-test/proxy_test.go +++ b/extras/hs-test/proxy_test.go @@ -3,112 +3,41 @@ package main import ( . "fd.io/hs-test/infra" "fmt" - "github.com/edwarnicke/exechelper" - . "github.com/onsi/ginkgo/v2" - "os" ) func init() { - RegisterNsTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest, EnvoyProxyHttpTcpTest) + RegisterVppProxyTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest) + RegisterEnvoyProxyTests(EnvoyProxyHttpTcpTest) } -func testProxyHttpTcp(s *NsSuite, proto string) error { - var outputFile string = s.ProcessIndex + "test" + s.Ppid + ".data" - var srcFilePpid string = s.ProcessIndex + "httpTestFile" + s.Ppid - const srcFileNoPpid = "httpTestFile" - const fileSize string = "10M" - stopServer := make(chan struct{}, 1) - serverRunning := make(chan struct{}, 1) - serverNetns := s.GetNetNamespaceByName("srv") - clientNetns := s.GetNetNamespaceByName("cln") - - // create test file - err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFilePpid)) - s.AssertNil(err, "failed to run truncate command: "+fmt.Sprint(err)) - defer func() { os.Remove(srcFilePpid) }() - - s.Log("test file created...") - - go func() { - defer GinkgoRecover() - s.StartHttpServer(serverRunning, stopServer, ":666", serverNetns) - }() - // TODO better error handling and recovery - <-serverRunning - - defer func(chan struct{}) { - stopServer <- struct{}{} - }(stopServer) - - s.Log("http server started...") - - clientVeth := s.GetInterfaceByName(ClientInterface) - c := fmt.Sprintf("ip netns exec %s wget --no-proxy --retry-connrefused"+ - " --retry-on-http-error=503 --tries=10 -O %s ", clientNetns, outputFile) - if proto == "tls" { - c += " --secure-protocol=TLSv1_3 --no-check-certificate https://" - } - c += fmt.Sprintf("%s:555/%s", clientVeth.Ip4AddressString(), srcFileNoPpid) - s.Log(c) - _, err = exechelper.CombinedOutput(c) - - defer func() { os.Remove(outputFile) }() - - s.AssertNil(err, "failed to run wget: '%s', cmd: %s", err, c) - stopServer <- struct{}{} - - s.AssertNil(AssertFileSize(outputFile, srcFilePpid)) - return nil -} - -func configureVppProxy(s *NsSuite, proto string) { - serverVeth := s.GetInterfaceByName(ServerInterface) - clientVeth := s.GetInterfaceByName(ClientInterface) - - testVppProxy := s.GetContainerByName("vpp").VppInstance - output := testVppProxy.Vppctl( - "test proxy server server-uri %s://%s/555 client-uri tcp://%s/666", +func configureVppProxy(s *VppProxySuite, proto string, proxyPort uint16) { + vppProxy := s.GetContainerByName(VppProxyContainerName).VppInstance + output := vppProxy.Vppctl( + "test proxy server server-uri %s://%s/%d client-uri tcp://%s/%d", proto, - clientVeth.Ip4AddressString(), - serverVeth.Peer.Ip4AddressString(), + s.VppProxyAddr(), + proxyPort, + s.NginxAddr(), + s.NginxPort(), ) s.Log("proxy configured: " + output) } -func VppProxyHttpTcpTest(s *NsSuite) { - proto := "tcp" - configureVppProxy(s, proto) - err := testProxyHttpTcp(s, proto) - s.AssertNil(err, fmt.Sprint(err)) +func VppProxyHttpTcpTest(s *VppProxySuite) { + var proxyPort uint16 = 8080 + configureVppProxy(s, "tcp", proxyPort) + uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort) + s.CurlDownloadResource(uri) } -func VppProxyHttpTlsTest(s *NsSuite) { - proto := "tls" - configureVppProxy(s, proto) - err := testProxyHttpTcp(s, proto) - s.AssertNil(err, fmt.Sprint(err)) -} - -func configureEnvoyProxy(s *NsSuite) { - envoyContainer := s.GetContainerByName("envoy") - s.AssertNil(envoyContainer.Create()) - - serverVeth := s.GetInterfaceByName(ServerInterface) - address := struct { - Server string - }{ - Server: serverVeth.Peer.Ip4AddressString(), - } - envoyContainer.CreateConfig( - "/etc/envoy/envoy.yaml", - "resources/envoy/proxy.yaml", - address, - ) - s.AssertNil(envoyContainer.Start()) +func VppProxyHttpTlsTest(s *VppProxySuite) { + var proxyPort uint16 = 8080 + configureVppProxy(s, "tls", proxyPort) + uri := fmt.Sprintf("https://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort) + s.CurlDownloadResource(uri) } -func EnvoyProxyHttpTcpTest(s *NsSuite) { - configureEnvoyProxy(s) - err := testProxyHttpTcp(s, "tcp") - s.AssertNil(err, fmt.Sprint(err)) +func EnvoyProxyHttpTcpTest(s *EnvoyProxySuite) { + uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort()) + s.CurlDownloadResource(uri) } |