]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-17.02.sh
Merge pull request #25168 from valentindavid/valentindavid/umount-move-recursive...
[thirdparty/systemd.git] / test / units / testsuite-17.02.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 # disable shellcheck warning about '"aaa"' type quotation
5 # shellcheck disable=SC2016
6
7 set -eux
8 set -o pipefail
9
10 # shellcheck source=test/units/assert.sh
11 . "$(dirname "$0")"/assert.sh
12
13 mkdir -p /run/udev/rules.d/
14
15 # test for ID_RENAMING= udev property and device unit state
16
17 cat >/run/udev/rules.d/50-testsuite.rules <<EOF
18 ACTION=="remove", GOTO="hoge_end"
19 SUBSYSTEM!="net", GOTO="hoge_end"
20 KERNEL!="hoge", GOTO="hoge_end"
21
22 OPTIONS="log_level=debug"
23
24 # emulate renaming
25 ACTION=="online", ENV{ID_RENAMING}="1"
26
27 LABEL="hoge_end"
28 EOF
29
30 udevadm control --log-priority=debug --reload --timeout=30
31
32 ip link add hoge type dummy
33 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/hoge
34 assert_not_in "ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
35 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
36 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
37
38 udevadm trigger --action=online --settle /sys/devices/virtual/net/hoge
39 assert_in "ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
40 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
41 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
42
43 udevadm trigger --action=move --settle /sys/devices/virtual/net/hoge
44 assert_not_in "ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
45 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
46 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
47
48 # test for renaming interface with NAME= (issue #25106)
49
50 cat >/run/udev/rules.d/50-testsuite.rules <<EOF
51 ACTION!="add", GOTO="hoge_end"
52 SUBSYSTEM!="net", GOTO="hoge_end"
53
54 OPTIONS="log_level=debug"
55
56 KERNEL=="hoge", NAME="foobar"
57 KERNEL=="foobar", NAME="hoge"
58
59 LABEL="hoge_end"
60 EOF
61
62 udevadm control --log-priority=debug --reload --timeout=30
63
64 udevadm trigger --action=add --settle /sys/devices/virtual/net/hoge
65 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/foobar
66 assert_not_in "ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/foobar)"
67 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
68 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
69 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "active" ]]; do sleep .5; done'
70 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "active" ]]; do sleep .5; done'
71
72 udevadm trigger --action=add --settle /sys/devices/virtual/net/foobar
73 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/hoge
74 assert_not_in "ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
75 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
76 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
77 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "inactive" ]]; do sleep .5; done'
78 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "inactive" ]]; do sleep .5; done'
79
80 # cleanup
81 rm -f /run/udev/rules.d/50-testsuite.rules
82 udevadm control --reload --timeout=30
83
84 # test for renaming interface with an external tool (issue #16967)
85
86 ip link set hoge name foobar
87 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/foobar
88 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
89 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
90 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "active" ]]; do sleep .5; done'
91 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "active" ]]; do sleep .5; done'
92
93 ip link set foobar name hoge
94 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/hoge
95 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
96 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
97 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "inactive" ]]; do sleep .5; done'
98 timeout 30 bash -c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "inactive" ]]; do sleep .5; done'
99
100 # cleanup
101 ip link del hoge
102
103 teardown_netif_renaming_conflict() {
104 set +ex
105
106 if [[ -n "$KILL_PID" ]]; then
107 kill "$KILL_PID"
108 fi
109
110 rm -rf "$TMPDIR"
111
112 rm -f /run/udev/rules.d/50-testsuite.rules
113 udevadm control --reload --timeout=30
114
115 ip link del hoge
116 ip link del foobar
117 }
118
119 test_netif_renaming_conflict() {
120 local since found=
121
122 trap teardown_netif_renaming_conflict RETURN
123
124 cat >/run/udev/rules.d/50-testsuite.rules <<EOF
125 ACTION!="add", GOTO="hoge_end"
126 SUBSYSTEM!="net", GOTO="hoge_end"
127
128 OPTIONS="log_level=debug"
129
130 KERNEL=="foobar", NAME="hoge"
131
132 LABEL="hoge_end"
133 EOF
134
135 udevadm control --log-priority=debug --reload --timeout=30
136
137 ip link add hoge type dummy
138 udevadm wait --timeout=30 --settle /sys/devices/virtual/net/hoge
139
140 TMPDIR=$(mktemp -d -p /tmp udev-tests.XXXXXX)
141 udevadm monitor --udev --property --subsystem-match=net >"$TMPDIR"/monitor.txt &
142 KILL_PID="$!"
143
144 # make sure that 'udevadm monitor' actually monitor uevents
145 sleep 1
146
147 since="$(date '+%H:%M:%S')"
148
149 # add another interface which will conflict with an existing interface
150 ip link add foobar type dummy
151
152 for _ in {1..40}; do
153 if (
154 grep -q 'ACTION=add' "$TMPDIR"/monitor.txt
155 grep -q 'DEVPATH=/devices/virtual/net/foobar' "$TMPDIR"/monitor.txt
156 grep -q 'SUBSYSTEM=net' "$TMPDIR"/monitor.txt
157 grep -q 'INTERFACE=foobar' "$TMPDIR"/monitor.txt
158 grep -q 'ID_NET_DRIVER=dummy' "$TMPDIR"/monitor.txt
159 grep -q 'ID_NET_NAME=foobar' "$TMPDIR"/monitor.txt
160 # Even when network interface renaming is failed, SYSTEMD_ALIAS with the conflicting name will be broadcast.
161 grep -q 'SYSTEMD_ALIAS=/sys/subsystem/net/devices/hoge' "$TMPDIR"/monitor.txt
162 grep -q 'UDEV_WORKER_FAILED=1' "$TMPDIR"/monitor.txt
163 grep -q 'UDEV_WORKER_ERRNO=17' "$TMPDIR"/monitor.txt
164 grep -q 'UDEV_WORKER_ERRNO_NAME=EEXIST' "$TMPDIR"/monitor.txt
165 ); then
166 cat "$TMPDIR"/monitor.txt
167 found=1
168 break
169 fi
170 sleep .5
171 done
172 test -n "$found"
173
174 timeout 30 bash -c "while ! journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
175 # check if the invalid SYSTEMD_ALIAS property for the interface foobar is ignored by PID1
176 assert_eq "$(systemctl show --property=SysFSPath --value /sys/subsystem/net/devices/hoge)" "/sys/devices/virtual/net/hoge"
177 }
178
179 test_netif_renaming_conflict
180
181 exit 0