aboutsummaryrefslogtreecommitdiff
path: root/test/apiv2
diff options
context:
space:
mode:
Diffstat (limited to 'test/apiv2')
-rw-r--r--test/apiv2/01-basic.at4
-rw-r--r--test/apiv2/10-images.at78
-rw-r--r--test/apiv2/20-containers.at12
-rw-r--r--test/apiv2/27-containersEvents.at27
-rw-r--r--test/apiv2/35-networks.at2
-rw-r--r--test/apiv2/README.md6
-rwxr-xr-xtest/apiv2/test-apiv286
7 files changed, 126 insertions, 89 deletions
diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at
index 564c7bed5..2747ccbd4 100644
--- a/test/apiv2/01-basic.at
+++ b/test/apiv2/01-basic.at
@@ -82,7 +82,7 @@ else
fi
# Simple events test (see #7078)
-t GET "events?stream=false" 200
-t GET "libpod/events?stream=false" 200
+t GET "events?stream=false&since=30s" 200
+t GET "libpod/events?stream=false&since=30s" 200
# vim: filetype=sh
diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at
index e67f559f3..36c2fc6aa 100644
--- a/test/apiv2/10-images.at
+++ b/test/apiv2/10-images.at
@@ -53,8 +53,8 @@ t POST "images/create?fromImage=alpine" 200 .error~null .status~".*Download comp
t POST "images/create?fromImage=alpine&tag=latest" 200
# 10977 - handle platform parameter correctly
-t POST "images/create?fromImage=alpine&platform=linux/arm64" 200
-t GET "images/alpine/json" 200 \
+t POST "images/create?fromImage=testimage:20210610&platform=linux/arm64" 200
+t GET "images/testimage:20210610/json" 200 \
.Architecture=arm64
# Make sure that new images are pulled
@@ -62,7 +62,7 @@ old_iid=$(podman image inspect --format "{{.ID}}" docker.io/library/alpine:lates
podman rmi -f docker.io/library/alpine:latest
podman tag $IMAGE docker.io/library/alpine:latest
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*$old_iid.*"
-podman untag $IMAGE docker.io/library/alpine:latest
+podman untag docker.io/library/alpine:latest
t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" 200
@@ -171,66 +171,32 @@ function cleanBuildTest() {
}
CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
cat > $TMPD/containerfile << EOF
-FROM quay.io/libpod/alpine_labels:latest
+FROM $IMAGE
EOF
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null
-curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
- -H "content-type: application/x-tar" \
- --dump-header "${TMPD}/headers.txt" \
- -o "${TMPD}/response.txt" \
- "http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
-
-BUILD_TEST_ERROR=""
-
-if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
- echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/x-tar)"
- BUILD_TEST_ERROR="1"
-fi
-
-if ! grep -q 'quay.io/libpod/alpine_labels' "${TMPD}/response.txt"; then
- echo -e "${red}NOK: Image build from tar failed image name not in response"
- BUILD_TEST_ERROR="1"
-fi
-
-curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
- -H "content-type: application/tar" \
- --dump-header "${TMPD}/headers.txt" \
- -o /dev/null \
- "http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
-if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
- echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
- BUILD_TEST_ERROR="1"
-fi
-
-# Yes, this is very un-RESTful re: Content-Type header ignored when compatibility endpoint used
-# See https://github.com/containers/podman/issues/11012
-curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
- -H "content-type: application/json" \
- --dump-header "${TMPD}/headers.txt" \
- -o /dev/null \
- "http://$HOST:$PORT/v1.40/build?dockerfile=containerfile" &> /dev/null
-if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
- echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/tar)"
- BUILD_TEST_ERROR="1"
-fi
-
-curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
- -H "content-type: application/json" \
- --dump-header "${TMPD}/headers.txt" \
- -o /dev/null \
- "http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null
-if ! grep -q '400 Bad Request' "${TMPD}/headers.txt"; then
- echo -e "${red}NOK: Image build should have failed with 400 (wrong Content-Type)"
- BUILD_TEST_ERROR="1"
-fi
+t POST "libpod/build?dockerfile=containerfile" $CONTAINERFILE_TAR 200 \
+ .stream~"STEP 1/1: FROM $IMAGE"
+
+# With -q, all we should get is image ID. Test both libpod & compat endpoints.
+t POST "libpod/build?dockerfile=containerfile&q=true" $CONTAINERFILE_TAR 200 \
+ .stream~'^[0-9a-f]\{64\}$'
+t POST "build?dockerfile=containerfile&q=true" $CONTAINERFILE_TAR 200 \
+ .stream~'^[0-9a-f]\{64\}$'
+
+# Override content-type and confirm that libpod rejects, but compat accepts
+t POST "libpod/build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 400 \
+ .cause='Content-Type: application/json is not supported. Should be "application/x-tar"'
+t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 200 \
+ .stream~"STEP 1/1: FROM $IMAGE"
+
+# PR #12091: output from compat API must now include {"aux":{"ID":"sha..."}}
+t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR 200 \
+ '.aux|select(has("ID")).ID~^sha256:[0-9a-f]\{64\}$'
t POST libpod/images/prune 200
t POST libpod/images/prune 200 length=0 []
cleanBuildTest
-if [[ "${BUILD_TEST_ERROR}" ]]; then
- exit 1
-fi
# vim: filetype=sh
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index 748a0750f..554a905d4 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -18,7 +18,7 @@ podman rm -a -f &>/dev/null
t GET "libpod/containers/json (at start: clean slate)" 200 length=0
-podman run $IMAGE true
+podman run -v /tmp:/tmp $IMAGE true
t GET libpod/containers/json 200 length=0
@@ -33,6 +33,7 @@ t GET libpod/containers/json?all=true 200 \
.[0].Command[0]="true" \
.[0].State~\\\(exited\\\|stopped\\\) \
.[0].ExitCode=0 \
+ .[0].Mounts~.*/tmp \
.[0].IsInfra=false
# Test compat API for Network Settings (.Network is N/A when rootless)
@@ -44,8 +45,13 @@ t GET /containers/json?all=true 200 \
length=1 \
.[0].Id~[0-9a-f]\\{64\\} \
.[0].Image=$IMAGE \
+ .[0].Mounts~.*/tmp \
$network_expect
+# compat API imageid with sha256: prefix
+t GET containers/json?limit=1 200 \
+ .[0].ImageID~sha256:[0-9a-f]\\{64\\}
+
# Make sure `limit` works.
t GET libpod/containers/json?limit=1 200 \
length=1 \
@@ -97,7 +103,7 @@ t GET libpod/containers/${cid}/json 200 \
t DELETE libpod/containers/$cid 204
CNAME=myfoo
-podman run --name $CNAME $IMAGE -td top
+podman run -d --name $CNAME $IMAGE top
t GET libpod/containers/json?all=true 200 \
.[0].Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.[0].Id' <<<"$output")
@@ -184,7 +190,7 @@ t GET containers/myctr/json 200 \
t DELETE images/localhost/newrepo:latest?force=true 200
t DELETE images/localhost/newrepo:v1?force=true 200
t DELETE images/localhost/newrepo:v2?force=true 200
-t DELETE libpod/containers/$cid 204
+t DELETE libpod/containers/$cid?force=true 204
t DELETE libpod/containers/myctr 204
t DELETE libpod/containers/bogus 404
diff --git a/test/apiv2/27-containersEvents.at b/test/apiv2/27-containersEvents.at
new file mode 100644
index 000000000..a86f2e353
--- /dev/null
+++ b/test/apiv2/27-containersEvents.at
@@ -0,0 +1,27 @@
+# -*- sh -*-
+#
+# test container-related events
+#
+
+podman pull $IMAGE &>/dev/null
+
+# Ensure clean slate
+podman rm -a -f &>/dev/null
+
+START=$(date +%s)
+
+podman run $IMAGE false || true
+
+# libpod api
+t GET "libpod/events?stream=false&since=$START" 200 \
+ 'select(.status | contains("start")).Action=start' \
+ 'select(.status | contains("died")).Action=died' \
+ 'select(.status | contains("died")).Actor.Attributes.containerExitCode=1'
+
+# compat api, uses status=die (#12643)
+t GET "events?stream=false&since=$START" 200 \
+ 'select(.status | contains("start")).Action=start' \
+ 'select(.status | contains("die")).Action=die' \
+ 'select(.status | contains("die")).Actor.Attributes.exitCode=1'
+
+# vim: filetype=sh
diff --git a/test/apiv2/35-networks.at b/test/apiv2/35-networks.at
index 713f677fa..0e2389bd5 100644
--- a/test/apiv2/35-networks.at
+++ b/test/apiv2/35-networks.at
@@ -7,7 +7,7 @@ t GET networks/non-existing-network 404 \
.cause='network not found'
t POST libpod/networks/create name='"network1"' 200 \
- .name=network1
+ .name=network1 \
.created~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
# --data '{"name":"network2","subnets":[{"subnet":"10.10.254.0/24"}],"Labels":{"abc":"val"}}'
diff --git a/test/apiv2/README.md b/test/apiv2/README.md
index 19727cec7..63d1f5b13 100644
--- a/test/apiv2/README.md
+++ b/test/apiv2/README.md
@@ -60,6 +60,12 @@ of POST parameters in the form 'key=value', separated by spaces:
t POST myentrypoint name=$name badparam='["foo","bar"]' 500 ! etc...
`t` will convert the param list to JSON form for passing to the server.
A numeric status code terminates processing of POST parameters.
+** As a special case, when one POST argument is a string ending in `.tar`,
+`t` will invoke `curl` with `--data-binary @PATH` and
+set `Content-type: application/x-tar`. This is useful for `build` endpoints.
+(To override `Content-type`, simply pass along an extra string argument
+matching `application/*`):
+ t POST myentrypoint /mytmpdir/myfile.tar application/foo 400
* The final arguments are one or more expected string results. If an
argument starts with a dot, `t` will invoke `jq` on the output to
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index c644b9578..391095539 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -48,6 +48,30 @@ TESTS_DIR=$(realpath $(dirname $0))
# Path to podman binary
PODMAN_BIN=${PODMAN:-${TESTS_DIR}/../../bin/podman}
+# Cleanup handlers
+clean_up_server() {
+ if [ -n "$service_pid" ]; then
+ # Remove any containers and images; this prevents the following warning:
+ # 'rm: cannot remove '/.../overlay': Device or resource busy
+ podman rm -a
+ podman rmi -af
+
+ stop_registry
+ stop_service
+ fi
+}
+
+# Any non-test-related error, be it syntax or podman-command, fails here.
+err_handler() {
+ echo "Fatal error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
+ echo "Log:"
+ sed -e 's/^/ >/' <$WORKDIR/output.log
+ echo "Bailing."
+ clean_up_server
+}
+
+trap err_handler ERR
+
# END setup
###############################################################################
# BEGIN infrastructure code - the helper functions used in tests themselves
@@ -182,6 +206,7 @@ function t() {
local method=$1; shift
local path=$1; shift
local curl_args
+ local content_type="application/json"
local testname="$method $path"
# POST requests may be followed by one or more key=value pairs.
@@ -190,13 +215,21 @@ function t() {
local -a post_args
for arg; do
case "$arg" in
- *=*) post_args+=("$arg"); shift ;;
+ *=*) post_args+=("$arg");
+ shift;;
+ *.tar) curl_args="--data-binary @$arg" ;
+ content_type="application/x-tar";
+ shift;;
+ application/*) content_type="$arg";
+ shift;;
[1-9][0-9][0-9]) break;;
*) die "Internal error: invalid POST arg '$arg'" ;;
esac
done
- curl_args="-d $(jsonify ${post_args[@]})"
- testname="$testname [$curl_args]"
+ if [[ -z "$curl_args" ]]; then
+ curl_args="-d $(jsonify ${post_args[@]})"
+ testname="$testname [$curl_args]"
+ fi
fi
# entrypoint path can include a descriptive comment; strip it off
@@ -228,14 +261,15 @@ function t() {
echo "\$ $testname" >>$LOG
rm -f $WORKDIR/curl.*
# -s = silent, but --write-out 'format' gives us important response data
- response=$(curl -s -X $method ${curl_args} \
- -H 'Content-type: application/json' \
- --dump-header $WORKDIR/curl.headers.out \
+ # The hairy "{ ...;rc=$?; } || :" lets us capture curl's exit code and
+ # give a helpful diagnostic if it fails.
+ { response=$(curl -s -X $method ${curl_args} \
+ -H "Content-type: $content_type" \
+ --dump-header $WORKDIR/curl.headers.out \
--write-out '%{http_code}^%{content_type}^%{time_total}' \
- -o $WORKDIR/curl.result.out "$url")
+ -o $WORKDIR/curl.result.out "$url"); rc=$?; } || :
# Any error from curl is instant bad news, from which we can't recover
- rc=$?
if [[ $rc -ne 0 ]]; then
echo "FATAL: curl failure ($rc) on $url - cannot continue" >&2
exit 1
@@ -328,10 +362,13 @@ function start_service() {
fi
echo $WORKDIR
- $PODMAN_BIN --root $WORKDIR/server_root --syslog=true \
- system service \
- --time 15 \
- tcp:127.0.0.1:$PORT \
+ # Some tests use shortnames; force registry override to work around
+ # docker.io throttling.
+ env CONTAINERS_REGISTRIES_CONF=$TESTS_DIR/../registries.conf $PODMAN_BIN \
+ --root $WORKDIR/server_root --syslog=true \
+ system service \
+ --time 15 \
+ tcp:127.0.0.1:$PORT \
&> $WORKDIR/server.log &
service_pid=$!
@@ -341,8 +378,8 @@ function start_service() {
function stop_service() {
# Stop the server
if [[ -n $service_pid ]]; then
- kill $service_pid
- wait $service_pid
+ kill $service_pid || :
+ wait $service_pid || :
fi
}
@@ -459,8 +496,9 @@ function wait_for_port() {
# podman # Needed by some test scripts to invoke the actual podman binary
############
function podman() {
- echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
- $PODMAN_BIN --root $WORKDIR/server_root "$@" >>$WORKDIR/output.log 2>&1
+ echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
+ env CONTAINERS_REGISTRIES_CONF=$TESTS_DIR/../registries.conf \
+ $PODMAN_BIN --root $WORKDIR/server_root "$@" >>$WORKDIR/output.log 2>&1
}
####################
@@ -516,23 +554,17 @@ start_service
for i in ${tests_to_run[@]}; do
TEST_CONTEXT="[$(basename $i .at)]"
+
+ # Clear output from 'podman' helper
+ >| $WORKDIR/output.log
+
source $i
done
# END entry handler
###############################################################################
-# Clean up
-
-if [ -n "$service_pid" ]; then
- # Remove any containers and images; this prevents the following warning:
- # 'rm: cannot remove '/.../overlay': Device or resource busy
- podman rm -a
- podman rmi -af
-
- stop_registry
- stop_service
-fi
+clean_up_server
test_count=$(<$testcounter_file)
failure_count=$(<$failures_file)