]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/units/testsuite-15.sh
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / test / units / testsuite-15.sh
CommitLineData
d632e6fe 1#!/usr/bin/env bash
7b3cec95 2# SPDX-License-Identifier: LGPL-2.1-or-later
084575ff
FS
3set -eux
4set -o pipefail
fbc42f13 5
7234a213
FS
6# shellcheck source=test/units/test-control.sh
7. "$(dirname "$0")"/test-control.sh
87993468
RM
8# shellcheck source=test/units/util.sh
9. "$(dirname "$0")"/util.sh
10
11maybe_mount_usr_overlay
12trap 'maybe_umount_usr_overlay' EXIT
7234a213 13
f3139ecd 14clear_unit() {
89562f08
FS
15 local unit_name="${1:?}"
16 local base suffix
17
18 systemctl stop "$unit_name" 2>/dev/null || :
19 rm -f /{etc,run,usr/lib}/systemd/system/"$unit_name"
20 rm -fr /{etc,run,usr/lib}/systemd/system/"$unit_name".d
21 rm -fr /{etc,run,usr/lib}/systemd/system/"$unit_name".{wants,requires}
22 if [[ $unit_name == *@* ]]; then
23 base="${unit_name%@*}"
24 suffix="${unit_name##*.}"
5731e137
ZJS
25 systemctl stop "$base@"*."$suffix" 2>/dev/null || :
26 rm -f /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix"
27 rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".d
28 rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".{wants,requires}
4e2ac45a 29 fi
fbc42f13
FB
30}
31
f3139ecd 32clear_units() {
38825267 33 for u in "$@"; do
5731e137 34 clear_unit "$u"
cc5549ca
ZJS
35 done
36 systemctl daemon-reload
fbc42f13
FB
37}
38
f3139ecd 39create_service() {
89562f08
FS
40 local service_name="${1:?}"
41 clear_units "${service_name}".service
fbc42f13 42
89562f08 43 cat >/etc/systemd/system/"$service_name".service <<EOF
fbc42f13 44[Unit]
89562f08 45Description=$service_name unit
fbc42f13
FB
46
47[Service]
5169595e 48ExecStart=sleep 100000
fbc42f13 49EOF
89562f08 50 mkdir -p /{etc,run,usr/lib}/systemd/system/"$service_name".service.{d,wants,requires}
fbc42f13
FB
51}
52
f3139ecd 53create_services() {
38825267
FS
54 for u in "$@"; do
55 create_service "$u"
cc5549ca 56 done
fbc42f13
FB
57}
58
f3139ecd 59check_ok() {
5169595e 60 x="$(systemctl show --value -p "${2:?}" "${1:?}")"
cc5549ca 61 case "$x" in
5169595e
ZJS
62 *${3:?}*) return 0 ;;
63 *) return 1 ;;
cc5549ca 64 esac
fbc42f13
FB
65}
66
f3139ecd 67check_ko() {
cc5549ca 68 ! check_ok "$@"
fbc42f13
FB
69}
70
f3139ecd 71testcase_basic_dropins() {
cc5549ca
ZJS
72 echo "Testing basic dropins..."
73
74 echo "*** test a wants b wants c"
2c7519c0
ZJS
75 create_services test15-a test15-b test15-c
76 ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/
77 ln -s ../test15-c.service /etc/systemd/system/test15-b.service.wants/
78 check_ok test15-a Wants test15-b.service
79 check_ok test15-b Wants test15-c.service
cc5549ca
ZJS
80
81 echo "*** test a wants,requires b"
2c7519c0
ZJS
82 create_services test15-a test15-b test15-c
83 ln -s ../test15-b.service /etc/systemd/system/test15-a.service.wants/
84 ln -s ../test15-b.service /etc/systemd/system/test15-a.service.requires/
85 check_ok test15-a Wants test15-b.service
86 check_ok test15-a Requires test15-b.service
cc5549ca
ZJS
87
88 echo "*** test a wants nonexistent"
2c7519c0
ZJS
89 create_service test15-a
90 ln -s ../nonexistent.service /etc/systemd/system/test15-a.service.wants/
91 check_ok test15-a Wants nonexistent.service
92 systemctl start test15-a
93 systemctl stop test15-a
cc5549ca
ZJS
94
95 echo "*** test a requires nonexistent"
2c7519c0 96 ln -sf ../nonexistent.service /etc/systemd/system/test15-a.service.requires/
cc5549ca 97 systemctl daemon-reload
2c7519c0 98 check_ok test15-a Requires nonexistent.service
cc5549ca
ZJS
99
100 # 'b' is already loaded when 'c' pulls it in via a dropin.
101 echo "*** test a,c require b"
2c7519c0
ZJS
102 create_services test15-a test15-b test15-c
103 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
104 ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
105 systemctl start test15-a
106 check_ok test15-c Requires test15-b.service
107 systemctl stop test15-a test15-b
cc5549ca
ZJS
108
109 # 'b' is already loaded when 'c' pulls it in via an alias dropin.
110 echo "*** test a wants alias"
2c7519c0
ZJS
111 create_services test15-a test15-b test15-c
112 ln -sf test15-c.service /etc/systemd/system/test15-c1.service
113 ln -sf ../test15-c.service /etc/systemd/system/test15-a.service.wants/
114 ln -sf ../test15-c1.service /etc/systemd/system/test15-b.service.wants/
115 systemctl start test15-a
116 check_ok test15-a Wants test15-c.service
117 check_ok test15-b Wants test15-c.service
118 systemctl stop test15-a test15-c
cc5549ca 119
3e1db806 120 echo "*** test service.d/ top level drop-in"
2c7519c0
ZJS
121 create_services test15-a test15-b
122 check_ko test15-a ExecCondition "/bin/echo a"
123 check_ko test15-b ExecCondition "/bin/echo b"
89562f08
FS
124 mkdir -p /run/systemd/system/service.d
125 cat >/run/systemd/system/service.d/override.conf <<EOF
d2724678
AZ
126[Service]
127ExecCondition=/bin/echo %n
128EOF
1aa0f384 129 systemctl daemon-reload
2c7519c0
ZJS
130 check_ok test15-a ExecCondition "/bin/echo test15-a"
131 check_ok test15-b ExecCondition "/bin/echo test15-b"
89562f08 132 rm -rf /run/systemd/system/service.d
d2724678 133
5731e137 134 clear_units test15-{a,b,c,c1}.service
fbc42f13
FB
135}
136
f3139ecd 137testcase_linked_units() {
3b5ab021
ZJS
138 echo "Testing linked units..."
139 echo "*** test linked unit (same basename)"
140
141 create_service test15-a
142 mv /etc/systemd/system/test15-a.service /
143 ln -s /test15-a.service /etc/systemd/system/
144 ln -s test15-a.service /etc/systemd/system/test15-b.service
145
146 check_ok test15-a Names test15-a.service
147 check_ok test15-a Names test15-b.service
148
149 echo "*** test linked unit (cross basename)"
150
151 mv /test15-a.service /test15-a@.scope
152 ln -fs /test15-a@.scope /etc/systemd/system/test15-a.service
153 systemctl daemon-reload
154
155 check_ok test15-a Names test15-a.service
156 check_ok test15-a Names test15-b.service
b903f16c
ZJS
157 check_ko test15-a Names test15-a@ # test15-a@.scope is the symlink target.
158 # Make sure it is completely ignored.
3b5ab021
ZJS
159
160 rm /test15-a@.scope
5731e137 161 clear_units test15-{a,b}.service
3b5ab021
ZJS
162}
163
7234a213 164testcase_template_alias() {
41b2d7ac
ZJS
165 echo "Testing instance alias..."
166 echo "*** forward"
167
168 create_service test15-a@
169 ln -s test15-a@inst.service /etc/systemd/system/test15-b@inst.service # alias
170
171 check_ok test15-a@inst Names test15-a@inst.service
172 check_ok test15-a@inst Names test15-b@inst.service
173
174 check_ok test15-a@other Names test15-a@other.service
175 check_ko test15-a@other Names test15-b@other.service
176
177 echo "*** reverse"
178
179 systemctl daemon-reload
180
181 check_ok test15-b@inst Names test15-a@inst.service
182 check_ok test15-b@inst Names test15-b@inst.service
183
184 check_ko test15-b@other Names test15-a@other.service
185 check_ok test15-b@other Names test15-b@other.service
186
5731e137 187 clear_units test15-{a,b}@.service
41b2d7ac
ZJS
188}
189
f3139ecd 190testcase_hierarchical_service_dropins() {
f80c874a 191 echo "Testing hierarchical service dropins..."
f5dd6e50
GGM
192 echo "*** test service.d/ top level drop-in"
193 create_services a-b-c
6854434c
ZJS
194 check_ko a-b-c ExecCondition "echo service.d"
195 check_ko a-b-c ExecCondition "echo a-.service.d"
196 check_ko a-b-c ExecCondition "echo a-b-.service.d"
197 check_ko a-b-c ExecCondition "echo a-b-c.service.d"
f5dd6e50
GGM
198
199 for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do
89562f08
FS
200 mkdir -p "/run/systemd/system/$dropin"
201 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
f5dd6e50 202[Service]
6854434c 203ExecCondition=echo $dropin
89562f08 204EOF
1aa0f384 205 systemctl daemon-reload
6854434c
ZJS
206 check_ok a-b-c ExecCondition "echo $dropin"
207
208 # Check that we can start a transient service in presence of the drop-ins
209 systemd-run -u a-b-c2.service -p Description='sleepy' sleep infinity
210
211 # The transient setting replaces the default
212 check_ok a-b-c2.service Description "sleepy"
213
214 # The override takes precedence for ExecCondition
215 # (except the last iteration when it only applies to the other service)
216 if [ "$dropin" != "a-b-c.service.d" ]; then
217 check_ok a-b-c2.service ExecCondition "echo $dropin"
218 fi
219
220 # Check that things are the same after a reload
221 systemctl daemon-reload
222 check_ok a-b-c2.service Description "sleepy"
223 if [ "$dropin" != "a-b-c.service.d" ]; then
224 check_ok a-b-c2.service ExecCondition "echo $dropin"
225 fi
226
227 systemctl stop a-b-c2.service
f5dd6e50
GGM
228 done
229 for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do
89562f08 230 rm -rf "/run/systemd/system/$dropin"
f5dd6e50
GGM
231 done
232
5731e137 233 clear_units a-b-c.service
f5dd6e50
GGM
234}
235
f3139ecd 236testcase_hierarchical_slice_dropins() {
f80c874a
ZJS
237 echo "Testing hierarchical slice dropins..."
238 echo "*** test slice.d/ top level drop-in"
239 # Slice units don't even need a fragment, so we test the defaults here
240 check_ok a-b-c.slice Description "Slice /a/b/c"
241 check_ok a-b-c.slice MemoryMax "infinity"
242
243 # Test drop-ins
244 for dropin in slice.d a-.slice.d a-b-.slice.d a-b-c.slice.d; do
89562f08
FS
245 mkdir -p "/run/systemd/system/$dropin"
246 cat >"/run/systemd/system/$dropin/override.conf" <<EOF
f80c874a
ZJS
247[Slice]
248MemoryMax=1000000000
89562f08 249EOF
f80c874a
ZJS
250 systemctl daemon-reload
251 check_ok a-b-c.slice MemoryMax "1000000000"
6854434c
ZJS
252
253 busctl call \
254 org.freedesktop.systemd1 \
255 /org/freedesktop/systemd1 \
256 org.freedesktop.systemd1.Manager \
257 StartTransientUnit 'ssa(sv)a(sa(sv))' \
258 'a-b-c.slice' 'replace' \
259 2 \
260 'Description' s 'slice too' \
261 'MemoryMax' t 1000000002 \
262 0
263
264 # The override takes precedence for MemoryMax
265 check_ok a-b-c.slice MemoryMax "1000000000"
266 # The transient setting replaces the default
267 check_ok a-b-c.slice Description "slice too"
268
269 # Check that things are the same after a reload
270 systemctl daemon-reload
271 check_ok a-b-c.slice MemoryMax "1000000000"
272 check_ok a-b-c.slice Description "slice too"
273
274 busctl call \
275 org.freedesktop.systemd1 \
276 /org/freedesktop/systemd1 \
277 org.freedesktop.systemd1.Manager \
278 StopUnit 'ss' \
279 'a-b-c.slice' 'replace'
280
89562f08 281 rm -f "/run/systemd/system/$dropin/override.conf"
f80c874a
ZJS
282 done
283
284 # Test unit with a fragment
89562f08 285 cat >/run/systemd/system/a-b-c.slice <<EOF
f80c874a
ZJS
286[Slice]
287MemoryMax=1000000001
89562f08 288EOF
f80c874a
ZJS
289 systemctl daemon-reload
290 check_ok a-b-c.slice MemoryMax "1000000001"
291
292 clear_units a-b-c.slice
293}
294
f3139ecd 295testcase_transient_service_dropins() {
c3fa408d
ZJS
296 echo "Testing dropins for a transient service..."
297 echo "*** test transient service drop-ins"
298
299 mkdir -p /etc/systemd/system/service.d
300 mkdir -p /etc/systemd/system/a-.service.d
301 mkdir -p /etc/systemd/system/a-b-.service.d
302 mkdir -p /etc/systemd/system/a-b-c.service.d
303
304 echo -e '[Service]\nStandardInputText=aaa' >/etc/systemd/system/service.d/drop1.conf
305 echo -e '[Service]\nStandardInputText=bbb' >/etc/systemd/system/a-.service.d/drop2.conf
306 echo -e '[Service]\nStandardInputText=ccc' >/etc/systemd/system/a-b-.service.d/drop3.conf
307 echo -e '[Service]\nStandardInputText=ddd' >/etc/systemd/system/a-b-c.service.d/drop4.conf
308
309 # There's no fragment yet, so this fails
310 systemctl cat a-b-c.service && exit 1
311
312 # xxx → eHh4Cg==
313 systemd-run -u a-b-c.service -p StandardInputData=eHh4Cg== sleep infinity
314
315 data=$(systemctl show -P StandardInputData a-b-c.service)
316 # xxx\naaa\n\bbb\nccc\nddd\n → eHh4…
317 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
318
319 # Do a reload and check again
320 systemctl daemon-reload
321 data=$(systemctl show -P StandardInputData a-b-c.service)
322 test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo="
323
324 clear_units a-b-c.service
325 rm /etc/systemd/system/service.d/drop1.conf \
326 /etc/systemd/system/a-.service.d/drop2.conf \
327 /etc/systemd/system/a-b-.service.d/drop3.conf
328}
329
f3139ecd 330testcase_transient_slice_dropins() {
40d4835d
ZJS
331 echo "Testing dropins for a transient slice..."
332 echo "*** test transient slice drop-ins"
333
334 # FIXME: implement reloading of individual units.
335 #
336 # The settings here are loaded twice. For most settings it doesn't matter,
337 # but Documentation is not deduplicated, so we current get repeated entried
338 # which is a bug.
339
340 mkdir -p /etc/systemd/system/slice.d
341 mkdir -p /etc/systemd/system/a-.slice.d
342 mkdir -p /etc/systemd/system/a-b-.slice.d
343 mkdir -p /etc/systemd/system/a-b-c.slice.d
344
345 echo -e '[Unit]\nDocumentation=man:drop1' >/etc/systemd/system/slice.d/drop1.conf
346 echo -e '[Unit]\nDocumentation=man:drop2' >/etc/systemd/system/a-.slice.d/drop2.conf
347 echo -e '[Unit]\nDocumentation=man:drop3' >/etc/systemd/system/a-b-.slice.d/drop3.conf
348 echo -e '[Unit]\nDocumentation=man:drop4' >/etc/systemd/system/a-b-c.slice.d/drop4.conf
349
6f3cec8a
ZJS
350 # Invoke daemon-reload to make sure that the call below doesn't fail
351 systemctl daemon-reload
352
40d4835d
ZJS
353 # No fragment is required, so this works
354 systemctl cat a-b-c.slice
355
356 busctl call \
357 org.freedesktop.systemd1 \
358 /org/freedesktop/systemd1 \
359 org.freedesktop.systemd1.Manager \
360 StartTransientUnit 'ssa(sv)a(sa(sv))' \
361 'a-b-c.slice' 'replace' \
362 1 \
363 'Documentation' as 1 'man:drop5' \
364 0
365
366 data=$(systemctl show -P Documentation a-b-c.slice)
367 test "$data" = "man:drop1 man:drop2 man:drop3 man:drop4 man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
368
369 # Do a reload and check again
370 systemctl daemon-reload
371 data=$(systemctl show -P Documentation a-b-c.slice)
372 test "$data" = "man:drop5 man:drop1 man:drop2 man:drop3 man:drop4"
373
374 clear_units a-b-c.slice
375 rm /etc/systemd/system/slice.d/drop1.conf \
376 /etc/systemd/system/a-.slice.d/drop2.conf \
377 /etc/systemd/system/a-b-.slice.d/drop3.conf
378}
379
f3139ecd 380testcase_template_dropins() {
cc5549ca 381 echo "Testing template dropins..."
fbc42f13 382
cc5549ca 383 create_services foo bar@ yup@
fbc42f13 384
54f44034
ZJS
385 # Declare some deps to check if the body was loaded
386 cat >>/etc/systemd/system/bar@.service <<EOF
387[Unit]
388After=bar-template-after.device
389EOF
390
391 cat >>/etc/systemd/system/yup@.service <<EOF
392[Unit]
393After=yup-template-after.device
394EOF
395
cc5549ca
ZJS
396 ln -s /etc/systemd/system/bar@.service /etc/systemd/system/foo.service.wants/bar@1.service
397 check_ok foo Wants bar@1.service
fbc42f13 398
54f44034
ZJS
399 echo "*** test bar-alias@.service→bar@.service, but instance symlinks point to yup@.service ***"
400 ln -s bar@.service /etc/systemd/system/bar-alias@.service
401 ln -s bar@1.service /etc/systemd/system/bar-alias@1.service
402 ln -s yup@.service /etc/systemd/system/bar-alias@2.service
403 ln -s yup@3.service /etc/systemd/system/bar-alias@3.service
404
405 # create some dropin deps
406 mkdir -p /etc/systemd/system/bar@{,0,1,2,3}.service.requires/
407 mkdir -p /etc/systemd/system/yup@{,0,1,2,3}.service.requires/
408 mkdir -p /etc/systemd/system/bar-alias@{,0,1,2,3}.service.requires/
409
410 ln -s ../bar-template-requires.device /etc/systemd/system/bar@.service.requires/
411 ln -s ../bar-0-requires.device /etc/systemd/system/bar@0.service.requires/
412 ln -s ../bar-1-requires.device /etc/systemd/system/bar@1.service.requires/
413 ln -s ../bar-2-requires.device /etc/systemd/system/bar@2.service.requires/
414 ln -s ../bar-3-requires.device /etc/systemd/system/bar@3.service.requires/
415
416 ln -s ../yup-template-requires.device /etc/systemd/system/yup@.service.requires/
417 ln -s ../yup-0-requires.device /etc/systemd/system/yup@0.service.requires/
418 ln -s ../yup-1-requires.device /etc/systemd/system/yup@1.service.requires/
419 ln -s ../yup-2-requires.device /etc/systemd/system/yup@2.service.requires/
420 ln -s ../yup-3-requires.device /etc/systemd/system/yup@3.service.requires/
421
422 ln -s ../bar-alias-template-requires.device /etc/systemd/system/bar-alias@.service.requires/
423 ln -s ../bar-alias-0-requires.device /etc/systemd/system/bar-alias@0.service.requires/
424 ln -s ../bar-alias-1-requires.device /etc/systemd/system/bar-alias@1.service.requires/
425 ln -s ../bar-alias-2-requires.device /etc/systemd/system/bar-alias@2.service.requires/
426 ln -s ../bar-alias-3-requires.device /etc/systemd/system/bar-alias@3.service.requires/
427
428 systemctl daemon-reload
429
430 echo '*** bar@0 is aliased by bar-alias@0 ***'
431 systemctl show -p Names,Requires bar@0
432 systemctl show -p Names,Requires bar-alias@0
433 check_ok bar@0 Names bar@0
e8630e69 434 check_ok bar@0 Names bar-alias@0
54f44034
ZJS
435
436 check_ok bar@0 After bar-template-after.device
437
438 check_ok bar@0 Requires bar-0-requires.device
e8630e69 439 check_ok bar@0 Requires bar-alias-0-requires.device
54f44034 440 check_ok bar@0 Requires bar-template-requires.device
e8630e69 441 check_ok bar@0 Requires bar-alias-template-requires.device
54f44034
ZJS
442 check_ko bar@0 Requires yup-template-requires.device
443
444 check_ok bar-alias@0 After bar-template-after.device
445
446 check_ok bar-alias@0 Requires bar-0-requires.device
447 check_ok bar-alias@0 Requires bar-alias-0-requires.device
448 check_ok bar-alias@0 Requires bar-template-requires.device
449 check_ok bar-alias@0 Requires bar-alias-template-requires.device
450 check_ko bar-alias@0 Requires yup-template-requires.device
451 check_ko bar-alias@0 Requires yup-0-requires.device
452
453 echo '*** bar@1 is aliased by bar-alias@1 ***'
454 systemctl show -p Names,Requires bar@1
455 systemctl show -p Names,Requires bar-alias@1
456 check_ok bar@1 Names bar@1
e8630e69 457 check_ok bar@1 Names bar-alias@1
54f44034
ZJS
458
459 check_ok bar@1 After bar-template-after.device
460
461 check_ok bar@1 Requires bar-1-requires.device
e8630e69 462 check_ok bar@1 Requires bar-alias-1-requires.device
54f44034
ZJS
463 check_ok bar@1 Requires bar-template-requires.device
464 # See https://github.com/systemd/systemd/pull/13119#discussion_r308145418
e8630e69 465 check_ok bar@1 Requires bar-alias-template-requires.device
54f44034
ZJS
466 check_ko bar@1 Requires yup-template-requires.device
467 check_ko bar@1 Requires yup-1-requires.device
468
469 check_ok bar-alias@1 After bar-template-after.device
470
471 check_ok bar-alias@1 Requires bar-1-requires.device
472 check_ok bar-alias@1 Requires bar-alias-1-requires.device
473 check_ok bar-alias@1 Requires bar-template-requires.device
474 check_ok bar-alias@1 Requires bar-alias-template-requires.device
475 check_ko bar-alias@1 Requires yup-template-requires.device
476 check_ko bar-alias@1 Requires yup-1-requires.device
477
478 echo '*** bar-alias@2 aliases yup@2, bar@2 is independent ***'
479 systemctl show -p Names,Requires bar@2
480 systemctl show -p Names,Requires bar-alias@2
481 check_ok bar@2 Names bar@2
482 check_ko bar@2 Names bar-alias@2
483
484 check_ok bar@2 After bar-template-after.device
485
486 check_ok bar@2 Requires bar-2-requires.device
487 check_ko bar@2 Requires bar-alias-2-requires.device
488 check_ok bar@2 Requires bar-template-requires.device
489 check_ko bar@2 Requires bar-alias-template-requires.device
490 check_ko bar@2 Requires yup-template-requires.device
491 check_ko bar@2 Requires yup-2-requires.device
492
493 check_ko bar-alias@2 After bar-template-after.device
494
495 check_ko bar-alias@2 Requires bar-2-requires.device
496 check_ok bar-alias@2 Requires bar-alias-2-requires.device
497 check_ko bar-alias@2 Requires bar-template-requires.device
498 check_ok bar-alias@2 Requires bar-alias-template-requires.device
499 check_ok bar-alias@2 Requires yup-template-requires.device
500 check_ok bar-alias@2 Requires yup-2-requires.device
501
502 echo '*** bar-alias@3 aliases yup@3, bar@3 is independent ***'
503 systemctl show -p Names,Requires bar@3
504 systemctl show -p Names,Requires bar-alias@3
505 check_ok bar@3 Names bar@3
506 check_ko bar@3 Names bar-alias@3
507
508 check_ok bar@3 After bar-template-after.device
509
510 check_ok bar@3 Requires bar-3-requires.device
511 check_ko bar@3 Requires bar-alias-3-requires.device
512 check_ok bar@3 Requires bar-template-requires.device
513 check_ko bar@3 Requires bar-alias-template-requires.device
514 check_ko bar@3 Requires yup-template-requires.device
515 check_ko bar@3 Requires yup-3-requires.device
516
e8630e69 517 check_ko bar-alias@3 After bar-template-after.device
54f44034 518
e8630e69 519 check_ko bar-alias@3 Requires bar-3-requires.device
54f44034 520 check_ok bar-alias@3 Requires bar-alias-3-requires.device
e8630e69 521 check_ko bar-alias@3 Requires bar-template-requires.device
54f44034 522 check_ok bar-alias@3 Requires bar-alias-template-requires.device
e8630e69
ZJS
523 check_ok bar-alias@3 Requires yup-template-requires.device
524 check_ok bar-alias@3 Requires yup-3-requires.device
54f44034 525
5731e137 526 clear_units foo.service {bar,yup,bar-alias}@{,1,2,3}.service
fbc42f13
FB
527}
528
f3139ecd 529testcase_alias_dropins() {
cc5549ca
ZJS
530 echo "Testing alias dropins..."
531
532 echo "*** test a wants b1 alias of b"
2c7519c0
ZJS
533 create_services test15-a test15-b
534 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
535 ln -sf ../test15-b1.service /etc/systemd/system/test15-a.service.wants/
536 check_ok test15-a Wants test15-b.service
537 systemctl start test15-a
538 systemctl --quiet is-active test15-b
539 systemctl stop test15-a test15-b
540 rm /etc/systemd/system/test15-b1.service
5731e137 541 clear_units test15-{a,b}.service
cc5549ca 542
e8630e69 543 # Check that dependencies don't vary.
cc5549ca 544 echo "*** test 2"
2c7519c0
ZJS
545 create_services test15-a test15-x test15-y
546 mkdir -p /etc/systemd/system/test15-a1.service.wants/
547 ln -sf test15-a.service /etc/systemd/system/test15-a1.service
548 ln -sf ../test15-x.service /etc/systemd/system/test15-a.service.wants/
549 ln -sf ../test15-y.service /etc/systemd/system/test15-a1.service.wants/
550 check_ok test15-a1 Wants test15-x.service # see [1]
551 check_ok test15-a1 Wants test15-y.service
552 systemctl start test15-a
553 check_ok test15-a1 Wants test15-x.service # see [2]
554 check_ok test15-a1 Wants test15-y.service
555 systemctl stop test15-a test15-x test15-y
556 rm /etc/systemd/system/test15-a1.service
557
5731e137 558 clear_units test15-{a,x,y}.service
fbc42f13
FB
559}
560
f3139ecd 561testcase_masked_dropins() {
cc5549ca
ZJS
562 echo "Testing masked dropins..."
563
2c7519c0 564 create_services test15-a test15-b
cc5549ca
ZJS
565
566 # 'b' is masked for both deps
567 echo "*** test a wants,requires b is masked"
2c7519c0
ZJS
568 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
569 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
570 check_ko test15-a Wants test15-b.service
571 check_ko test15-a Requires test15-b.service
cc5549ca
ZJS
572
573 # 'a' wants 'b' and 'b' is masked at a lower level
574 echo "*** test a wants b, mask override"
2c7519c0
ZJS
575 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.wants/test15-b.service
576 ln -sf /dev/null /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
577 check_ok test15-a Wants test15-b.service
cc5549ca
ZJS
578
579 # 'a' wants 'b' and 'b' is masked at a higher level
580 echo "*** test a wants b, mask"
2c7519c0
ZJS
581 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
582 ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
583 check_ko test15-a Wants test15-b.service
cc5549ca
ZJS
584
585 # 'a' is masked but has an override config file
586 echo "*** test a is masked but has an override"
2c7519c0
ZJS
587 create_services test15-a test15-b
588 ln -sf /dev/null /etc/systemd/system/test15-a.service
589 cat >/usr/lib/systemd/system/test15-a.service.d/override.conf <<EOF
67348e79 590[Unit]
2c7519c0 591After=test15-b.service
67348e79 592EOF
2c7519c0 593 check_ok test15-a UnitFileState masked
cc5549ca
ZJS
594
595 # 'b1' is an alias for 'b': masking 'b' dep should not influence 'b1' dep
596 echo "*** test a wants b, b1, and one is masked"
2c7519c0
ZJS
597 create_services test15-a test15-b
598 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
599 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
600 ln -sf ../test15-b1.service /usr/lib/systemd/system/test15-a.service.wants/test15-b1.service
601 systemctl cat test15-a
602 systemctl show -p Wants,Requires test15-a
603 systemctl cat test15-b1
604 systemctl show -p Wants,Requires test15-b1
605 check_ok test15-a Wants test15-b.service
606 check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
607 rm /etc/systemd/system/test15-b1.service
cc5549ca
ZJS
608
609 # 'b1' is an alias for 'b': masking 'b1' should not influence 'b' dep
610 echo "*** test a wants b, alias dep is masked"
2c7519c0
ZJS
611 create_services test15-a test15-b
612 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
613 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b1.service
614 ln -sf ../test15-b.service /usr/lib/systemd/system/test15-a.service.wants/test15-b.service
615 check_ok test15-a Wants test15-b.service
616 check_ko test15-a Wants test15-b1.service # the alias does not show up in the list of units
617 rm /etc/systemd/system/test15-b1.service
cc5549ca
ZJS
618
619 # 'a' has Wants=b.service but also has a masking
620 # dropin 'b': 'b' should still be pulled in.
621 echo "*** test a wants b both ways"
2c7519c0
ZJS
622 create_services test15-a test15-b
623 ln -sf /dev/null /etc/systemd/system/test15-a.service.wants/test15-b.service
89562f08 624 cat >/usr/lib/systemd/system/test15-a.service.d/wants-b.conf <<EOF
fbc42f13 625[Unit]
2c7519c0 626Wants=test15-b.service
fbc42f13 627EOF
2c7519c0 628 check_ok test15-a Wants test15-b.service
cc5549ca
ZJS
629
630 # mask a dropin that points to an nonexistent unit.
631 echo "*** test a wants nonexistent is masked"
2c7519c0
ZJS
632 create_services test15-a
633 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/nonexistent.service
634 ln -sf ../nonexistent.service /usr/lib/systemd/system/test15-a.service.requires/
635 check_ko test15-a Requires nonexistent.service
cc5549ca
ZJS
636
637 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
638 # masked at a higher level.
639 echo "*** test a wants b is masked"
2c7519c0
ZJS
640 create_services test15-a test15-b test15-c
641 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
642 ln -sf ../test15-b.service /run/systemd/system/test15-c.service.requires/
643 ln -sf /dev/null /etc/systemd/system/test15-c.service.requires/test15-b.service
644 systemctl start test15-a
645 check_ko test15-c Requires test15-b.service
646 systemctl stop test15-a test15-b
cc5549ca
ZJS
647
648 # 'b' is already loaded when 'c' pulls it in via a dropin but 'b' is
649 # masked at a lower level.
650 echo "*** test a requires b is masked"
2c7519c0
ZJS
651 create_services test15-a test15-b test15-c
652 ln -sf ../test15-b.service /etc/systemd/system/test15-a.service.requires/
653 ln -sf ../test15-b.service /etc/systemd/system/test15-c.service.requires/
654 ln -sf /dev/null /run/systemd/system/test15-c.service.requires/test15-b.service
655 systemctl start test15-a
656 check_ok test15-c Requires test15-b.service
657 systemctl stop test15-a test15-b
cc5549ca
ZJS
658
659 # 'a' requires 2 aliases of 'b' and one of them is a mask.
660 echo "*** test a requires alias of b, other alias masked"
2c7519c0
ZJS
661 create_services test15-a test15-b
662 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
663 ln -sf test15-b.service /etc/systemd/system/test15-b2.service
664 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b1.service
665 ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
666 ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
667 check_ok test15-a Requires test15-b
cc5549ca
ZJS
668
669 # Same as above but now 'b' is masked.
670 echo "*** test a requires alias of b, b dep masked"
2c7519c0
ZJS
671 create_services test15-a test15-b
672 ln -sf test15-b.service /etc/systemd/system/test15-b1.service
673 ln -sf test15-b.service /etc/systemd/system/test15-b2.service
674 ln -sf ../test15-b1.service /run/systemd/system/test15-a.service.requires/
675 ln -sf ../test15-b2.service /usr/lib/systemd/system/test15-a.service.requires/
676 ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
677 check_ok test15-a Requires test15-b
678
5731e137 679 clear_units test15-{a,b}.service
fbc42f13
FB
680}
681
f3139ecd 682testcase_invalid_dropins() {
7a670b1d
TM
683 echo "Testing invalid dropins..."
684 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
685 systemctl cat nonexistent@.service || true
686 create_services a
687 systemctl daemon-reload
688 # Assertion failed on earlier versions, command exits unsuccessfully on later versions
689 systemctl cat a@.service || true
690 systemctl stop a
5731e137 691 clear_units a.service
7a670b1d
TM
692 return 0
693}
694
f3139ecd 695testcase_symlink_dropin_directory() {
cf6562e4
YW
696 # For issue #21920.
697 echo "Testing symlink drop-in directory..."
698 create_services test15-a
699 rmdir /{etc,run,usr/lib}/systemd/system/test15-a.service.d
700 mkdir -p /tmp/testsuite-15-test15-a-dropin-directory
701 ln -s /tmp/testsuite-15-test15-a-dropin-directory /etc/systemd/system/test15-a.service.d
702 cat >/tmp/testsuite-15-test15-a-dropin-directory/override.conf <<EOF
703[Unit]
704Description=hogehoge
705EOF
706 ln -s /tmp/testsuite-15-test15-a-dropin-directory-nonexistent /run/systemd/system/test15-a.service.d
707 touch /tmp/testsuite-15-test15-a-dropin-directory-regular
708 ln -s /tmp/testsuite-15-test15-a-dropin-directory-regular /usr/lib/systemd/system/test15-a.service.d
709 check_ok test15-a Description hogehoge
710
5731e137 711 clear_units test15-a.service
cf6562e4
YW
712}
713
7234a213 714run_testcases
fbc42f13
FB
715
716touch /testok