2016-07-04 18:43:02 +03:00
#!/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.
2017-10-01 16:34:23 +03:00
set -euo pipefail
2016-07-04 18:43:02 +03:00
. ${ 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
2017-02-25 00:28:47 +03:00
# is now part of the base layer, then we stop layering but still keep it
# in the origin
# - test that layering a pkg that's already in the base layer works
# - test that layering a pkg that's already layered fails (string match)
# - test that layering a different provides that's already layered works
2016-07-04 18:43:02 +03:00
# - 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
# make sure the package is not already layered
vm_assert_layered_pkg foo absent
2017-02-25 00:28:47 +03:00
# remember this current commit for later
vm_cmd ostree refs $( vm_get_booted_csum) --create vmcheck_tmp/without_foo
2017-06-29 17:11:25 +03:00
vm_build_rpm foo
2017-02-25 00:28:47 +03:00
vm_rpmostree install foo
echo "ok install foo"
2016-07-04 18:43:02 +03:00
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
2017-02-25 00:28:47 +03:00
# remember it for later
vm_cmd ostree refs $( vm_get_booted_csum) --create vmcheck_tmp/with_foo
csum_with_foo = $( vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/with_foo)
# check that upgrading to it will make the package dormant
2016-07-04 18:43:02 +03:00
2017-02-25 00:28:47 +03:00
vm_rpmostree upgrade
2016-07-04 18:43:02 +03:00
vm_reboot
2017-02-25 00:28:47 +03:00
if [ [ $( vm_get_booted_csum) != $csum_with_foo ] ] ; then
assert_not_reached " new csum does not refer to expected csum $csum_with_foo "
2016-07-04 18:43:02 +03:00
fi
2017-02-25 00:28:47 +03:00
if ! vm_has_dormant_packages foo; then
assert_not_reached "pkg foo is not dormant"
2016-07-04 18:43:02 +03:00
fi
2017-02-25 00:28:47 +03:00
echo "ok layered to dormant"
2016-07-04 18:43:02 +03:00
2017-06-29 17:11:25 +03:00
vm_build_rpm bar conflicts foo
2017-01-17 21:29:48 +03:00
if vm_rpmostree pkg-add bar; then
2016-07-04 18:43:02 +03:00
assert_not_reached "pkg-add bar succeeded but it conflicts with foo in base"
fi
2017-02-25 00:28:47 +03:00
echo "ok can't layer conflicting pkg (dormant)"
2016-07-04 18:43:02 +03:00
2017-02-25 00:28:47 +03:00
# now check that upgrading to a new base layer that drops foo relayers it
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/without_foo
vm_rpmostree upgrade
2016-07-04 18:43:02 +03:00
vm_reboot
2017-02-25 00:28:47 +03:00
2016-07-04 18:43:02 +03:00
vm_assert_layered_pkg foo present
2017-02-25 00:28:47 +03:00
echo "ok dormant to layered"
2016-07-04 18:43:02 +03:00
2017-01-17 21:29:48 +03:00
if vm_rpmostree pkg-add foo; then
2016-07-04 18:43:02 +03:00
assert_not_reached "pkg-add foo succeeded even though it's already layered"
fi
echo "ok can't layer pkg already layered"
2017-01-17 21:29:48 +03:00
if vm_rpmostree pkg-add bar; then
2016-07-04 18:43:02 +03:00
assert_not_reached "pkg-add bar succeeded but it conflicts with layered foo"
fi
2017-02-25 00:28:47 +03:00
echo "ok can't layer conflicting pkg (layered)"
2016-07-04 18:43:02 +03:00
2017-02-25 00:28:47 +03:00
# ok, now let's go back to the depl where foo is in the layer
vm_rpmostree rollback
2017-01-17 21:29:48 +03:00
vm_rpmostree pkg-remove foo
2016-07-04 18:43:02 +03:00
vm_reboot
2017-02-25 00:28:47 +03:00
if vm_has_requested_packages foo; then
assert_not_reached "foo is still in the origin"
fi
2016-07-04 18:43:02 +03:00
echo "ok pkg-remove foo"
2017-02-25 00:28:47 +03:00
if vm_rpmostree 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 (base)"
# ok, now go back to a base layer without foo and add bar
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/without_foo
vm_rpmostree upgrade
2017-01-17 21:29:48 +03:00
vm_rpmostree pkg-add bar
2016-07-04 18:43:02 +03:00
vm_reboot
2017-02-25 00:28:47 +03:00
2016-07-04 18:43:02 +03:00
vm_assert_layered_pkg bar present
echo "ok pkg-add bar"
2017-02-25 00:28:47 +03:00
# now let's try to do an upgrade to a base layer which *has* foo
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/with_foo
2017-01-17 21:29:48 +03:00
if vm_rpmostree upgrade; then
2016-07-04 18:43:02 +03:00
assert_not_reached "upgrade succeeded but new base has conflicting pkg foo"
fi
echo "ok can't upgrade with conflicting layered pkg"