summaryrefslogtreecommitdiffstats
path: root/test/units/TEST-74-AUX-UTILS.machine-id-setup.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:40 +0000
commitfc53809803cd2bc2434e312b19a18fa36776da12 (patch)
treeb4b43bd6538f51965ce32856e9c053d0f90919c8 /test/units/TEST-74-AUX-UTILS.machine-id-setup.sh
parentAdding upstream version 255.5. (diff)
downloadsystemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz
systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/units/TEST-74-AUX-UTILS.machine-id-setup.sh')
-rwxr-xr-xtest/units/TEST-74-AUX-UTILS.machine-id-setup.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/units/TEST-74-AUX-UTILS.machine-id-setup.sh b/test/units/TEST-74-AUX-UTILS.machine-id-setup.sh
new file mode 100755
index 0000000..c2b9db5
--- /dev/null
+++ b/test/units/TEST-74-AUX-UTILS.machine-id-setup.sh
@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2064
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/test-control.sh
+. "$(dirname "$0")"/test-control.sh
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+root_mock() {
+ local root="${1:?}"
+
+ mkdir -p "$root"
+ # Put a tmpfs over the "root", so we're able to remount it as read-only
+ # when needed
+ mount -t tmpfs tmpfs "$root"
+ mkdir "$root/etc" "$root/run"
+}
+
+root_cleanup() {
+ local root="${1:?}"
+
+ umount --recursive "$root"
+ rm -fr "$root"
+}
+
+testcase_sanity() {
+ systemd-machine-id-setup
+ systemd-machine-id-setup --help
+ systemd-machine-id-setup --version
+ systemd-machine-id-setup --print
+ systemd-machine-id-setup --root= --print
+ systemd-machine-id-setup --root=/ --print
+
+ (! systemd-machine-id-setup "")
+ (! systemd-machine-id-setup --foo)
+}
+
+testcase_invalid() {
+ local root machine_id
+
+ root="$(mktemp -d)"
+ trap "root_cleanup $root" RETURN
+ root_mock "$root"
+
+ systemd-machine-id-setup --print --root "$root"
+ echo abc >>"$root/etc/machine-id"
+ machine_id="$(systemd-machine-id-setup --print --root "$root")"
+ diff <(echo "$machine_id") "$root/etc/machine-id"
+}
+
+testcase_transient() {
+ local root transient_id committed_id
+
+ root="$(mktemp -d)"
+ trap "root_cleanup $root" RETURN
+ root_mock "$root"
+
+ systemd-machine-id-setup --print --root "$root"
+ echo abc >>"$root/etc/machine-id"
+ mount -o remount,ro "$root"
+ mount -t tmpfs tmpfs "$root/run"
+ transient_id="$(systemd-machine-id-setup --print --root "$root")"
+ mount -o remount,rw "$root"
+ committed_id="$(systemd-machine-id-setup --print --commit --root "$root")"
+ [[ "$transient_id" == "$committed_id" ]]
+ diff "$root/etc/machine-id" "$root/run/machine-id"
+}
+
+# Check if we correctly processed the invalid machine ID we set up in the respective
+# test.sh file
+systemctl --state=failed --no-legend --no-pager >/failed
+test ! -s /failed
+
+run_testcases