From 3ddf3f21c1505b276cee9754abc2454a25c3de0c Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 09:14:31 +0200 Subject: [PATCH 1/8] test: fix and add tests Signed-off-by: Antonio Murdaca --- test/helpers.bash | 4 +-- test/pod.bats | 28 +++++++++++++++++++ {testdata => test/testdata}/README.md | 0 .../testdata}/container_config.json | 0 .../testdata}/container_exit_test.json | 0 .../testdata}/container_redis.json | 0 .../testdata}/sandbox_config.json | 0 7 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/pod.bats rename {testdata => test/testdata}/README.md (100%) rename {testdata => test/testdata}/container_config.json (100%) rename {testdata => test/testdata}/container_exit_test.json (100%) rename {testdata => test/testdata}/container_redis.json (100%) rename {testdata => test/testdata}/sandbox_config.json (100%) diff --git a/test/helpers.bash b/test/helpers.bash index b4f44d28..14547b13 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -4,7 +4,7 @@ INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")") # Test data path. -TESTDATA="${INTEGRATION_ROOT}/../testdata" +TESTDATA="${INTEGRATION_ROOT}/testdata" # Root directory of the repository. OCID_ROOT=${OCID_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)} @@ -70,7 +70,7 @@ function wait_until_reachable() { # Start ocid. function start_ocid() { - "$OCID_BINARY" --debug --socket "$TESTDIR/ocid.sock" --runtime "$RUNC_BINARY" --root "$TESTDIR/ocid" & OCID_PID=$! + "$OCID_BINARY" --debug --socket "$TESTDIR/ocid.sock" --runtime "$RUNC_BINARY" --root "$TESTDIR/ocid" --sandboxdir "$TESTDIR/sandboxes" --containerdir "$TESTDIR/ocid/containers" & OCID_PID=$! wait_until_reachable } diff --git a/test/pod.bats b/test/pod.bats new file mode 100644 index 00000000..5217f5af --- /dev/null +++ b/test/pod.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +load helpers + +function teardown() { + stop_ocid + cleanup_test +} + +# PR#59 +@test "pod release name on remove" { + skip "cannot be run in a container yet" + + start_ocid + run ocic pod create --config "$TESTDATA"/sandbox_config.json + [ "$status" -eq 0 ] + id="$output" + run ocic pod stop --id "$id" + [ "$status" -eq 0 ] + sleep 5 # FIXME: there's a race between container kill and delete below + run ocic pod remove --id "$id" + [ "$status" -eq 0 ] + run ocic pod create --config "$TESTDATA"/sandbox_config.json + [ "$status" -eq 0 ] + + # TODO: cleanup all the stuff from runc, meaning list pods and stop remove them + # pod list + pod stop + pod remove in cleanup +} diff --git a/testdata/README.md b/test/testdata/README.md similarity index 100% rename from testdata/README.md rename to test/testdata/README.md diff --git a/testdata/container_config.json b/test/testdata/container_config.json similarity index 100% rename from testdata/container_config.json rename to test/testdata/container_config.json diff --git a/testdata/container_exit_test.json b/test/testdata/container_exit_test.json similarity index 100% rename from testdata/container_exit_test.json rename to test/testdata/container_exit_test.json diff --git a/testdata/container_redis.json b/test/testdata/container_redis.json similarity index 100% rename from testdata/container_redis.json rename to test/testdata/container_redis.json diff --git a/testdata/sandbox_config.json b/test/testdata/sandbox_config.json similarity index 100% rename from testdata/sandbox_config.json rename to test/testdata/sandbox_config.json From 5a922dbdf67b8c2ee05305892af90564fb71adce Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:02:26 +0200 Subject: [PATCH 2/8] Makefile: fix .gitvalidation Signed-off-by: Antonio Murdaca --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4aa52226..40688fbe 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -EPOCH_TEST_COMMIT ?= 7fc874e05e74faa81e7c423b6514fc5c474c6b34 +EPOCH_TEST_COMMIT ?= 78aae PROJECT := github.com/kubernetes-incubator/cri-o GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") From 56f2b34def03f39b69c7a33b7d3d4b40103f7c31 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:14:46 +0200 Subject: [PATCH 3/8] cmd/client: lowercase error Signed-off-by: Antonio Murdaca --- cmd/client/sandbox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/client/sandbox.go b/cmd/client/sandbox.go index af2f684d..88f0a3e3 100644 --- a/cmd/client/sandbox.go +++ b/cmd/client/sandbox.go @@ -74,7 +74,7 @@ var stopPodSandboxCommand = cli.Command{ err = StopPodSandbox(client, context.String("id")) if err != nil { - return fmt.Errorf("Stopping the pod sandbox failed: %v", err) + return fmt.Errorf("stopping the pod sandbox failed: %v", err) } return nil }, From 4578cc93d1eb5524a63b0f919465a1a7495934d9 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:40:08 +0200 Subject: [PATCH 4/8] server: fix panic when listing sandboxes Signed-off-by: Antonio Murdaca --- server/sandbox.go | 6 ++++++ server/server.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/server/sandbox.go b/server/sandbox.go index f24dd5b2..796e2c30 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -313,6 +313,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR } s.releasePodName(sb.name) + s.removeSandbox(sandboxID) return &pb.RemovePodSandboxResponse{}, nil } @@ -380,6 +381,11 @@ func (s *Server) ListPodSandbox(context.Context, *pb.ListPodSandboxRequest) (*pb for _, sb := range s.state.sandboxes { podInfraContainerName := sb.name + "-infra" podInfraContainer := sb.getContainer(podInfraContainerName) + if podInfraContainer == nil { + // this can't really happen, but if it does because of a bug + // it's better not to panic + continue + } if err := s.runtime.UpdateStatus(podInfraContainer); err != nil { return nil, err } diff --git a/server/server.go b/server/server.go index 6876ac01..68bc895b 100644 --- a/server/server.go +++ b/server/server.go @@ -179,6 +179,12 @@ func (s *Server) hasSandbox(id string) bool { return ok } +func (s *Server) removeSandbox(id string) { + s.stateLock.Lock() + delete(s.state.sandboxes, id) + s.stateLock.Unlock() +} + func (s *Server) addContainer(c *oci.Container) { s.stateLock.Lock() sandbox := s.state.sandboxes[c.Sandbox()] From ab8b65b09ec6528ab041074fa5f61eb562e27125 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:40:33 +0200 Subject: [PATCH 5/8] test: cleanup pods at test teardown Signed-off-by: Antonio Murdaca --- test/helpers.bash | 15 ++++++++++++++- test/pod.bats | 9 ++++----- test/runtimeversion.bats | 1 - 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/test/helpers.bash b/test/helpers.bash index 14547b13..43e2ea86 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -74,12 +74,25 @@ function start_ocid() { wait_until_reachable } +function cleanup_pods() { + run ocic pod list + [ "$status" -eq 0 ] + printf '%s\n' "$output" | while IFS= read -r line + do + pod=$(echo "$line" | sed -e 's/ID: //g') + ocic pod stop --id "$pod" + sleep 1 + ocic pod remove --id "$pod" + done +} + # Stop ocid. function stop_ocid() { kill "$OCID_PID" } function cleanup_test() { + cleanup_pods + stop_ocid rm -rf "$TESTDIR" - # TODO(runcom): runc list and kill/delete everything! } diff --git a/test/pod.bats b/test/pod.bats index 5217f5af..c1ab938f 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -3,17 +3,19 @@ load helpers function teardown() { - stop_ocid cleanup_test } # PR#59 @test "pod release name on remove" { - skip "cannot be run in a container yet" + if "$TRAVIS"; then + skip "cannot yet run this test in a container" + fi start_ocid run ocic pod create --config "$TESTDATA"/sandbox_config.json [ "$status" -eq 0 ] + echo "$output" id="$output" run ocic pod stop --id "$id" [ "$status" -eq 0 ] @@ -22,7 +24,4 @@ function teardown() { [ "$status" -eq 0 ] run ocic pod create --config "$TESTDATA"/sandbox_config.json [ "$status" -eq 0 ] - - # TODO: cleanup all the stuff from runc, meaning list pods and stop remove them - # pod list + pod stop + pod remove in cleanup } diff --git a/test/runtimeversion.bats b/test/runtimeversion.bats index 8c83ae21..bda02af5 100644 --- a/test/runtimeversion.bats +++ b/test/runtimeversion.bats @@ -3,7 +3,6 @@ load helpers function teardown() { - stop_ocid cleanup_test } From 22cd20e70574dff60b5c0c960986aebbfbe6ab9a Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:46:17 +0200 Subject: [PATCH 6/8] test: fix readme and sleep just 1 Signed-off-by: Antonio Murdaca --- test/README.md | 1 - test/pod.bats | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index f9c593ca..1730a15c 100644 --- a/test/README.md +++ b/test/README.md @@ -59,7 +59,6 @@ function setup() { # teardown is called at the end of every test. function teardown() { - stop_ocid cleanup_test } diff --git a/test/pod.bats b/test/pod.bats index c1ab938f..0ed6496c 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -19,7 +19,7 @@ function teardown() { id="$output" run ocic pod stop --id "$id" [ "$status" -eq 0 ] - sleep 5 # FIXME: there's a race between container kill and delete below + sleep 1 # FIXME: there's a race between container kill and delete below run ocic pod remove --id "$id" [ "$status" -eq 0 ] run ocic pod create --config "$TESTDATA"/sandbox_config.json From 560b0a6a9b531442e5a074406ac9a53f06b80383 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:51:35 +0200 Subject: [PATCH 7/8] Makefile: pass $TRAVIS env to tests Signed-off-by: Antonio Murdaca --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 40688fbe..869fa415 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ dbuild: ocidimage docker rm ${OCID_INSTANCE} integration: ocidimage - docker run -e TESTFLAGS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${OCID_IMAGE} make localintegration + docker run -e TESTFLAGS -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${OCID_IMAGE} make localintegration localintegration: binaries ./test/test_runner.sh ${TESTFLAGS} From 77c40487de98dcbcded877452eeccfcfe8b45590 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:54:16 +0200 Subject: [PATCH 8/8] test: suggests sudo make localintegration Signed-off-by: Antonio Murdaca --- test/helpers.bash | 23 ++++++++++++----------- test/pod.bats | 7 +++++-- test/runtimeversion.bats | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/test/helpers.bash b/test/helpers.bash index 43e2ea86..1657c70e 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -76,23 +76,24 @@ function start_ocid() { function cleanup_pods() { run ocic pod list - [ "$status" -eq 0 ] - printf '%s\n' "$output" | while IFS= read -r line - do - pod=$(echo "$line" | sed -e 's/ID: //g') - ocic pod stop --id "$pod" - sleep 1 - ocic pod remove --id "$pod" - done + if [ "$status" -eq 0 ]; then + printf '%s\n' "$output" | while IFS= read -r line + do + pod=$(echo "$line" | sed -e 's/ID: //g') + ocic pod stop --id "$pod" + sleep 1 + ocic pod remove --id "$pod" + done + fi } # Stop ocid. function stop_ocid() { - kill "$OCID_PID" + if [ "$OCID_PID" != "" ]; then + kill "$OCID_PID" >/dev/null 2>&1 + fi } function cleanup_test() { - cleanup_pods - stop_ocid rm -rf "$TESTDIR" } diff --git a/test/pod.bats b/test/pod.bats index 0ed6496c..0a347a4e 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -8,8 +8,9 @@ function teardown() { # PR#59 @test "pod release name on remove" { - if "$TRAVIS"; then - skip "cannot yet run this test in a container" + # this test requires docker, thus it can't yet be run in a container + if [ "$TRAVIS" = "true" ]; then # instead of $TRAVIS, add a function is_containerized to skip here + skip "cannot yet run this test in a container, use sudo make localintegration" fi start_ocid @@ -24,4 +25,6 @@ function teardown() { [ "$status" -eq 0 ] run ocic pod create --config "$TESTDATA"/sandbox_config.json [ "$status" -eq 0 ] + stop_ocid + cleanup_pods } diff --git a/test/runtimeversion.bats b/test/runtimeversion.bats index bda02af5..60bbfa2e 100644 --- a/test/runtimeversion.bats +++ b/test/runtimeversion.bats @@ -10,4 +10,5 @@ function teardown() { start_ocid ocic runtimeversion [ "$status" -eq 0 ] + stop_ocid }