2017-10-04 19:05:25 +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.
set -euo pipefail
. ${ commondir } /libtest.sh
. ${ commondir } /libvm.sh
set -x
osname = $( vm_get_booted_deployment_info osname)
2018-07-09 19:55:09 +03:00
vm_kargs_now( ) {
vm_rpmostree kargs " $@ "
vm_reboot
}
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs > kargs.txt
2018-06-28 20:44:33 +03:00
conf_content = $( vm_cmd grep -h ^options /boot/loader/entries/ostree-*.conf | head -1 | sed -e 's,options ,,' )
2017-10-04 19:05:25 +03:00
assert_file_has_content_literal kargs.txt " $conf_content "
echo "ok kargs display matches options"
2018-07-09 19:55:09 +03:00
vm_kargs_now --append= FOO = BAR --append= APPENDARG = VALAPPEND --append= APPENDARG = 2NDAPPEND
2017-10-04 19:05:25 +03:00
# read the conf file into a txt for future comparison
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > tmp_conf.txt
2017-10-04 19:05:25 +03:00
assert_file_has_content_literal tmp_conf.txt 'FOO=BAR'
assert_file_has_content_literal tmp_conf.txt 'APPENDARG=VALAPPEND APPENDARG=2NDAPPEND'
2018-06-26 17:38:45 +03:00
# Ensure the result flows through with rpm-ostree kargs
vm_rpmostree kargs > kargs.txt
2017-10-05 21:50:59 +03:00
assert_file_has_content_literal kargs.txt 'FOO=BAR'
assert_file_has_content_literal kargs.txt 'APPENDARG=VALAPPEND APPENDARG=2NDAPPEND'
2017-10-04 19:05:25 +03:00
echo "ok kargs append"
2018-06-26 17:38:45 +03:00
# Test for rpm-ostree kargs delete
2018-07-09 19:55:09 +03:00
vm_kargs_now kargs --delete FOO
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > tmp_conf.txt
2017-10-04 19:05:25 +03:00
assert_not_file_has_content tmp_conf.txt 'FOO=BAR'
echo "ok delete a single key/value pair"
2018-06-26 17:38:45 +03:00
if vm_rpmostree kargs --delete APPENDARG 2>err.txt; then
2017-10-05 21:50:59 +03:00
assert_not_reached "Delete A key with multiple values unexpectedly succeeded"
2017-10-04 19:05:25 +03:00
fi
2019-03-22 18:49:59 +03:00
assert_file_has_content err.txt "Multiple values for key 'APPENDARG' found"
2017-10-04 19:05:25 +03:00
echo "ok failed to delete key with multiple values"
2018-07-09 19:55:09 +03:00
vm_kargs_now --delete APPENDARG = VALAPPEND
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > tmp_conf.txt
2017-10-05 21:50:59 +03:00
assert_not_file_has_content tmp_conf.txt 'APPENDARG=VALAPPEND'
assert_file_has_content tmp_conf.txt 'APPENDARG=2NDAPPEND'
echo "ok delete a single key/value pair from multi valued key pairs"
2018-06-26 17:38:45 +03:00
# Test for rpm-ostree kargs replace
2019-05-01 17:07:31 +03:00
vm_status_watch_start
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs --append= REPLACE_TEST = TEST --append= REPLACE_MULTI_TEST = TEST --append= REPLACE_MULTI_TEST = NUMBERTWO
2019-05-01 17:07:31 +03:00
vm_status_watch_check "Transaction: kargs --append=REPLACE_TEST=TEST --append=REPLACE_MULTI_TEST=TEST --append=REPLACE_MULTI_TEST=NUMBERTWO"
2017-10-05 21:50:59 +03:00
2017-10-25 22:37:24 +03:00
# Test for replacing key/value pair with only one value
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs --replace= REPLACE_TEST = HELLO
2018-07-09 19:55:09 +03:00
if vm_pending_is_staged; then
vm_reboot
fi
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > tmp_conf.txt
2017-10-05 21:50:59 +03:00
assert_file_has_content_literal tmp_conf.txt 'REPLACE_TEST=HELLO'
echo "ok replacing one key/value pair"
2017-10-25 22:37:24 +03:00
# Test for replacing key/value pair with multi vars
2018-06-26 17:38:45 +03:00
if vm_rpmostree kargs --replace= REPLACE_MULTI_TEST = ERR 2>err.txt; then
2017-10-05 21:50:59 +03:00
assert_not_reached "Replace a key with multiple values unexpectedly succeeded"
fi
2019-03-22 18:49:59 +03:00
assert_file_has_content err.txt "Multiple values for key 'REPLACE_MULTI_TEST' found"
2017-10-05 21:50:59 +03:00
echo "ok failed to replace key with multiple values"
2017-10-25 22:37:24 +03:00
# Test for replacing one of the values for multi value keys
2018-07-09 19:55:09 +03:00
vm_kargs_now --replace= REPLACE_MULTI_TEST = TEST = NEWTEST
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > tmp_conf.txt
2017-10-05 21:50:59 +03:00
assert_file_has_content tmp_conf.txt "REPLACE_MULTI_TEST=NEWTEST"
assert_not_file_has_content tmp_conf.txt "REPLACE_MULTI_TEST=TEST"
assert_file_has_content tmp_conf.txt "REPLACE_MULTI_TEST=NUMBERTWO"
echo "ok replacing value from multi-valued key pairs"
2017-10-04 19:05:25 +03:00
2018-07-09 19:55:09 +03:00
# Test --deploy-index=1
2017-10-04 19:05:25 +03:00
vm_rpmostree rollback
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs --deploy-index= 1 > kargs.txt
2017-10-25 22:37:24 +03:00
assert_file_has_content kargs.txt 'REPLACE_MULTI_TEST=NUMBERTWO'
assert_file_has_content kargs.txt 'APPENDARG=2NDAPPEND'
echo "ok kargs correctly displayed for specific deployment indices"
# Test if the proc-cmdline option produces the same result as /proc/cmdline
vm_cmd cat /proc/cmdline > cmdlinekargs.txt
2018-06-26 17:38:45 +03:00
for arg in $( vm_rpmostree kargs --import-proc-cmdline | tail -n +2) ; do
2017-10-25 22:37:24 +03:00
case " $arg " in
ostree = *) # Skip the ostree arg due to potential boot version difference
; ;
*) assert_file_has_content cmdlinekargs.txt " $arg "
; ;
esac
done
echo "ok import kargs from current deployment"
2018-06-16 01:06:02 +03:00
# Test for https://github.com/projectatomic/rpm-ostree/issues/1392
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs --append= PACKAGE = TEST
2018-06-16 01:06:02 +03:00
vm_build_rpm foo
2018-12-10 17:27:19 +03:00
vm_rpmostree install foo | tee out.txt
# make sure the string hasn't changed for the next negative check below
assert_file_has_content out.txt 'Enabled rpm-md'
2018-12-10 19:21:46 +03:00
vm_pending_is_staged # this is default now, but just being explicit
2018-12-10 17:27:19 +03:00
vm_rpmostree kargs --append= PACKAGE2 = TEST2 | tee out.txt
# check that kargs modifications are done offline
assert_not_file_has_content out.txt 'Enabled rpm-md'
echo "ok kargs work offline"
2018-07-09 19:55:09 +03:00
vm_reboot
2018-06-16 01:06:02 +03:00
2018-06-28 20:44:33 +03:00
vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname .conf > kargs.txt
2018-06-16 01:06:02 +03:00
assert_file_has_content_literal kargs.txt 'PACKAGE=TEST'
2018-12-10 19:21:46 +03:00
assert_file_has_content_literal kargs.txt 'PACKAGE2=TEST2'
2018-06-16 01:06:02 +03:00
echo "ok kargs with multiple operations"
2018-06-26 17:38:45 +03:00
vm_rpmostree kargs > kargs.txt
2018-06-16 01:06:02 +03:00
assert_file_has_content_literal kargs.txt 'PACKAGE=TEST'
2018-12-10 19:21:46 +03:00
assert_file_has_content_literal kargs.txt 'PACKAGE2=TEST2'
2018-06-16 01:06:02 +03:00
echo "ok kargs display with multiple operations"