summaryrefslogtreecommitdiff
path: root/test/system
diff options
context:
space:
mode:
Diffstat (limited to 'test/system')
-rw-r--r--test/system/010-images.bats39
-rw-r--r--test/system/130-kill.bats101
-rw-r--r--test/system/helpers.bash2
3 files changed, 129 insertions, 13 deletions
diff --git a/test/system/010-images.bats b/test/system/010-images.bats
index 543876509..66ef53590 100644
--- a/test/system/010-images.bats
+++ b/test/system/010-images.bats
@@ -45,18 +45,33 @@ size | [0-9]\\\+
}
@test "podman images - history output" {
- run_podman images --format json
- actual=$(echo $output | jq -r '.[0].history | length')
- is "$actual" "0"
-
- run_podman tag $PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:$PODMAN_TEST_IMAGE_TAG test-image
- run_podman images --format json
- actual=$(echo $output | jq -r '.[1].history | length')
- is "$actual" "0"
- actual=$(echo $output | jq -r '.[0].history | length')
- is "$actual" "1"
- actual=$(echo $output | jq -r '.[0].history[0]')
- is "$actual" "$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME:$PODMAN_TEST_IMAGE_TAG"
+ # podman history is persistent: it permanently alters our base image.
+ # Create a dummy image here so we leave our setup as we found it.
+ run_podman run --name my-container $IMAGE true
+ run_podman commit my-container my-test-image
+
+ run_podman images my-test-image --format '{{ .History }}'
+ is "$output" "" "Image has empty history to begin with"
+
+ # Generate two randomish tags; 'tr' because they must be all lower-case
+ rand_name1="test-image-history-$(random_string 10 | tr A-Z a-z)"
+ rand_name2="test-image-history-$(random_string 10 | tr A-Z a-z)"
+
+ # Tag once, rmi, and make sure the tag name appears in history
+ run_podman tag my-test-image $rand_name1
+ run_podman rmi $rand_name1
+ run_podman images my-test-image --format '{{ .History }}'
+ is "$output" "localhost/${rand_name1}:latest" "image history after one tag"
+
+ # Repeat with second tag. Now both tags should be in history
+ run_podman tag my-test-image $rand_name2
+ run_podman rmi $rand_name2
+ run_podman images my-test-image --format '{{ .History }}'
+ is "$output" "localhost/${rand_name2}:latest, localhost/${rand_name1}:latest" \
+ "image history after two tags"
+
+ run_podman rmi my-test-image
+ run_podman rm my-container
}
# vim: filetype=sh
diff --git a/test/system/130-kill.bats b/test/system/130-kill.bats
new file mode 100644
index 000000000..aae7f114f
--- /dev/null
+++ b/test/system/130-kill.bats
@@ -0,0 +1,101 @@
+#!/usr/bin/env bats -*- bats -*-
+#
+# tests for podman kill
+#
+
+load helpers
+
+@test "podman kill - test signal handling in containers" {
+ # Start a container that will handle all signals by emitting 'got: N'
+ local -a signals=(1 2 3 4 5 6 8 10 12 13 14 15 16 20 21 22 23 24 25 26 64)
+ run_podman run -d $IMAGE sh -c "for i in ${signals[*]}; do trap \"echo got: \$i\" \$i; done; echo READY; while ! test -e /stop; do sleep 0.05; done;echo DONE"
+ cid="$output"
+
+ # Run 'logs -f' on that container, but run it in the background with
+ # redirection to a named pipe from which we (foreground job) read
+ # and confirm that signals are received. We can't use run_podman here.
+ local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
+ mkfifo $fifo
+ $PODMAN logs -f $cid >$fifo </dev/null &
+ podman_log_pid=$!
+
+ # Open the FIFO for reading, and keep it open. This prevents a race
+ # condition in which the container can exit (e.g. if for some reason
+ # it doesn't handle the signal) and we (this test) try to read from
+ # the FIFO. Since there wouldn't be an active writer, the open()
+ # would hang forever. With this exec we keep the FD open, allowing
+ # 'read -t' to time out and report a useful error.
+ exec 5<$fifo
+
+ # First container emits READY when ready; wait for it.
+ read -t 10 -u 5 ready
+ is "$ready" "READY" "first log message from container"
+
+ # Helper function: send the given signal, verify that it's received.
+ kill_and_check() {
+ local signal=$1
+ local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1'
+
+ run_podman kill -s $signal $cid
+ read -t 10 -u 5 actual || die "Timed out: no ACK for kill -s $signal"
+ is "$actual" "got: $signum" "Signal $signal handled by container"
+ }
+
+ # Send signals in random order; make sure each one is received
+ for s in $(fmt --width=2 <<< "${signals[*]}" | sort --random-sort);do
+ kill_and_check $s
+ done
+
+ # Variations: with leading dash; by name, with/without dash or SIG
+ kill_and_check -1 1
+ kill_and_check -INT 2
+ kill_and_check FPE 8
+ kill_and_check -SIGUSR1 10
+ kill_and_check SIGUSR2 12
+
+ # Done. Tell the container to stop, and wait for final DONE
+ run_podman exec $cid touch /stop
+ read -t 5 -u 5 done || die "Timed out waiting for DONE from container"
+ is "$done" "DONE" "final log message from container"
+
+ # Clean up
+ run_podman wait $cid
+ run_podman rm $cid
+ wait $podman_log_pid
+}
+
+@test "podman kill - rejects invalid args" {
+ # These errors are thrown by the imported docker/signal.ParseSignal()
+ local -a bad_signal_names=(0 SIGBADSIG SIG BADSIG %% ! "''" '""' " ")
+ for s in ${bad_signal_names[@]}; do
+ # 'nosuchcontainer' is fine: podman should bail before it gets there
+ run_podman 125 kill -s $s nosuchcontainer
+ is "$output" "Error: Invalid signal: $s" "Error from kill -s $s"
+
+ run_podman 125 pod kill -s $s nosuchpod
+ is "$output" "Error: Invalid signal: $s" "Error from pod kill -s $s"
+ done
+
+ # Special case: these too are thrown by docker/signal.ParseSignal(),
+ # but the dash sign is stripped by our wrapper in utils, so the
+ # error message doesn't include the dash.
+ local -a bad_dash_signals=(-0 -SIGBADSIG -SIG -BADSIG -)
+ for s in ${bad_dash_signals[@]}; do
+ run_podman 125 kill -s $s nosuchcontainer
+ is "$output" "Error: Invalid signal: ${s##-}" "Error from kill -s $s"
+ done
+
+ # This error (signal out of range) is thrown by our wrapper
+ local -a bad_signal_nums=(65 -65 96 999 99999999)
+ for s in ${bad_signal_nums[@]}; do
+ run_podman 125 kill -s $s nosuchcontainer
+ is "$output" "Error: valid signals are 1 through 64" \
+ "Error from kill -s $s"
+ done
+
+ # 'podman create' uses the same parsing code
+ run_podman 125 create --stop-signal=99 $IMAGE
+ is "$output" "Error: valid signals are 1 through 64" "podman create"
+}
+
+# vim: filetype=sh
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 8c061d2c9..940f3f426 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -36,7 +36,7 @@ function basic_setup() {
if [ "$1" == "$PODMAN_TEST_IMAGE_FQN" ]; then
found_needed_image=1
else
- echo "# setup(): removing stray images" >&3
+ echo "# setup(): removing stray images $1 $2" >&3
run_podman rmi --force "$1" >/dev/null 2>&1 || true
run_podman rmi --force "$2" >/dev/null 2>&1 || true
fi