2017-06-05 19:39:46 +03:00
#!/bin/bash
#
# Copyright (C) 2017 Red Hat, Inc.
#
# 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
2017-06-05 19:39:46 +03:00
. ${ commondir } /libtest.sh
. ${ commondir } /libvm.sh
set -x
2017-06-29 17:11:25 +03:00
# create a new vmcheck commit which has foo and bar in it already so that we can
# target them with our override
2017-06-05 19:39:46 +03:00
# make sure the packages are not already layered
vm_assert_layered_pkg foo absent
2017-06-29 17:11:25 +03:00
vm_assert_layered_pkg bar absent
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
'.deployments[0]["base-checksum"]|not' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["pending-base-checksum"]|not' \
'.deployments[0]["base-removals"]|length == 0' \
'.deployments[0]["requested-base-removals"]|length == 0'
2017-06-05 19:39:46 +03:00
2017-06-20 19:21:57 +03:00
vm_cmd ostree refs $( vm_get_booted_csum) \
2017-06-29 17:11:25 +03:00
--create vmcheck_tmp/without_foo_and_bar
2017-06-05 19:39:46 +03:00
2017-06-29 17:11:25 +03:00
# create a new branch with foo and bar
vm_build_rpm foo
vm_build_rpm bar
vm_rpmostree install foo bar
2017-06-05 19:39:46 +03:00
vm_cmd ostree refs $( vm_get_deployment_info 0 checksum) \
2017-06-29 17:11:25 +03:00
--create vmcheck_tmp/with_foo_and_bar
2017-06-05 19:39:46 +03:00
vm_rpmostree cleanup -p
# upgrade to new commit with foo in the base layer
2017-06-29 17:11:25 +03:00
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/with_foo_and_bar
2017-06-05 19:39:46 +03:00
vm_rpmostree upgrade
vm_reboot
2017-06-29 17:11:25 +03:00
if ! vm_has_packages foo bar; then
assert_not_reached "foo or bar not in base layer"
2017-06-05 19:39:46 +03:00
fi
echo "ok setup"
2017-10-13 16:22:15 +03:00
# And now we move the local cache; this will force an error if we ever try to
# reach the repo. This implicitly tests that `override remove/reset` operate in
# cache-only mode.
vm_rpmostree cleanup --repomd
vm_cmd mv /tmp/vmcheck/yumrepo{ ,.bak}
2017-07-04 20:50:52 +03:00
# funky jq syntax: see test-override-local-replace.sh for an explanation of how
# this works. the only difference here is the [.0] which we use to access the
# nevra of each gv_nevra element.
2017-11-07 23:53:10 +03:00
vm_rpmostree override remove foo bar
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 2' \
2017-07-04 20:50:52 +03:00
'[.deployments[0]["base-removals"][][.0]]|index("foo-1.0-1.x86_64") >= 0' \
'[.deployments[0]["base-removals"][][.0]]|index("bar-1.0-1.x86_64") >= 0' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["requested-base-removals"]|length == 2' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0' \
2017-06-29 17:11:25 +03:00
'.deployments[0]["requested-base-removals"]|index("bar") >= 0'
echo "ok override remove foo and bar"
2017-06-05 19:39:46 +03:00
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck
2017-10-13 16:22:15 +03:00
vm_rpmostree upgrade --cache-only
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 2' \
2017-07-04 20:50:52 +03:00
'[.deployments[0]["base-removals"][][.0]]|index("foo-1.0-1.x86_64") >= 0' \
'[.deployments[0]["base-removals"][][.0]]|index("bar-1.0-1.x86_64") >= 0' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["requested-base-removals"]|length == 2' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0' \
2017-06-29 17:11:25 +03:00
'.deployments[0]["requested-base-removals"]|index("bar") >= 0'
2017-06-05 19:39:46 +03:00
echo "ok override remove carried through upgrade"
2017-11-07 23:53:10 +03:00
vm_rpmostree override reset foo
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 1' \
2017-07-04 20:50:52 +03:00
'[.deployments[0]["base-removals"][][.0]]|index("bar-1.0-1.x86_64") >= 0' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["requested-base-removals"]|length == 1' \
2017-06-29 17:11:25 +03:00
'.deployments[0]["requested-base-removals"]|index("bar") >= 0'
2017-06-05 19:39:46 +03:00
echo "ok override reset foo"
2017-11-07 23:53:10 +03:00
vm_rpmostree override reset --all
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 0' \
'.deployments[0]["requested-base-removals"]|length == 0'
2017-06-05 19:39:46 +03:00
echo "ok override reset --all"
2017-06-20 19:21:57 +03:00
# check that upgrading to a base without foo works
2017-11-07 23:53:10 +03:00
vm_rpmostree override remove foo
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 1' \
2017-07-04 20:50:52 +03:00
'[.deployments[0]["base-removals"][][.0]]|index("foo-1.0-1.x86_64") >= 0' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["requested-base-removals"]|length == 1' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0'
2017-06-29 17:11:25 +03:00
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/without_foo_and_bar
2017-10-13 16:22:15 +03:00
vm_rpmostree upgrade --cache-only
2017-06-05 19:39:46 +03:00
vm_assert_status_jq \
2017-06-20 19:21:57 +03:00
'.deployments[0]["base-removals"]|length == 0' \
'.deployments[0]["requested-base-removals"]|length == 1' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0'
echo "ok override remove requested but not applied"
# check that upgrading again to a base with foo turns the override back on
2017-06-29 17:11:25 +03:00
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/with_foo_and_bar
2017-10-13 16:22:15 +03:00
vm_rpmostree upgrade --cache-only
2017-06-20 19:21:57 +03:00
vm_assert_status_jq \
'.deployments[0]["base-removals"]|length == 1' \
2017-07-04 20:50:52 +03:00
'[.deployments[0]["base-removals"][][.0]]|index("foo-1.0-1.x86_64") >= 0' \
2017-06-20 19:21:57 +03:00
'.deployments[0]["requested-base-removals"]|length == 1' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0'
echo "ok override remove re-applied"
vm_rpmostree cleanup -p
2017-06-05 19:39:46 +03:00
2017-10-13 16:22:15 +03:00
# Restore the local yum repo.
vm_cmd mv /tmp/vmcheck/yumrepo{ .bak,}
echo "ok override remove/reset operate offline"
2017-06-05 19:39:46 +03:00
# a few error checks
2017-11-07 23:53:10 +03:00
if vm_rpmostree override remove non-existent-package; then
2017-06-05 19:39:46 +03:00
assert_not_reached "override remove non-existent-package succeeded?"
fi
echo "ok override remove non-existent-package fails"
vm_rpmostree install foo
2017-11-07 23:53:10 +03:00
if vm_rpmostree override remove foo; then
2017-06-05 19:39:46 +03:00
assert_not_reached "override remove layered pkg foo succeeded?"
fi
vm_rpmostree cleanup -p
echo "ok override remove layered pkg foo fails"
# the next two error checks expect an upgraded layer with foo builtin
2017-06-29 17:11:25 +03:00
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/with_foo_and_bar
2017-06-05 19:39:46 +03:00
vm_rpmostree upgrade
2017-11-07 23:53:10 +03:00
vm_rpmostree override remove foo
2017-06-05 19:39:46 +03:00
if vm_rpmostree install foo; then
assert_not_reached "tried to layer pkg removed by override"
fi
# the check blocking this isn't related to overrides, though for consistency
# let's make sure this fails here too
2017-06-29 17:11:25 +03:00
if vm_rpmostree install /tmp/vmcheck/yumrepo/packages/x86_64/foo-1.0-1.x86_64.rpm; then
2017-06-05 19:39:46 +03:00
assert_not_reached "tried to layer local pkg removed by override"
fi
vm_rpmostree cleanup -p
echo "ok can't layer pkg removed by override"
2017-06-29 17:11:25 +03:00
vm_build_rpm foo-ext requires "foo = 1.0-1"
2017-06-05 19:39:46 +03:00
vm_rpmostree upgrade --install foo-ext
2017-11-07 23:53:10 +03:00
if vm_rpmostree override remove foo; then
2017-06-05 19:39:46 +03:00
assert_not_reached "override remove base pkg needed by layered pkg succeeded?"
fi
vm_rpmostree cleanup -p
echo "ok override remove base dep to layered pkg fails"