summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/container.go
diff options
context:
space:
mode:
authorAdrian Villin <avillin@cisco.com>2024-06-06 04:26:30 -0400
committerDave Wallace <dwallacelf@gmail.com>2024-06-12 23:38:25 +0000
commiteaa7d91ad77f9c6691b42b0e9f631166b4bcf44f (patch)
tree702ea477d752d49a4dc5690d538e6fc666b435e8 /extras/hs-test/container.go
parent6c37845a87588da8082b931bfce8c680ba1a9ad6 (diff)
hs-test: improved suite teardown and replaced PIDs with PPIDs
- Fixed an issue where containers wouldn't stop and get removed when a test run is interrupted - Replaced PIDs with Ginkgo process indexes + PPIDs - Fixed CPU allocation for envoy and nginx-ldp containers - All container logs should now get saved properly Type: test Change-Id: I4c737c1d326390494c0dda1ec6d3fc1f04f51663 Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/container.go')
-rw-r--r--extras/hs-test/container.go25
1 files changed, 11 insertions, 14 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 080eb736ad4..97b71b5385f 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -78,7 +78,7 @@ func newContainer(suite *HstSuite, yamlInput ContainerConfig) (*Container, error
}
if _, ok := yamlInput["volumes"]; ok {
- workingVolumeDir := logDir + CurrentSpecReport().LeafNodeText + volumeDir
+ workingVolumeDir := logDir + suite.getCurrentTestName() + volumeDir
workDirReplacer := strings.NewReplacer("$HST_DIR", workDir)
volDirReplacer := strings.NewReplacer("$HST_VOLUME_DIR", workingVolumeDir)
for _, volu := range yamlInput["volumes"].([]interface{}) {
@@ -132,7 +132,9 @@ func (c *Container) getContainerWorkDir() (res string) {
}
func (c *Container) getContainerArguments() string {
- args := "--ulimit nofile=90000:90000 --cap-add=all --privileged --network host --rm"
+ args := "--ulimit nofile=90000:90000 --cap-add=all --privileged --network host"
+ c.allocateCpus()
+ args += fmt.Sprintf(" --cpuset-cpus=\"%d-%d\"", c.allocatedCpus[0], c.allocatedCpus[len(c.allocatedCpus)-1])
args += c.getVolumesAsCliOption()
args += c.getEnvVarsAsCliOption()
if *vppSourceFileDir != "" {
@@ -180,11 +182,9 @@ func (c *Container) prepareCommand() (string, error) {
cmd := "docker run "
if c.runDetached {
- cmd += " -dt"
+ cmd += " -d"
}
- c.allocateCpus()
- cmd += fmt.Sprintf(" --cpuset-cpus=\"%d-%d\"", c.allocatedCpus[0], c.allocatedCpus[len(c.allocatedCpus)-1])
cmd += " " + c.getContainerArguments()
c.suite.log(cmd)
@@ -260,7 +260,7 @@ func (c *Container) copy(sourceFileName string, targetFileName string) error {
}
func (c *Container) createFile(destFileName string, content string) error {
- f, err := os.CreateTemp("/tmp", "hst-config"+c.suite.pid)
+ f, err := os.CreateTemp("/tmp", "hst-config"+c.suite.ppid)
if err != nil {
return err
}
@@ -302,7 +302,7 @@ func (c *Container) exec(command string, arguments ...any) string {
func (c *Container) getLogDirPath() string {
testId := c.suite.getTestId()
- testName := CurrentSpecReport().LeafNodeText
+ testName := c.suite.getCurrentTestName()
logDirPath := logDir + testName + "/" + testId + "/"
cmd := exec.Command("mkdir", "-p", logDirPath)
@@ -314,17 +314,13 @@ func (c *Container) getLogDirPath() string {
}
func (c *Container) saveLogs() {
- cmd := exec.Command("docker", "inspect", "--format='{{.State.Status}}'", c.name)
- if output, _ := cmd.CombinedOutput(); !strings.Contains(string(output), "running") {
- return
- }
-
testLogFilePath := c.getLogDirPath() + "container-" + c.name + ".log"
- cmd = exec.Command("docker", "logs", "--details", "-t", c.name)
+ cmd := exec.Command("docker", "logs", "--details", "-t", c.name)
+ c.suite.log(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
- Fail("fetching logs error: " + fmt.Sprint(err))
+ c.suite.log(err)
}
f, err := os.Create(testLogFilePath)
@@ -356,6 +352,7 @@ func (c *Container) stop() error {
}
c.vppInstance = nil
c.saveLogs()
+ c.suite.log("docker stop " + c.name + " -t 0")
return exechelper.Run("docker stop " + c.name + " -t 0")
}