mirror of
https://github.com/systemd/systemd.git
synced 2025-09-05 01:44:45 +03:00
test: merge TEST-14-MACHINE-ID into TEST-74-AUX-UTILS
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
../TEST-01-BASIC/Makefile
|
|
@@ -1,16 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
set -e
|
|
||||||
|
|
||||||
TEST_DESCRIPTION="/etc/machine-id testing"
|
|
||||||
IMAGE_NAME="badid"
|
|
||||||
TEST_NO_NSPAWN=1
|
|
||||||
|
|
||||||
# shellcheck source=test/test-functions
|
|
||||||
. "${TEST_BASE_DIR:?}/test-functions"
|
|
||||||
|
|
||||||
test_append_files() {
|
|
||||||
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >"${1:?}/etc/machine-id"
|
|
||||||
}
|
|
||||||
|
|
||||||
do_test "$@"
|
|
@@ -7,4 +7,10 @@ TEST_DESCRIPTION="Tests for auxiliary utilities"
|
|||||||
# shellcheck source=test/test-functions
|
# shellcheck source=test/test-functions
|
||||||
. "${TEST_BASE_DIR:?}/test-functions"
|
. "${TEST_BASE_DIR:?}/test-functions"
|
||||||
|
|
||||||
|
test_append_files() {
|
||||||
|
local workspace="${1:?}"
|
||||||
|
|
||||||
|
printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >"$workspace/etc/machine-id"
|
||||||
|
}
|
||||||
|
|
||||||
do_test "$@"
|
do_test "$@"
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
[Unit]
|
|
||||||
Description=TEST-14-MACHINE-ID
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
ExecStartPre=rm -f /failed /testok
|
|
||||||
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
|
|
||||||
ExecStart=/bin/sh -e -x -c 'systemctl --state=failed --no-legend --no-pager >/failed ; echo OK >/testok'
|
|
||||||
Type=oneshot
|
|
@@ -1,39 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
set -eux
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
function setup_root {
|
|
||||||
local _root="$1"
|
|
||||||
mkdir -p "$_root"
|
|
||||||
mount -t tmpfs tmpfs "$_root"
|
|
||||||
mkdir -p "$_root/etc" "$_root/run"
|
|
||||||
}
|
|
||||||
|
|
||||||
function check {
|
|
||||||
printf "Expected\n"
|
|
||||||
cat "$1"
|
|
||||||
printf "\nGot\n"
|
|
||||||
cat "$2"
|
|
||||||
cmp "$1" "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
r="$(pwd)/overwrite-broken-machine-id"
|
|
||||||
setup_root "$r"
|
|
||||||
systemd-machine-id-setup --print --root "$r"
|
|
||||||
echo abc >>"$r/etc/machine-id"
|
|
||||||
id="$(systemd-machine-id-setup --print --root "$r")"
|
|
||||||
echo "$id" >expected
|
|
||||||
check expected "$r/etc/machine-id"
|
|
||||||
|
|
||||||
r="$PWD/transient-machine-id"
|
|
||||||
setup_root "$r"
|
|
||||||
systemd-machine-id-setup --print --root "$r"
|
|
||||||
echo abc >>"$r/etc/machine-id"
|
|
||||||
mount -o remount,ro "$r"
|
|
||||||
mount -t tmpfs tmpfs "$r/run"
|
|
||||||
transient_id="$(systemd-machine-id-setup --print --root "$r")"
|
|
||||||
mount -o remount,rw "$r"
|
|
||||||
commited_id="$(systemd-machine-id-setup --print --commit --root "$r")"
|
|
||||||
[[ "$transient_id" = "$commited_id" ]]
|
|
||||||
check "$r/etc/machine-id" "$r/run/machine-id"
|
|
82
test/units/testsuite-74.machine-id-setup.sh
Executable file
82
test/units/testsuite-74.machine-id-setup.sh
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
# shellcheck disable=SC2064
|
||||||
|
set -eux
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Create a list of all functions prefixed with testcase_
|
||||||
|
mapfile -t TESTCASES < <(declare -F | awk '$3 ~ /^testcase_/ {print $3;}')
|
||||||
|
|
||||||
|
if [[ "${#TESTCASES[@]}" -eq 0 ]]; then
|
||||||
|
echo >&2 "No test cases found, this is most likely an error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for testcase in "${TESTCASES[@]}"; do
|
||||||
|
"$testcase"
|
||||||
|
done
|
Reference in New Issue
Block a user