hs-test: use relative paths for docker volumes 49/40249/3
authorFilip Tehlar <ftehlar@cisco.com>
Wed, 24 Jan 2024 10:59:44 +0000 (11:59 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Mon, 29 Jan 2024 19:58:37 +0000 (19:58 +0000)
Type: test

Change-Id: I9d5c15662e50ceea08d2ccc653db36c5e3df869e
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
extras/hs-test/container.go
extras/hs-test/hst_suite.go
extras/hs-test/ldp_test.go
extras/hs-test/topo-containers/2peerVeth.yaml
extras/hs-test/topo-containers/nginxProxyAndServer.yaml
extras/hs-test/topo-containers/ns.yaml
extras/hs-test/topo-containers/single.yaml

index 812198d..86f511c 100644 (file)
@@ -12,7 +12,8 @@ import (
 )
 
 const (
-       logDir string = "/tmp/hs-test/"
+       logDir    string = "/tmp/hs-test/"
+       volumeDir string = "/volumes"
 )
 
 var (
@@ -37,7 +38,7 @@ type Container struct {
        vppInstance      *VppInstance
 }
 
-func newContainer(yamlInput ContainerConfig) (*Container, error) {
+func newContainer(suite *HstSuite, yamlInput ContainerConfig) (*Container, error) {
        containerName := yamlInput["name"].(string)
        if len(containerName) == 0 {
                err := fmt.Errorf("container name must not be blank")
@@ -48,6 +49,7 @@ func newContainer(yamlInput ContainerConfig) (*Container, error) {
        container.volumes = make(map[string]Volume)
        container.envVars = make(map[string]string)
        container.name = containerName
+       container.suite = suite
 
        if image, ok := yamlInput["image"]; ok {
                container.image = image.(string)
@@ -74,19 +76,20 @@ func newContainer(yamlInput ContainerConfig) (*Container, error) {
        }
 
        if _, ok := yamlInput["volumes"]; ok {
-               r := strings.NewReplacer("$HST_DIR", workDir)
+               workingVolumeDir := logDir + container.suite.T().Name() + volumeDir
+               workDirReplacer := strings.NewReplacer("$HST_DIR", workDir)
+               volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir)
                for _, volu := range yamlInput["volumes"].([]interface{}) {
                        volumeMap := volu.(ContainerConfig)
-                       hostDir := r.Replace(volumeMap["host-dir"].(string))
+                       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)
-
                }
        }
 
@@ -342,7 +345,7 @@ func (c *Container) stop() error {
 func (c *Container) createConfig(targetConfigName string, templateName string, values any) {
        template := template.Must(template.ParseFiles(templateName))
 
-       f, err := os.CreateTemp("/tmp/hs-test/", "hst-config")
+       f, err := os.CreateTemp(logDir, "hst-config")
        c.suite.assertNil(err)
        defer os.Remove(f.Name())
 
index 12a66e4..7f93b15 100644 (file)
@@ -221,13 +221,15 @@ func (s *HstSuite) loadContainerTopology(topologyName string) {
        for _, elem := range yamlTopo.Volumes {
                volumeMap := elem["volume"].(VolumeConfig)
                hostDir := volumeMap["host-dir"].(string)
+               workingVolumeDir := logDir + s.T().Name() + volumeDir
+               volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir)
+               hostDir = volDirReplacer.Replace(hostDir)
                s.volumes = append(s.volumes, hostDir)
        }
 
        s.containers = make(map[string]*Container)
        for _, elem := range yamlTopo.Containers {
-               newContainer, err := newContainer(elem)
-               newContainer.suite = s
+               newContainer, err := newContainer(s, elem)
                if err != nil {
                        s.T().Fatalf("container config error: %v", err)
                }
index 90a6182..b6249cd 100644 (file)
@@ -26,7 +26,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
        s.log("starting VPPs")
 
        clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
-               clientContainer.getContainerWorkDir())
+               clientContainer.getHostWorkDir())
        err := clnVclConf.
                newStanza("vcl").
                append("rx-fifo-size 4000000").
@@ -39,7 +39,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
        s.assertNil(err)
 
        serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
-               serverContainer.getContainerWorkDir())
+               serverContainer.getHostWorkDir())
        err = srvVclConf.
                newStanza("vcl").
                append("rx-fifo-size 4000000").
index 36de33b..e1591fb 100644 (file)
@@ -1,11 +1,11 @@
 ---
 volumes:
   - volume: &server-vol
-      host-dir: /tmp/server-share
-      container-dir: /tmp/server-share
+      host-dir: "$HST_VOLUME_DIR/server-share"
+      container-dir: "/tmp/server-share"
       is-default-work-dir: true
   - volume: &client-vol
-      host-dir: /tmp/client-share
+      host-dir: "$HST_VOLUME_DIR/client-share"
       container-dir: "/tmp/client-share"
       is-default-work-dir: true
 
index bac6a2d..cc6b780 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol-proxy
-      host-dir: /tmp/shared-vol-proxy
+      host-dir: "$HST_VOLUME_DIR/shared-vol-proxy"
 
 containers:
   - name: "vpp-proxy"
index 2b1902b..2298ad2 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol
-      host-dir: /tmp/shared-vol
+      host-dir: "$HST_VOLUME_DIR/shared-vol"
 
 # $HST_DIR will be replaced during runtime by path to hs-test directory
 containers:
index 6fd4d31..b6970c5 100644 (file)
@@ -1,7 +1,7 @@
 ---
 volumes:
   - volume: &shared-vol
-      host-dir: /tmp/shared-vol
+      host-dir: "$HST_VOLUME_DIR/shared-vol"
 
 containers:
   - name: "vpp"