]>
Commit | Line | Data |
---|---|---|
fcb24270 | 1 | #!/bin/bash |
818567fc | 2 | set -e |
7ae8162f | 3 | TEST_DESCRIPTION="/etc/machine-id testing" |
054ee249 | 4 | TEST_NO_NSPAWN=1 |
c2d4da00 | 5 | |
fcb24270 EV |
6 | . $TEST_BASE_DIR/test-functions |
7 | ||
fcb24270 EV |
8 | test_setup() { |
9 | create_empty_image | |
10 | mkdir -p $TESTDIR/root | |
11 | mount ${LOOPDEV}p1 $TESTDIR/root | |
12 | ||
13 | # Create what will eventually be our root filesystem onto an overlay | |
14 | ( | |
15 | LOG_LEVEL=5 | |
16 | eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) | |
17 | ||
18 | setup_basic_environment | |
069a254f | 19 | printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id |
fcb24270 EV |
20 | dracut_install mount cmp |
21 | ||
22 | # setup the testsuite service | |
23 | cat >$initdir/etc/systemd/system/testsuite.service <<EOF | |
24 | [Unit] | |
25 | Description=Testsuite service | |
fcb24270 EV |
26 | |
27 | [Service] | |
28 | ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok' | |
29 | Type=oneshot | |
30 | EOF | |
31 | ||
32 | cat >$initdir/test-machine-id-setup.sh <<'EOF' | |
33 | #!/bin/bash | |
34 | ||
35 | set -e | |
36 | set -x | |
37 | ||
38 | function setup_root { | |
39 | local _root="$1" | |
40 | mkdir -p "$_root" | |
41 | mount -t tmpfs tmpfs "$_root" | |
42 | mkdir -p "$_root/etc" "$_root/run" | |
43 | } | |
44 | ||
45 | function check { | |
46 | printf "Expected\n" | |
47 | cat "$1" | |
48 | printf "\nGot\n" | |
49 | cat "$2" | |
50 | cmp "$1" "$2" | |
51 | } | |
52 | ||
53 | r="$(pwd)/overwrite-broken-machine-id" | |
54 | setup_root "$r" | |
55 | systemd-machine-id-setup --print --root "$r" | |
56 | echo abc >>"$r/etc/machine-id" | |
57 | id=$(systemd-machine-id-setup --print --root "$r") | |
58 | echo $id >expected | |
59 | check expected "$r/etc/machine-id" | |
a6f72863 EV |
60 | |
61 | r="$(pwd)/transient-machine-id" | |
62 | setup_root "$r" | |
da2d1421 EV |
63 | systemd-machine-id-setup --print --root "$r" |
64 | echo abc >>"$r/etc/machine-id" | |
a6f72863 EV |
65 | mount -o remount,ro "$r" |
66 | mount -t tmpfs tmpfs "$r/run" | |
67 | transient_id=$(systemd-machine-id-setup --print --root "$r") | |
68 | mount -o remount,rw "$r" | |
69 | commited_id=$(systemd-machine-id-setup --print --commit --root "$r") | |
70 | [[ "$transient_id" = "$commited_id" ]] | |
71 | check "$r/etc/machine-id" "$r/run/machine-id" | |
fcb24270 EV |
72 | EOF |
73 | chmod +x $initdir/test-machine-id-setup.sh | |
74 | ||
75 | setup_testsuite | |
76 | ) || return 1 | |
77 | ||
78 | # mask some services that we do not want to run in these tests | |
79 | ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service | |
80 | ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service | |
81 | ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service | |
82 | ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket | |
83 | ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service | |
84 | ||
85 | ddebug "umount $TESTDIR/root" | |
86 | umount $TESTDIR/root | |
87 | } | |
88 | ||
fcb24270 | 89 | do_test "$@" |