hs-test: fix incorrect volume mounts 78/43078/12
authorAdrian Villin <[email protected]>
Mon, 2 Jun 2025 10:12:03 +0000 (12:12 +0200)
committerFlorin Coras <[email protected]>
Wed, 4 Jun 2025 15:45:51 +0000 (15:45 +0000)
- 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 <[email protected]>
12 files changed:
extras/hs-test/http_test.go
extras/hs-test/infra/common/suite_common.go
extras/hs-test/infra/container.go
extras/hs-test/infra/hst_suite.go
extras/hs-test/infra/suite_envoy_proxy.go
extras/hs-test/proxy_test.go
extras/hs-test/topo-containers/2peerVeth.yaml
extras/hs-test/topo-containers/envoyProxy.yaml
extras/hs-test/topo-containers/nginxProxy.yaml
extras/hs-test/topo-containers/single.yaml
extras/hs-test/topo-containers/singleCpuPinning.yaml
extras/hs-test/topo-containers/vppProxy.yaml

index e572826..bbc14ed 100644 (file)
@@ -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"
index 32fa02b..c15b016 100644 (file)
@@ -29,7 +29,7 @@ var RunningInCi bool
 
 const (
        LogDir    string = "/tmp/hs-test/"
-       VolumeDir string = "/volumes"
+       VolumeDir string = "/vol"
 )
 
 type HstCommon struct {
index 5bb8040..0426516 100644 (file)
@@ -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() {
index 6190e44..4e82272 100644 (file)
@@ -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]
index 2d18427..aac4588 100644 (file)
@@ -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() {
index 9e107b5..875d79f 100644 (file)
@@ -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)
 }
index e1591fb..790739b 100644 (file)
@@ -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:
index cbb00d8..cb2d673 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol
-      host-dir: "$HST_VOLUME_DIR/shared-vol"
+      host-dir: "$HST_VOLUME_DIR/shared"
 
 containers:
   - name: "vpp"
index d9ddc14..5290186 100644 (file)
@@ -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"
index 7b2f91e..d1f43ad 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol
-      host-dir: "$HST_VOLUME_DIR/shared-vol"
+      host-dir: "$HST_VOLUME_DIR/shared"
 
 containers:
   - name: "vpp"
index 6e673aa..0a41ac8 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol
-      host-dir: "$HST_VOLUME_DIR/shared-vol"
+      host-dir: "$HST_VOLUME_DIR/shared"
 
 containers:
   - name: "vpp"
index 557d65d..5f02480 100644 (file)
@@ -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"