2017-01-04 20:29:01 +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-01-04 20:29:01 +03:00
. ${ commondir } /libtest.sh
. ${ commondir } /libvm.sh
set -x
# SUMMARY: Tests for the `initramfs` functionality
base = $( vm_get_booted_csum)
vm_rpmostree initramfs > initramfs.txt
assert_file_has_content initramfs.txt "Initramfs regeneration.*disabled"
echo "ok initramfs status"
if vm_rpmostree initramfs --disable 2>err.txt; then
assert_not_reached "Unexpectedly succeeded at disabling"
fi
assert_file_has_content err.txt "already.*disabled"
if vm_rpmostree initramfs --reboot 2>err.txt; then
assert_not_reached "reboot worked?"
fi
2018-09-12 21:13:29 +03:00
assert_file_has_content err.txt "reboot.*used with.*enable.*disable"
if vm_rpmostree initramfs --arg= foo 2>err.txt; then
assert_not_reached "arg worked?"
fi
assert_file_has_content err.txt "arg.*used with.*enable"
2017-01-04 20:29:01 +03:00
echo "ok initramfs state"
2019-05-01 17:07:31 +03:00
vm_status_watch_start
2018-09-10 18:15:22 +03:00
vm_rpmostree initramfs --enable > initramfs.txt
2019-05-01 17:07:31 +03:00
vm_status_watch_check "Transaction: initramfs --enable"
2018-09-10 18:15:22 +03:00
assert_file_has_content initramfs.txt "Initramfs regeneration.*enabled"
vm_rpmostree initramfs > initramfs.txt
assert_file_has_content initramfs.txt "Initramfs regeneration.*enabled"
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
2017-01-27 07:31:53 +03:00
'.deployments[1].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[1]["regenerate-initramfs"]|not'
2017-01-04 20:29:01 +03:00
vm_reboot
assert_not_streq $base $( vm_get_booted_csum)
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[0]["initramfs-args"]|length == 0' \
'.deployments[1]["regenerate-initramfs"]|not' \
'.deployments[1]["initramfs-args"]|not'
2017-01-04 20:29:01 +03:00
if vm_rpmostree initramfs --enable 2>err.txt; then
assert_not_reached "Unexpectedly succeeded at enabling"
fi
assert_file_has_content err.txt "already.*enabled"
echo "ok initramfs enabled"
2018-09-10 18:15:22 +03:00
vm_rpmostree initramfs --disable > initramfs.txt
assert_file_has_content initramfs.txt "Initramfs regeneration.*disabled"
vm_rpmostree initramfs > initramfs.txt
assert_file_has_content initramfs.txt "Initramfs regeneration.*disabled"
2017-01-04 20:29:01 +03:00
vm_reboot
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'
2017-01-04 20:29:01 +03:00
echo "ok initramfs disabled"
vm_reboot_cmd rpm-ostree initramfs --enable --reboot
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[1]["regenerate-initramfs"]|not'
2017-01-04 20:29:01 +03:00
vm_reboot_cmd rpm-ostree initramfs --disable --reboot
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]|not' \
'.deployments[1]["regenerate-initramfs"]'
2017-01-04 20:29:01 +03:00
echo "ok initramfs enable disable reboot"
assert_streq $base $( vm_get_booted_csum)
2017-02-18 01:36:49 +03:00
osname = $( vm_get_booted_deployment_info osname)
2017-01-04 20:29:01 +03:00
for file in first second; do
vm_cmd touch /etc/rpmostree-initramfs-testing-$file
vm_rpmostree initramfs --enable --arg= "-I" --arg= " /etc/rpmostree-initramfs-testing- $file "
2018-09-12 21:13:29 +03:00
vm_rpmostree initramfs > initramfs.txt
assert_file_has_content initramfs.txt " Initramfs.*args.*-I.*/etc/rpmostree-initramfs-testing- $file "
2017-01-04 20:29:01 +03:00
vm_reboot
2017-02-08 01:49:20 +03:00
vm_assert_status_jq \
2017-01-27 07:31:53 +03:00
'.deployments[0].booted' \
'.deployments[0]["regenerate-initramfs"]' \
'.deployments[0]["initramfs-args"]|index("-I") == 0' \
'.deployments[0]["initramfs-args"]|index("/etc/rpmostree-initramfs-testing-' ${ file } '") == 1' \
'.deployments[0]["initramfs-args"]|length == 2'
2018-06-28 20:44:33 +03:00
initramfs = $( vm_cmd grep ^initrd /boot/loader/entries/ostree-2-$osname .conf | sed -e 's,initrd ,/boot/,' )
2017-01-04 20:29:01 +03:00
test -n " ${ initramfs } "
vm_cmd lsinitrd $initramfs > lsinitrd.txt
assert_file_has_content lsinitrd.txt /etc/rpmostree-initramfs-testing-${ file }
done
2018-07-13 19:22:05 +03:00
echo "ok initramfs args enable"
2017-01-04 20:29:01 +03:00
vm_rpmostree initramfs --disable
2018-07-13 19:22:05 +03:00
vm_reboot
2018-06-28 20:44:33 +03:00
initramfs = $( vm_cmd grep ^initrd /boot/loader/entries/ostree-2-$osname .conf | sed -e 's,initrd ,/boot/,' )
2017-01-04 20:29:01 +03:00
test -n " ${ initramfs } "
vm_cmd lsinitrd $initramfs > lsinitrd.txt
assert_not_file_has_content lsinitrd.txt /etc/rpmostree-initramfs-testing
2018-07-13 19:22:05 +03:00
echo "ok initramfs disable"