vmcheck: add more pkg layering tests

- Rename test-layering.sh to test-layering-basic.sh and make it test
  both pkg-add and pkg-remove.
- Add test-layering-relayer.sh, which verifies that pkgs are properly
  relayered during the creation of new deployments (e.g. upgrades,
  rebases, deploys).
- Add test-layering-rpmdb.sh, which verifies that packages respect the
  rpm requirements before being overlayed.

Closes: #371
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2016-07-04 11:43:02 -04:00 committed by Atomic Bot
parent ba05972bbb
commit f8907b6d53
4 changed files with 250 additions and 30 deletions

View File

@ -32,6 +32,19 @@ vm_send() {
$SCP -r "$@" vmcheck:$dir
}
# copy the test repo to the vm
vm_send_test_repo() {
vm_send /tmp/vmcheck ${commondir}/compose/yum/repo
cat > vmcheck.repo << EOF
[test-repo]
name=test-repo
baseurl=file:///tmp/vmcheck/repo
EOF
vm_send /etc/yum.repos.d vmcheck.repo
}
# wait until ssh is available on the vm
# - $1 timeout in second (optional)
vm_ssh_wait() {
@ -119,3 +132,26 @@ vm_has_layered_packages() {
vm_get_booted_csum() {
vm_get_booted_deployment_info checksum
}
# make multiple consistency checks on a test pkg
# - $1 package to check for
# - $2 either "present" or "absent"
vm_assert_layered_pkg() {
pkg=$1; shift
policy=$1; shift
set +e
vm_has_packages $pkg; pkg_in_rpmdb=$?
vm_has_layered_packages $pkg; pkg_is_layered=$?
[ $pkg_in_rpmdb == 0 ] && [ $pkg_is_layered == 0 ]; pkg_present=$?
[ $pkg_in_rpmdb != 0 ] && [ $pkg_is_layered != 0 ]; pkg_absent=$?
set -e
if [ $policy == present ] && [ $pkg_present != 0 ]; then
assert_not_reached "pkg $pkg is not present"
fi
if [ $policy == absent ] && [ $pkg_absent != 0 ]; then
assert_not_reached "pkg $pkg is not absent"
fi
}

View File

@ -24,47 +24,33 @@ set -e
set -x
# make sure package foo is not already layered
if vm_has_files /usr/bin/foo; then
assert_not_reached "/usr/bin/foo already present"
elif vm_has_packages foo; then
assert_not_reached "foo already in rpmdb"
elif vm_has_layered_packages foo; then
assert_not_reached "foo already layered"
fi
# SUMMARY: basic sanity check of package layering
# METHOD:
# Add a package, verify that it was added, then remove it, and verify that
# it was removed.
vm_send /tmp/vmcheck ${commondir}/compose/yum/repo
vm_send_test_repo
cat > vmcheck.repo << EOF
[test-repo]
name=test-repo
baseurl=file:///tmp/vmcheck/repo
EOF
vm_send /etc/yum.repos.d vmcheck.repo
# make sure the package is not already layered
vm_assert_layered_pkg foo absent
vm_cmd rpm-ostree pkg-add foo
echo "ok pkg-add foo"
vm_reboot
if ! vm_has_files /usr/bin/foo; then
assert_not_reached "/usr/bin/foo not present"
elif ! vm_has_packages foo; then
assert_not_reached "foo not in rpmdb"
elif ! vm_has_layered_packages foo; then
assert_not_reached "foo not layered"
fi
echo "ok pkg foo present"
vm_assert_layered_pkg foo present
echo "ok pkg foo added"
if ! vm_cmd foo | grep "Happy foobing!"; then
if ! vm_cmd /usr/bin/foo | grep "Happy foobing!"; then
assert_not_reached "foo printed wrong output"
fi
echo "ok correct output"
vm_cmd rpm-ostree rollback
vm_cmd rpm-ostree pkg-remove foo
echo "ok pkg-remove foo"
vm_reboot
if vm_has_layered_packages foo; then
assert_not_reached "foo is still layered after rollback"
fi
echo "ok rollback"
vm_assert_layered_pkg foo absent
echo "ok pkg foo removed"

View File

@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright (C) 2016 Jonathan Lebon <jlebon@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
set -e
. ${commondir}/libtest.sh
. ${commondir}/libvm.sh
set -x
# SUMMARY: check that packages get carried over during reployments from
# upgrades, deploys, and rebases.
# METHOD:
# Add a package, then test that after an upgrade, deploy, or rebase, we
# still have the package.
vm_send_test_repo
# make sure the package is not already layered
vm_assert_layered_pkg foo absent
vm_cmd rpm-ostree pkg-add foo
echo "ok pkg-add foo"
vm_reboot
vm_assert_layered_pkg foo present
echo "ok pkg foo added"
reboot_and_assert_base() {
vm_reboot
basecsum=$(vm_get_booted_deployment_info base-checksum)
if [[ $basecsum != $1 ]]; then
assert_not_reached "new base-checksum does not refer to expected base $1"
fi
}
# UPGRADE
# let's synthesize an upgrade
commit=$(vm_cmd ostree commit -b vmcheck --tree=ref=vmcheck)
vm_cmd rpm-ostree upgrade
reboot_and_assert_base $commit
echo "ok upgrade"
vm_assert_layered_pkg foo present
echo "ok pkg foo relayered on upgrade"
# DEPLOY
commit=$(vm_cmd ostree commit -b vmcheck \
--tree=ref=vmcheck --add-metadata-string=version=my-commit)
vm_cmd rpm-ostree deploy my-commit
reboot_and_assert_base $commit
echo "ok deploy"
vm_assert_layered_pkg foo present
echo "ok pkg foo relayered on deploy"
# REBASE
commit=$(vm_cmd ostree commit -b rebase_test --tree=ref=vmcheck)
vm_cmd rpm-ostree rebase rebase_test
reboot_and_assert_base $commit
echo "ok rebase"
vm_assert_layered_pkg foo present
echo "ok pkg foo relayered on rebase"

View File

@ -0,0 +1,114 @@
#!/bin/bash
#
# Copyright (C) 2016 Jonathan Lebon <jlebon@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
set -e
. ${commondir}/libtest.sh
. ${commondir}/libvm.sh
set -x
# SUMMARY: check that package layering respects rpmdb
# METHOD:
# - test that during a relayer (e.g. upgrade), if a previously layered pkg
# is now part of the base layer, then we gently drop the pkg as layered
# - test that layering a pkg that's already in the base layer fails
# - test that layering a pkg that's already layered fails
# - test that layering a new pkg that conflicts with a layered pkg fails
# - test that layering a new pkg that conflicts with a base pkg fails
# - test that relayering on a base with a conflicting package fails
vm_send_test_repo
# make sure the package is not already layered
vm_assert_layered_pkg foo absent
vm_cmd rpm-ostree pkg-add foo
echo "ok pkg-add foo"
vm_reboot
vm_assert_layered_pkg foo present
echo "ok pkg foo added"
# let's synthesize an upgrade in which the commit we're upgrading to has foo as
# part of its base, so we recommit our current (non-base) layer to the branch
csum=$(vm_cmd ostree commit -b vmcheck --tree=ref=$(vm_get_booted_csum))
# check that upgrading to it will elide the layered pkg from the origin
vm_cmd rpm-ostree upgrade | tee out.txt
assert_file_has_content out.txt "'foo' .* will no longer be layered"
echo "ok layered pkg foo elision msg"
vm_reboot
new_csum=$(vm_get_booted_csum)
if [[ $new_csum != $csum ]]; then
assert_not_reached "new csum does not refer to expected csum $csum"
fi
if ! vm_has_packages foo; then
assert_not_reached "pkg foo is not in rpmdb"
elif vm_has_layered_packages foo; then
assert_not_reached "pkg foo is layered"
fi
echo "ok layered pkg foo elision"
if vm_cmd rpm-ostree pkg-add foo; then
assert_not_reached "pkg-add foo succeeded even though it's already in rpmdb"
fi
echo "ok can't layer pkg already in base"
if vm_cmd rpm-ostree pkg-add bar; then
assert_not_reached "pkg-add bar succeeded but it conflicts with foo in base"
fi
echo "ok can't layer conflicting pkg in base"
# let's go back to that first depl in which foo is really layered
vm_cmd rpm-ostree rollback
vm_reboot
vm_assert_layered_pkg foo present
if vm_cmd rpm-ostree pkg-add foo; then
assert_not_reached "pkg-add foo succeeded even though it's already layered"
fi
echo "ok can't layer pkg already layered"
if vm_cmd rpm-ostree pkg-add bar; then
assert_not_reached "pkg-add bar succeeded but it conflicts with layered foo"
fi
echo "ok can't layer conflicting pkg already layered"
# let's go back to the original depl without anything
# XXX: this would be simpler if we had an --onto here
vm_cmd rpm-ostree pkg-remove foo
vm_reboot
vm_assert_layered_pkg foo absent
echo "ok pkg-remove foo"
vm_cmd rpm-ostree pkg-add bar
vm_reboot
vm_assert_layered_pkg bar present
echo "ok pkg-add bar"
# now let's try to do an upgrade -- the latest commit there is still the one we
# created at the beginning of this test, containing foo in the base
if vm_cmd rpm-ostree upgrade; then
assert_not_reached "upgrade succeeded but new base has conflicting pkg foo"
fi
echo "ok can't upgrade with conflicting layered pkg"