From 2474f132fdb123f2874a41595c5edd14826c95d3 Mon Sep 17 00:00:00 2001 From: Adrian Villin Date: Mon, 2 Jun 2025 12:12:03 +0200 Subject: [PATCH] hs-test: fix incorrect volume mounts - shortened volume names to avoid hitting unix socket character limit - volume paths are updated upon container creation Type: fix Change-Id: I601060a902cbba930c324653a600a98c603986c2 Signed-off-by: Adrian Villin --- extras/hs-test/http_test.go | 2 +- extras/hs-test/infra/common/suite_common.go | 2 +- extras/hs-test/infra/container.go | 54 +++++++++++++++------- extras/hs-test/infra/hst_suite.go | 12 +---- extras/hs-test/infra/suite_envoy_proxy.go | 1 + extras/hs-test/proxy_test.go | 6 +-- extras/hs-test/topo-containers/2peerVeth.yaml | 8 ++-- extras/hs-test/topo-containers/envoyProxy.yaml | 2 +- extras/hs-test/topo-containers/nginxProxy.yaml | 2 +- extras/hs-test/topo-containers/single.yaml | 2 +- .../hs-test/topo-containers/singleCpuPinning.yaml | 2 +- extras/hs-test/topo-containers/vppProxy.yaml | 2 +- 12 files changed, 53 insertions(+), 42 deletions(-) diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index e572826a19d..bbc14ed1112 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -585,7 +585,6 @@ func HttpClientPostRepeatTest(s *NoTopoSuite) { func httpClientRepeat(s *NoTopoSuite, requestMethod string, clientArgs string) { vpp := s.Containers.Vpp.VppInstance - logPath := s.Containers.NginxServer.GetContainerWorkDir() + "/" + s.Containers.NginxServer.Name + "-access.log" serverAddress := s.Interfaces.Tap.Ip4AddressString() + ":" + s.Ports.NginxServer replyCountInt := 0 repeatAmount := 10000 @@ -598,6 +597,7 @@ func httpClientRepeat(s *NoTopoSuite, requestMethod string, clientArgs string) { s.CreateNginxServer() s.AssertNil(s.Containers.NginxServer.Start()) + logPath := s.Containers.NginxServer.GetContainerWorkDir() + "/" + s.Containers.NginxServer.Name + "-access.log" if requestMethod == "post" { fileName := "/tmp/test_file.txt" diff --git a/extras/hs-test/infra/common/suite_common.go b/extras/hs-test/infra/common/suite_common.go index 32fa02b41cf..c15b0168059 100644 --- a/extras/hs-test/infra/common/suite_common.go +++ b/extras/hs-test/infra/common/suite_common.go @@ -29,7 +29,7 @@ var RunningInCi bool const ( LogDir string = "/tmp/hs-test/" - VolumeDir string = "/volumes" + VolumeDir string = "/vol" ) type HstCommon struct { diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go index 5bb8040005e..0426516ae1c 100644 --- a/extras/hs-test/infra/container.go +++ b/extras/hs-test/infra/container.go @@ -47,6 +47,7 @@ type Container struct { VppInstance *VppInstance AllocatedCpus []int ctx context.Context + volumeYamlConf []any } func newContainer(suite *HstSuite, yamlInput ContainerConfig) (*Container, error) { @@ -88,21 +89,7 @@ func newContainer(suite *HstSuite, yamlInput ContainerConfig) (*Container, error } if _, ok := yamlInput["volumes"]; ok { - workingVolumeDir := LogDir + suite.GetCurrentTestName() + VolumeDir - workDirReplacer := strings.NewReplacer("$HST_DIR", workDir) - volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir) - for _, volu := range yamlInput["volumes"].([]interface{}) { - volumeMap := volu.(ContainerConfig) - hostDir := workDirReplacer.Replace(volumeMap["host-dir"].(string)) - hostDir = volDirReplacer.Replace(hostDir) - containerDir := volumeMap["container-dir"].(string) - isDefaultWorkDir := false - - if isDefault, ok := volumeMap["is-default-work-dir"]; ok { - isDefaultWorkDir = isDefault.(bool) - } - container.addVolume(hostDir, containerDir, isDefaultWorkDir) - } + container.volumeYamlConf = yamlInput["volumes"].([]any) } if _, ok := yamlInput["vars"]; ok { @@ -162,6 +149,8 @@ func (c *Container) PullDockerImage(name string, ctx context.Context) { // Creates a container func (c *Container) Create() error { + c.createVolumePaths() + var sliceOfImageNames []string images, err := c.Suite.Docker.ImageList(c.ctx, image.ListOptions{}) c.Suite.AssertNil(err) @@ -310,12 +299,36 @@ func (c *Container) Run() { c.Suite.AssertNil(c.Start()) } +func (c *Container) createVolumePaths() { + workingVolumeDir := LogDir + c.Suite.GetCurrentTestName() + VolumeDir + workDirReplacer := strings.NewReplacer("$HST_DIR", workDir) + volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir) + + for _, volu := range c.volumeYamlConf { + volumeMap := volu.(ContainerConfig) + hostDir := workDirReplacer.Replace(volumeMap["host-dir"].(string)) + hostDir = volDirReplacer.Replace(hostDir) + containerDir := volumeMap["container-dir"].(string) + isDefaultWorkDir := false + + if isDefault, ok := volumeMap["is-default-work-dir"]; ok { + isDefaultWorkDir = isDefault.(bool) + } + c.addVolume(hostDir, containerDir, isDefaultWorkDir) + } +} + func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) { var volume Volume - volume.HostDir = strings.Replace(hostDir, "volumes", c.Suite.GetTestId()+"/"+"volumes", 1) + volume.HostDir = strings.Replace(hostDir, "vol", c.Suite.GetTestId()+"/"+"vol", 1) volume.ContainerDir = containerDir volume.IsDefaultWorkDir = isDefaultWorkDir c.Volumes[hostDir] = volume + if volume.IsDefaultWorkDir && len(volume.HostDir)+len(defaultApiSocketFilePath) > 108 { + c.Suite.Log("**************************************************************\n" + + "Default api socket file path exceeds 108 bytes. Test may fail.\n" + + "**************************************************************") + } } func (c *Container) getVolumesAsSlice() []string { @@ -542,6 +555,13 @@ func (c *Container) stop() error { if err := c.Suite.Docker.ContainerStop(c.ctx, c.ID, containerTypes.StopOptions{Timeout: &timeout}); err != nil { return err } + + for n, v := range c.Volumes { + if v.IsDefaultWorkDir { + delete(c.Volumes, n) + } + } + return nil } @@ -558,7 +578,7 @@ func (c *Container) CreateConfigFromTemplate(targetConfigName string, templateNa err = f.Close() c.Suite.AssertNil(err, err) - c.copy(f.Name(), targetConfigName) + c.Suite.AssertNil(c.copy(f.Name(), targetConfigName)) } func init() { diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go index 6190e444d8e..4e822723a37 100644 --- a/extras/hs-test/infra/hst_suite.go +++ b/extras/hs-test/infra/hst_suite.go @@ -39,7 +39,6 @@ type HstSuite struct { HstCommon AllContainers map[string]*Container StartedContainers []*Container - Volumes []string NetConfigs []NetConfig NetInterfaces map[string]*NetInterface Ip4AddrAllocator *Ip4AddressAllocator @@ -424,15 +423,6 @@ func (s *HstSuite) LoadContainerTopology(topologyName string) { Fail("unmarshal error: " + fmt.Sprint(err)) } - for _, elem := range yamlTopo.Volumes { - volumeMap := elem["volume"].(VolumeConfig) - hostDir := volumeMap["host-dir"].(string) - workingVolumeDir := LogDir + s.GetCurrentTestName() + VolumeDir - volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir) - hostDir = volDirReplacer.Replace(hostDir) - s.Volumes = append(s.Volumes, hostDir) - } - s.AllContainers = make(map[string]*Container) for _, elem := range yamlTopo.Containers { newContainer, err := newContainer(s, elem) @@ -573,7 +563,7 @@ func (s *HstSuite) GetTestId() string { } if _, ok := s.TestIds[testName]; !ok { - s.TestIds[testName] = time.Now().Format("2006-01-02_15-04-05") + s.TestIds[testName] = time.Now().Format("060102_150405") } return s.TestIds[testName] diff --git a/extras/hs-test/infra/suite_envoy_proxy.go b/extras/hs-test/infra/suite_envoy_proxy.go index 2d184270b84..aac4588e029 100644 --- a/extras/hs-test/infra/suite_envoy_proxy.go +++ b/extras/hs-test/infra/suite_envoy_proxy.go @@ -65,6 +65,7 @@ func (s *EnvoyProxySuite) SetupSuite() { s.Containers.Curl = s.GetContainerByName("curl") s.Ports.Nginx = s.GeneratePortAsInt() s.Ports.Proxy = s.GeneratePortAsInt() + s.Ports.EnvoyAdmin = s.GeneratePortAsInt() } func (s *EnvoyProxySuite) SetupTest() { diff --git a/extras/hs-test/proxy_test.go b/extras/hs-test/proxy_test.go index 9e107b5127e..875d79f7577 100644 --- a/extras/hs-test/proxy_test.go +++ b/extras/hs-test/proxy_test.go @@ -28,7 +28,7 @@ func init() { RegisterVppUdpProxyTests(VppProxyUdpTest, VppConnectUdpProxyTest, VppConnectUdpInvalidCapsuleTest, VppConnectUdpUnknownCapsuleTest, VppConnectUdpClientCloseTest, VppConnectUdpInvalidTargetTest) RegisterVppUdpProxySoloTests(VppProxyUdpMigrationMTTest, VppConnectUdpStressMTTest, VppConnectUdpStressTest) - RegisterEnvoyProxyTests(EnvoyProxyHttpGetTcpTest, EnvoyProxyHttpPutTcpTest) + RegisterEnvoyProxyTests(EnvoyHttpGetTcpTest, EnvoyHttpPutTcpTest) RegisterNginxProxySoloTests(NginxMirroringTest, MirrorMultiThreadTest) } @@ -141,12 +141,12 @@ func VppProxyHttpPutTlsTest(s *VppProxySuite) { s.CurlUploadResource(uri, CurlContainerTestFile) } -func EnvoyProxyHttpGetTcpTest(s *EnvoyProxySuite) { +func EnvoyHttpGetTcpTest(s *EnvoyProxySuite) { uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.Ports.Proxy) s.CurlDownloadResource(uri) } -func EnvoyProxyHttpPutTcpTest(s *EnvoyProxySuite) { +func EnvoyHttpPutTcpTest(s *EnvoyProxySuite) { uri := fmt.Sprintf("http://%s:%d/upload/testFile", s.ProxyAddr(), s.Ports.Proxy) s.CurlUploadResource(uri, CurlContainerTestFile) } diff --git a/extras/hs-test/topo-containers/2peerVeth.yaml b/extras/hs-test/topo-containers/2peerVeth.yaml index e1591fb9019..790739bd3ca 100644 --- a/extras/hs-test/topo-containers/2peerVeth.yaml +++ b/extras/hs-test/topo-containers/2peerVeth.yaml @@ -1,12 +1,12 @@ --- volumes: - volume: &server-vol - host-dir: "$HST_VOLUME_DIR/server-share" - container-dir: "/tmp/server-share" + host-dir: "$HST_VOLUME_DIR/server" + container-dir: "/tmp/server" is-default-work-dir: true - volume: &client-vol - host-dir: "$HST_VOLUME_DIR/client-share" - container-dir: "/tmp/client-share" + host-dir: "$HST_VOLUME_DIR/client" + container-dir: "/tmp/client" is-default-work-dir: true containers: diff --git a/extras/hs-test/topo-containers/envoyProxy.yaml b/extras/hs-test/topo-containers/envoyProxy.yaml index cbb00d868db..cb2d673b788 100644 --- a/extras/hs-test/topo-containers/envoyProxy.yaml +++ b/extras/hs-test/topo-containers/envoyProxy.yaml @@ -1,7 +1,7 @@ --- volumes: - volume: &shared-vol - host-dir: "$HST_VOLUME_DIR/shared-vol" + host-dir: "$HST_VOLUME_DIR/shared" containers: - name: "vpp" diff --git a/extras/hs-test/topo-containers/nginxProxy.yaml b/extras/hs-test/topo-containers/nginxProxy.yaml index d9ddc14590f..52901865782 100644 --- a/extras/hs-test/topo-containers/nginxProxy.yaml +++ b/extras/hs-test/topo-containers/nginxProxy.yaml @@ -1,7 +1,7 @@ --- volumes: - volume: &shared-vol-nginx-proxy - host-dir: "$HST_VOLUME_DIR/shared-vol-nginx-proxy" + host-dir: "$HST_VOLUME_DIR/shared" containers: - name: "vpp" diff --git a/extras/hs-test/topo-containers/single.yaml b/extras/hs-test/topo-containers/single.yaml index 7b2f91ebc76..d1f43ad07b4 100644 --- a/extras/hs-test/topo-containers/single.yaml +++ b/extras/hs-test/topo-containers/single.yaml @@ -1,7 +1,7 @@ --- volumes: - volume: &shared-vol - host-dir: "$HST_VOLUME_DIR/shared-vol" + host-dir: "$HST_VOLUME_DIR/shared" containers: - name: "vpp" diff --git a/extras/hs-test/topo-containers/singleCpuPinning.yaml b/extras/hs-test/topo-containers/singleCpuPinning.yaml index 6e673aa85bf..0a41ac84698 100644 --- a/extras/hs-test/topo-containers/singleCpuPinning.yaml +++ b/extras/hs-test/topo-containers/singleCpuPinning.yaml @@ -1,7 +1,7 @@ --- volumes: - volume: &shared-vol - host-dir: "$HST_VOLUME_DIR/shared-vol" + host-dir: "$HST_VOLUME_DIR/shared" containers: - name: "vpp" diff --git a/extras/hs-test/topo-containers/vppProxy.yaml b/extras/hs-test/topo-containers/vppProxy.yaml index 557d65d644a..5f0248027a1 100644 --- a/extras/hs-test/topo-containers/vppProxy.yaml +++ b/extras/hs-test/topo-containers/vppProxy.yaml @@ -1,7 +1,7 @@ --- volumes: - volume: &shared-vol - host-dir: "$HST_VOLUME_DIR/shared-vol" + host-dir: "$HST_VOLUME_DIR/shared" containers: - name: "vpp-proxy" -- 2.16.6