summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/container.go
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2023-03-20 12:39:20 +0100
committerFlorin Coras <florin.coras@gmail.com>2023-03-29 04:43:40 +0000
commitb41b0af609fce6fbe62b476f826a90bded9052ad (patch)
treea67b24867b9651df3d4c6ed71115f1322a294ec5 /extras/hs-test/container.go
parent7c11156752abc32d3c1e7be4517a06aa7716d8d1 (diff)
hs-test: containerize ab and wrk
Type: test Signed-off-by: Filip Tehlar <ftehlar@cisco.com> Change-Id: I66af84257fa0692d9be3445d49b52fb7ca810d27
Diffstat (limited to 'extras/hs-test/container.go')
-rw-r--r--extras/hs-test/container.go40
1 files changed, 33 insertions, 7 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go
index 1f600f9fe24..1dc49b763a5 100644
--- a/extras/hs-test/container.go
+++ b/extras/hs-test/container.go
@@ -27,6 +27,7 @@ type Volume struct {
type Container struct {
suite *HstSuite
isOptional bool
+ runDetached bool
name string
image string
extraRunningArgs string
@@ -65,6 +66,12 @@ func newContainer(yamlInput ContainerConfig) (*Container, error) {
container.isOptional = false
}
+ if runDetached, ok := yamlInput["run-detached"]; ok {
+ container.runDetached = runDetached.(bool)
+ } else {
+ container.runDetached = true
+ }
+
if _, ok := yamlInput["volumes"]; ok {
r := strings.NewReplacer("$HST_DIR", workDir)
for _, volu := range yamlInput["volumes"].([]interface{}) {
@@ -119,7 +126,7 @@ func (c *Container) getContainerWorkDir() (res string) {
}
func (c *Container) getContainerArguments() string {
- args := "--cap-add=all --privileged --network host --rm"
+ args := "--ulimit nofile=90000:90000 --cap-add=all --privileged --network host --rm"
args += c.getVolumesAsCliOption()
args += c.getEnvVarsAsCliOption()
args += " --name " + c.name + " " + c.image
@@ -139,19 +146,38 @@ func (c *Container) start() error {
return exechelper.Run(cmd)
}
-func (c *Container) run() error {
+func (c *Container) prepareCommand() (string, error) {
if c.name == "" {
- return fmt.Errorf("run container failed: name is blank")
+ return "", fmt.Errorf("run container failed: name is blank")
}
- cmd := "docker run -d " + c.getContainerArguments()
+ cmd := "docker run "
+ if c.runDetached {
+ cmd += " -d"
+ }
+ cmd += " " + c.getContainerArguments()
+
c.suite.log(cmd)
- err := exechelper.Run(cmd)
+ return cmd, nil
+}
+
+func (c *Container) combinedOutput() (string, error) {
+ cmd, err := c.prepareCommand()
if err != nil {
- return fmt.Errorf("container run failed: %s", err)
+ return "", err
}
- return nil
+ byteOutput, err := exechelper.CombinedOutput(cmd)
+ return string(byteOutput), err
+}
+
+func (c *Container) run() error {
+ cmd, err := c.prepareCommand()
+ if err != nil {
+ return err
+ }
+
+ return exechelper.Run(cmd)
}
func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) {