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