rpm-ostree/tests/kolainst/destructive/initramfs-etc
Jonathan Lebon 4da10dc11e Add new ex initramfs-etc command
This command allows users to cheaply inject configuration files in the
initramfs stage without having to regenerate the whole initramfs (or
even a new OSTree commit). This will be useful for configuring services
involved in bringing up the root block device.

```
$ echo 'hello world' > /etc/foobar
$ rpm-ostree ex initramfs-etc --track /etc/foobar
Staging deployment... done
Run "systemctl reboot" to start a reboot
$ rpm-ostree status
State: idle
Deployments:
  ostree://fedora:fedora/x86_64/coreos/testing-devel
                   Version: 32.20200716.dev.1 (2020-07-16T02:47:29Z)
                    Commit: 9a817d75bef81b955179be6e602d1e6ae350645b6323231a62ba2ee6e5b9644b
              GPGSignature: (unsigned)
              InitramfsEtc: /etc/foobar

● ostree://fedora:fedora/x86_64/coreos/testing-devel
                   Version: 32.20200716.dev.1 (2020-07-16T02:47:29Z)
                    Commit: 9a817d75bef81b955179be6e602d1e6ae350645b6323231a62ba2ee6e5b9644b
              GPGSignature: (unsigned)
$ reboot
(boot into rd.break)
sh-5.0# cat /etc/foobar
hello world
```

See the libostree side of this at:
https://github.com/ostreedev/ostree/pull/2155

Lots more discussions in:
https://github.com/coreos/fedora-coreos-tracker/issues/94

Closes: #1930
2020-10-30 00:48:54 +01:00

80 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
. ${KOLA_EXT_DATA}/libtest.sh
cd $(mktemp -d)
# From https://github.com/ostreedev/ostree/blob/95a6d1514/tests/kolainst/destructive/overlay-initrds.sh#L23
check_for_dracut_karg() {
local karg=$1; shift
# https://github.com/dracutdevs/dracut/blob/38ea7e821b/modules.d/98dracut-systemd/dracut-cmdline.sh#L17
journalctl -b 0 -t dracut-cmdline \
--grep "Using kernel command line parameters:.* ${karg} "
}
case "${AUTOPKGTEST_REBOOT_MARK:-}" in
"")
mkdir -p /etc/cmdline.d
echo 'foobar' > /etc/cmdline.d/foobar.conf
rpm-ostree ex initramfs-etc --track /etc/cmdline.d/foobar.conf
rpm-ostree status > status.txt
assert_file_has_content_literal status.txt "InitramfsEtc: /etc/cmdline.d/foobar.conf"
rpm-ostree status --json > status.json
assert_jq status.json \
'.deployments[0]["initramfs-etc"]|length == 1' \
'.deployments[0]["initramfs-etc"][0] == "/etc/cmdline.d/foobar.conf"'
/tmp/autopkgtest-reboot 1
;;
1)
check_for_dracut_karg foobar
rpm-ostree ex initramfs-etc --track /etc/cmdline.d/foobar.conf > out.txt
assert_file_has_content_literal out.txt "No changes."
# right now we don't rechecksum all the files so changing the file alone
# isn't noticed, but we could in the future
echo 'barbaz' > /etc/cmdline.d/foobar.conf
rpm-ostree ex initramfs-etc --track /etc/cmdline.d/foobar.conf > out.txt
assert_file_has_content_literal out.txt "No changes."
# but --force-sync should also plow through
rpm-ostree ex initramfs-etc --force-sync > out.txt
assert_file_has_content_literal out.txt "Staging deployment"
/tmp/autopkgtest-reboot 2
;;
2)
check_for_dracut_karg barbaz
if check_for_dracut_karg foobar; then
assert_not_reached "Found karg foobar; expected barbaz"
fi
# let's try tracking a whole directory instead
echo 'bazboo' > /etc/cmdline.d/bazboo.conf
# and for fun, let's use the the locked finalization flow
rpm-ostree ex initramfs-etc --lock-finalization \
--untrack /etc/cmdline.d/foobar.conf \
--track /etc/cmdline.d
rpm-ostree status > status.txt
assert_file_has_content_literal status.txt "InitramfsEtc: /etc/cmdline.d"
rpm-ostree status --json > status.json
assert_jq status.json \
'.deployments[0]["initramfs-etc"]|length == 1' \
'.deployments[0]["initramfs-etc"][0] == "/etc/cmdline.d"'
/tmp/autopkgtest-reboot-prepare 3
rpm-ostree finalize-deployment --allow-missing-checksum
;;
3)
check_for_dracut_karg barbaz
check_for_dracut_karg bazboo
# finally, check that passing no args prints the tracked files
rpm-ostree ex initramfs-etc > out.txt
assert_file_has_content_literal out.txt "Tracked files:"
assert_file_has_content_literal out.txt "/etc/cmdline.d"
;;
*) echo "unexpected mark: ${AUTOPKGTEST_REBOOT_MARK}"; exit 1;;
esac