]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/TEST-14-MACHINE-ID/test.sh
Merge branch 'predictable-interface-names'
[thirdparty/systemd.git] / test / TEST-14-MACHINE-ID / test.sh
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
4 set -e
5 TEST_DESCRIPTION="/etc/machine-id testing"
6 TEST_NO_NSPAWN=1
7
8 . $TEST_BASE_DIR/test-functions
9
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
29 [Service]
30 ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
31 Type=oneshot
32 EOF
33
34 cat >$initdir/test-machine-id-setup.sh <<'EOF'
35 #!/bin/bash
36
37 set -e
38 set -x
39
40 function setup_root {
41 local _root="$1"
42 mkdir -p "$_root"
43 mount -t tmpfs tmpfs "$_root"
44 mkdir -p "$_root/etc" "$_root/run"
45 }
46
47 function check {
48 printf "Expected\n"
49 cat "$1"
50 printf "\nGot\n"
51 cat "$2"
52 cmp "$1" "$2"
53 }
54
55 r="$(pwd)/overwrite-broken-machine-id"
56 setup_root "$r"
57 systemd-machine-id-setup --print --root "$r"
58 echo abc >>"$r/etc/machine-id"
59 id=$(systemd-machine-id-setup --print --root "$r")
60 echo $id >expected
61 check expected "$r/etc/machine-id"
62
63 r="$(pwd)/transient-machine-id"
64 setup_root "$r"
65 systemd-machine-id-setup --print --root "$r"
66 echo abc >>"$r/etc/machine-id"
67 mount -o remount,ro "$r"
68 mount -t tmpfs tmpfs "$r/run"
69 transient_id=$(systemd-machine-id-setup --print --root "$r")
70 mount -o remount,rw "$r"
71 commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
72 [[ "$transient_id" = "$commited_id" ]]
73 check "$r/etc/machine-id" "$r/run/machine-id"
74 EOF
75 chmod +x $initdir/test-machine-id-setup.sh
76
77 setup_testsuite
78 ) || return 1
79
80 # mask some services that we do not want to run in these tests
81 ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
82 ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
83 ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
84 ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
85 ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
86
87 ddebug "umount $TESTDIR/root"
88 umount $TESTDIR/root
89 }
90
91 do_test "$@"