]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-14-MACHINE-ID/test.sh
scripts: use 4 space indentation
[thirdparty/systemd.git] / test / TEST-14-MACHINE-ID / test.sh
CommitLineData
fcb24270 1#!/bin/bash
818567fc 2set -e
7ae8162f 3TEST_DESCRIPTION="/etc/machine-id testing"
054ee249 4TEST_NO_NSPAWN=1
c2d4da00 5
fcb24270
EV
6. $TEST_BASE_DIR/test-functions
7
fcb24270
EV
8test_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]
25Description=Testsuite service
fcb24270
EV
26
27[Service]
28ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
29Type=oneshot
30EOF
31
32cat >$initdir/test-machine-id-setup.sh <<'EOF'
33#!/bin/bash
34
35set -e
36set -x
37
38function 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
45function check {
46 printf "Expected\n"
47 cat "$1"
48 printf "\nGot\n"
49 cat "$2"
50 cmp "$1" "$2"
51}
52
53r="$(pwd)/overwrite-broken-machine-id"
54setup_root "$r"
55systemd-machine-id-setup --print --root "$r"
56echo abc >>"$r/etc/machine-id"
57id=$(systemd-machine-id-setup --print --root "$r")
58echo $id >expected
59check expected "$r/etc/machine-id"
a6f72863
EV
60
61r="$(pwd)/transient-machine-id"
62setup_root "$r"
da2d1421
EV
63systemd-machine-id-setup --print --root "$r"
64echo abc >>"$r/etc/machine-id"
a6f72863
EV
65mount -o remount,ro "$r"
66mount -t tmpfs tmpfs "$r/run"
67transient_id=$(systemd-machine-id-setup --print --root "$r")
68mount -o remount,rw "$r"
69commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
70[[ "$transient_id" = "$commited_id" ]]
71check "$r/etc/machine-id" "$r/run/machine-id"
fcb24270
EV
72EOF
73chmod +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 89do_test "$@"