From 1aae9db96c7e65aa9d30b0482db4f4b78e3dde5d Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Tue, 29 Aug 2017 15:53:10 -0400 Subject: [PATCH 1/2] Add file-backed swap to prevent OOM Without any swap space enabled, it's possible some intensive operation can chew up all the memory on the test VM. Enabling swap space will prevent this for minor cases, but could lead to disk-thrashing if the memory demand is excessive. Since the test system never reboots, using a file-backed swap should suffice. Though not ideal, it's easy to setup and doesn't require any interactions with the cloud that owns the VM or the job that created it. Signed-off-by: Chris Evich --- contrib/test/crio-integration-playbook.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/test/crio-integration-playbook.yaml b/contrib/test/crio-integration-playbook.yaml index 0ad67aa4..35b9e003 100644 --- a/contrib/test/crio-integration-playbook.yaml +++ b/contrib/test/crio-integration-playbook.yaml @@ -76,6 +76,13 @@ async: 600 poll: 10 when: ansible_distribution == 'Fedora' + - name: Setup swap to prevent kernel firing off the OOM killer + shell: | + truncate -s 8G /root/swap && \ + export SWAPDEV=$(losetup --show -f /root/swap | head -1) && \ + mkswap $SWAPDEV && \ + swapon $SWAPDEV && \ + swapon --show - name: Make testing directories to conform to testing standards file: path: "{{ item }}" From 635e0e24159138567318aa53af8bc1d49f0ce3a5 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 31 Aug 2017 08:46:26 -0400 Subject: [PATCH 2/2] Refactor kpod tests Move kpod tests from kpod.bats to kpod_[commandname].bats Also make sure all status checks have a echo $output before them. Signed-off-by: Ryan Cole Signed-off-by: Daniel J Walsh --- test/kpod.bats | 254 ----------------------------------------- test/kpod_diff.bats | 14 ++- test/kpod_export.bats | 6 +- test/kpod_history.bats | 83 ++++++++++++++ test/kpod_images.bats | 49 ++++++++ test/kpod_inspect.bats | 61 ++++++++++ test/kpod_load.bats | 10 +- test/kpod_mount.bats | 4 +- test/kpod_ps.bats | 36 ++---- test/kpod_pull.bats | 62 ++++++++++ test/kpod_push.bats | 85 ++++++++++++++ test/kpod_rename.bats | 1 + test/kpod_save.bats | 11 +- test/kpod_stats.bats | 1 + test/kpod_version.bats | 13 +++ 15 files changed, 396 insertions(+), 294 deletions(-) delete mode 100644 test/kpod.bats create mode 100644 test/kpod_history.bats create mode 100644 test/kpod_images.bats create mode 100644 test/kpod_inspect.bats create mode 100644 test/kpod_pull.bats create mode 100644 test/kpod_push.bats create mode 100644 test/kpod_version.bats diff --git a/test/kpod.bats b/test/kpod.bats deleted file mode 100644 index 6e5d4342..00000000 --- a/test/kpod.bats +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -IMAGE="alpine:latest" -ROOT="$TESTDIR/crio" -RUNROOT="$TESTDIR/crio-run" -KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" - -function teardown() { - cleanup_test -} - -@test "kpod version test" { - run ${KPOD_BINARY} version - echo "$output" - [ "$status" -eq 0 ] -} - -@test "kpod pull from docker with tag" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull debian:6.0.10 - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi debian:6.0.10 - [ "$status" -eq 0 ] -} - -@test "kpod pull from docker without tag" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull debian - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi debian - [ "$status" -eq 0 ] -} - -@test "kpod pull from a non-docker registry with tag" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull registry.fedoraproject.org/fedora:rawhide - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi registry.fedoraproject.org/fedora:rawhide - [ "$status" -eq 0 ] -} - -@test "kpod pull from a non-docker registry without tag" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull registry.fedoraproject.org/fedora - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi registry.fedoraproject.org/fedora - [ "$status" -eq 0 ] -} - -@test "kpod pull using digest" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull alpine@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi alpine:latest - [ "$status" -eq 0 ] -} - -@test "kpod pull from a non existent image" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull umohnani/get-started - echo "$output" - [ "$status" -ne 0 ] -} - -@test "kpod history default" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run ${KPOD_BINARY} ${KPOD_OPTIONS} history $IMAGE - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod history with Go template format" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run ${KPOD_BINARY} ${KPOD_OPTIONS} history --format "{{.ID}} {{.Created}}" $IMAGE - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod history human flag" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run ${KPOD_BINARY} ${KPOD_OPTIONS} history --human=false $IMAGE - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod history quiet flag" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run ${KPOD_BINARY} ${KPOD_OPTIONS} history -q $IMAGE - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod history no-trunc flag" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run ${KPOD_BINARY} ${KPOD_OPTIONS} history --no-trunc $IMAGE - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod history json flag" { - run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE - [ "$status" -eq 0 ] - run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} history --format json $IMAGE | python -m json.tool" - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE - [ "$status" -eq 0 ] -} - -@test "kpod push to containers/storage" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" containers-storage:[$ROOT]busybox:test - echo "$output" - [ "$status" -eq 0 ] - run crioctl image remove "$IMAGE" - run crioctl image remove busybox:test - stop_crio -} - -@test "kpod push to directory" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" - echo "$output" - [ "$status" -eq 0 ] - run mkdir /tmp/busybox - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" dir:/tmp/busybox - echo "$output" - [ "$status" -eq 0 ] - run crioctl image remove "$IMAGE" - run rm -rf /tmp/busybox - stop_crio -} - -@test "kpod push to docker archive" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" docker-archive:/tmp/busybox-archive:1.26 - echo "$output" - [ "$status" -eq 0 ] - rm /tmp/busybox-archive - run crioctl image remove "$IMAGE" - stop_crio -} - -@test "kpod push to oci without compression" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" - echo "$output" - [ "$status" -eq 0 ] - run mkdir /tmp/oci-busybox - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" oci:/tmp/oci-busybox - echo "$output" - [ "$status" -eq 0 ] - run rm -rf /tmp/oci-busybox - run crioctl image remove "$IMAGE" - stop_crio -} - -@test "kpod push without signatures" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" - echo "$output" - [ "$status" -eq 0 ] - run mkdir /tmp/busybox - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS push --remove-signatures "$IMAGE" dir:/tmp/busybox - echo "$output" - [ "$status" -eq 0 ] - run rm -rf /tmp/busybox - run crioctl image remove "$IMAGE" - stop_crio -} - -@test "kpod inspect image" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull redis:alpine - [ "$status" -eq 0 ] - run bash -c "${KPOD_BINARY} $KPOD_OPTIONS inspect redis:alpine | python -m json.tool" - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi redis:alpine - [ "$status" -eq 0 ] -} - - -@test "kpod inspect non-existent container" { - run ${KPOD_BINARY} $KPOD_OPTIONS inspect 14rcole/non-existent - echo "$output" - [ "$status" -ne 0 ] -} - -@test "kpod inspect with format" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull redis:alpine - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS inspect --format {{.ID}} redis:alpine - [ "$status" -eq 0 ] - inspectOutput="$output" - run ${KPOD_BINARY} $KPOD_OPTIONS images --quiet redis:alpine - [ "$status" -eq 0 ] - [ "$output" = "$inspectOutput" ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi redis:alpine - [ "$status" -eq 0 ] -} - -@test "kpod inspect specified type" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull redis:alpine - [ "$status" -eq 0 ] - run bash -c "${KPOD_BINARY} $KPOD_OPTIONS inspect --type image redis:alpine | python -m json.tool" - echo "$output" - [ "$status" -eq 0 ] - run ${KPOD_BINARY} $KPOD_OPTIONS rmi redis:alpine - [ "$status" -eq 0 ] -} - -@test "kpod images" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull debian:6.0.10 - run ${KPOD_BINARY} $KPOD_OPTIONS images - [ "$status" -eq 0 ] -} - -@test "kpod images test valid json" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull debian:6.0.10 - run ${KPOD_BINARY} $KPOD_OPTIONS images --format json - echo "$output" | python -m json.tool - [ "$status" -eq 0 ] -} - -@test "kpod images check name json output" { - run ${KPOD_BINARY} $KPOD_OPTIONS pull debian:6.0.10 - run ${KPOD_BINARY} $KPOD_OPTIONS images --format json - echo "$output" - name=$(echo $output | python -c 'import sys; import json; print(json.loads(sys.stdin.read())[0])["names"][0]') - [ "$name" = "docker.io/library/debian:6.0.10" ] -} diff --git a/test/kpod_diff.bats b/test/kpod_diff.bats index 328419b7..2db28f44 100644 --- a/test/kpod_diff.bats +++ b/test/kpod_diff.bats @@ -5,7 +5,7 @@ load helpers IMAGE="alpine:latest" ROOT="$TESTDIR/crio" RUNROOT="$TESTDIR/crio-run" -KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT $STORAGE_OPTS" function teardown() { cleanup_test @@ -13,25 +13,31 @@ function teardown() { @test "test diff of image and parent" { run ${KPOD_BINARY} $KPOD_OPTIONS pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS diff $IMAGE - [ "$status" -eq 0 ] echo "$output" + [ "$status" -eq 0 ] run ${KKPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] } @test "test diff on non-existent layer" { run ${KPOD_BINARY} $KPOD_OPTIONS diff "abc123" - [ "$status" -ne 0 ] echo "$output" + [ "$status" -ne 0 ] } @test "test diff with json output" { run ${KPOD_BINARY} $KPOD_OPTIONS pull $IMAGE + echo "$output" [ "$status" -eq 0 ] # run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} diff --format json $IMAGE | python -m json.tool" run ${KPOD_BINARY} $KPOD_OPTIONS diff --format json $IMAGE - [ "$status" -eq 0 ] echo "$output" + [ "$status" -eq 0 ] run ${KKPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] } diff --git a/test/kpod_export.bats b/test/kpod_export.bats index 808d39ff..febf72db 100644 --- a/test/kpod_export.bats +++ b/test/kpod_export.bats @@ -10,12 +10,12 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" @test "kpod export output flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -25,11 +25,7 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" echo "$output" [ "$status" -eq 0 ] cleanup_ctrs - [ "$status" -eq 0 ] cleanup_pods - [ "$status" -eq 0 ] stop_crio - [ "$status" -eq 0 ] rm -f container.tar - [ "$status" -eq 0 ] } diff --git a/test/kpod_history.bats b/test/kpod_history.bats new file mode 100644 index 00000000..047f1b5f --- /dev/null +++ b/test/kpod_history.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats + +load helpers + +IMAGE="alpine:latest" +ROOT="$TESTDIR/crio" +RUNROOT="$TESTDIR/crio-run" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" + +function teardown() { + cleanup_test +} + +@test "kpod history default" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} ${KPOD_OPTIONS} history $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod history with Go template format" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} ${KPOD_OPTIONS} history --format "{{.ID}} {{.Created}}" $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod history human flag" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} ${KPOD_OPTIONS} history --human=false $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod history quiet flag" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + [ "$status" -eq 0 ] + run ${KPOD_BINARY} ${KPOD_OPTIONS} history -q $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod history no-trunc flag" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} ${KPOD_OPTIONS} history --no-trunc $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod history json flag" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" + [ "$status" -eq 0 ] + run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} history --format json $IMAGE | python -m json.tool" + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" + [ "$status" -eq 0 ] +} diff --git a/test/kpod_images.bats b/test/kpod_images.bats new file mode 100644 index 00000000..c7fb7880 --- /dev/null +++ b/test/kpod_images.bats @@ -0,0 +1,49 @@ +#!/usr/bin/env bats + +load helpers + +IMAGE="debian:6.0.10" +ROOT="$TESTDIR/crio" +RUNROOT="$TESTDIR/crio-run" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" + +function teardown() { + cleanup_test +} + +@test "kpod images" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS images + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod images test valid json" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS images --format json + echo "$output" | python -m json.tool + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod images check name json output" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS images --format json + echo "$output" + name=$(echo $output | python -c 'import sys; import json; print(json.loads(sys.stdin.read())[0])["names"][0]') + [ "$name" = "docker.io/library/${IMAGE}" ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} diff --git a/test/kpod_inspect.bats b/test/kpod_inspect.bats new file mode 100644 index 00000000..2f537d31 --- /dev/null +++ b/test/kpod_inspect.bats @@ -0,0 +1,61 @@ +#!/usr/bin/env bats + +load helpers + +IMAGE="redis:alpine" +ROOT="$TESTDIR/crio" +RUNROOT="$TESTDIR/crio-run" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" + +function teardown() { + cleanup_test +} + +@test "kpod inspect image" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run bash -c "${KPOD_BINARY} $KPOD_OPTIONS inspect ${IMAGE} | python -m json.tool" + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} + + +@test "kpod inspect non-existent container" { + run ${KPOD_BINARY} $KPOD_OPTIONS inspect 14rcole/non-existent + echo "$output" + [ "$status" -ne 0 ] +} + +@test "kpod inspect with format" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS inspect --format {{.ID}} ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + inspectOutput="$output" + run ${KPOD_BINARY} $KPOD_OPTIONS images --quiet ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + [ "$output" = "$inspectOutput" ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod inspect specified type" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] + run bash -c "${KPOD_BINARY} $KPOD_OPTIONS inspect --type image ${IMAGE} | python -m json.tool" + echo "$output" + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi ${IMAGE} + echo "$output" + [ "$status" -eq 0 ] +} diff --git a/test/kpod_load.bats b/test/kpod_load.bats index 6dcdd2f8..2eb4f26a 100644 --- a/test/kpod_load.bats +++ b/test/kpod_load.bats @@ -5,7 +5,7 @@ load helpers IMAGE="alpine:latest" ROOT="$TESTDIR/crio" RUNROOT="$TESTDIR/crio-run" -KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT $STORAGE_OPTS" function teardown() { cleanup_test @@ -13,10 +13,13 @@ function teardown() { @test "kpod load input flag" { run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} save -o alpine.tar $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} load -i alpine.tar echo "$output" @@ -24,21 +27,24 @@ function teardown() { rm -f alpine.tar [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] } @test "kpod load using quiet flag" { run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} save -o alpine.tar $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} load -q -i alpine.tar echo "$output" [ "$status" -eq 0 ] rm -f alpine.tar - [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE [ "$status" -eq 0 ] } diff --git a/test/kpod_mount.bats b/test/kpod_mount.bats index 517b627c..00862a94 100644 --- a/test/kpod_mount.bats +++ b/test/kpod_mount.bats @@ -42,7 +42,9 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" echo "$output" [ "$status" -eq 0 ] touch $root/foobar - ${KPOD_BINARY} ${KPOD_OPTIONS} unmount $ctr_id + run ${KPOD_BINARY} ${KPOD_OPTIONS} unmount $ctr_id + echo "$output" + [ "$status" -eq 0 ] cleanup_ctrs cleanup_pods stop_crio diff --git a/test/kpod_ps.bats b/test/kpod_ps.bats index 5954be6b..1608bd32 100644 --- a/test/kpod_ps.bats +++ b/test/kpod_ps.bats @@ -15,12 +15,12 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" @test "kpod ps default" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -35,17 +35,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps all flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -59,17 +58,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps size flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -83,17 +81,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps quiet flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -107,17 +104,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps latest flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -131,17 +127,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps last flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -155,17 +150,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps no-trunc flag" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -176,17 +170,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps format flag = json" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -197,17 +190,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps format flag = go template" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -218,17 +210,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps filter flag - ancestor" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -239,17 +230,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps filter flag - id" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -261,17 +251,16 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } @test "kpod ps filter flag - status" { start_crio - [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" [ "$status" -eq 0 ] pod_id="$output" run crioctl image pull "$IMAGE" + echo "$output" [ "$status" -eq 0 ] run crioctl ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" echo "$output" @@ -283,5 +272,4 @@ KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}" cleanup_ctrs cleanup_pods stop_crio - [ "$status" -eq 0 ] } diff --git a/test/kpod_pull.bats b/test/kpod_pull.bats new file mode 100644 index 00000000..58bbc633 --- /dev/null +++ b/test/kpod_pull.bats @@ -0,0 +1,62 @@ +#!/usr/bin/env bats + +load helpers + +ROOT="$TESTDIR/crio" +RUNROOT="$TESTDIR/crio-run" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" + +function teardown() { + cleanup_test +} + +@test "kpod pull from docker with tag" { + run ${KPOD_BINARY} ${KPOD_OPTIONS} pull debian:6.0.10 + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi debian:6.0.10 + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod pull from docker without tag" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull debian + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi debian + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod pull from a non-docker registry with tag" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull registry.fedoraproject.org/fedora:rawhide + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi registry.fedoraproject.org/fedora:rawhide + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod pull from a non-docker registry without tag" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull registry.fedoraproject.org/fedora + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi registry.fedoraproject.org/fedora + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod pull using digest" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull alpine@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS rmi alpine:latest + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod pull from a non existent image" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull umohnani/get-started + echo "$output" + [ "$status" -ne 0 ] +} diff --git a/test/kpod_push.bats b/test/kpod_push.bats new file mode 100644 index 00000000..ea1d96c4 --- /dev/null +++ b/test/kpod_push.bats @@ -0,0 +1,85 @@ +#!/usr/bin/env bats + +load helpers + +IMAGE="alpine:latest" +ROOT="$TESTDIR/crio" +RUNROOT="$TESTDIR/crio-run" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" + +function teardown() { + cleanup_test +} + +@test "kpod push to containers/storage" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" containers-storage:[$ROOT]busybox:test + echo "$output" + [ "$status" -eq 0 ] + run kpod rmi "$IMAGE" busybox:test + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod push to directory" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] + run mkdir /tmp/busybox + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" dir:/tmp/busybox + echo "$output" + [ "$status" -eq 0 ] + rm -rf /tmp/busybox + run kpod rmi "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod push to docker archive" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" docker-archive:/tmp/busybox-archive:1.26 + echo "$output" + [ "$status" -eq 0 ] + rm /tmp/busybox-archive + run kpod rmi "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod push to oci without compression" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] + run mkdir /tmp/oci-busybox + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS push "$IMAGE" oci:/tmp/oci-busybox + echo "$output" + [ "$status" -eq 0 ] + rm -rf /tmp/oci-busybox + run kpod rmi "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] +} + +@test "kpod push without signatures" { + run ${KPOD_BINARY} $KPOD_OPTIONS pull "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] + run mkdir /tmp/busybox + echo "$output" + [ "$status" -eq 0 ] + run ${KPOD_BINARY} $KPOD_OPTIONS push --remove-signatures "$IMAGE" dir:/tmp/busybox + echo "$output" + [ "$status" -eq 0 ] + rm -rf /tmp/busybox + run kpod rmi "$IMAGE" + echo "$output" + [ "$status" -eq 0 ] +} diff --git a/test/kpod_rename.bats b/test/kpod_rename.bats index 9419ce2d..34c54d09 100644 --- a/test/kpod_rename.bats +++ b/test/kpod_rename.bats @@ -15,6 +15,7 @@ function teardown() { @test "kpod rename successful" { start_crio run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run crioctl pod run --config "$TESTDATA"/sandbox_config.json echo "$output" diff --git a/test/kpod_save.bats b/test/kpod_save.bats index cfa3bad9..b67e4734 100644 --- a/test/kpod_save.bats +++ b/test/kpod_save.bats @@ -5,7 +5,7 @@ load helpers IMAGE="alpine:latest" ROOT="$TESTDIR/crio" RUNROOT="$TESTDIR/crio-run" -KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT --storage-driver vfs" +KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT $STORAGE_OPTS" function teardown() { cleanup_test @@ -13,38 +13,41 @@ function teardown() { @test "kpod save output flag" { run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} save -o alpine.tar $IMAGE echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] rm -f alpine.tar - [ "$status" -eq 0 ] } @test "kpod save using stdout" { run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} save > alpine.tar $IMAGE echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] rm -f alpine.tar - [ "$status" -eq 0 ] } @test "kpod save quiet flag" { run ${KPOD_BINARY} ${KPOD_OPTIONS} pull $IMAGE + echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} save -q -o alpine.tar $IMAGE echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} ${KPOD_OPTIONS} rmi $IMAGE + echo "$output" [ "$status" -eq 0 ] rm -f alpine.tar - [ "$status" -eq 0 ] } @test "kpod save non-existent image" { diff --git a/test/kpod_stats.bats b/test/kpod_stats.bats index c9f58cc9..c3d6b365 100644 --- a/test/kpod_stats.bats +++ b/test/kpod_stats.bats @@ -81,6 +81,7 @@ function teardown() { echo "$output" [ "$status" -eq 0 ] run ${KPOD_BINARY} $KPOD_OPTIONS stats --no-stream --format {{.ID}} "$ctr_id" + echo "$output" [ "$status" -eq 0 ] # once ps is implemented, run ps -q and see if that equals the output from above cleanup_ctrs diff --git a/test/kpod_version.bats b/test/kpod_version.bats new file mode 100644 index 00000000..e6c062b8 --- /dev/null +++ b/test/kpod_version.bats @@ -0,0 +1,13 @@ +#!/usr/bin/env bats + +load helpers + +function teardown() { + cleanup_test +} + +@test "kpod version test" { + run ${KPOD_BINARY} version + echo "$output" + [ "$status" -eq 0 ] +}