-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/compose: Target FCOS 31, move off of PAPR
Again, a lot going on here, but essentially, we adapt the compose tests to run either privileged or fully unprivileged via supermin, just like cosa. I actually got more than halfway through this initially using `cosa build` directly for testing. But in the end, we simply need more flexibility than that. We want to be able to manipulate exactly how rpm-ostree is called, and cosa is very opinionated about this (and may also change from under us in the future). (Another big difference for example is that cosa doesn't care about non-unified mode, whereas we *need* to have coverage for this until we fully kill it.) Really, the most important bit we want from there is the unprivileged-via-supermin bits. So we copy and adapt that here. One obvious improvement then is sharing this code more easily (e.g. a `cosa runasroot` or something?) However, we still use the FCOS manifest (frozen at a specific tag). It's a realistic example, and because of the lockfiles and pool, we get good reproducibility.
- Loading branch information
Showing
28 changed files
with
802 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,78 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
dn=$(cd $(dirname $0) && pwd) | ||
# freeze on a specific commit for tests for reproducibility and since it should | ||
# always work to target older treefiles | ||
FEDORA_COREOS_CONFIG_COMMIT=088fc2dec535aca392958e9c30c17cf19ef4b568 | ||
|
||
export topsrcdir=$(cd $dn/.. && pwd) | ||
. ${dn}/common/libtest-core.sh | ||
. ${dn}/common/libtestrepos.sh | ||
dn=$(cd "$(dirname "$0")" && pwd) | ||
topsrcdir=$(cd "$dn/.." && pwd) | ||
commondir=$(cd "$dn/common" && pwd) | ||
export topsrcdir commondir | ||
|
||
# avoid refetching yum metadata everytime | ||
export RPMOSTREE_USE_CACHED_METADATA=1 | ||
# shellcheck source=common/libtest-core.sh | ||
. "${commondir}/libtest-core.sh" | ||
|
||
export LOGDIR=${LOGDIR:-$(pwd)/test-compose-logs} | ||
mkdir -p ${LOGDIR} | ||
|
||
colour_print() { | ||
colour=$1; shift | ||
[ ! -t 1 ] || echo -en "\e[${colour}m" | ||
echo -n "$@" | ||
[ ! -t 1 ] || echo -en "\e[0m" | ||
echo | ||
} | ||
read -r -a tests <<< "$(filter_tests "${topsrcdir}/tests/compose")" | ||
if [ ${#tests[*]} -eq 0 ]; then | ||
echo "No tests selected; mistyped filter?" | ||
exit 0 | ||
fi | ||
|
||
pass_print() { | ||
colour_print 32 "$@" # green | ||
} | ||
JOBS=${JOBS:-$(ncpus)} | ||
|
||
fail_print() { | ||
colour_print 31 "$@" # red | ||
} | ||
# re-use the same FCOS config and RPMs if it already exists | ||
if [ ! -d compose-cache ]; then | ||
mkdir -p compose-cache | ||
|
||
skip_print() { | ||
colour_print 34 "$@" # blue | ||
} | ||
# first, download all the RPMs into a directory | ||
echo "Caching test fixtures in compose-cache/" | ||
|
||
uid=$(id -u) | ||
test_compose_datadir=/var/tmp/rpmostree-compose-cache-${uid} | ||
export test_compose_datadir | ||
mkdir -p ${test_compose_datadir} | ||
datadir_owner=$(stat -c '%u' ${test_compose_datadir}) | ||
test ${uid} = ${datadir_owner} | ||
# Really want to use cosa fetch for this and just share the pkgcache repo. | ||
# Though for now we still need to support non-unified mode. Once we don't, we | ||
# can clean this up. | ||
pushd compose-cache | ||
git clone https://github.com/coreos/fedora-coreos-config config | ||
pushd config | ||
git checkout "${FEDORA_COREOS_CONFIG_COMMIT}" | ||
# we flatten the treefile to make it easier to manipulate in tests (we have | ||
# lots of tests that check for include logic already) | ||
rpm-ostree compose tree --print-only manifest.yaml > manifest.json | ||
rm manifest.yaml | ||
mv manifests/{passwd,group} . | ||
rm -rf manifests/ | ||
popd | ||
|
||
# Create a consistent cache of the RPMs | ||
echo "Preparing compose tests... $(date)" | ||
tmp_repo=${test_compose_datadir}/tmp-repo | ||
if test -z "${RPMOSTREE_COMPOSE_CACHEONLY:-}"; then | ||
setup_rpmmd_repos ${dn}/composedata | ||
ostree --repo=${tmp_repo} init --mode=bare-user | ||
# Ensure all subsequent tests have the RPMs | ||
mkdir -p ${test_compose_datadir}/{fedora-local,cache} | ||
rpm-ostree compose --repo=${tmp_repo} tree --download-only-rpms --cachedir=${test_compose_datadir}/cache ${dn}/composedata/fedora-base.json | ||
find ${test_compose_datadir}/cache/ -name '*.rpm' | while read f; do | ||
mv $f ${test_compose_datadir}/fedora-local | ||
done | ||
(cd ${test_compose_datadir}/fedora-local && createrepo_c .) | ||
mkdir cachedir | ||
# we just need a repo so we can download stuff (but see note above about | ||
# sharing pkgcache repo in the future) | ||
ostree init --repo=repo --mode=archive | ||
rpm-ostree compose tree --unified-core --download-only-rpms --repo=repo \ | ||
config/manifest.json --cachedir cachedir \ | ||
--ex-lockfile config/manifest-lock.x86_64.json \ | ||
--ex-lockfile config/manifest-lock.overrides.x86_64.yaml | ||
rm -rf repo | ||
(cd cachedir && createrepo_c .) | ||
echo -e "[cache]\nbaseurl=$(pwd)/cachedir\ngpgcheck=0" > config/cache.repo | ||
pushd config | ||
python3 -c ' | ||
import sys, json | ||
y = json.load(sys.stdin) | ||
y["repos"] = ["cache"] | ||
json.dump(y, sys.stdout)' < manifest.json > manifest.json.new | ||
mv manifest.json{.new,} | ||
git add . | ||
git -c user.email="composetest@localhost.com" -c user.name="composetest" \ | ||
commit -am 'modifications for tests' | ||
popd | ||
popd | ||
fi | ||
echo "Done preparing compose tests! $(date)" | ||
rm ${tmp_repo} -rf | ||
|
||
total=0 | ||
pass=0 | ||
fail=0 | ||
skip=0 | ||
all_tests="$(cd ${dn}/compose-tests && ls test-*.sh | sort)" | ||
if [ "${RPMOSTREE_COMPOSE_TEST_FILTER:-}" == odd ]; then | ||
# https://superuser.com/a/101760/237392 | ||
all_tests="$(sed -n 'p;n' <<< ${all_tests})" | ||
elif [ "${RPMOSTREE_COMPOSE_TEST_FILTER:-}" == even ]; then | ||
all_tests="$(sed -n 'n;p' <<< ${all_tests})" | ||
fi | ||
tests="" | ||
if [ -n "${TESTS+ }" ]; then | ||
for tf in ${all_tests}; do | ||
tfbn=$(basename "$tf" .sh) | ||
tfbn=" ${tfbn#test-} " | ||
if [[ " $TESTS " != *$tfbn* ]]; then | ||
echo "Skipping: ${tf}" | ||
continue | ||
fi | ||
tests="${tests} ${tf}" | ||
done | ||
else | ||
tests="${all_tests}" | ||
fi | ||
echo "Running ${#tests[*]} tests ${JOBS} at a time" | ||
|
||
if test -z "${tests}"; then | ||
fatal "error: No tests match ${TESTS}" | ||
fi | ||
outputdir="${topsrcdir}/compose-logs" | ||
fixtures="$(pwd)/compose-cache" | ||
echo "Test results outputting to ${outputdir}/" | ||
|
||
echo "Compose tests starting: $(date)" | ||
echo "Executing: ${tests}" | ||
echo "Writing logs to ${LOGDIR}" | ||
(for tf in ${tests}; do echo $tf; done) | \ | ||
parallel -v -j +1 --progress --halt soon,fail=1 \ | ||
--results ${LOGDIR}/parallel --quote /bin/sh -c "${dn}/compose-tests/run-test.sh {}" | ||
echo "$(date): All tests passed" | ||
echo -n "${tests[*]}" | parallel -d' ' -j "${JOBS}" --line-buffer \ | ||
"${topsrcdir}/tests/compose/runtest.sh" "${outputdir}" "${fixtures}" |
Oops, something went wrong.