mirror of https://github.com/containers/podman.git
Merge pull request #15469 from edsantiago/test_cleanup_apiv2
APIv2 test cleanup
This commit is contained in:
commit
d122aa4935
|
@ -63,7 +63,7 @@ podman pull -q $IMAGE
|
||||||
|
|
||||||
# test podman image SCP
|
# test podman image SCP
|
||||||
# ssh needs to work so we can validate that the failure is past argument parsing
|
# ssh needs to work so we can validate that the failure is past argument parsing
|
||||||
podman system connection add --default test ssh://$USER@localhost/run/user/$UID/podman/podman.sock
|
podman system connection add --default test ssh://$USER@localhost/run/user/$MYUID/podman/podman.sock
|
||||||
# should fail but need to check the output...
|
# should fail but need to check the output...
|
||||||
# status 125 here means that the save/load fails due to
|
# status 125 here means that the save/load fails due to
|
||||||
# cirrus weirdness with exec.Command. All of the args have been parsed successfully.
|
# cirrus weirdness with exec.Command. All of the args have been parsed successfully.
|
||||||
|
|
|
@ -529,21 +529,21 @@ sleep 3
|
||||||
t GET containers/status-test/json 200 .State.Status="exited"
|
t GET containers/status-test/json 200 .State.Status="exited"
|
||||||
|
|
||||||
# test podman generate spec as input for the api
|
# test podman generate spec as input for the api
|
||||||
podman create --name=specgen alpine_labels
|
cname=specgen$(random_string 10)
|
||||||
|
podman create --name=$cname $IMAGE
|
||||||
|
|
||||||
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
|
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
|
||||||
|
|
||||||
podman generate spec -f ${TMPD}/input.txt -c specgen
|
podman generate spec -f ${TMPD}/myspec.json -c $cname
|
||||||
|
|
||||||
curl -XPOST -o ${TMPD}/response.txt --dump-header ${TMPD}/headers.txt -H content-type:application/json http://$HOST:$PORT/v4.0.0/libpod/containers/create -d "@${TMPD}/input.txt"
|
# Create a container based on that spec
|
||||||
|
t POST libpod/containers/create ${TMPD}/myspec.json 201 \
|
||||||
|
.Id~[0-9a-f]\\{64\\}
|
||||||
|
|
||||||
if ! grep -q '201 Created' "${TMPD}/headers.txt"; then
|
# Verify
|
||||||
cat "${TMPD}/headers.txt"
|
t GET libpod/containers/$cname/json 200 \
|
||||||
cat "${TMPD}/response.txt"
|
.ImageName=$IMAGE \
|
||||||
echo -e "${red}NOK: container create failed"
|
.Name=$cname
|
||||||
rm -rf $TMPD
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf $TMPD
|
rm -rf $TMPD
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,26 @@ podman pull $IMAGE &>/dev/null
|
||||||
# Ensure clean slate
|
# Ensure clean slate
|
||||||
podman rm -a -f &>/dev/null
|
podman rm -a -f &>/dev/null
|
||||||
|
|
||||||
CTR="ArchiveTestingCtr"
|
CTR="ArchiveTestingCtr$(random_string 5)"
|
||||||
|
|
||||||
TMPD=$(mktemp -d podman-apiv2-test.archive.XXXXXXXX)
|
TMPD=$(mktemp -d podman-apiv2-test.archive.XXXXXXXX)
|
||||||
HELLO_TAR="${TMPD}/hello.tar"
|
HELLO_TAR="${TMPD}/hello.tar"
|
||||||
echo "Hello" > $TMPD/hello.txt
|
HELLO_S="Hello_$(random_string 8)"
|
||||||
|
echo "$HELLO_S" > $TMPD/hello.txt
|
||||||
tar --owner=1042 --group=1043 --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null
|
tar --owner=1042 --group=1043 --format=posix -C $TMPD -cvf ${HELLO_TAR} hello.txt &> /dev/null
|
||||||
|
|
||||||
|
# Start a container, and wait for it. (I know we don't actually do anything
|
||||||
|
# if we time out. If we do, subsequent tests will fail. I just want to avoid
|
||||||
|
# a race between container-start and tests-start)
|
||||||
podman run -d --name "${CTR}" "${IMAGE}" top
|
podman run -d --name "${CTR}" "${IMAGE}" top
|
||||||
|
timeout=10
|
||||||
|
while [[ $timeout -gt 0 ]]; do
|
||||||
|
if podman container exists "${CTR}"; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
timeout=$((timeout - 1))
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
function cleanUpArchiveTest() {
|
function cleanUpArchiveTest() {
|
||||||
podman container stop "${CTR}" &> /dev/null
|
podman container stop "${CTR}" &> /dev/null
|
||||||
|
@ -30,63 +42,47 @@ t HEAD "containers/nonExistentCtr/archive?path=%2F" 404
|
||||||
t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404
|
t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404
|
||||||
t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200
|
t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200
|
||||||
|
|
||||||
curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \
|
# Send tarfile to container...
|
||||||
-X PUT \
|
t PUT "/containers/${CTR}/archive?path=%2Ftmp%2F" ${HELLO_TAR} 200 ''
|
||||||
-H "Content-Type: application/x-tar" \
|
|
||||||
--upload-file "${HELLO_TAR}" &> /dev/null
|
|
||||||
|
|
||||||
if ! podman exec -it "${CTR}" "grep" "Hello" "/tmp/hello.txt" &> /dev/null ; then
|
# ...and 'exec cat file' to confirm that it got extracted into place.
|
||||||
echo -e "${red}NOK: The hello.txt file has not been uploaded.${nc}" 1>&2;
|
cat >$TMPD/exec.json <<EOF
|
||||||
cleanUpArchiveTest
|
{ "AttachStdout":true,"Cmd":["cat","/tmp/hello.txt"]}
|
||||||
exit 1
|
EOF
|
||||||
fi
|
t POST containers/${CTR}/exec $TMPD/exec.json 201 .Id~[0-9a-f]\\{64\\}
|
||||||
|
eid=$(jq -r '.Id' <<<"$output")
|
||||||
|
# The 017 is the byte length
|
||||||
|
t POST exec/$eid/start 200 $'\001\017'$HELLO_S
|
||||||
|
|
||||||
|
# Now fetch hello.txt back as a tarfile
|
||||||
t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200
|
t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200
|
||||||
|
t GET "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200
|
||||||
|
|
||||||
curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" \
|
# Check important-looking header
|
||||||
--dump-header "${TMPD}/headers.txt" \
|
PATH_STAT="$(grep X-Docker-Container-Path-Stat "$WORKDIR/curl.headers.out" | cut -d " " -f 2 | base64 -d --ignore-garbage)"
|
||||||
-o "${TMPD}/body.tar" \
|
|
||||||
-X GET &> /dev/null
|
|
||||||
|
|
||||||
PATH_STAT="$(grep X-Docker-Container-Path-Stat "${TMPD}/headers.txt" | cut -d " " -f 2 | base64 -d --ignore-garbage)"
|
is "$(jq -r .name <<<$PATH_STAT)" "hello.txt" "Docker-Path-Stat .name"
|
||||||
|
is "$(jq -r .size <<<$PATH_STAT)" "15" "Docker-Path-Stat .size"
|
||||||
|
|
||||||
ARCHIVE_TEST_ERROR=""
|
# Check filename and its contents
|
||||||
|
tar_tf=$(tar tf $WORKDIR/curl.result.out)
|
||||||
|
is "$tar_tf" "hello.txt" "fetched tarball: file name"
|
||||||
|
|
||||||
if [ "$(echo "${PATH_STAT}" | jq ".name")" != '"hello.txt"' ]; then
|
tar_contents=$(tar xf $WORKDIR/curl.result.out --to-stdout)
|
||||||
echo -e "${red}NOK: Wrong name in X-Docker-Container-Path-Stat header.${nc}" 1>&2;
|
is "$tar_contents" "$HELLO_S" "fetched tarball: file contents"
|
||||||
ARCHIVE_TEST_ERROR="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(echo "${PATH_STAT}" | jq ".size")" != "6" ]; then
|
|
||||||
echo -e "${red}NOK: Wrong size in X-Docker-Container-Path-Stat header.${nc}" 1>&2;
|
|
||||||
ARCHIVE_TEST_ERROR="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! tar -tf "${TMPD}/body.tar" | grep "hello.txt" &> /dev/null; then
|
|
||||||
echo -e "${red}NOK: Body doesn't contain expected file.${nc}" 1>&2;
|
|
||||||
ARCHIVE_TEST_ERROR="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then
|
|
||||||
echo -e "${red}NOK: Content of file doesn't match.${nc}" 1>&2;
|
|
||||||
ARCHIVE_TEST_ERROR="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# test if uid/gid was set correctly in the server
|
|
||||||
uidngid=$($PODMAN_BIN --root $WORKDIR/server_root exec "${CTR}" stat -c "%u:%g" "/tmp/hello.txt")
|
|
||||||
if [[ "${uidngid}" != "1042:1043" ]]; then
|
|
||||||
echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2;
|
|
||||||
ARCHIVE_TEST_ERROR="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: uid/gid should be also preserved on way back (GET request)
|
# TODO: uid/gid should be also preserved on way back (GET request)
|
||||||
# right now it ends up as root:root instead of 1042:1043
|
# right now it ends up as 0/0 instead of 1042/1043
|
||||||
#if [[ "$(tar -tvf "${TMPD}/body.tar")" != *"1042/1043"* ]]; then
|
tar_uidgid=$(tar tvf $WORKDIR/curl.result.out | awk '{print $2}')
|
||||||
# echo -e "${red}NOK: UID/GID of the file doesn't match.${nc}" 1>&2;
|
is "$tar_uidgid" "0/0" "fetched tarball: file uid/gid"
|
||||||
# ARCHIVE_TEST_ERROR="1"
|
|
||||||
#fi
|
# test if uid/gid was set correctly in the server. Again, via exec.
|
||||||
|
cat >$TMPD/exec.json <<EOF
|
||||||
|
{ "AttachStdout":true,"Cmd":["stat","-c","%u:%g","/tmp/hello.txt"]}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
t POST containers/${CTR}/exec $TMPD/exec.json 201 .Id~[0-9a-f]\\{64\\}
|
||||||
|
eid=$(jq -r '.Id' <<<"$output")
|
||||||
|
t POST exec/$eid/start 200 $'\001\012'1042:1043
|
||||||
|
|
||||||
cleanUpArchiveTest
|
cleanUpArchiveTest
|
||||||
if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ REGISTRY_IMAGE="${PODMAN_TEST_IMAGE_REGISTRY}/${PODMAN_TEST_IMAGE_USER}/registry
|
||||||
# BEGIN setup
|
# BEGIN setup
|
||||||
|
|
||||||
USER=$PODMAN_ROOTLESS_USER
|
USER=$PODMAN_ROOTLESS_USER
|
||||||
UID=$PODMAN_ROOTLESS_UID
|
MYUID=$PODMAN_ROOTLESS_UID
|
||||||
TMPDIR=${TMPDIR:-/tmp}
|
TMPDIR=${TMPDIR:-/tmp}
|
||||||
WORKDIR=$(mktemp --tmpdir -d $ME.tmp.XXXXXX)
|
WORKDIR=$(mktemp --tmpdir -d $ME.tmp.XXXXXX)
|
||||||
|
|
||||||
|
@ -135,7 +135,8 @@ function like() {
|
||||||
##############
|
##############
|
||||||
function _show_ok() {
|
function _show_ok() {
|
||||||
local ok=$1
|
local ok=$1
|
||||||
local testname=$2
|
# Exec tests include control characters; filter them out
|
||||||
|
local testname=$(tr -d \\012 <<<"$2"|cat -vT)
|
||||||
|
|
||||||
# If output is a tty, colorize pass/fail
|
# If output is a tty, colorize pass/fail
|
||||||
local red=
|
local red=
|
||||||
|
@ -254,14 +255,24 @@ function t() {
|
||||||
# Slurp the command line until we see a 3-digit status code.
|
# Slurp the command line until we see a 3-digit status code.
|
||||||
if [[ $method = "POST" || $method == "PUT" || $method = "DELETE" ]]; then
|
if [[ $method = "POST" || $method == "PUT" || $method = "DELETE" ]]; then
|
||||||
local -a post_args
|
local -a post_args
|
||||||
|
|
||||||
|
if [[ $method = "POST" ]]; then
|
||||||
|
function _add_curl_args() { curl_args+=(--data-binary @$1); }
|
||||||
|
else
|
||||||
|
function _add_curl_args() { curl_args+=(--upload-file $1); }
|
||||||
|
fi
|
||||||
|
|
||||||
for arg; do
|
for arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
*=*) post_args+=("$arg");
|
*=*) post_args+=("$arg");
|
||||||
shift;;
|
shift;;
|
||||||
*.tar) curl_args+=(--data-binary @$arg);
|
*.json) _add_curl_args $arg;
|
||||||
|
content_type="application/json";
|
||||||
|
shift;;
|
||||||
|
*.tar) _add_curl_args $arg;
|
||||||
content_type="application/x-tar";
|
content_type="application/x-tar";
|
||||||
shift;;
|
shift;;
|
||||||
*.yaml) curl_args+=(--data-binary @$arg);
|
*.yaml) _add_curl_args $arg;
|
||||||
shift;;
|
shift;;
|
||||||
application/*) content_type="$arg";
|
application/*) content_type="$arg";
|
||||||
shift;;
|
shift;;
|
||||||
|
|
Loading…
Reference in New Issue