]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/TEST-14-MACHINE-ID/test.sh
test: Drop SKIP_INITRD for QEMU-based tests
[thirdparty/systemd.git] / test / TEST-14-MACHINE-ID / test.sh
CommitLineData
fcb24270
EV
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
818567fc 4set -e
7ae8162f 5TEST_DESCRIPTION="/etc/machine-id testing"
054ee249 6TEST_NO_NSPAWN=1
c2d4da00 7
fcb24270
EV
8. $TEST_BASE_DIR/test-functions
9
fcb24270
EV
10test_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
069a254f 21 printf "556f48e837bc4424a710fa2e2c9d3e3c\ne3d\n" >$initdir/etc/machine-id
fcb24270
EV
22 dracut_install mount cmp
23
24 # setup the testsuite service
25 cat >$initdir/etc/systemd/system/testsuite.service <<EOF
26[Unit]
27Description=Testsuite service
28After=multi-user.target
29
30[Service]
31ExecStart=/bin/sh -e -x -c '/test-machine-id-setup.sh; systemctl --state=failed --no-legend --no-pager > /failed ; echo OK > /testok'
32Type=oneshot
33EOF
34
35cat >$initdir/test-machine-id-setup.sh <<'EOF'
36#!/bin/bash
37
38set -e
39set -x
40
41function 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
48function check {
49 printf "Expected\n"
50 cat "$1"
51 printf "\nGot\n"
52 cat "$2"
53 cmp "$1" "$2"
54}
55
56r="$(pwd)/overwrite-broken-machine-id"
57setup_root "$r"
58systemd-machine-id-setup --print --root "$r"
59echo abc >>"$r/etc/machine-id"
60id=$(systemd-machine-id-setup --print --root "$r")
61echo $id >expected
62check expected "$r/etc/machine-id"
a6f72863
EV
63
64r="$(pwd)/transient-machine-id"
65setup_root "$r"
da2d1421
EV
66systemd-machine-id-setup --print --root "$r"
67echo abc >>"$r/etc/machine-id"
a6f72863
EV
68mount -o remount,ro "$r"
69mount -t tmpfs tmpfs "$r/run"
70transient_id=$(systemd-machine-id-setup --print --root "$r")
71mount -o remount,rw "$r"
72commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
73[[ "$transient_id" = "$commited_id" ]]
74check "$r/etc/machine-id" "$r/run/machine-id"
fcb24270
EV
75EOF
76chmod +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
fcb24270 92do_test "$@"