hs-test: use relative paths for docker volumes
Type: test
Change-Id: I9d5c15662e50ceea08d2ccc653db36c5e3df869e
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 812198d..86f511c 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -12,7 +12,8 @@
)
const (
- logDir string = "/tmp/hs-test/"
+ logDir string = "/tmp/hs-test/"
+ volumeDir string = "/volumes"
)
var (
@@ -37,7 +38,7 @@
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 @@
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 @@
}
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) 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())
diff --git a/extras/hs-test/hst_suite.go b/extras/hs-test/hst_suite.go
index 12a66e4..7f93b15 100644
--- a/extras/hs-test/hst_suite.go
+++ b/extras/hs-test/hst_suite.go
@@ -221,13 +221,15 @@
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)
}
diff --git a/extras/hs-test/ldp_test.go b/extras/hs-test/ldp_test.go
index 90a6182..b6249cd 100644
--- a/extras/hs-test/ldp_test.go
+++ b/extras/hs-test/ldp_test.go
@@ -26,7 +26,7 @@
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 @@
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").
diff --git a/extras/hs-test/topo-containers/2peerVeth.yaml b/extras/hs-test/topo-containers/2peerVeth.yaml
index 36de33b..e1591fb 100644
--- a/extras/hs-test/topo-containers/2peerVeth.yaml
+++ b/extras/hs-test/topo-containers/2peerVeth.yaml
@@ -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
diff --git a/extras/hs-test/topo-containers/nginxProxyAndServer.yaml b/extras/hs-test/topo-containers/nginxProxyAndServer.yaml
index bac6a2d..cc6b780 100644
--- a/extras/hs-test/topo-containers/nginxProxyAndServer.yaml
+++ b/extras/hs-test/topo-containers/nginxProxyAndServer.yaml
@@ -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"
diff --git a/extras/hs-test/topo-containers/ns.yaml b/extras/hs-test/topo-containers/ns.yaml
index 2b1902b..2298ad2 100644
--- a/extras/hs-test/topo-containers/ns.yaml
+++ b/extras/hs-test/topo-containers/ns.yaml
@@ -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:
diff --git a/extras/hs-test/topo-containers/single.yaml b/extras/hs-test/topo-containers/single.yaml
index 6fd4d31..b6970c5 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: /tmp/shared-vol
+ host-dir: "$HST_VOLUME_DIR/shared-vol"
containers:
- name: "vpp"