Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add helper for status json inspections #609

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 12 additions & 31 deletions tests/check/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,16 @@ $OSTREE remote add --set=gpg-verify=false testos file://$(pwd)/testos-repo testo
$OSTREE pull testos:testos/buildmaster/x86_64-runtime
ostree admin --sysroot=sysroot deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmaster/x86_64-runtime

rpm-ostree status | tee OUTPUT-status.txt

assert_file_has_content OUTPUT-status.txt '1\.0\.10'
assert_status_jq '.deployments[0].version == "1.0.10"'
echo "ok status shows right version"

rpm-ostree status --json > status.json
json-glib-format status.json
jq '.deployments[0].version' < status.json > version.txt
assert_file_has_content version.txt '1\.0\.10'

os_repository_new_commit
rpm-ostree upgrade --os=testos

$OSTREE remote add --set=gpg-verify=false otheros file://$(pwd)/testos-repo testos/buildmaster/x86_64-runtime
rpm-ostree rebase --os=testos otheros:

rpm-ostree status | tee OUTPUT-status.txt

assert_not_file_has_content OUTPUT-status.txt '1\.0\.10'
version=$(date "+%Y%m%d\.0")
assert_file_has_content OUTPUT-status.txt $version
assert_status_jq '.deployments[0].version == "'$(date "+%Y%m%d.0")'"'
echo "ok rebase onto newer version"

# Test 'upgrade --check' w/ no upgrade
Expand All @@ -74,32 +63,28 @@ echo "ok rebase onto newer version"

# Jump backward to 1.0.9
rpm-ostree deploy --os=testos 1.0.9
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt '1\.0\.9'
assert_status_jq '.deployments[0].version == "1.0.9"'
echo "ok deploy older known version"

# Remember the current revision for later.
revision=$($OSTREE rev-parse otheros:testos/buildmaster/x86_64-runtime)

# Jump forward to a locally known version.
rpm-ostree deploy --os=testos 1.0.10
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt '1\.0\.10'
assert_status_jq '.deployments[0].version == "1.0.10"'
echo "ok deploy newer known version"

# Jump forward to a new, locally unknown version.
# Here we also test the "version=" argument prefix.
os_repository_new_commit 1 1
rpm-ostree deploy --os=testos version=$(date "+%Y%m%d.1")
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt $(date "+%Y%m%d\.1")
assert_status_jq '.deployments[0].version == "'$(date "+%Y%m%d.1")'"'
echo "ok deploy newer unknown version"

# Jump backward again to 1.0.9, but this time using the
# "revision=" argument prefix (and test case sensitivity).
rpm-ostree deploy --os=testos REVISION=$revision
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt '1\.0\.9'
assert_status_jq '.deployments[0].version == "1.0.9"'
echo "ok deploy older version by revision"

# Make a commit on a different branch and make sure that it doesn't let us
Expand All @@ -114,27 +99,23 @@ echo "ok error on deploying commit on other branch"
# Make sure we can do an upgrade after a deploy
os_repository_new_commit 2 3
rpm-ostree upgrade --os=testos
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt $(date "+%Y%m%d\.3")
assert_status_jq '.deployments[0].version == "'$(date "+%Y%m%d.3")'"'
echo "ok upgrade after deploy"

# Make sure we're currently on otheros
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt otheros:testos/buildmaster/x86_64-runtime
assert_status_jq '.deployments[0].origin|startswith("otheros:")'

os_repository_new_commit 2 2
rpm-ostree rebase --os=testos testos:testos/buildmaster/x86_64-runtime $(date "+%Y%m%d.2")
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt testos
assert_file_has_content OUTPUT-status.txt $(date "+%Y%m%d\.2")
assert_status_jq '.deployments[0].origin|startswith("testos:")'
assert_status_jq '.deployments[0].version == "'$(date "+%Y%m%d.2")'"'
echo "ok rebase onto other branch at specific version"

branch=testos/buildmaster/x86_64-runtime
new_csum=$($REMOTE_OSTREE commit -b $branch --tree=ref=$branch)
rpm-ostree rebase --os=testos otheros:$branch $new_csum
rpm-ostree status | head --lines 5 | tee OUTPUT-status.txt
assert_file_has_content OUTPUT-status.txt otheros
assert_file_has_content OUTPUT-status.txt $new_csum
assert_status_jq '.deployments[0].origin|startswith("otheros:")'
assert_status_jq '.deployments[0].checksum == "'$new_csum'"'
echo "ok rebase onto other branch at specific checksum"

if rpm-ostree rebase --os=testos testos:testos/buildmaster/x86_64-runtime $other_rev 2>OUTPUT-err; then
Expand Down
17 changes: 10 additions & 7 deletions tests/common/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,18 @@ ensure_dbus ()
fi
}

