hs-test: use relative paths for docker volumes

Type: test

Change-Id: I9d5c15662e50ceea08d2ccc653db36c5e3df869e
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
This commit is contained in:
Filip Tehlar
2024-01-24 11:59:44 +01:00
committed by Florin Coras
parent af1ddd39f1
commit a1bd50c7a2
7 changed files with 22 additions and 17 deletions

View 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())

View 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)
}

View 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").

View 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

View 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"

View 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:

View File

@ -1,7 +1,7 @@
---
volumes:
- volume: &shared-vol
host-dir: /tmp/shared-vol
host-dir: "$HST_VOLUME_DIR/shared-vol"
containers:
- name: "vpp"