2013-07-07 21:45:18 +04:00
#!/bin/bash
#
# Copyright (C) 2011,2013 Colin Walters <walters@verbum.org>
#
2018-01-30 22:26:26 +03:00
# SPDX-License-Identifier: LGPL-2.0+
#
2013-07-07 21:45:18 +04:00
# 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.
2016-01-27 19:44:10 +03:00
set -euo pipefail
2013-07-07 21:45:18 +04:00
. $( dirname $0 ) /libtest.sh
2015-07-14 20:30:05 +03:00
# Exports OSTREE_SYSROOT so --sysroot not needed.
2017-09-01 23:15:33 +03:00
setup_os_repository "archive" "syslinux"
2013-07-07 21:45:18 +04:00
2018-04-24 19:51:38 +03:00
echo "1..7"
2013-07-07 21:45:18 +04:00
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo pull-local --remote= testos testos-repo testos/buildmaster/x86_64-runtime
2015-03-03 15:13:54 +03:00
rev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
2013-07-07 21:45:18 +04:00
export rev
# This initial deployment gets kicked off with some kernel arguments
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree admin deploy --karg= root = LABEL = MOO --karg= quiet --os= testos testos:testos/buildmaster/x86_64-runtime
2013-07-07 21:45:18 +04:00
assert_has_dir sysroot/boot/ostree/testos-${ bootcsum }
echo "ok deploy command"
# Commit + upgrade twice, so that we'll rotate out the original deployment
2013-09-20 16:09:06 +04:00
bootcsum1 = ${ bootcsum }
2013-07-07 21:45:18 +04:00
os_repository_new_commit
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo remote add --set= gpg-verify= false testos file://$( pwd ) /testos-repo testos/buildmaster/x86_64-runtime
${ CMD_PREFIX } ostree admin upgrade --os= testos
2013-09-20 16:09:06 +04:00
bootcsum2 = ${ bootcsum }
os_repository_new_commit "1"
bootcsum3 = ${ bootcsum }
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2013-07-07 21:45:18 +04:00
2015-03-03 15:13:54 +03:00
newrev = $( ${ CMD_PREFIX } ostree --repo= sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
2013-07-07 21:45:18 +04:00
assert_not_streq ${ rev } ${ newrev }
2013-09-20 16:09:06 +04:00
assert_not_streq ${ bootcsum1 } ${ bootcsum2 }
assert_not_streq ${ bootcsum2 } ${ bootcsum3 }
assert_not_has_dir sysroot/boot/ostree/testos-${ bootcsum1 }
2013-07-07 21:45:18 +04:00
assert_has_dir sysroot/boot/ostree/testos-${ bootcsum }
2013-09-20 16:09:06 +04:00
assert_has_dir sysroot/boot/ostree/testos-${ bootcsum2 }
2013-07-07 21:45:18 +04:00
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${ newrev } .0/etc/os-release 'NAME=TestOS'
echo "ok deploy and GC /boot"
2013-07-16 00:13:12 +04:00
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree admin cleanup
2013-07-16 00:13:12 +04:00
assert_has_dir sysroot/boot/ostree/testos-${ bootcsum }
assert_file_has_content sysroot/ostree/deploy/testos/deploy/${ newrev } .0/etc/os-release 'NAME=TestOS'
echo "ok manual cleanup"
2018-02-23 20:46:32 +03:00
2018-04-24 19:51:38 +03:00
# Commit + upgrade twice, so that we'll rotate out the original deployment
os_repository_new_commit "1"
${ CMD_PREFIX } ostree admin upgrade --os= testos
oldversion = ${ version }
# another commit with *same* bootcsum but *new* content
os_repository_new_commit "1" "2"
newversion = ${ version }
2018-06-27 17:45:43 +03:00
assert_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf ${ oldversion }
2018-04-24 19:51:38 +03:00
${ CMD_PREFIX } ostree admin upgrade --os= testos
2018-06-27 17:45:43 +03:00
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf ${ newversion }
2018-04-24 19:51:38 +03:00
echo "ok new version same bootcsum"
2018-02-23 20:46:32 +03:00
assert_n_pinned( ) {
local n = $1
${ CMD_PREFIX } ostree admin status > status.txt
local n_pinned = " $( grep -F -c -e 'Pinned: yes' < status.txt) "
if test " ${ n_pinned } " '!=' " ${ n } " ; then
cat status.txt
fatal " ${ n_pinned } != ${ n } "
fi
}
assert_n_deployments( ) {
local n = $1
${ CMD_PREFIX } ostree admin status > status.txt
local n_deployments = " $( grep -F -c -e 'Version: ' < status.txt) "
if test " ${ n_deployments } " '!=' " ${ n } " ; then
cat status.txt
fatal " ${ n_deployments } != ${ n } "
fi
}
assert_n_pinned 0
${ CMD_PREFIX } ostree admin pin 0
assert_n_pinned 1
${ CMD_PREFIX } ostree admin pin -u 0
assert_n_pinned 0
echo "ok pin unpin"
2019-06-17 17:41:00 +03:00
${ CMD_PREFIX } ostree admin pin 0 1
2018-02-23 20:46:32 +03:00
assert_n_pinned 2
assert_n_deployments 2
os_repository_new_commit
${ CMD_PREFIX } ostree admin upgrade --os= testos
assert_n_pinned 2
assert_n_deployments 3
echo "ok pin across upgrades"
${ CMD_PREFIX } ostree admin pin -u 1
os_repository_new_commit
${ CMD_PREFIX } ostree admin upgrade --os= testos
assert_n_pinned 1
assert_n_deployments 3
os_repository_new_commit
${ CMD_PREFIX } ostree admin upgrade --os= testos
assert_n_pinned 1
assert_n_deployments 3
echo "ok pinning"