# Assert that @expression is true in @jsonfile
assert_status_jq() {
vm_rpmostree status --json > status.json

assert_status_file_jq() {
status_file=$1; shift
for expression in "$@"; do
if ! jq -e "${expression}" >/dev/null < status.json; then
jq . < status.json | sed -e 's/^/# /' >&2
echo 1>&2 "${expression} failed to match in status.json"
if ! jq -e "${expression}" >/dev/null < $status_file; then
jq . < $status_file | sed -e 's/^/# /' >&2
echo 1>&2 "${expression} failed to match in $status_file"
exit 1
fi
done
}

assert_status_jq() {
rpm-ostree status --json > status.json
assert_status_file_jq status.json "$@"
}
5 changes: 5 additions & 0 deletions tests/common/libvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@ vm_assert_layered_pkg() {
assert_not_reached "pkg $pkg is not absent"
fi
}

vm_assert_status_jq() {
vm_rpmostree status --json > status.json
assert_status_file_jq status.json "$@"
}
36 changes: 20 additions & 16 deletions tests/vmcheck/test-initramfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,20 @@ assert_file_has_content err.txt "reboot.*used with.*enable"
echo "ok initramfs state"

vm_rpmostree initramfs --enable
assert_status_jq \
vm_assert_status_jq \
'.deployments[1].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[1]["regenerate-initramfs"]|not'

vm_reboot

assert_not_streq $base $(vm_get_booted_csum)
assert_status_jq '.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[0]["initramfs-args"]|length == 0' \
'.deployments[1]["regenerate-initramfs"]|not' \
'.deployments[1]["initramfs-args"]|not'
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[0]["initramfs-args"]|length == 0' \
'.deployments[1]["regenerate-initramfs"]|not' \
'.deployments[1]["initramfs-args"]|not'

if vm_rpmostree initramfs --enable 2>err.txt; then
assert_not_reached "Unexpectedly succeeded at enabling"
Expand All @@ -66,21 +67,24 @@ echo "ok initramfs enabled"

vm_rpmostree initramfs --disable
vm_reboot
assert_status_jq '.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'

echo "ok initramfs disabled"

vm_reboot_cmd rpm-ostree initramfs --enable --reboot
assert_status_jq '.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[1]["regenerate-initramfs"]|not'
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[1]["regenerate-initramfs"]|not'

vm_reboot_cmd rpm-ostree initramfs --disable --reboot
assert_status_jq '.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'

echo "ok initramfs enable disable reboot"

Expand All @@ -89,7 +93,7 @@ for file in first second; do
vm_cmd touch /etc/rpmostree-initramfs-testing-$file
vm_rpmostree initramfs --enable --arg="-I" --arg="/etc/rpmostree-initramfs-testing-$file"
vm_reboot
assert_status_jq \
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[0]["initramfs-args"]|index("-I") == 0' \
Expand Down
10 changes: 6 additions & 4 deletions tests/vmcheck/test-layering-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ vm_send_test_repo

# make sure the package is not already layered
vm_assert_layered_pkg foo absent
assert_status_jq '.deployments[0]["base-checksum"]|not' \
'.deployments[0]["pending-base-checksum"]|not'
vm_assert_status_jq \
'.deployments[0]["base-checksum"]|not' \
'.deployments[0]["pending-base-checksum"]|not'

# Be sure an unprivileged user exists
vm_cmd getent passwd bin
Expand All @@ -46,8 +47,9 @@ vm_rpmostree pkg-add foo-1.0
echo "ok pkg-add foo"

vm_reboot
assert_status_jq '.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not'
vm_assert_status_jq \
'.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not'

vm_assert_layered_pkg foo-1.0 present
echo "ok pkg foo added"
Expand Down
17 changes: 10 additions & 7 deletions tests/vmcheck/test-layering-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ reboot_and_assert_base() {

# UPGRADE

assert_status_jq '.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not'
vm_assert_status_jq \
'.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not'
# let's synthesize an upgrade
commit=$(vm_cmd ostree commit -b vmcheck --tree=ref=vmcheck)
vm_rpmostree upgrade
assert_status_jq '.deployments[1]["base-checksum"]' \
'.deployments[1]["pending-base-checksum"]'
vm_assert_status_jq \
'.deployments[1]["base-checksum"]' \
'.deployments[1]["pending-base-checksum"]'
vm_rpmostree status --json > status.json
reboot_and_assert_base $commit
assert_status_jq '.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not' \
'.deployments[1]["pending-base-checksum"]'
vm_assert_status_jq \
'.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not' \
'.deployments[1]["pending-base-checksum"]'
echo "ok upgrade"

vm_assert_layered_pkg foo present
Expand Down