2019-08-20 16:13:20 +08:00
|
|
|
#!/usr/bin/env bash
|
2017-03-07 07:11:40 +08:00
|
|
|
|
2020-05-28 12:10:04 +08:00
|
|
|
BUILDAH_BINARY=${BUILDAH_BINARY:-$(dirname ${BASH_SOURCE})/../bin/buildah}
|
|
|
|
IMGTYPE_BINARY=${IMGTYPE_BINARY:-$(dirname ${BASH_SOURCE})/../bin/imgtype}
|
2017-03-07 07:11:40 +08:00
|
|
|
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
|
2017-06-17 02:21:43 +08:00
|
|
|
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
|
2017-07-21 01:41:51 +08:00
|
|
|
PATH=$(dirname ${BASH_SOURCE})/..:${PATH}
|
2020-04-28 02:12:30 +08:00
|
|
|
OCI=$(${BUILDAH_BINARY} info --format '{{.host.OCIRuntime}}' || command -v runc || command -v crun)
|
2017-03-07 07:11:40 +08:00
|
|
|
|
2019-04-02 05:56:29 +08:00
|
|
|
# Default timeout for a buildah command.
|
2019-04-03 21:38:25 +08:00
|
|
|
BUILDAH_TIMEOUT=${BUILDAH_TIMEOUT:-300}
|
2019-04-02 05:56:29 +08:00
|
|
|
|
2020-01-30 00:05:20 +08:00
|
|
|
# We don't invoke gnupg directly in many places, but this avoids ENOTTY errors
|
|
|
|
# when we invoke it directly in batch mode, and CI runs us without a terminal
|
|
|
|
# attached.
|
|
|
|
export GPG_TTY=/dev/null
|
|
|
|
|
2017-03-07 07:11:40 +08:00
|
|
|
function setup() {
|
2020-09-18 22:15:36 +08:00
|
|
|
pushd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
|
|
|
|
2018-05-18 05:50:13 +08:00
|
|
|
suffix=$(dd if=/dev/urandom bs=12 count=1 status=none | od -An -tx1 | sed -e 's, ,,g')
|
|
|
|
TESTDIR=${BATS_TMPDIR}/tmp${suffix}
|
2017-03-08 04:54:51 +08:00
|
|
|
rm -fr ${TESTDIR}
|
|
|
|
mkdir -p ${TESTDIR}/{root,runroot}
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
|
|
|
|
2017-03-28 15:01:59 +08:00
|
|
|
function starthttpd() {
|
2017-03-30 03:50:32 +08:00
|
|
|
pushd ${2:-${TESTDIR}} > /dev/null
|
2018-04-19 16:52:24 +08:00
|
|
|
go build -o serve ${TESTSDIR}/serve/serve.go
|
2017-03-28 15:01:59 +08:00
|
|
|
HTTP_SERVER_PORT=$((RANDOM+32768))
|
|
|
|
./serve ${HTTP_SERVER_PORT} ${1:-${BATS_TMPDIR}} &
|
|
|
|
HTTP_SERVER_PID=$!
|
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function stophttpd() {
|
|
|
|
if test -n "$HTTP_SERVER_PID" ; then
|
|
|
|
kill -HUP ${HTTP_SERVER_PID}
|
|
|
|
unset HTTP_SERVER_PID
|
|
|
|
unset HTTP_SERVER_PORT
|
|
|
|
fi
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:11:40 +08:00
|
|
|
function teardown() {
|
2017-03-28 15:01:59 +08:00
|
|
|
stophttpd
|
2020-02-27 03:23:33 +08:00
|
|
|
|
|
|
|
# Workaround for #1991 - buildah + overlayfs leaks mount points.
|
|
|
|
# Many tests leave behind /var/tmp/.../root/overlay and sub-mounts;
|
|
|
|
# let's find those and clean them up, otherwise 'rm -rf' fails.
|
|
|
|
# 'sort -r' guarantees that we umount deepest subpaths first.
|
|
|
|
mount |\
|
|
|
|
awk '$3 ~ testdir { print $3 }' testdir="^${TESTDIR}/" |\
|
|
|
|
sort -r |\
|
|
|
|
xargs --no-run-if-empty --max-lines=1 umount
|
|
|
|
|
2017-03-08 04:54:51 +08:00
|
|
|
rm -fr ${TESTDIR}
|
2020-09-18 22:15:36 +08:00
|
|
|
|
|
|
|
popd
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
|
|
|
|
2019-12-09 21:45:52 +08:00
|
|
|
function _prefetch() {
|
Move away from using docker.io
November 2020, docker.io started restricting unauthenticated
image pulls. Try to work around this by using a custom
registries.conf file.
For the most part this means copying images from docker.io
to quay.io, via:
$ skopeo copy --all docker://docker.io/library/img:tag \
docker://quay.io/libpod/img:tag
...for the following values of 'img:tag':
busybox:musl
centos:7 centos:8 centos:latest
composer:latest
debian:latest ubuntu:latest
docker:latest
php:7.2
For each of those, it was necessary to go into the quay.io
GUI, click the image name, click the settings (gear) icon
at bottom left, click 'Make public', and confirm.
This process did not work in four instances, which required
special-casing:
commit.bats : openshift/hello-openshift did not match the
mirroring rules; I switched to alpine instead.
Nalin confirmed on IRC that there was no magic
reason for requiring hello-openshift.
pull.bats : change a SHA. AFAICT there was nothing magic
about the SHA being used, it was just a
convenient one for purposes of testing
pull-by-sha. I simply switched to the SHA
of an image present on quay.
registries.bats : was assuming that fedora-minimal shortname
would be pulled from fedora registry.
Unfortunately, we have a copy on quay
(for podman tests), so that's what we
pull by shortname, and it does not match
the SHA of the fedoraproject.org one.
Solution: pull by tag (fedora-minimal:32)
and hope that nobody ever mirrors that one
on quay.
run.bats : another pull-by-SHA, but this time I changed
the SHA to a named tag, and skopeo copy'd
that image from docker.io to the given name
on quay. This time there _is_ something
magic about that particular SHA (it's an
image with a specific volume quirk) but
there's no actual reason to reference it
by SHA - we simply did so because we have
no control over tag names on docker.io.
Since we control tag names on quay.io,
it's easy and more maintainable to give
this image a descriptive tag.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-12-08 06:36:43 +08:00
|
|
|
# Tell podman to use the same mirror registries as buildah, to
|
|
|
|
# avoid docker.io
|
|
|
|
export REGISTRIES_CONFIG_PATH=${TESTSDIR}/registries.conf
|
|
|
|
|
2019-12-09 21:45:52 +08:00
|
|
|
if [ -z "${_BUILDAH_IMAGE_CACHEDIR}" ]; then
|
|
|
|
_pgid=$(sed -ne 's/^NSpgid:\s*//p' /proc/$$/status)
|
|
|
|
export _BUILDAH_IMAGE_CACHEDIR=${BATS_TMPDIR}/buildah-image-cache.$_pgid
|
|
|
|
mkdir -p ${_BUILDAH_IMAGE_CACHEDIR}
|
|
|
|
fi
|
|
|
|
|
|
|
|
local _podman_opts="--root ${TESTDIR}/root --storage-driver ${STORAGE_DRIVER}"
|
|
|
|
|
|
|
|
for img in "$@"; do
|
|
|
|
echo "# [checking for: $img]" >&2
|
|
|
|
fname=$(tr -c a-zA-Z0-9.- - <<< "$img")
|
|
|
|
if [ -e $_BUILDAH_IMAGE_CACHEDIR/$fname.tar ]; then
|
|
|
|
echo "# [restoring from cache: $_BUILDAH_IMAGE_CACHEDIR / $img]" >&2
|
|
|
|
podman $_podman_opts load -i $_BUILDAH_IMAGE_CACHEDIR/$fname.tar
|
|
|
|
else
|
tests: prefetch: use buildah, not podman, for pulls
The _prefetch helper has proven invaluable in reducing pull-
related flakes. However, it is now failing because it uses
podman to pull, and buildah tests rely on shortnames, and
podman no longer works with shortnames.
Solution: use buildah, not podman, for initial image pulls.
(The reason we used podman in the first place is because
buildah does not have save/load. But since image store
is shared, we can use buildah for pull and podman for save
and load.)
Add shortname config to registries.conf. I don't think it's
actually necessary or even used, but we can tweak it later.
And, fix one test in from.bats that was using inconsistent
names between buildah and podman.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-03-23 23:55:06 +08:00
|
|
|
echo "# [buildah pull $img]" >&2
|
|
|
|
buildah pull $img || (
|
2019-12-09 21:45:52 +08:00
|
|
|
echo "Retrying:"
|
tests: prefetch: use buildah, not podman, for pulls
The _prefetch helper has proven invaluable in reducing pull-
related flakes. However, it is now failing because it uses
podman to pull, and buildah tests rely on shortnames, and
podman no longer works with shortnames.
Solution: use buildah, not podman, for initial image pulls.
(The reason we used podman in the first place is because
buildah does not have save/load. But since image store
is shared, we can use buildah for pull and podman for save
and load.)
Add shortname config to registries.conf. I don't think it's
actually necessary or even used, but we can tweak it later.
And, fix one test in from.bats that was using inconsistent
names between buildah and podman.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-03-23 23:55:06 +08:00
|
|
|
buildah pull $img || (
|
2019-12-09 21:45:52 +08:00
|
|
|
echo "Re-retrying:"
|
tests: prefetch: use buildah, not podman, for pulls
The _prefetch helper has proven invaluable in reducing pull-
related flakes. However, it is now failing because it uses
podman to pull, and buildah tests rely on shortnames, and
podman no longer works with shortnames.
Solution: use buildah, not podman, for initial image pulls.
(The reason we used podman in the first place is because
buildah does not have save/load. But since image store
is shared, we can use buildah for pull and podman for save
and load.)
Add shortname config to registries.conf. I don't think it's
actually necessary or even used, but we can tweak it later.
And, fix one test in from.bats that was using inconsistent
names between buildah and podman.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-03-23 23:55:06 +08:00
|
|
|
buildah pull $img
|
2019-12-09 21:45:52 +08:00
|
|
|
)
|
|
|
|
)
|
|
|
|
rm -f $_BUILDAH_IMAGE_CACHEDIR/$fname.tar
|
2020-02-07 01:04:17 +08:00
|
|
|
echo "# [podman save --format oci-archive $img >$_BUILDAH_IMAGE_CACHEDIR/$fname.tar ]" >&2
|
|
|
|
podman $_podman_opts save --format oci-archive --output=${_BUILDAH_IMAGE_CACHEDIR}/$fname.tar $img
|
2019-12-09 21:45:52 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:11:40 +08:00
|
|
|
function createrandom() {
|
|
|
|
dd if=/dev/urandom bs=1 count=${2:-256} of=${1:-${BATS_TMPDIR}/randomfile} status=none
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildah() {
|
2019-10-19 00:10:48 +08:00
|
|
|
${BUILDAH_BINARY} --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@"
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
2017-05-23 00:08:20 +08:00
|
|
|
|
|
|
|
function imgtype() {
|
2019-10-29 06:03:31 +08:00
|
|
|
${IMGTYPE_BINARY} -root ${TESTDIR}/root -runroot ${TESTDIR}/runroot -storage-driver ${STORAGE_DRIVER} "$@"
|
2017-05-23 00:08:20 +08:00
|
|
|
}
|
2018-09-03 19:20:52 +08:00
|
|
|
|
2019-04-02 05:56:29 +08:00
|
|
|
#################
|
|
|
|
# run_buildah # Invoke buildah, with timeout, using BATS 'run'
|
|
|
|
#################
|
|
|
|
#
|
|
|
|
# This is the preferred mechanism for invoking buildah:
|
|
|
|
#
|
|
|
|
# * we use 'timeout' to abort (with a diagnostic) if something
|
|
|
|
# takes too long; this is preferable to a CI hang.
|
|
|
|
# * we log the command run and its output. This doesn't normally
|
|
|
|
# appear in BATS output, but it will if there's an error.
|
|
|
|
# * we check exit status. Since the normal desired code is 0,
|
|
|
|
# that's the default; but the first argument can override:
|
|
|
|
#
|
|
|
|
# run_buildah 125 nonexistent-subcommand
|
|
|
|
# run_buildah '?' some-other-command # let our caller check status
|
|
|
|
#
|
|
|
|
# Since we use the BATS 'run' mechanism, $output and $status will be
|
|
|
|
# defined for our caller.
|
|
|
|
#
|
|
|
|
function run_buildah() {
|
|
|
|
# Number as first argument = expected exit code; default 0
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
# --retry as first argument = retry 3 times on error (eg registry flakes)
|
|
|
|
local expected_rc=0
|
|
|
|
local retry=1
|
2019-04-02 05:56:29 +08:00
|
|
|
case "$1" in
|
|
|
|
[0-9]) expected_rc=$1; shift;;
|
|
|
|
[1-9][0-9]) expected_rc=$1; shift;;
|
|
|
|
[12][0-9][0-9]) expected_rc=$1; shift;;
|
|
|
|
'?') expected_rc= ; shift;; # ignore exit code
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
--retry) retry=3; shift;; # retry network flakes
|
2019-04-02 05:56:29 +08:00
|
|
|
esac
|
|
|
|
|
2019-04-05 21:56:11 +08:00
|
|
|
# Remember command args, for possible use in later diagnostic messages
|
|
|
|
MOST_RECENT_BUILDAH_COMMAND="buildah $*"
|
|
|
|
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
while [ $retry -gt 0 ]; do
|
|
|
|
retry=$(( retry - 1 ))
|
|
|
|
|
|
|
|
# stdout is only emitted upon error; this echo is to help a debugger
|
|
|
|
echo "\$ $BUILDAH_BINARY $*"
|
|
|
|
run timeout --foreground --kill=10 $BUILDAH_TIMEOUT ${BUILDAH_BINARY} --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@"
|
|
|
|
# without "quotes", multiple lines are glommed together into one
|
|
|
|
if [ -n "$output" ]; then
|
|
|
|
echo "$output"
|
|
|
|
fi
|
|
|
|
if [ "$status" -ne 0 ]; then
|
|
|
|
echo -n "[ rc=$status ";
|
|
|
|
if [ -n "$expected_rc" ]; then
|
|
|
|
if [ "$status" -eq "$expected_rc" ]; then
|
|
|
|
echo -n "(expected) ";
|
|
|
|
else
|
|
|
|
echo -n "(** EXPECTED $expected_rc **) ";
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$status" -eq 124 -o "$status" -eq 137 ]; then
|
|
|
|
# FIXME: 'timeout -v' requires coreutils-8.29; travis seems to have
|
|
|
|
# an older version. If/when travis updates, please add -v
|
|
|
|
# to the 'timeout' command above, and un-comment this out:
|
|
|
|
# if expr "$output" : ".*timeout: sending" >/dev/null; then
|
|
|
|
echo "*** TIMED OUT ***"
|
|
|
|
# This does not get the benefit of a retry
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
|
2019-04-02 05:56:29 +08:00
|
|
|
if [ -n "$expected_rc" ]; then
|
|
|
|
if [ "$status" -eq "$expected_rc" ]; then
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
return
|
|
|
|
elif [ $retry -gt 0 ]; then
|
|
|
|
echo "[ RETRYING ]" >&2
|
|
|
|
sleep 30
|
2019-04-02 05:56:29 +08:00
|
|
|
else
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
die "exit code is $status; expected $expected_rc"
|
2019-04-02 05:56:29 +08:00
|
|
|
fi
|
|
|
|
fi
|
BATS tests: make more robust
Add a --retry flag to run_buildah; intended for tests which
really need to pull an image, and can't rely on prefetch().
It will try a failed buildah command three times, waiting
thirty seconds between retries.
This is imperfect: there's no way to specify the number of
retries, no way to specify the timeout, and no way to
combine --retry with an expected (i.e. nonzero) exit
status. (FWIW I can't think of any possible use for that).
It is, though, quick, minimal-impact, easy to remember
and use.
Add --retry option to various tests in pull.bats and
registries.bats.
And, while I'm at it, add expect_output checks to many
of the new encryption checks in pull.bats and from.bats.
This actually caught a bug in a test, a check that was
failing (expected) but for the wrong reason (missing
file, not wrong key). Have I mentioned, lately, that
tests should check error message strings, not just
exit status?
Fixes: #2473
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-07-17 04:54:34 +08:00
|
|
|
done
|
2019-04-02 05:56:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#########
|
|
|
|
# die # Abort with helpful message
|
|
|
|
#########
|
|
|
|
function die() {
|
|
|
|
echo "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" >&2
|
|
|
|
echo "#| FAIL: $*" >&2
|
|
|
|
echo "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >&2
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2019-04-05 23:59:54 +08:00
|
|
|
###################
|
|
|
|
# expect_output # Compare actual vs expected string; fail if mismatch
|
|
|
|
###################
|
2019-04-02 05:56:29 +08:00
|
|
|
#
|
2019-04-05 23:59:54 +08:00
|
|
|
# Compares $output against the given string argument. Optional second
|
|
|
|
# argument is descriptive text to show as the error message (default:
|
|
|
|
# the command most recently run by 'run_buildah'). This text can be
|
|
|
|
# useful to isolate a failure when there are multiple identical
|
|
|
|
# run_buildah invocations, and the difference is solely in the
|
|
|
|
# config or setup; see, e.g., run.bats:run-cmd().
|
|
|
|
#
|
|
|
|
# By default we run an exact string comparison; use --substring to
|
|
|
|
# look for the given string anywhere in $output.
|
|
|
|
#
|
|
|
|
# By default we look in "$output", which is set in run_buildah().
|
|
|
|
# To override, use --from="some-other-string" (e.g. "${lines[0]}")
|
2019-04-02 05:56:29 +08:00
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
2019-04-05 23:59:54 +08:00
|
|
|
# expect_output "this is exactly what we expect"
|
|
|
|
# expect_output "foo=bar" "description of this particular test"
|
|
|
|
# expect_output --from="${lines[0]}" "expected first line"
|
2019-04-02 05:56:29 +08:00
|
|
|
#
|
2019-04-05 23:59:54 +08:00
|
|
|
function expect_output() {
|
|
|
|
# By default we examine $output, the result of run_buildah
|
|
|
|
local actual="$output"
|
|
|
|
local check_substring=
|
|
|
|
|
|
|
|
# option processing: recognize --from="...", --substring
|
|
|
|
local opt
|
|
|
|
for opt; do
|
|
|
|
local value=$(expr "$opt" : '[^=]*=\(.*\)')
|
|
|
|
case "$opt" in
|
|
|
|
--from=*) actual="$value"; shift;;
|
|
|
|
--substring) check_substring=1; shift;;
|
|
|
|
--) shift; break;;
|
|
|
|
-*) die "Invalid option '$opt'" ;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
local expect="$1"
|
|
|
|
local testname="${2:-${MOST_RECENT_BUILDAH_COMMAND:-[no test name given]}}"
|
2019-04-02 05:56:29 +08:00
|
|
|
|
|
|
|
if [ -z "$expect" ]; then
|
|
|
|
if [ -z "$actual" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
expect='[no output]'
|
|
|
|
elif [ "$actual" = "$expect" ]; then
|
|
|
|
return
|
2019-04-05 23:59:54 +08:00
|
|
|
elif [ -n "$check_substring" ]; then
|
|
|
|
if [[ "$actual" =~ $expect ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2019-04-02 05:56:29 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# This is a multi-line message, which may in turn contain multi-line
|
2020-12-22 00:19:56 +08:00
|
|
|
# output, so let's format it ourselves, readably
|
2019-04-02 05:56:29 +08:00
|
|
|
local -a actual_split
|
|
|
|
readarray -t actual_split <<<"$actual"
|
|
|
|
printf "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" >&2
|
2019-10-19 00:10:48 +08:00
|
|
|
printf "#| FAIL: %s\n" "$testname" >&2
|
2019-04-02 05:56:29 +08:00
|
|
|
printf "#| expected: '%s'\n" "$expect" >&2
|
|
|
|
printf "#| actual: '%s'\n" "${actual_split[0]}" >&2
|
|
|
|
local line
|
|
|
|
for line in "${actual_split[@]:1}"; do
|
|
|
|
printf "#| > '%s'\n" "$line" >&2
|
|
|
|
done
|
|
|
|
printf "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" >&2
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:56:11 +08:00
|
|
|
#######################
|
|
|
|
# expect_line_count # Check the expected number of output lines
|
|
|
|
#######################
|
|
|
|
#
|
|
|
|
# ...from the most recent run_buildah command
|
|
|
|
#
|
|
|
|
function expect_line_count() {
|
|
|
|
local expect="$1"
|
|
|
|
local testname="${2:-${MOST_RECENT_BUILDAH_COMMAND:-[no test name given]}}"
|
|
|
|
|
|
|
|
local actual="${#lines[@]}"
|
|
|
|
if [ "$actual" -eq "$expect" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" >&2
|
|
|
|
printf "#| FAIL: $testname\n" >&2
|
|
|
|
printf "#| Expected %d lines of output, got %d\n" $expect $actual >&2
|
|
|
|
printf "#| Output was:\n" >&2
|
|
|
|
local line
|
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
printf "#| >%s\n" "$line" >&2
|
|
|
|
done
|
|
|
|
printf "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" >&2
|
|
|
|
false
|
|
|
|
}
|
2019-04-02 05:56:29 +08:00
|
|
|
|
2018-09-03 19:20:52 +08:00
|
|
|
function check_options_flag_err() {
|
|
|
|
flag="$1"
|
2020-04-16 21:48:43 +08:00
|
|
|
[ "$status" -eq 125 ]
|
2018-09-03 19:20:52 +08:00
|
|
|
[[ $output = *"No options ($flag) can be specified after"* ]]
|
|
|
|
}
|
2019-11-06 02:22:07 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# skip_if_chroot #
|
|
|
|
####################
|
|
|
|
function skip_if_chroot() {
|
|
|
|
if test "$BUILDAH_ISOLATION" = "chroot"; then
|
|
|
|
skip "${1:-test does not work when \$BUILDAH_ISOLATION = chroot}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
######################
|
|
|
|
# skip_if_rootless #
|
|
|
|
######################
|
|
|
|
function skip_if_rootless() {
|
|
|
|
if test "$BUILDAH_ISOLATION" = "rootless"; then
|
|
|
|
skip "${1:-test does not work when \$BUILDAH_ISOLATION = rootless}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
########################
|
|
|
|
# skip_if_no_runtime # 'buildah run' can't work without a runtime
|
|
|
|
########################
|
|
|
|
function skip_if_no_runtime() {
|
2020-04-28 02:12:30 +08:00
|
|
|
if type -p "${OCI}" &> /dev/null; then
|
2019-11-06 02:22:07 +08:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-04-28 02:12:30 +08:00
|
|
|
skip "runtime \"$OCI\" not found"
|
2019-11-06 02:22:07 +08:00
|
|
|
}
|
2019-11-06 01:06:42 +08:00
|
|
|
|
|
|
|
##################
|
|
|
|
# is_cgroupsv2 # Returns true if host system has cgroupsv2 enabled
|
|
|
|
##################
|
|
|
|
function is_cgroupsv2() {
|
|
|
|
local cgroupfs_t=$(stat -f -c %T /sys/fs/cgroup)
|
|
|
|
test "$cgroupfs_t" = "cgroup2fs"
|
|
|
|
}
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# skip_if_cgroupsv2 # Some tests don't work with cgroupsv2
|
|
|
|
#######################
|
|
|
|
function skip_if_cgroupsv2() {
|
|
|
|
if is_cgroupsv2; then
|
|
|
|
skip "${1:-test does not work with cgroups v2}"
|
|
|
|
fi
|
|
|
|
}
|
2020-08-24 16:48:58 +08:00
|
|
|
|
|
|
|
##########################
|
|
|
|
# skip_if_in_container #
|
|
|
|
##########################
|
|
|
|
function skip_if_in_container() {
|
|
|
|
if test "$CONTAINER" = "podman"; then
|
|
|
|
skip "This test is not working inside a container"
|
|
|
|
fi
|
|
|
|
}
|