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:

committed by
Florin Coras

parent
af1ddd39f1
commit
a1bd50c7a2
@ -12,7 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
logDir string = "/tmp/hs-test/"
|
logDir string = "/tmp/hs-test/"
|
||||||
|
volumeDir string = "/volumes"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -37,7 +38,7 @@ type Container struct {
|
|||||||
vppInstance *VppInstance
|
vppInstance *VppInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainer(yamlInput ContainerConfig) (*Container, error) {
|
func newContainer(suite *HstSuite, yamlInput ContainerConfig) (*Container, error) {
|
||||||
containerName := yamlInput["name"].(string)
|
containerName := yamlInput["name"].(string)
|
||||||
if len(containerName) == 0 {
|
if len(containerName) == 0 {
|
||||||
err := fmt.Errorf("container name must not be blank")
|
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.volumes = make(map[string]Volume)
|
||||||
container.envVars = make(map[string]string)
|
container.envVars = make(map[string]string)
|
||||||
container.name = containerName
|
container.name = containerName
|
||||||
|
container.suite = suite
|
||||||
|
|
||||||
if image, ok := yamlInput["image"]; ok {
|
if image, ok := yamlInput["image"]; ok {
|
||||||
container.image = image.(string)
|
container.image = image.(string)
|
||||||
@ -74,19 +76,20 @@ func newContainer(yamlInput ContainerConfig) (*Container, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := yamlInput["volumes"]; ok {
|
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{}) {
|
for _, volu := range yamlInput["volumes"].([]interface{}) {
|
||||||
volumeMap := volu.(ContainerConfig)
|
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)
|
containerDir := volumeMap["container-dir"].(string)
|
||||||
isDefaultWorkDir := false
|
isDefaultWorkDir := false
|
||||||
|
|
||||||
if isDefault, ok := volumeMap["is-default-work-dir"]; ok {
|
if isDefault, ok := volumeMap["is-default-work-dir"]; ok {
|
||||||
isDefaultWorkDir = isDefault.(bool)
|
isDefaultWorkDir = isDefault.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
container.addVolume(hostDir, containerDir, isDefaultWorkDir)
|
container.addVolume(hostDir, containerDir, isDefaultWorkDir)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +345,7 @@ func (c *Container) stop() error {
|
|||||||
func (c *Container) createConfig(targetConfigName string, templateName string, values any) {
|
func (c *Container) createConfig(targetConfigName string, templateName string, values any) {
|
||||||
template := template.Must(template.ParseFiles(templateName))
|
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)
|
c.suite.assertNil(err)
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
|
|
||||||
|
@ -221,13 +221,15 @@ func (s *HstSuite) loadContainerTopology(topologyName string) {
|
|||||||
for _, elem := range yamlTopo.Volumes {
|
for _, elem := range yamlTopo.Volumes {
|
||||||
volumeMap := elem["volume"].(VolumeConfig)
|
volumeMap := elem["volume"].(VolumeConfig)
|
||||||
hostDir := volumeMap["host-dir"].(string)
|
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.volumes = append(s.volumes, hostDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.containers = make(map[string]*Container)
|
s.containers = make(map[string]*Container)
|
||||||
for _, elem := range yamlTopo.Containers {
|
for _, elem := range yamlTopo.Containers {
|
||||||
newContainer, err := newContainer(elem)
|
newContainer, err := newContainer(s, elem)
|
||||||
newContainer.suite = s
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.T().Fatalf("container config error: %v", err)
|
s.T().Fatalf("container config error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
|
|||||||
s.log("starting VPPs")
|
s.log("starting VPPs")
|
||||||
|
|
||||||
clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
|
clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
|
||||||
clientContainer.getContainerWorkDir())
|
clientContainer.getHostWorkDir())
|
||||||
err := clnVclConf.
|
err := clnVclConf.
|
||||||
newStanza("vcl").
|
newStanza("vcl").
|
||||||
append("rx-fifo-size 4000000").
|
append("rx-fifo-size 4000000").
|
||||||
@ -39,7 +39,7 @@ func (s *VethsSuite) TestLDPreloadIperfVpp() {
|
|||||||
s.assertNil(err)
|
s.assertNil(err)
|
||||||
|
|
||||||
serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
|
serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
|
||||||
serverContainer.getContainerWorkDir())
|
serverContainer.getHostWorkDir())
|
||||||
err = srvVclConf.
|
err = srvVclConf.
|
||||||
newStanza("vcl").
|
newStanza("vcl").
|
||||||
append("rx-fifo-size 4000000").
|
append("rx-fifo-size 4000000").
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
---
|
---
|
||||||
volumes:
|
volumes:
|
||||||
- volume: &server-vol
|
- volume: &server-vol
|
||||||
host-dir: /tmp/server-share
|
host-dir: "$HST_VOLUME_DIR/server-share"
|
||||||
container-dir: /tmp/server-share
|
container-dir: "/tmp/server-share"
|
||||||
is-default-work-dir: true
|
is-default-work-dir: true
|
||||||
- volume: &client-vol
|
- volume: &client-vol
|
||||||
host-dir: /tmp/client-share
|
host-dir: "$HST_VOLUME_DIR/client-share"
|
||||||
container-dir: "/tmp/client-share"
|
container-dir: "/tmp/client-share"
|
||||||
is-default-work-dir: true
|
is-default-work-dir: true
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
volumes:
|
volumes:
|
||||||
- volume: &shared-vol-proxy
|
- volume: &shared-vol-proxy
|
||||||
host-dir: /tmp/shared-vol-proxy
|
host-dir: "$HST_VOLUME_DIR/shared-vol-proxy"
|
||||||
|
|
||||||
containers:
|
containers:
|
||||||
- name: "vpp-proxy"
|
- name: "vpp-proxy"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
volumes:
|
volumes:
|
||||||
- volume: &shared-vol
|
- 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
|
# $HST_DIR will be replaced during runtime by path to hs-test directory
|
||||||
containers:
|
containers:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
volumes:
|
volumes:
|
||||||
- volume: &shared-vol
|
- volume: &shared-vol
|
||||||
host-dir: /tmp/shared-vol
|
host-dir: "$HST_VOLUME_DIR/shared-vol"
|
||||||
|
|
||||||
containers:
|
containers:
|
||||||
- name: "vpp"
|
- name: "vpp"
|
||||||
|
Reference in New Issue
Block a user