2017-06-05 19:38:39 +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:38:39 +03:00
. ${ commondir } /libtest.sh
. ${ commondir } /libvm.sh
set -x
2018-04-16 02:47:22 +03:00
# More miscellaneous tests
2018-03-14 19:02:49 +03:00
2019-02-04 19:51:18 +03:00
# Custom origin and local repo rebases. This is essentially the RHCOS workflow.
# https://github.com/projectatomic/rpm-ostree/pull/1406
# https://github.com/projectatomic/rpm-ostree/pull/1732
2018-06-08 22:39:56 +03:00
booted_csum = $( vm_get_booted_csum)
oscontainer_source = "oscontainer://quay.io/exampleos@sha256:98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4"
if vm_rpmostree rebase --skip-purge --custom-origin-url " ${ oscontainer_source } " \
:${ booted_csum } 2>err.txt; then
fatal "rebased without description"
fi
assert_file_has_content_literal err.txt '--custom-origin-description must be supplied'
vm_rpmostree rebase --skip-purge --custom-origin-description "'Updated via pivot'" \
--custom-origin-url " ${ oscontainer_source } " \
:${ booted_csum }
vm_rpmostree status > status.txt
assert_file_has_content_literal status.txt 'CustomOrigin: Updated via pivot'
assert_file_has_content_literal status.txt " ${ oscontainer_source } "
vm_rpmostree upgrade >out.txt
assert_file_has_content_literal out.txt 'Pinned to commit by custom origin: Updated via pivot'
vm_rpmostree cleanup -p
2019-02-04 19:51:18 +03:00
echo "ok rebase with custom origin"
# Try again but making it think it's pulling from another local repo
vm_rpmostree rebase --skip-purge /sysroot/ostree/repo:${ booted_csum } --experimental
vm_rpmostree upgrade >out.txt
assert_file_has_content_literal out.txt 'Pinned to commit; no upgrade available'
vm_rpmostree cleanup -p
echo "ok rebase from local repo remote"
2018-06-08 22:39:56 +03:00
2017-07-26 00:49:10 +03:00
# Add metadata string containing EnfOfLife attribtue
META_ENDOFLIFE_MESSAGE = "this is a test for metadata message"
commit = $( vm_cmd ostree commit -b vmcheck \
2018-10-05 19:57:00 +03:00
--tree= ref = vmcheck --add-metadata-string= ostree.endoflife= " ' ${ META_ENDOFLIFE_MESSAGE } ' " )
2017-07-26 00:49:10 +03:00
vm_rpmostree upgrade
vm_assert_status_jq " .deployments[0][\"endoflife\"] == \" ${ META_ENDOFLIFE_MESSAGE } \" "
echo "ok endoflife metadata gets parsed correctly"
# Build a layered commit and check if EndOfLife still present
vm_build_rpm foo
vm_rpmostree install foo
vm_assert_status_jq " .deployments[0][\"endoflife\"] == \" ${ META_ENDOFLIFE_MESSAGE } \" "
echo "ok layered commit inherits the endoflife attribute"
2017-08-03 16:41:18 +03:00
2018-06-28 17:19:46 +03:00
# Check whether it's staged; `rollback` is only supported with
# the soon-to-be-legacy mode of not staging deployments by default.
if vm_pending_is_staged; then
vm_assert_status_jq ".deployments[1][\"booted\"] == true"
if vm_rpmostree rollback 2>err.txt; then
fatal "rolled back staged?"
fi
assert_file_has_content err.txt 'error: Staged.*remove.*cleanup'
# For the pinning tests, we need two real deployments, so
# let's reboot now, then we need to get back to the previous state,
# so reboot again.
vm_reboot
vm_rpmostree rollback
vm_reboot
vm_rpmostree rollback
else
vm_rpmostree rollback
vm_assert_status_jq ".deployments[0][\"booted\"] == true" \
".deployments[1][\"booted\"] == false"
vm_rpmostree rollback
vm_assert_status_jq ".deployments[0][\"booted\"] == false" \
".deployments[1][\"booted\"] == true"
echo "ok rollback"
fi
vm_rpmostree status
echo "before pinning"
2017-08-21 22:30:42 +03:00
2018-03-08 03:50:37 +03:00
# Pinning
2018-06-28 17:19:46 +03:00
vm_cmd ostree admin pin 0 > pin.txt
assert_file_has_content pin.txt 'is now pinned'
2018-03-08 03:50:37 +03:00
vm_rpmostree status > status.txt
assert_file_has_content_literal status.txt "Pinned: yes"
2018-06-28 17:19:46 +03:00
vm_cmd ostree admin pin -u 0 > pin.txt
assert_file_has_content_literal pin.txt 'is now unpinned'
2018-03-08 03:50:37 +03:00
vm_rpmostree status > status.txt
assert_not_file_has_content status.txt "Pinned: yes"
echo "ok pinning"
2018-05-22 22:20:33 +03:00
# trying to clean up a pinned pending deployment should be a no-op
2018-06-28 17:19:46 +03:00
vm_cmd ostree admin pin 0 > pin.txt
assert_file_has_content pin.txt 'is now pinned'
2018-05-22 22:20:33 +03:00
vm_assert_status_jq ".deployments|length == 2" \
".deployments[0][\"pinned\"] == true"
2018-03-23 00:41:42 +03:00
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 2"
2018-05-22 22:20:33 +03:00
echo "ok pinned pending"
vm_build_rpm bar
vm_rpmostree install bar
vm_assert_status_jq ".deployments|length == 3"
# but that new one shouldn't be pinned
vm_assert_status_jq ".deployments[0][\"pinned\"] == false"
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 2"
echo "ok pinning not carried over"
# and now check that we can unpin and cleanup
2018-06-28 17:19:46 +03:00
vm_cmd ostree admin pin -u 0 > pin.txt
assert_file_has_content_literal pin.txt 'is now unpinned'
2018-05-22 22:20:33 +03:00
vm_assert_status_jq ".deployments[0][\"pinned\"] == false"
2018-03-23 00:41:42 +03:00
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 1"
2018-05-22 22:20:33 +03:00
echo "ok unpin"
2018-03-23 00:41:42 +03:00
2017-08-21 22:30:42 +03:00
# https://github.com/ostreedev/ostree/pull/1055
vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck --timestamp= \" October 25 1985\"
if vm_rpmostree upgrade 2>err.txt; then
fatal "upgraded to older commit?"
fi
assert_file_has_content err.txt "chronologically older"
echo "ok failed to upgrade to older commit"
2017-09-06 19:19:55 +03:00
# https://github.com/projectatomic/rpm-ostree/issues/365
2017-09-13 23:33:47 +03:00
vm_build_rpm base-package \
2017-09-06 19:19:55 +03:00
files /usr/app \
install " mkdir -p %{buildroot}/usr/app
echo one > %{ buildroot} /usr/app/conflict-file"
2017-09-13 23:33:47 +03:00
vm_rpmostree install base-package
2017-09-06 19:19:55 +03:00
2017-09-13 23:33:47 +03:00
# build a file having exact same content and check for merging
vm_build_rpm test-merging \
files /usr/app \
install " mkdir -p %{buildroot}/usr/app
echo one > %{ buildroot} /usr/app/conflict-file"
vm_rpmostree install test-merging
echo "ok identical file merges"
# have a file with same file path but different content, testing for conflicts
2017-09-06 19:19:55 +03:00
vm_build_rpm conflict-pkg \
files /usr/app \
install " mkdir -p %{buildroot}/usr/app
echo two > %{ buildroot} /usr/app/conflict-file"
if vm_rpmostree install conflict-pkg 2>err.txt; then
assert_not_reached "Install packages with conflicting files unexpected succeeded"
fi
assert_not_file_has_content err.txt "Writing rpmdb"
assert_file_has_content err.txt "File exists"
echo "ok detecting file name conflicts before writing rpmdb"
2017-09-11 23:00:40 +03:00
# check that the way we detect deployment changes is not dependent on pending-*
# https://github.com/projectatomic/rpm-ostree/issues/981
vm_rpmostree cleanup -rp
2018-06-28 17:19:46 +03:00
vm_rpmostree status
echo "before redeploy"
2017-09-11 23:00:40 +03:00
csum = $( vm_cmd ostree commit -b vmcheck --tree= ref = vmcheck)
# restart to make daemon see the pending checksum
vm_cmd systemctl restart rpm-ostreed
vm_assert_status_jq '.deployments[0]["pending-base-checksum"]'
# hard reset to booted csum (simulates what deploy does to remote refspecs)
vm_cmd ostree reset vmcheck $( vm_get_booted_csum)
rc = 0
vm_rpmostree deploy $( vm_get_booted_csum) > out.txt || rc = $?
if [ $rc != 77 ] ; then
assert_not_reached "trying to re-deploy same commit didn't exit 77"
fi
assert_file_has_content out.txt 'No change.'
vm_assert_status_jq '.deployments[0]["pending-base-checksum"]|not'
echo "ok changes to deployment variant don't affect deploy"
2017-09-20 23:26:29 +03:00
vm_build_rpm bad-post post "echo a bad post >&2 && false"
cursor = $( vm_get_journal_cursor)
if vm_rpmostree install bad-post & > err.txt; then
assert_not_reached "installing pkg with failing post unexpectedly succeeded"
fi
assert_file_has_content err.txt "run.*journalctl.*for more information"
vm_assert_journal_has_content $cursor 'rpm-ostree(bad-post.post).*a bad post'
echo "ok script output prefixed in journal"
2017-10-05 22:33:40 +03:00
2019-02-01 17:57:27 +03:00
vm_build_rpm check-ostree-booted post "test -f /run/ostree-booted"
vm_rpmostree install check-ostree-booted
echo "ok /run/ostree-booted in scriptlet container"
2017-10-05 22:33:40 +03:00
# check refresh-md/-C functionality
# local repos are always cached, so let's start up an http server for the same
# vmcheck repo
2018-09-06 23:09:04 +03:00
vm_start_httpd vmcheck /var/tmp 8888
2018-03-09 22:52:12 +03:00
vm_ansible_inline <<EOF
- copy:
content: |
[ vmcheck-http]
name = vmcheck-http
baseurl = http://localhost:8888/vmcheck/yumrepo
gpgcheck = 0
dest: /etc/yum.repos.d/vmcheck-http.repo
2017-10-05 22:33:40 +03:00
EOF
vm_rpmostree cleanup -rpmb
vm_cmd rm -f /etc/yum.repos.d/vmcheck.repo
vm_build_rpm_repo_mode skip refresh-md-old-pkg
2018-11-26 18:52:45 +03:00
vm_rpmostree refresh-md | tee out.txt
assert_file_has_content_literal out.txt "Updating metadata for 'vmcheck-http'"
2017-10-05 22:33:40 +03:00
vm_build_rpm_repo_mode skip refresh-md-new-pkg
2018-11-26 18:52:45 +03:00
vm_rpmostree refresh-md | tee out.txt # shouldn't do anything since it hasn't expired yet
assert_file_has_content_literal out.txt "rpm-md repo 'vmcheck-http' (cached)"
2017-10-13 16:22:15 +03:00
if vm_rpmostree install refresh-md-new-pkg --dry-run; then
2017-10-05 22:33:40 +03:00
assert_not_reached "successfully dry-run installed new pkg from cached rpmmd?"
fi
2018-11-26 18:52:45 +03:00
vm_rpmostree refresh-md -f | tee out.txt
assert_file_has_content_literal out.txt "Updating metadata for 'vmcheck-http'"
2017-10-13 16:22:15 +03:00
if ! vm_rpmostree install refresh-md-new-pkg --dry-run; then
2017-10-05 22:33:40 +03:00
assert_not_reached "failed to dry-run install new pkg from cached rpmmd?"
fi
2017-10-13 16:20:10 +03:00
vm_stop_httpd vmcheck
2017-10-13 16:22:15 +03:00
echo "ok refresh-md"
2018-10-05 19:57:00 +03:00
# check that a failed staging shows up in status
# first create a staged deployment
vm_build_rpm test-stage-fail
vm_rpmostree install test-stage-fail
vm_pending_is_staged
# OK, now make sure we'll fail. One nuclear way to do this is to just delete the
# deployment root it expects to exist. I played with overriding the service file
# so we just do e.g. /usr/bin/false, but the issue is we still want the "start"
# journal msg to be emitted.
vm_cmd rm -rf $( vm_get_deployment_root 0)
# and now check that we notice there was a failure in `status`
vm_reboot
vm_rpmostree status > status.txt
assert_file_has_content status.txt "failed to finalize previous deployment"
2018-10-12 19:06:56 +03:00
assert_file_has_content status.txt "error: opendir"
2018-10-05 19:57:00 +03:00
echo "ok previous staged failure in status"