tests: Trim out dead code from libtest.sh, rework SRCDIR
The main goal here is to get `assert_jq()` usable in kola tests. This was forked from ostree long ago but we aren't using most of it. I want to try to move this into kola where we're just using `tests/common` but this code references `tests/gpghome` which we weren't using. Only a few things here reference `SRCDIR` - change those to fail for now if it's not set, since we're not running those tests in kola yet. I will eventually try to clean that up later.
This commit is contained in:
parent
fc5825a8f9
commit
edeefcff23
@ -26,12 +26,12 @@ fi
|
||||
LIBTEST_SH=1
|
||||
|
||||
self="$(realpath $0)"
|
||||
if test -z "${SRCDIR:-}"; then
|
||||
if test -z "${SRCDIR:-}" && test -n "${topsrcdir:-}"; then
|
||||
SRCDIR=${topsrcdir}/tests
|
||||
commondir=${SRCDIR}/common
|
||||
fi
|
||||
. ${SRCDIR}/common/libtest-core.sh
|
||||
|
||||
UPDATEINFO=${SRCDIR}/utils/updateinfo
|
||||
commondir=${commondir:-${KOLA_EXT_DATA}}
|
||||
. ${commondir}/libtest-core.sh
|
||||
|
||||
for bin in jq; do
|
||||
if ! command -v $bin >/dev/null; then
|
||||
@ -85,254 +85,10 @@ case $(stat -f --printf '%T' /) in
|
||||
*) echo "Not using overlayfs" ;;
|
||||
esac
|
||||
|
||||
export TEST_GPG_KEYID="472CDAFA"
|
||||
|
||||
# GPG when creating signatures demands a writable
|
||||
# homedir in order to create lockfiles. Work around
|
||||
# this by copying locally.
|
||||
echo "Copying gpghome to ${test_tmpdir}"
|
||||
cp -a "${SRCDIR}/gpghome" ${test_tmpdir}
|
||||
chmod -R u+w "${test_tmpdir}"
|
||||
export TEST_GPG_KEYHOME=${test_tmpdir}/gpghome
|
||||
export OSTREE_GPG_HOME=${test_tmpdir}/gpghome/trusted
|
||||
|
||||
if test -n "${OT_TESTS_DEBUG:-}"; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
if test -n "${OT_TESTS_VALGRIND:-}"; then
|
||||
CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp"
|
||||
fi
|
||||
|
||||
# A wrapper which also possibly disables xattrs for CI testing
|
||||
ostree_repo_init() {
|
||||
repo=$1
|
||||
shift
|
||||
${CMD_PREFIX} ostree --repo=${repo} init "$@"
|
||||
if test -n "${OSTREE_NO_XATTRS:-}"; then
|
||||
echo -e 'disable-xattrs=true\n' >> ${repo}/config
|
||||
fi
|
||||
}
|
||||
|
||||
setup_test_repository () {
|
||||
mode=$1
|
||||
shift
|
||||
|
||||
oldpwd=`pwd`
|
||||
|
||||
cd ${test_tmpdir}
|
||||
if test -n "${mode}"; then
|
||||
ostree_repo_init repo --mode=${mode}
|
||||
else
|
||||
ostree_repo_init repo
|
||||
fi
|
||||
ot_repo="--repo=$(pwd)/repo"
|
||||
export OSTREE="${CMD_PREFIX} ostree ${ot_repo}"
|
||||
|
||||
cd ${test_tmpdir}/files
|
||||
$OSTREE commit -b test2 -s "Test Commit 1" -m "Commit body first"
|
||||
|
||||
mkdir baz
|
||||
echo moo > baz/cow
|
||||
echo alien > baz/saucer
|
||||
mkdir baz/deeper
|
||||
echo hi > baz/deeper/ohyeah
|
||||
ln -s nonexistent baz/alink
|
||||
mkdir baz/another/
|
||||
echo x > baz/another/y
|
||||
|
||||
cd ${test_tmpdir}/files
|
||||
$OSTREE commit -b test2 -s "Test Commit 2" -m "Commit body second"
|
||||
$OSTREE fsck -q
|
||||
|
||||
cd $oldpwd
|
||||
}
|
||||
|
||||
run_temp_webserver() {
|
||||
env PYTHONUNBUFFERED=1 setsid python3 -m http.server 0 >${test_tmpdir}/httpd-output &
|
||||
for x in $(seq 50); do
|
||||
if test -e ${test_tmpdir}/httpd-output; then
|
||||
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) (http://.*) \.\.\.,\1,' < ${test_tmpdir}/httpd-output > ${test_tmpdir}/httpd-port
|
||||
if ! cmp ${test_tmpdir}/httpd-output ${test_tmpdir}/httpd-port 1>/dev/null; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
port=$(cat ${test_tmpdir}/httpd-port)
|
||||
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
|
||||
}
|
||||
|
||||
setup_fake_remote_repo1() {
|
||||
mode=$1
|
||||
args=$2
|
||||
shift
|
||||
oldpwd=`pwd`
|
||||
mkdir ostree-srv
|
||||
cd ostree-srv
|
||||
ostree_repo_init gnomerepo --mode=$mode
|
||||
mkdir gnomerepo-files
|
||||
cd gnomerepo-files
|
||||
echo first > firstfile
|
||||
mkdir baz
|
||||
echo moo > baz/cow
|
||||
echo alien > baz/saucer
|
||||
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit --add-metadata-string version=3.0 -b main -s "A remote commit" -m "Some Commit body"
|
||||
mkdir baz/deeper
|
||||
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit --add-metadata-string version=3.1 -b main -s "Add deeper"
|
||||
echo hi > baz/deeper/ohyeah
|
||||
mkdir baz/another/
|
||||
echo x > baz/another/y
|
||||
${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit --add-metadata-string version=3.2 -b main -s "The rest"
|
||||
cd ..
|
||||
rm -rf gnomerepo-files
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir ${test_tmpdir}/httpd
|
||||
cd httpd
|
||||
ln -s ${test_tmpdir}/ostree-srv ostree
|
||||
run_temp_webserver
|
||||
cd ${oldpwd}
|
||||
|
||||
export OSTREE="ostree --repo=repo"
|
||||
}
|
||||
|
||||
setup_os_boot_syslinux() {
|
||||
# Stub syslinux configuration
|
||||
mkdir -p sysroot/boot/loader.0
|
||||
ln -s loader.0 sysroot/boot/loader
|
||||
touch sysroot/boot/loader/syslinux.cfg
|
||||
# And a compatibility symlink
|
||||
mkdir -p sysroot/boot/syslinux
|
||||
ln -s ../loader/syslinux.cfg sysroot/boot/syslinux/syslinux.cfg
|
||||
}
|
||||
|
||||
setup_os_boot_uboot() {
|
||||
# Stub U-Boot configuration
|
||||
mkdir -p sysroot/boot/loader.0
|
||||
ln -s loader.0 sysroot/boot/loader
|
||||
touch sysroot/boot/loader/uEnv.txt
|
||||
# And a compatibility symlink
|
||||
ln -s loader/uEnv.txt sysroot/boot/uEnv.txt
|
||||
}
|
||||
|
||||
setup_os_repository () {
|
||||
mode=$1
|
||||
bootmode=$2
|
||||
shift
|
||||
|
||||
oldpwd=`pwd`
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir testos-repo
|
||||
if test -n "$mode"; then
|
||||
ostree_repo_init testos-repo --mode=${mode}
|
||||
else
|
||||
ostree_repo_init testos-repo
|
||||
fi
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir osdata
|
||||
cd osdata
|
||||
mkdir -p boot usr/bin usr/lib/modules/3.6.0 usr/share usr/etc
|
||||
echo "a kernel" > boot/vmlinuz-3.6.0
|
||||
echo "an initramfs" > boot/initramfs-3.6.0
|
||||
bootcsum=$(cat boot/vmlinuz-3.6.0 boot/initramfs-3.6.0 | sha256sum | cut -f 1 -d ' ')
|
||||
export bootcsum
|
||||
mv boot/vmlinuz-3.6.0 boot/vmlinuz-3.6.0-${bootcsum}
|
||||
mv boot/initramfs-3.6.0 boot/initramfs-3.6.0-${bootcsum}
|
||||
|
||||
echo "an executable" > usr/bin/sh
|
||||
echo "some shared data" > usr/share/langs.txt
|
||||
echo "a library" > usr/lib/libfoo.so.0
|
||||
ln -s usr/bin bin
|
||||
cat > usr/etc/os-release <<EOF
|
||||
NAME=TestOS
|
||||
VERSION=42
|
||||
ID=testos
|
||||
VERSION_ID=42
|
||||
PRETTY_NAME="TestOS 42"
|
||||
EOF
|
||||
echo "a config file" > usr/etc/aconfigfile
|
||||
mkdir -p usr/etc/NetworkManager
|
||||
echo "a default daemon file" > usr/etc/NetworkManager/nm.conf
|
||||
mkdir -p usr/etc/testdirectory
|
||||
echo "a default daemon file" > usr/etc/testdirectory/test
|
||||
|
||||
ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.9 -b testos/buildmaster/x86_64-runtime -s "Build"
|
||||
|
||||
# Ensure these commits have distinct second timestamps
|
||||
sleep 2
|
||||
echo "a new executable" > usr/bin/sh
|
||||
ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.10 -b testos/buildmaster/x86_64-runtime -s "Build"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
cp -a osdata osdata-devel
|
||||
cd osdata-devel
|
||||
mkdir -p usr/include
|
||||
echo "a development header" > usr/include/foo.h
|
||||
ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string version=1.0.9 -b testos/buildmaster/x86_64-devel -s "Build"
|
||||
|
||||
ostree --repo=${test_tmpdir}/testos-repo fsck -q
|
||||
|
||||
cd ${test_tmpdir}
|
||||
# sysroot dir already made by setup-session.sh
|
||||
ostree admin --sysroot=sysroot init-fs sysroot
|
||||
if test -n "${OSTREE_NO_XATTRS:-}"; then
|
||||
echo -e 'disable-xattrs=true\n' >> sysroot/ostree/repo/config
|
||||
fi
|
||||
ostree admin --sysroot=sysroot os-init testos
|
||||
|
||||
case $bootmode in
|
||||
"syslinux")
|
||||
setup_os_boot_syslinux
|
||||
;;
|
||||
"uboot")
|
||||
setup_os_boot_uboot
|
||||
;;
|
||||
esac
|
||||
|
||||
cd ${test_tmpdir}
|
||||
mkdir ${test_tmpdir}/httpd
|
||||
cd httpd
|
||||
ln -s ${test_tmpdir} ostree
|
||||
run_temp_webserver
|
||||
cd ${oldpwd}
|
||||
}
|
||||
|
||||
os_repository_new_commit ()
|
||||
{
|
||||
boot_checksum_iteration=$1
|
||||
content_iteration=$2
|
||||
echo "BOOT ITERATION: $boot_checksum_iteration"
|
||||
if test -z "$boot_checksum_iteration"; then
|
||||
boot_checksum_iteration=0
|
||||
fi
|
||||
if test -z "$content_iteration"; then
|
||||
content_iteration=0
|
||||
fi
|
||||
cd ${test_tmpdir}/osdata
|
||||
rm boot/*
|
||||
echo "new: a kernel ${boot_checksum_iteration}" > boot/vmlinuz-3.6.0
|
||||
echo "new: an initramfs ${boot_checksum_iteration}" > boot/initramfs-3.6.0
|
||||
bootcsum=$(cat boot/vmlinuz-3.6.0 boot/initramfs-3.6.0 | sha256sum | cut -f 1 -d ' ')
|
||||
export bootcsum
|
||||
mv boot/vmlinuz-3.6.0 boot/vmlinuz-3.6.0-${bootcsum}
|
||||
mv boot/initramfs-3.6.0 boot/initramfs-3.6.0-${bootcsum}
|
||||
|
||||
echo "a new default config file" > usr/etc/a-new-default-config-file
|
||||
mkdir -p usr/etc/new-default-dir
|
||||
echo "a new default dir and file" > usr/etc/new-default-dir/moo
|
||||
|
||||
echo "content iteration ${content_iteration}" > usr/bin/content-iteration
|
||||
|
||||
version=$(date "+%Y%m%d.${content_iteration}")
|
||||
echo "version: $version"
|
||||
|
||||
ostree --repo=${test_tmpdir}/testos-repo commit --add-metadata-string "version=${version}" -b testos/buildmaster/x86_64-runtime -s "Build"
|
||||
cd ${test_tmpdir}
|
||||
}
|
||||
|
||||
check_root_test ()
|
||||
{
|
||||
if test "$(id -u)" != "0"; then
|
||||
@ -371,7 +127,7 @@ get_obj_path() {
|
||||
}
|
||||
|
||||
uinfo_cmd() {
|
||||
$UPDATEINFO --repo "${test_tmpdir}/yumrepo" "$@"
|
||||
${SRCDIR}/utils/updateinfo --repo "${test_tmpdir}/yumrepo" "$@"
|
||||
}
|
||||
|
||||
# builds a new RPM and adds it to the testdir's repo
|
||||
|
Loading…
Reference in New Issue
Block a user