vmcheck: add basic test for local RPM installs
Closes: #657 Approved by: cgwalters
This commit is contained in:
parent
81c43e81fb
commit
fd64084b9b
@ -163,24 +163,30 @@ vm_has_packages() {
|
||||
done
|
||||
}
|
||||
|
||||
# retrieve info from the booted deployment
|
||||
# - $1 key to retrieve
|
||||
vm_get_booted_deployment_info() {
|
||||
key=$1
|
||||
# retrieve info from a deployment
|
||||
# - $1 index of deployment (or -1 for booted)
|
||||
# - $2 key to retrieve
|
||||
vm_get_deployment_info() {
|
||||
idx=$1
|
||||
key=$2
|
||||
vm_rpmostree status --json | \
|
||||
python -c "
|
||||
import sys, json
|
||||
deployments = json.load(sys.stdin)[\"deployments\"]
|
||||
booted = None
|
||||
for deployment in deployments:
|
||||
if deployment[\"booted\"]:
|
||||
booted = deployment
|
||||
break
|
||||
if not booted:
|
||||
idx = $idx
|
||||
if idx < 0:
|
||||
for i, depl in enumerate(deployments):
|
||||
if depl[\"booted\"]:
|
||||
idx = i
|
||||
if idx < 0:
|
||||
print \"Failed to determine currently booted deployment\"
|
||||
exit(1)
|
||||
if \"$key\" in booted:
|
||||
data = booted[\"$key\"]
|
||||
if idx >= len(deployments):
|
||||
print \"Deployment index $idx is out of range\"
|
||||
exit(1)
|
||||
depl = deployments[idx]
|
||||
if \"$key\" in depl:
|
||||
data = depl[\"$key\"]
|
||||
if type(data) is list:
|
||||
print \" \".join(data)
|
||||
else:
|
||||
@ -188,6 +194,12 @@ if \"$key\" in booted:
|
||||
"
|
||||
}
|
||||
|
||||
# retrieve info from the booted deployment
|
||||
# - $1 key to retrieve
|
||||
vm_get_booted_deployment_info() {
|
||||
vm_get_deployment_info -1 $1
|
||||
}
|
||||
|
||||
# print the layered packages
|
||||
vm_get_layered_packages() {
|
||||
vm_get_booted_deployment_info packages
|
||||
@ -198,6 +210,10 @@ vm_get_requested_packages() {
|
||||
vm_get_booted_deployment_info requested-packages
|
||||
}
|
||||
|
||||
vm_get_local_packages() {
|
||||
vm_get_booted_deployment_info requested-local-packages
|
||||
}
|
||||
|
||||
# check that the packages are currently layered
|
||||
# - $@ packages to check for
|
||||
vm_has_layered_packages() {
|
||||
@ -220,6 +236,15 @@ vm_has_requested_packages() {
|
||||
done
|
||||
}
|
||||
|
||||
vm_has_local_packages() {
|
||||
pkgs=$(vm_get_local_packages)
|
||||
for pkg in "$@"; do
|
||||
if [[ " $pkgs " != *$pkg* ]]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
vm_has_dormant_packages() {
|
||||
vm_has_requested_packages "$@" && \
|
||||
! vm_has_layered_packages "$@"
|
||||
@ -240,12 +265,15 @@ vm_assert_layered_pkg() {
|
||||
set +e
|
||||
vm_has_packages $pkg; pkg_in_rpmdb=$?
|
||||
vm_has_layered_packages $pkg; pkg_is_layered=$?
|
||||
vm_has_local_packages $pkg; pkg_is_layered_local=$?
|
||||
vm_has_requested_packages $pkg; pkg_is_requested=$?
|
||||
[ $pkg_in_rpmdb == 0 ] && \
|
||||
[ $pkg_is_layered == 0 ] && \
|
||||
[ $pkg_is_requested == 0 ]; pkg_present=$?
|
||||
( ( [ $pkg_is_layered == 0 ] &&
|
||||
[ $pkg_is_requested == 0 ] ) ||
|
||||
[ $pkg_is_layered_local == 0 ] ); pkg_present=$?
|
||||
[ $pkg_in_rpmdb != 0 ] && \
|
||||
[ $pkg_is_layered != 0 ] && \
|
||||
[ $pkg_is_layered_local != 0 ] && \
|
||||
[ $pkg_is_requested != 0 ]; pkg_absent=$?
|
||||
set -e
|
||||
|
||||
|
@ -95,6 +95,7 @@ echo "ok pkg foo removed"
|
||||
vm_rpmostree cleanup -b
|
||||
vm_assert_status_jq '.deployments|length == 2'
|
||||
echo "ok baseline cleanup"
|
||||
|
||||
vm_rpmostree cleanup -r
|
||||
vm_assert_status_jq '.deployments|length == 1'
|
||||
vm_rpmostree cleanup -pr
|
||||
|
67
tests/vmcheck/test-layering-local.sh
Executable file
67
tests/vmcheck/test-layering-local.sh
Executable file
@ -0,0 +1,67 @@
|
||||
#!/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.
|
||||
|
||||
set -e
|
||||
|
||||
. ${commondir}/libtest.sh
|
||||
. ${commondir}/libvm.sh
|
||||
|
||||
set -x
|
||||
|
||||
vm_send_test_repo
|
||||
|
||||
vm_assert_layered_pkg foo absent
|
||||
|
||||
vm_rpmostree install /tmp/vmcheck/repo/packages/x86_64/foo-1.0-1.x86_64.rpm
|
||||
echo "ok install foo locally"
|
||||
|
||||
vm_reboot
|
||||
|
||||
vm_assert_status_jq '.deployments[0]["packages"]|length == 0'
|
||||
vm_assert_status_jq '.deployments[0]["requested-packages"]|length == 0'
|
||||
vm_assert_status_jq '.deployments[0]["requested-local-packages"]|length == 1'
|
||||
vm_has_local_packages foo-1.0-1.x86_64
|
||||
vm_assert_layered_pkg foo-1.0-1.x86_64 present
|
||||
echo "ok pkg foo added locally"
|
||||
|
||||
# check that we can still request foo and it's dormant
|
||||
vm_rpmostree install foo
|
||||
|
||||
vm_assert_status_jq '.deployments[0]["packages"]|length == 0'
|
||||
vm_assert_status_jq '.deployments[0]["requested-packages"]|length == 1'
|
||||
vm_assert_status_jq '.deployments[0]["requested-local-packages"]|length == 1'
|
||||
echo "ok request foo"
|
||||
|
||||
# check that uninstalling the local rpm makes us go back to repos
|
||||
vm_rpmostree uninstall foo-1.0-1.x86_64
|
||||
|
||||
vm_assert_status_jq '.deployments[0]["packages"]|length == 1'
|
||||
vm_assert_status_jq '.deployments[0]["requested-packages"]|length == 1'
|
||||
vm_assert_status_jq '.deployments[0]["requested-local-packages"]|length == 0'
|
||||
echo "ok layer foo back from repos"
|
||||
|
||||
# check that trying to install a package already in the base errors out
|
||||
vm_cmd ostree refs $(vm_get_deployment_info 0 checksum) --create vmcheck_tmp/with_foo
|
||||
vm_cmd ostree commit -b vmcheck --tree=ref=vmcheck_tmp/with_foo
|
||||
vm_rpmostree uninstall foo
|
||||
vm_rpmostree upgrade # upgrades to new base which has foo
|
||||
if vm_rpmostree install /tmp/vmcheck/repo/packages/x86_64/foo-1.0-1.x86_64.rpm; then
|
||||
assert_not_reached "didn't error out when trying to install same pkg"
|
||||
fi
|
||||
echo "ok error on layering same pkg in base"
|
Loading…
Reference in New Issue
Block a user