2014-07-16 17:02:45 +04:00
#!/bin/bash
#
# Copyright (C) 2014 Colin Walters <walters@verbum.org>
#
# 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
2016-06-06 19:46:48 +03:00
. ${ commondir } /libtest.sh
2017-01-16 21:58:50 +03:00
export RPMOSTREE_SUPPRESS_REQUIRES_ROOT_CHECK = yes
2014-07-16 17:02:45 +04:00
2016-06-06 19:08:29 +03:00
ensure_dbus
2015-04-01 14:25:36 +03:00
2017-09-11 23:00:40 +03:00
echo "1..25"
2014-07-16 17:02:45 +04:00
setup_os_repository "archive-z2" "syslinux"
echo "ok setup"
2015-09-01 21:46:32 +03:00
# Note: Daemon already knows what sysroot to use, so avoid passing
# --sysroot=sysroot to rpm-ostree commands as it will result
# in a warning message.
2016-12-22 20:39:28 +03:00
OSTREE = "ostree --repo=sysroot/ostree/repo"
REMOTE_OSTREE = " ostree --repo=testos-repo --gpg-homedir= ${ test_tmpdir } /gpghome "
2017-03-06 23:53:02 +03:00
rpm-ostree --version > version.yaml
python -c 'import yaml; v=yaml.safe_load(open("version.yaml")); assert("Version" in v["rpm-ostree"])'
echo "ok yaml version"
2014-07-16 17:02:45 +04:00
# This initial deployment gets kicked off with some kernel arguments
2016-12-22 20:39:28 +03:00
$OSTREE remote add --set= gpg-verify= false testos file://$( pwd ) /testos-repo testos/buildmaster/x86_64-runtime
$OSTREE pull testos:testos/buildmaster/x86_64-runtime
2014-07-16 17:02:45 +04:00
ostree admin --sysroot= sysroot deploy --karg= root = LABEL = MOO --karg= quiet --os= testos testos:testos/buildmaster/x86_64-runtime
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "1.0.10"'
2016-05-25 00:40:10 +03:00
echo "ok status shows right version"
2014-10-28 07:47:25 +03:00
2017-04-21 04:51:35 +03:00
rpm-ostree status > status.txt
assert_file_has_content status.txt 'Version: 1.0.10'
assert_not_file_has_content status.txt StateRoot:
rpm-ostree status -v > status.txt
assert_file_has_content status.txt StateRoot:
echo "ok status text"
2017-03-23 04:44:09 +03:00
dbus-send --session --dest= org.projectatomic.rpmostree1 --print-reply= literal /org/projectatomic/rpmostree1/testos org.projectatomic.rpmostree1.OSExperimental.Moo boolean:true > moo.txt
assert_file_has_content moo.txt '🐄'
echo "ok experimental"
2014-07-16 17:02:45 +04:00
os_repository_new_commit
2015-09-01 21:46:32 +03:00
rpm-ostree upgrade --os= testos
2014-09-30 17:54:14 +04:00
2016-12-22 20:39:28 +03:00
$OSTREE remote add --set= gpg-verify= false otheros file://$( pwd ) /testos-repo testos/buildmaster/x86_64-runtime
2015-09-01 21:46:32 +03:00
rpm-ostree rebase --os= testos otheros:
2014-10-28 07:47:25 +03:00
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "' $( date "+%Y%m%d.0" ) '"'
2016-05-25 00:40:10 +03:00
echo "ok rebase onto newer version"
2015-11-04 19:28:43 +03:00
# Test 'upgrade --check' w/ no upgrade
# XXX Disabled this because source repo has no /usr/share/rpm
# Maybe that's too heavy a requirement to just check for an
# upgrade, but on the other hand this is *RPM*-ostree.
#rpm-ostree upgrade --os=testos --check
#test "$?" = "77" || (echo 1>&2 "Expected exit code 77, got $?"; exit 1)
# Jump backward to 1.0.9
rpm-ostree deploy --os= testos 1.0.9
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "1.0.9"'
2016-05-25 00:40:10 +03:00
echo "ok deploy older known version"
2015-11-04 19:28:43 +03:00
# Remember the current revision for later.
2016-12-22 20:39:28 +03:00
revision = $( $OSTREE rev-parse otheros:testos/buildmaster/x86_64-runtime)
2015-11-04 19:28:43 +03:00
# Jump forward to a locally known version.
rpm-ostree deploy --os= testos 1.0.10
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "1.0.10"'
2016-05-25 00:40:10 +03:00
echo "ok deploy newer known version"
2015-11-04 19:28:43 +03:00
# Jump forward to a new, locally unknown version.
# Here we also test the "version=" argument prefix.
os_repository_new_commit 1 1
rpm-ostree deploy --os= testos version = $( date "+%Y%m%d.1" )
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "' $( date "+%Y%m%d.1" ) '"'
2016-05-25 00:40:10 +03:00
echo "ok deploy newer unknown version"
2015-11-04 19:28:43 +03:00
# Jump backward again to 1.0.9, but this time using the
# "revision=" argument prefix (and test case sensitivity).
rpm-ostree deploy --os= testos REVISION = $revision
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "1.0.9"'
2016-05-25 00:40:10 +03:00
echo "ok deploy older version by revision"
2016-04-12 11:59:16 +03:00
2016-10-18 00:21:46 +03:00
# Make a commit on a different branch and make sure that it doesn't let us
# deploy it
2016-12-22 20:39:28 +03:00
other_rev = $( $REMOTE_OSTREE commit -b other-branch --tree= ref = $revision )
2016-10-18 00:21:46 +03:00
if rpm-ostree deploy --os= testos REVISION = $other_rev 2>OUTPUT-err; then
assert_not_reached "Deploying an out-of-branch commit unexpectedly succeeded."
fi
assert_file_has_content OUTPUT-err 'Checksum .* not found in .*'
echo "ok error on deploying commit on other branch"
2017-02-08 01:17:56 +03:00
# Make sure we can do an upgrade after a deploy
os_repository_new_commit 2 3
rpm-ostree upgrade --os= testos
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].version == "' $( date "+%Y%m%d.3" ) '"'
2017-02-08 01:17:56 +03:00
echo "ok upgrade after deploy"
2016-12-21 18:40:42 +03:00
# Make sure we're currently on otheros
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].origin|startswith("otheros:")'
2016-12-21 18:40:42 +03:00
os_repository_new_commit 2 2
rpm-ostree rebase --os= testos testos:testos/buildmaster/x86_64-runtime $( date "+%Y%m%d.2" )
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].origin|startswith("testos:")'
assert_status_jq '.deployments[0].version == "' $( date "+%Y%m%d.2" ) '"'
2016-12-21 18:40:42 +03:00
echo "ok rebase onto other branch at specific version"
branch = testos/buildmaster/x86_64-runtime
2016-12-22 20:39:28 +03:00
new_csum = $( $REMOTE_OSTREE commit -b $branch --tree= ref = $branch )
rpm-ostree rebase --os= testos otheros:$branch $new_csum
2017-02-08 01:49:20 +03:00
assert_status_jq '.deployments[0].origin|startswith("otheros:")'
assert_status_jq '.deployments[0].checksum == "' $new_csum '"'
2016-12-21 18:40:42 +03:00
echo "ok rebase onto other branch at specific checksum"
if rpm-ostree rebase --os= testos testos:testos/buildmaster/x86_64-runtime $other_rev 2>OUTPUT-err; then
assert_not_reached "Rebasing onto out-of-branch commit unexpectedly succeeded."
fi
assert_file_has_content OUTPUT-err 'Checksum .* not found in .*'
echo "ok error on rebasing onto commit on other branch"
2016-12-22 20:39:28 +03:00
# Make sure that we can deploy from a remote which has gone from unsigned to
# signed commits.
$REMOTE_OSTREE commit -b $branch --tree= ref = $branch \
--gpg-sign= $TEST_GPG_KEYID --add-metadata-string version = gpg-signed
$OSTREE remote add secureos file://$( pwd ) /testos-repo
rpm-ostree rebase --os= testos secureos:$branch gpg-signed
echo "ok deploy from remote with unsigned and signed commits"
2017-05-05 22:40:55 +03:00
rpm-ostree rebase --os= testos :$branch
assert_status_jq '.deployments[0].origin|startswith("testos/")'
echo "ok rebase from refspec with remote to local branch"
$OSTREE commit -b another-branch --tree= ref = $branch
rpm-ostree rebase --os= testos another-branch
assert_status_jq '.deployments[0].origin == "another-branch"'
echo "ok rebase from local branch to local branch"
2017-09-11 23:00:40 +03:00
csum1 = $( $OSTREE commit -b another-branch --tree= ref = $branch )
csum2 = $( $OSTREE commit -b another-branch --tree= ref = $branch )
rpm-ostree deploy --os= testos $csum1
if [ " $( $OSTREE rev-parse another-branch) " != $csum2 ] ; then
assert_not_reached "deploying from local branch changes branch"
fi
echo "ok local deploy doesn't affect branch"
2017-07-21 04:55:22 +03:00
rpm-ostree rebase --skip-purge --os= testos testos:testos/buildmaster/x86_64-runtime
assert_status_jq '.deployments[0].origin == "testos:testos/buildmaster/x86_64-runtime"'
ostree --repo= ${ test_tmpdir } /testos-repo commit --add-metadata-string version = 1.0.2 -b testos/stable/x86_64-runtime -s "Build" \
--tree= ref = testos/buildmaster/x86_64-runtime
rpm-ostree rebase --skip-purge --os= testos -b testos/stable/x86_64-runtime
assert_status_jq '.deployments[0].origin == "testos:testos/stable/x86_64-runtime"'
ostree --repo= ${ test_tmpdir } /sysroot/ostree/repo commit -b localbranch --tree= ref = testos:testos/stable/x86_64-runtime
rpm-ostree rebase --skip-purge --os= testos -m '' -b localbranch
assert_status_jq '.deployments[0].origin == "localbranch"'
echo "ok rebase new syntax"
rpm-ostree rebase --os= testos :another-branch
2017-02-14 05:01:31 +03:00
originpath = $( ostree admin --sysroot= sysroot --print-current-dir) .origin
echo "unconfigured-state=Access to TestOS requires ONE BILLION DOLLARS" >> ${ originpath }
2016-08-06 16:07:56 +03:00
rpm-ostree reload
2017-02-14 05:01:31 +03:00
rpm-ostree status
if rpm-ostree upgrade --os= testos 2>err.txt; then
assert_not_reached "Upgraded from unconfigured-state"
fi
assert_file_has_content err.txt 'ONE BILLION DOLLARS'
echo "ok unconfigured status"
2016-04-12 11:59:16 +03:00
# Ensure it returns an error when passing a wrong option.
rpm-ostree --help | awk '/^$/ {in_commands=0} {if(in_commands==1){print $0}} /^Builtin Commands:/ {in_commands=1}' > commands
while read command; do
2016-04-27 15:11:06 +03:00
if rpm-ostree $command --n0t-3xisting-0ption & >/dev/null; then
2016-04-12 11:59:16 +03:00
assert_not_reached " command $command --n0t-3xisting-0ption was successful "
fi
done < commands
2016-05-25 00:40:10 +03:00
echo "ok error on unknown command options"
2016-04-27 15:11:06 +03:00
if rpm-ostree nosuchcommand --nosuchoption 2>err.txt; then
assert_not_reached "Expected an error for nosuchcommand"
fi
assert_file_has_content err.txt 'Unknown.*command'
2016-05-25 00:40:10 +03:00
echo "ok error on unknown command"
2017-07-13 23:39:01 +03:00
2017-07-21 20:32:58 +03:00
cat >test-rpmostree-gi-arch <<EOF
2017-07-13 23:39:01 +03:00
#!/usr/bin/python2
import gi
gi.require_version( "RpmOstree" , "1.0" )
from gi.repository import RpmOstree
assert RpmOstree.get_basearch( ) = = 'x86_64'
assert RpmOstree.varsubst_basearch( 'http://example.com/foo/\${basearch}/bar' ) = = 'http://example.com/foo/x86_64/bar'
EOF
2017-07-21 20:32:58 +03:00
chmod a+x test-rpmostree-gi-arch
2017-07-13 23:39:01 +03:00
case $( arch) in
2017-07-21 20:32:58 +03:00
x86_64) ./test-rpmostree-gi-arch; ;
2017-07-13 23:39:01 +03:00
*) echo " Skipping RPM architecture test on $( arch) "
esac
echo "ok rpmostree arch"
2017-07-21 20:32:58 +03:00
cat >test-rpmostree-gi <<EOF
#!/usr/bin/python2
import gi
gi.require_version( "RpmOstree" , "1.0" )
from gi.repository import RpmOstree
assert RpmOstree.check_version( 2017, 6)
# If this fails for you, please come back in a time machine and say hi
assert not RpmOstree.check_version( 3000, 1)
EOF
chmod a+x test-rpmostree-gi
./test-rpmostree-gi
echo "ok rpmostree version"