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
2018-01-28 23:16:22 +03:00
# create a new branch with foo and bar.
# foo has files in /lib, to test our re-canonicalization to /usr
vm_build_rpm foo \
files " %dir /lib/foo
2018-02-08 00:54:18 +03:00
/lib/foo/foo.txt
/lib/foo/shared.txt" \
install ' mkdir -p %{ buildroot} /lib/foo && \
echo %{ name} > %{ buildroot} /lib/foo/foo.txt && \
echo shared > %{ buildroot} /lib/foo/shared.txt'
# make bar co-own /lib/foo and /lib/foo/shared.txt
vm_build_rpm bar \
files " %dir /lib/foo
/lib/foo/bar.txt
/lib/foo/shared.txt" \
install ' mkdir -p %{ buildroot} /lib/foo && \
echo %{ name} > %{ buildroot} /lib/foo/bar.txt && \
echo shared > %{ buildroot} /lib/foo/shared.txt'
2017-06-29 17:11:25 +03:00
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.
2018-02-08 00:54:18 +03:00
# remove just bar first to check deletion handling
vm_rpmostree override remove bar
vm_assert_status_jq \
'.deployments[0]["base-removals"]|length == 1' \
'[.deployments[0]["base-removals"][][.0]]|index("bar-1.0-1.x86_64") >= 0' \
'.deployments[0]["requested-base-removals"]|length == 1' \
'.deployments[0]["requested-base-removals"]|index("bar") >= 0'
newroot = $( vm_get_deployment_root 0)
# And test that we removed fully owned files, but not shared files
vm_cmd " test -d ${ newroot } /usr/lib/foo && \
test -f ${ newroot } /usr/lib/foo/foo.txt && \
test -f ${ newroot } /usr/lib/foo/shared.txt && \
test ! -f ${ newroot } /usr/lib/foo/bar.txt"
echo "ok override remove bar"
# now also remove foo
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 == 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'
2018-01-28 23:16:22 +03:00
newroot = $( vm_get_deployment_root 0)
2018-02-08 00:54:18 +03:00
# And this tests handling /lib -> /usr/lib as well as removal of shared files
vm_cmd " test -d ${ newroot } /usr/lib && \
test '!' -f ${ newroot } /usr/lib/foo/foo.txt && \
test '!' -f ${ newroot } /usr/lib/foo/shared.txt && \
2018-01-28 23:16:22 +03:00
test '!' -d ${ newroot } /usr/lib/foo"
2017-06-29 17:11:25 +03:00
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'
2018-06-13 19:00:56 +03:00
vm_rpmostree override reset --all | & tee out.txt
assert_file_has_content out.txt "No change."
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'
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'
2018-04-03 21:00:07 +03:00
echo "ok active -> inactive -> active override remove"
# make sure we can reset it while it's inactive
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck_tmp/without_foo_and_bar
vm_rpmostree upgrade --cache-only
vm_assert_status_jq \
'.deployments[0]["base-removals"]|length == 0' \
'.deployments[0]["requested-base-removals"]|length == 1' \
'.deployments[0]["requested-base-removals"]|index("foo") >= 0'
vm_rpmostree override reset foo
vm_assert_status_jq \
'.deployments[0]["base-removals"]|length == 0' \
'.deployments[0]["requested-base-removals"]|length == 0'
echo "ok reset inactive override remove"
2017-06-20 19:21:57 +03:00
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"
2018-06-01 20:58:16 +03:00
vm_build_rpm baz
vm_rpmostree install baz
if vm_rpmostree override remove baz; then
2017-06-05 19:39:46 +03:00
assert_not_reached "override remove layered pkg foo succeeded?"
fi
vm_rpmostree cleanup -p
2018-06-01 20:58:16 +03:00
echo "ok override remove layered pkg baz fails"
2017-06-05 19:39:46 +03:00
# 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"
2018-06-12 16:44:34 +03:00
vm_build_rpm boo
vm_rpmostree override remove foo --install boo
vm_rpmostree cleanup -p
echo "ok remove and --install at the same time"