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