aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorAdrian Villin <avillin@cisco.com>2024-07-23 12:14:19 +0200
committerDave Wallace <dwallacelf@gmail.com>2024-07-24 23:41:04 +0000
commit007be4fa7f869b73a940f4af0988581dd4b8a8ae (patch)
tree96a6d2d9218a0928db5f251350e8d547706dc935 /extras
parentd9da4eeb7945ab039c182f6960a629b05dd5f024 (diff)
hs-test: check container state after startup
- tests will now fail if a container exits right after startup - fixed MirroringTest (still broken with multiple workers) Type: test Change-Id: I47b51c2bcf53f535aa2d06c2f5b09a9559631117 Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras')
-rw-r--r--extras/hs-test/docker/Dockerfile.nginx-server2
-rw-r--r--extras/hs-test/infra/container.go25
2 files changed, 25 insertions, 2 deletions
diff --git a/extras/hs-test/docker/Dockerfile.nginx-server b/extras/hs-test/docker/Dockerfile.nginx-server
index 1971158131b..0720c6f2cb7 100644
--- a/extras/hs-test/docker/Dockerfile.nginx-server
+++ b/extras/hs-test/docker/Dockerfile.nginx-server
@@ -9,4 +9,4 @@ RUN apt-get update \
COPY resources/nginx/nginx_server_mirroring.conf /nginx.conf
-ENTRYPOINT ["nginx", "-c", "/nginx.conf"]
+ENTRYPOINT nginx -c /nginx.conf
diff --git a/extras/hs-test/infra/container.go b/extras/hs-test/infra/container.go
index 46cee976556..7317499b15f 100644
--- a/extras/hs-test/infra/container.go
+++ b/extras/hs-test/infra/container.go
@@ -14,6 +14,7 @@ import (
"time"
containerTypes "github.com/docker/docker/api/types/container"
+ "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/stdcopy"
"github.com/edwarnicke/exechelper"
@@ -179,6 +180,7 @@ func (c *Container) Create() error {
resp, err := c.Suite.Docker.ContainerCreate(
c.ctx,
&containerTypes.Config{
+ Hostname: c.Name,
Image: c.Image,
Env: c.getEnvVars(),
Cmd: strings.Split(c.ExtraRunningArgs, " "),
@@ -216,7 +218,9 @@ func (c *Container) allocateCpus() {
// Starts a container
func (c *Container) Start() error {
var err error
- for nTries := 0; nTries < 5; nTries++ {
+ var nTries int
+
+ for nTries = 0; nTries < 5; nTries++ {
err = c.Suite.Docker.ContainerStart(c.ctx, c.ID, containerTypes.StartOptions{})
if err == nil {
continue
@@ -224,6 +228,25 @@ func (c *Container) Start() error {
c.Suite.Log("Error while starting " + c.Name + ". Retrying...")
time.Sleep(1 * time.Second)
}
+ if nTries >= 5 {
+ return err
+ }
+
+ // wait for container to start
+ time.Sleep(1 * time.Second)
+
+ // check if container exited right after startup
+ containers, err := c.Suite.Docker.ContainerList(c.ctx, containerTypes.ListOptions{
+ All: true,
+ Filters: filters.NewArgs(filters.Arg("name", c.Name)),
+ })
+ if err != nil {
+ return err
+ }
+ if containers[0].State == "exited" {
+ c.Suite.Log("Container details: " + fmt.Sprint(containers[0]))
+ return fmt.Errorf("Container %s exited: '%s'", c.Name, containers[0].Status)
+ }
return err
}