2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # shellcheck disable=SC2016
7 # shellcheck source=test/units/util.sh
8 .
"$(dirname "$0")"/util.sh
15 machinectl status long-running
&>/dev
/null
&& machinectl
kill --signal=KILL long-running
16 mountpoint
-q /var
/lib
/machines
&& timeout
10 sh
-c "until umount /var/lib/machines; do sleep .5; done"
17 [[ -n "${NSPAWN_FRAGMENT:-}" ]] && rm -f "/etc/systemd/nspawn/$NSPAWN_FRAGMENT" "/var/lib/machines/$NSPAWN_FRAGMENT"
18 rm -f /run
/systemd
/nspawn
/*.nspawn
23 systemctl service-log-level systemd-machined debug
24 systemctl service-log-level systemd-importd debug
25 # per request in https://github.com/systemd/systemd/pull/35117
26 systemctl edit
--runtime --stdin 'systemd-nspawn@.service' --drop-in=debug.conf
<<EOF
28 Environment=SYSTEMD_LOG_LEVEL=debug
31 # Mount temporary directory over /var/lib/machines to not pollute the image
32 mkdir
-p /var
/lib
/machines
33 mount
--bind "$(mktemp --tmpdir=/var/tmp -d)" /var
/lib
/machines
35 # Create a couple of containers we can refer to in tests
37 create_dummy_container
"/var/lib/machines/container$i"
38 machinectl start
"container$i"
40 # Create one "long running" container with some basic signal handling
41 create_dummy_container
/var
/lib
/machines
/long-running
42 cat >/var
/lib
/machines
/long-running
/sbin
/init
<<\EOF
49 trap 'touch /terminate; kill 0' RTMIN
+3
50 trap 'touch /poweroff' RTMIN
+4
51 trap 'touch /reboot' INT
52 trap 'touch /trap' TRAP
55 # We need to wait for the sleep process asynchronously in order to allow
56 # bash to process signals
59 # notify that the process is ready
68 long_running_machine_start
() {
69 # shellcheck disable=SC2015
70 machinectl status long-running
&>/dev
/null
&& return 0 || true
72 # Ensure the service stopped.
73 systemctl stop systemd-nspawn@long-running.service
2>/dev
/null ||
:
75 rm -f /var
/lib
/machines
/long-running
/ready
76 machinectl start long-running
77 # !!!! DO NOT REMOVE THIS TEST
78 # The test makes sure that the long-running's init script has enough time to start and registered signal traps
79 timeout
30 bash
-c "until test -e /var/lib/machines/long-running/ready; do sleep .5; done"
82 long_running_machine_start
85 machinectl
--no-pager --help
88 machinectl list
--no-legend --no-ask-password
90 machinectl status long-running long-running long-running
91 machinectl status
--full long-running
92 machinectl status
--quiet --lines=1 long-running
93 machinectl status
--lines=0 --max-addresses=0 long-running
94 machinectl status
--machine=testuser@.
host long-running
95 machinectl status
--output=help long-running
96 while read -r output
; do
97 machinectl status
--output="$output" long-running
98 done < <(machinectl
--output=help)
101 machinectl show
--all
102 machinectl show
--all --machine=root@
103 machinectl show
--all --machine=testuser@
104 [[ "$(machinectl show --property=PoolPath --value)" == "/var/lib/machines" ]]
105 machinectl show long-running
106 machinectl show long-running long-running long-running
--all
107 [[ "$(machinectl show --property=RootDirectory --value long-running)" == "/var/lib/machines/long-running" ]]
109 machinectl
enable long-running
110 test -L /etc
/systemd
/system
/machines.target.wants
/systemd-nspawn@long-running.service
111 machinectl
enable long-running long-running long-running container1
112 machinectl disable long-running
113 test ! -L /etc
/systemd
/system
/machines.target.wants
/systemd-nspawn@long-running.service
114 machinectl disable long-running long-running long-running container1
116 [[ "$(machinectl shell testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "" ]]
117 [[ "$(machinectl shell --setenv=FOO=bar testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "bar" ]]
119 [[ "$(machinectl show --property=State --value long-running)" == "running" ]]
120 # Equivalent to machinectl kill --signal=SIGRTMIN+4 --kill-whom=leader
121 rm -f /var
/lib
/machines
/long-running
/poweroff
122 machinectl poweroff long-running
123 timeout
10 bash
-c "until test -e /var/lib/machines/long-running/poweroff; do sleep .5; done"
124 # Equivalent to machinectl kill --signal=SIGINT --kill-whom=leader
125 rm -f /var
/lib
/machines
/long-running
/reboot
126 machinectl reboot long-running
127 timeout
10 bash
-c "until test -e /var/lib/machines/long-running/reboot; do sleep .5; done"
128 # Test for 'machinectl terminate'
129 rm -f /var
/lib
/machines
/long-running
/terminate
130 machinectl terminate long-running
131 timeout
10 bash
-c "until test -e /var/lib/machines/long-running/terminate; do sleep .5; done"
132 timeout
10 bash
-c "while machinectl status long-running &>/dev/null; do sleep .5; done"
134 long_running_machine_start
135 # Test for 'machinectl kill'
136 rm -f /var
/lib
/machines
/long-running
/trap
137 machinectl
kill --signal=SIGTRAP
--kill-whom=leader long-running
138 timeout
10 bash
-c "until test -e /var/lib/machines/long-running/trap; do sleep .5; done"
139 # Multiple machines at once
140 machinectl poweroff long-running long-running long-running
141 machinectl reboot long-running long-running long-running
142 machinectl
kill --signal=SIGTRAP
--kill-whom=leader long-running long-running long-running
143 # All used signals should've been caught by a handler
144 [[ "$(machinectl show --property=State --value long-running)" == "running" ]]
146 cp /etc
/machine-id
/tmp
/foo
147 machinectl copy-to long-running
/tmp
/foo
/root
/foo
148 test -f /var
/lib
/machines
/long-running
/root
/foo
149 machinectl copy-from long-running
/root
/foo
/tmp
/bar
150 diff /tmp
/foo
/tmp
/bar
153 # machinectl bind is covered by testcase_check_machinectl_bind() in nspawn tests
155 machinectl list-images
156 machinectl list-images
--no-legend
157 machinectl image-status
158 machinectl image-status container1
159 machinectl image-status container1 container1 container
{0.
.4}
160 machinectl show-image
161 machinectl show-image container1
162 machinectl show-image container1 container1 container
{0.
.4}
164 machinectl clone container1 clone1
165 machinectl show-image clone1
166 machinectl rename clone1 clone2
167 (! machinectl show-image clone1
)
168 machinectl show-image clone2
169 # `machinectl read-only` uses chattr (ioctl(FS_IOC_SETFLAGS)) when the container is backed by a directory,
170 # and this operation might not be implemented on certain filesystems (i.e. tmpfs on older kernels), so check
171 # if we have chattr support before running following tests
172 if lsattr
-d /var
/lib
/machines
>/dev
/null
; then
173 [[ "$(machinectl show-image --property=ReadOnly --value clone2)" == no
]]
174 machinectl read-only clone2
yes
175 [[ "$(machinectl show-image --property=ReadOnly --value clone2)" == yes ]]
176 machinectl read-only clone2 no
177 [[ "$(machinectl show-image --property=ReadOnly --value clone2)" == no
]]
179 machinectl remove clone2
181 machinectl clone container1
"clone$i"
183 machinectl remove clone
{0.
.4}
185 machinectl clone container1
".hidden$i"
187 machinectl list-images
--all
188 test -d /var
/lib
/machines
/.hidden1
190 test ! -d /var
/lib
/machines
/.hidden1
192 # Prepare a simple raw container
194 dd if=/dev
/zero of
=/var
/tmp
/container.raw bs
=1M count
=256
195 mkfs.ext4
/var
/tmp
/container.raw
196 mount
-o loop
/var
/tmp
/container.raw
/tmp
/mnt
197 cp -r /var
/lib
/machines
/container
1/* /tmp
/mnt
199 # Try to import it, run it, export it, and re-import it
200 machinectl import-raw
/var
/tmp
/container.raw container-raw
201 [[ "$(machinectl show-image --property=Type --value container-raw)" == "raw" ]]
202 machinectl start container-raw
203 machinectl export-raw container-raw
/var
/tmp
/container-export.raw
204 machinectl import-raw
/var
/tmp
/container-export.raw container-raw-reimport
205 [[ "$(machinectl show-image --property=Type --value container-raw-reimport)" == "raw" ]]
206 rm -f /var
/tmp
/container
{,-export}.raw
208 # Prepare a simple tar.gz container
209 tar -pczf /var
/tmp
/container.
tar.gz
-C /var
/lib
/machines
/container1 .
210 # Try to import it, run it, export it, and re-import it
211 machinectl import-tar
/var
/tmp
/container.
tar.gz container-tar
212 [[ "$(machinectl show-image --property=Type --value container-tar)" =~ directory|subvolume
]]
213 machinectl start container-tar
214 machinectl export-tar container-tar
/var
/tmp
/container-export.
tar.gz
215 machinectl import-tar
/var
/tmp
/container-export.
tar.gz container-tar-reimport
216 [[ "$(machinectl show-image --property=Type --value container-tar-reimport)" =~ directory|subvolume
]]
217 rm -f /var
/tmp
/container
{,-export}.
tar.gz
219 # Try to import a container directory & run it
220 cp -r /var
/lib
/machines
/container1
/var
/tmp
/container.dir
221 machinectl import-fs
/var
/tmp
/container.dir container-dir
222 [[ "$(machinectl show-image --property=Type --value container-dir)" =~ directory|subvolume
]]
223 machinectl start container-dir
224 rm -fr /var
/tmp
/container.dir
226 timeout
10 bash
-c "until machinectl clean --all; do sleep .5; done"
228 NSPAWN_FRAGMENT
="machinectl-test-$RANDOM.nspawn"
229 cat >"/var/lib/machines/$NSPAWN_FRAGMENT" <<EOF
233 machinectl
cat "$NSPAWN_FRAGMENT"
234 EDITOR
=true
script -qec "machinectl edit $NSPAWN_FRAGMENT" /dev
/null
235 test -f "/etc/systemd/nspawn/$NSPAWN_FRAGMENT"
236 diff "/var/lib/machines/$NSPAWN_FRAGMENT" "/etc/systemd/nspawn/$NSPAWN_FRAGMENT"
238 cat >/tmp
/fragment.nspawn
<<EOF
242 machinectl
cat /tmp
/fragment.nspawn
243 EDITOR
="cp /tmp/fragment.nspawn" script -qec "machinectl edit $NSPAWN_FRAGMENT" /dev
/null
244 diff /tmp
/fragment.nspawn
"/etc/systemd/nspawn/$NSPAWN_FRAGMENT"
246 for opt
in format lines machine max-addresses output setenv verify
; do
247 (! machinectl status
"--$opt=" long-running
)
248 (! machinectl status
"--$opt=-1" long-running
)
249 (! machinectl status
"--$opt=''" long-running
)
251 (! machinectl show
"")
252 (! machinectl
enable)
253 (! machinectl
enable "")
254 (! machinectl disable
)
255 (! machinectl disable
"")
256 (! machinectl read-only container1
"")
257 (! machinectl read-only container1 foo
)
258 (! machinectl read-only container1
-- -1)
264 long_running_machine_start
266 varlinkctl introspect
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine
267 varlinkctl introspect
/run
/systemd
/machine
/io.systemd.Machine io.systemd.MachineImage
268 varlinkctl introspect
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.Machine
269 varlinkctl introspect
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage
271 # test io.systemd.Machine.List
272 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{}' |
grep 'long-running'
273 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{}' |
grep '.host'
274 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"long-running"}'
276 pid
=$
(varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"long-running"}' | jq
'.leader')
277 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"long-running"}' >/tmp
/expected
278 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
"{\"pid\":$pid}" |
diff /tmp
/expected
-
279 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
"{\"name\":\"long-running\", \"pid\":$pid}" |
diff /tmp
/expected
-
280 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
"{\"name\":\"non-existent\", \"pid\":$pid}")
281 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":""}')
282 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"ah@??.hmm"}')
284 # test io.systemd.Machine.Kill
285 # sending TRAP signal
286 rm -f /var
/lib
/machines
/long-running
/trap
287 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Kill
'{"name":"long-running", "whom": "leader", "signal": 5}'
288 timeout
120 bash
-c "until test -e /var/lib/machines/long-running/trap; do sleep .5; done"
290 # test io.systemd.Machine.Terminate
291 long_running_machine_start
292 rm -f /var
/lib
/machines
/long-running
/terminate
293 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Terminate
'{"name":"long-running"}'
294 timeout
30 bash
-c "until test -e /var/lib/machines/long-running/terminate; do sleep .5; done"
295 timeout
30 bash
-c "while varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{\"name\":\"long-running\"}'; do sleep 0.5; done"
297 # test io.systemd.Machine.Register
298 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Register
'{"name": "registered-container", "class": "container"}'
299 timeout
30 bash
-c "until varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{\"name\":\"registered-container\"}'; do sleep 0.5; done"
301 # test io.systemd.Machine.Unregister
302 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Unregister
'{"name": "registered-container"}'
303 timeout
30 bash
-c "while varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{\"name\":\"registered-container\"}'; do sleep 0.5; done"
305 # test io.systemd.Machine.List with sshAddress and sshPrivateKeyPath fields
306 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Register
'{"name": "registered-container", "class": "container", "sshAddress": "localhost", "sshPrivateKeyPath": "/non-existent"}'
307 timeout
30 bash
-c "until varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{\"name\":\"registered-container\"}'; do sleep 0.5; done"
308 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"registered-container"}' | jq
'.sshAddress' |
grep -q 'localhost'
309 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name":"registered-container"}' | jq
'.sshPrivateKeyPath' |
grep -q 'non-existent'
310 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Unregister
'{"name": "registered-container"}'
312 # test io.systemd.Machine.List with addresses, OSRelease, and UIDShift fields
313 create_dummy_container
"/var/lib/machines/container-without-os-release"
314 cat >>/var
/lib
/machines
/container-without-os-release
/sbin
/init
<<\EOF
319 ip link add hoge
type dummy
321 ip address add
192.0.2.1/24 dev hoge
325 trap 'kill 0' RTMIN
+3
326 trap 'kill $PID' EXIT
328 # We need to wait for the sleep process asynchronously in order to allow
329 # bash to process signals
332 # notify that the process is ready
340 machinectl start
"container-without-os-release"
341 timeout
30 bash
-c "until test -e /var/lib/machines/container-without-os-release/ready; do sleep .5; done"
342 rm -f /var
/lib
/machines
/container-without-os-release
/etc
/os-release
/var
/lib
/machines
/container-without-os-release
/usr
/lib
/os-release
343 (! varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": "container-without-os-release", "acquireMetadata": "yes"}')
344 output
=$
(varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": "container-without-os-release", "acquireMetadata": "graceful"}')
345 assert_eq
"$(echo "$output" | jq --seq .name | tr -d \\036)" '"container-without-os-release"'
346 assert_eq
"$(echo "$output" | jq --seq .class | tr -d \\036)" '"container"'
347 assert_eq
"$(echo "$output" | jq --seq .service | tr -d \\036)" '"systemd-nspawn"'
348 assert_eq
"$(echo "$output" | jq --seq .rootDirectory | tr -d \\036)" '"/var/lib/machines/container-without-os-release"'
349 assert_eq
"$(echo "$output" | jq --seq .unit | tr -d \\036)" '"systemd-nspawn@container-without-os-release.service"'
350 assert_eq
"$(echo "$output" | jq --seq .addresses[0].family | tr -d \\036)" '2'
351 assert_eq
"$(echo "$output" | jq --seq .addresses[0].address[0] | tr -d \\036)" '192'
352 assert_eq
"$(echo "$output" | jq --seq .addresses[0].address[1] | tr -d \\036)" '0'
353 assert_eq
"$(echo "$output" | jq --seq .addresses[0].address[2] | tr -d \\036)" '2'
354 assert_eq
"$(echo "$output" | jq --seq .addresses[0].address[3] | tr -d \\036)" '1'
355 # test for listing multiple machines.
356 long_running_machine_start
357 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{}'
358 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"acquireMetadata": "no"}'
359 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"acquireMetadata": "graceful"}'
360 # check if machined does not try to send anything after error message
362 TS
="$(date '+%H:%M:%S')"
363 (! varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"acquireMetadata": "yes"}')
365 (! journalctl
-u systemd-machined.service
--since="$TS" --grep 'Connection busy')
366 machinectl terminate container-without-os-release
368 (ip addr show lo |
grep -q 192.168.1.100) || ip address add
192.168.1.100/24 dev lo
369 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host"}' |
grep 'addresses')
370 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host", "acquireMetadata": "yes"}' |
grep 'addresses'
371 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host"}' |
grep 'OSRelease')
372 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host", "acquireMetadata": "yes"}' |
grep 'OSRelease'
373 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host"}' |
grep 'acquireUIDShift')
374 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.List
'{"name": ".host", "acquireMetadata": "yes"}' |
grep 'UIDShift'
376 # test io.systemd.Machine.Open
378 # Reducing log level here is to work-around check in end.service (end.sh). Read https://github.com/systemd/systemd/pull/34867 for more details
379 systemctl service-log-level systemd-machined info
380 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host"}')
381 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": ""}')
382 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": null}')
383 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": "foo"}')
384 systemctl service-log-level systemd-machined debug
386 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": "tty"}'
387 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": "login"}'
388 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": "shell"}'
390 rm -f /tmp
/none-existent-file
391 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.Open
'{"name": ".host", "mode": "shell", "user": "root", "path": "/bin/sh", "args": ["/bin/sh", "-c", "echo $FOO > /tmp/none-existent-file"], "environment": ["FOO=BAR"]}'
392 timeout
30 bash
-c "until test -e /tmp/none-existent-file; do sleep .5; done"
393 grep -q "BAR" /tmp
/none-existent-file
395 # test io.systemd.Machine.MapFrom
396 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapFrom
'{"name": "long-running", "uid":0, "gid": 0}'
397 container_uid
=$
(varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapFrom
'{"name": "long-running", "uid":0}' | jq
'.uid')
398 container_gid
=$
(varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapFrom
'{"name": "long-running", "gid":0}' | jq
'.gid')
399 # test io.systemd.Machine.MapTo
400 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapTo
"{\"uid\": $container_uid, \"gid\": $container_gid}" |
grep "long-running"
401 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapTo
'{"uid": 0}')
402 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.MapTo
'{"gid": 0}')
404 # io.systemd.Machine.BindMount is covered by testcase_check_machinectl_bind() in nspawn tests
406 # test io.systemd.Machine.CopyTo
407 rm -f /tmp
/foo
/var
/lib
/machines
/long-running
/root
/foo
408 cp /etc
/machine-id
/tmp
/foo
409 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.CopyTo
'{"name": "long-running", "source": "/tmp/foo", "destination": "/root/foo"}'
410 diff /tmp
/foo
/var
/lib
/machines
/long-running
/root
/foo
411 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.CopyTo
'{"name": "long-running", "source": "/tmp/foo", "destination": "/root/foo"}') # FileExists
412 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.CopyTo
'{"name": "long-running", "source": "/tmp/foo", "destination": "/root/foo", "replace": true}'
414 echo "sample-test-output" > /tmp
/foo
415 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.CopyTo
'{"name": "long-running", "source": "/tmp/foo", "destination": "/root/foo", "replace": true}'
416 diff /tmp
/foo
/var
/lib
/machines
/long-running
/root
/foo
417 rm -f /tmp
/foo
/var
/lib
/machines
/long-running
/root
/foo
419 # test io.systemd.Machine.CopyFrom
420 cp /etc
/machine-id
/var
/lib
/machines
/long-running
/foo
421 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.CopyFrom
'{"name": "long-running", "source": "/foo"}'
422 diff /var
/lib
/machines
/long-running
/foo
/foo
423 rm -f /var
/lib
/machines
/long-running
/root
/foo
/foo
425 # test io.systemd.Machine.OpenRootDirectory
426 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.OpenRootDirectory
'{"name": ".host"}'
427 varlinkctl call
/run
/systemd
/machine
/io.systemd.Machine io.systemd.Machine.OpenRootDirectory
'{"name": "long-running"}'
429 # Terminating machine, otherwise acquiring image metadata by io.systemd.MachineImage.List may fail in the below.
430 machinectl terminate long-running
431 # wait for the container being stopped, otherwise acquiring image metadata by io.systemd.MachineImage.List may fail in the below.
432 timeout
10 bash
-c "while machinectl status long-running &>/dev/null; do sleep .5; done"
433 systemctl
kill --signal=KILL systemd-nspawn@long-running.service ||
:
435 # test io.systemd.MachineImage.List
436 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{}' |
grep 'long-running'
437 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{}' |
grep '.host'
438 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running"}'
439 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running", "acquireMetadata": "yes"}' |
grep 'OSRelease'
441 # test io.systemd.MachineImage.Update
442 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.Update
'{"name":"long-running", "newName": "long-running-renamed", "readOnly": true}'
443 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-renamed"}'
444 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-renamed"}' | jq
'.readOnly' |
grep 'true'
446 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.Update
'{"name":"long-running-renamed", "newName": "long-running", "readOnly": false}'
447 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running"}'
448 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running"}' | jq
'.readOnly' |
grep 'false'
450 # test io.systemd.MachineImage.Clone
451 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.Clone
'{"name":"long-running", "newName": "long-running-cloned", "readOnly": true}'
452 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-cloned"}'
453 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-cloned"}' | jq
'.readOnly' |
grep 'true'
454 # this is for io.systemd.MachineImage.CleanPool test
455 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.Clone
'{"name":"long-running", "newName": "long-running-to-cleanup", "readOnly": true}'
457 # test io.systemd.MachineImage.Remove
458 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.Remove
'{"name":"long-running-cloned"}'
459 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-cloned"}')
461 # test io.systemd.MachineImage.SetPoolLimit
462 FSTYPE
="$(stat --file-system --format "%T
" /var/lib/machines)"
463 if [[ "$FSTYPE" == "btrfs" ]]; then
464 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.SetPoolLimit
'{"limit": 18446744073709551615}' # UINT64_MAX
467 # test io.systemd.MachineImage.CleanPool
468 varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-to-cleanup"}'
469 varlinkctl
--more call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.CleanPool
'{"mode":"all"}' |
grep "long-running-to-cleanup"
470 (! varlinkctl call
/run
/systemd
/machine
/io.systemd.MachineImage io.systemd.MachineImage.List
'{"name":"long-running-to-cleanup"}')