From 8792e5c5c5e8e4f6c514ff81c97a7fb31890d657 Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Wed, 14 Aug 2024 12:38:20 +0200 Subject: 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 --- extras/hs-test/infra/suite_vpp_proxy.go | 179 ++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 extras/hs-test/infra/suite_vpp_proxy.go (limited to 'extras/hs-test/infra/suite_vpp_proxy.go') diff --git a/extras/hs-test/infra/suite_vpp_proxy.go b/extras/hs-test/infra/suite_vpp_proxy.go new file mode 100644 index 00000000000..bfe7de7f54b --- /dev/null +++ b/extras/hs-test/infra/suite_vpp_proxy.go @@ -0,0 +1,179 @@ +// Suite for VPP proxy testing +// +// The topology consists of 3 containers: curl (client), VPP (proxy), nginx (target HTTP server). +// VPP has 2 tap interfaces configured, one for client network and second for server/target network. + +package hst + +import ( + "fmt" + . "github.com/onsi/ginkgo/v2" + "reflect" + "runtime" + "strings" +) + +// These correspond to names used in yaml config +const ( + ClientTapInterfaceName = "hstcln" + ServerTapInterfaceName = "hstsrv" +) + +type VppProxySuite struct { + HstSuite + nginxPort uint16 +} + +var vppProxyTests = map[string][]func(s *VppProxySuite){} +var vppProxySoloTests = map[string][]func(s *VppProxySuite){} + +func RegisterVppProxyTests(tests ...func(s *VppProxySuite)) { + vppProxyTests[getTestFilename()] = tests +} + +func RegisterVppProxySoloTests(tests ...func(s *VppProxySuite)) { + vppProxySoloTests[getTestFilename()] = tests +} + +func (s *VppProxySuite) SetupSuite() { + s.HstSuite.SetupSuite() + s.LoadNetworkTopology("2taps") + s.LoadContainerTopology("vppProxy") +} + +func (s *VppProxySuite) SetupTest() { + s.HstSuite.SetupTest() + + // VPP HTTP connect-proxy + vppContainer := s.GetContainerByName(VppProxyContainerName) + vpp, err := vppContainer.newVppInstance(vppContainer.AllocatedCpus) + s.AssertNotNil(vpp, fmt.Sprint(err)) + s.AssertNil(vpp.Start()) + clientInterface := s.GetInterfaceByName(ClientTapInterfaceName) + s.AssertNil(vpp.createTap(clientInterface, 1)) + serverInterface := s.GetInterfaceByName(ServerTapInterfaceName) + s.AssertNil(vpp.createTap(serverInterface, 2)) + + // nginx HTTP server + nginxContainer := s.GetTransientContainerByName(NginxServerContainerName) + s.AssertNil(nginxContainer.Create()) + s.nginxPort = 80 + nginxSettings := struct { + LogPrefix string + Address string + Port uint16 + }{ + LogPrefix: nginxContainer.Name, + Address: serverInterface.Ip4AddressString(), + Port: s.nginxPort, + } + nginxContainer.CreateConfig( + "/nginx.conf", + "./resources/nginx/nginx_server.conf", + nginxSettings, + ) + s.AssertNil(nginxContainer.Start()) +} + +func (s *VppProxySuite) TearDownTest() { + if CurrentSpecReport().Failed() { + s.CollectNginxLogs(NginxServerContainerName) + } + s.HstSuite.TearDownTest() +} + +func (s *VppProxySuite) NginxPort() uint16 { + return s.nginxPort +} + +func (s *VppProxySuite) NginxAddr() string { + return s.GetInterfaceByName(ServerTapInterfaceName).Ip4AddressString() +} + +func (s *VppProxySuite) VppProxyAddr() string { + return s.GetInterfaceByName(ClientTapInterfaceName).Peer.Ip4AddressString() +} + +func (s *VppProxySuite) CurlRequest(targetUri string) (string, string) { + args := fmt.Sprintf("--insecure --noproxy '*' %s", targetUri) + body, log := s.RunCurlContainer(args) + return body, log +} + +func (s *VppProxySuite) CurlRequestViaTunnel(targetUri string, proxyUri string) (string, string) { + args := fmt.Sprintf("--insecure -p -x %s %s", proxyUri, targetUri) + body, log := s.RunCurlContainer(args) + return body, log +} + +func (s *VppProxySuite) CurlDownloadResource(uri string) { + args := fmt.Sprintf("--insecure --noproxy '*' --remote-name --output-dir /tmp %s", uri) + _, log := s.RunCurlContainer(args) + s.AssertNotContains(log, "Recv failure") + s.AssertContains(log, "HTTP/1.1 200") +} + +func (s *VppProxySuite) CurlDownloadResourceViaTunnel(uri string, proxyUri string) { + args := fmt.Sprintf("--insecure -p -x %s --remote-name --output-dir /tmp %s", proxyUri, uri) + _, log := s.RunCurlContainer(args) + s.AssertNotContains(log, "Recv failure") + s.AssertContains(log, "HTTP/1.1 200") +} + +var _ = Describe("VppProxySuite", Ordered, ContinueOnFailure, func() { + var s VppProxySuite + BeforeAll(func() { + s.SetupSuite() + }) + BeforeEach(func() { + s.SetupTest() + }) + AfterAll(func() { + s.TearDownSuite() + }) + AfterEach(func() { + s.TearDownTest() + }) + + for filename, tests := range vppProxyTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, func(ctx SpecContext) { + s.Log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(SuiteTimeout)) + } + } +}) + +var _ = Describe("VppProxySuiteSolo", Ordered, ContinueOnFailure, func() { + var s VppProxySuite + BeforeAll(func() { + s.SetupSuite() + }) + BeforeEach(func() { + s.SetupTest() + }) + AfterAll(func() { + s.TearDownSuite() + }) + AfterEach(func() { + s.TearDownTest() + }) + + for filename, tests := range vppProxySoloTests { + for _, test := range tests { + test := test + pc := reflect.ValueOf(test).Pointer() + funcValue := runtime.FuncForPC(pc) + testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2] + It(testName, Label("SOLO"), func(ctx SpecContext) { + s.Log(testName + ": BEGIN") + test(&s) + }, SpecTimeout(SuiteTimeout)) + } + } +}) -- cgit 1.2.3-korg