Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/hack/test-templates.sh
1637 views
1
#!/usr/bin/env bash
2
3
# SPDX-FileCopyrightText: Copyright The Lima Authors
4
# SPDX-License-Identifier: Apache-2.0
5
6
set -eu -o pipefail
7
8
# will prevent msys2 converting Linux path arguments into Windows paths before passing to limactl
9
export MSYS2_ARG_CONV_EXCL='*'
10
11
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
# shellcheck source=common.inc.sh
13
source "${scriptdir}/common.inc.sh"
14
15
if [ "$#" -ne 1 ]; then
16
ERROR "Usage: $0 FILE.yaml"
17
exit 1
18
fi
19
20
# Resolve any ../ fragments in the filename because they are invalid in relative template locators
21
FILE="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
22
NAME="$(basename -s .yaml "$FILE")"
23
OS_HOST="$(uname -o)"
24
25
# On Windows $HOME of the bash runner, %USERPROFILE% of the host machine and mounting point in the guest machine
26
# are all different folders. This will handle path differences, when values are explicitly set.
27
HOME_HOST=${HOME_HOST:-$HOME}
28
HOME_GUEST=${HOME_GUEST:-$HOME}
29
FILE_HOST=$FILE
30
if [ "${OS_HOST}" = "Msys" ]; then
31
FILE_HOST="$(cygpath -w "$FILE")"
32
fi
33
34
INFO "Validating \"$FILE_HOST\""
35
limactl validate "$FILE_HOST"
36
37
# --cpus=1 is needed for running vz on GHA: https://github.com/lima-vm/lima/pull/1511#issuecomment-1574937888
38
LIMACTL_CREATE=(limactl --tty=false create --cpus=1 --memory=1)
39
40
CONTAINER_ENGINE="nerdctl"
41
42
declare -A CHECKS=(
43
["proxy-settings"]="1"
44
["systemd"]="1"
45
["systemd-strict"]="1"
46
["mount-home"]="1"
47
["container-engine"]="1"
48
["restart"]="1"
49
# snapshot tests are too flaky (especially with archlinux)
50
["snapshot-online"]=""
51
["snapshot-offline"]=""
52
["clone"]=""
53
["port-forwards"]="1"
54
["static-port-forwards"]=""
55
["vmnet"]=""
56
["disk"]=""
57
["user-v2"]=""
58
["mount-path-with-spaces"]=""
59
["provision-data"]=""
60
["provision-yq"]=""
61
["param-env-variables"]=""
62
["set-user"]=""
63
["preserve-env"]="1"
64
)
65
66
case "$NAME" in
67
"default")
68
# CI failure:
69
# "[hostagent] failed to confirm whether /c/Users/runneradmin [remote] is successfully mounted"
70
[ "${OS_HOST}" = "Msys" ] && CHECKS["mount-home"]=
71
;;
72
"alpine"*)
73
WARNING "Alpine does not support systemd"
74
CHECKS["systemd"]=
75
CHECKS["container-engine"]=
76
[ "$NAME" = "alpine-iso-9p-writable" ] && CHECKS["mount-path-with-spaces"]="1"
77
;;
78
"k3s")
79
ERROR "File \"$FILE\" is not testable with this script"
80
exit 1
81
;;
82
"fedora")
83
WARNING "Relaxing systemd tests for fedora (For avoiding CI failure)"
84
# CI failure:
85
# ● run-r2b459797f5b04262bfa79984077a65c7.service loaded failed failed /usr/bin/systemctl start man-db-cache-update
86
CHECKS["systemd-strict"]=
87
;;
88
"test-misc")
89
CHECKS["disk"]=1
90
CHECKS["snapshot-online"]="1"
91
CHECKS["snapshot-offline"]="1"
92
CHECKS["clone"]="1"
93
CHECKS["mount-path-with-spaces"]="1"
94
CHECKS["provision-data"]="1"
95
CHECKS["provision-yq"]="1"
96
CHECKS["param-env-variables"]="1"
97
CHECKS["set-user"]="1"
98
;;
99
"static-port-forward")
100
CHECKS["static-port-forwards"]="1"
101
CHECKS["port-forwards"]=""
102
CHECKS["container-engine"]=""
103
CHECKS["restart"]=""
104
;;
105
"docker")
106
CONTAINER_ENGINE="docker"
107
;;
108
"wsl2")
109
# TODO https://github.com/lima-vm/lima/issues/3268
110
CHECKS["proxy-settings"]=
111
;;
112
esac
113
114
if limactl ls -q | grep -q "$NAME"; then
115
ERROR "Instance $NAME already exists"
116
exit 1
117
fi
118
119
case "$(limactl tmpl yq "$FILE_HOST" '.networks[].lima')" in
120
"shared")
121
CHECKS["vmnet"]=1
122
;;
123
"user-v2")
124
CHECKS["port-forwards"]=""
125
CHECKS["user-v2"]=1
126
;;
127
esac
128
129
if [[ -n ${CHECKS["port-forwards"]} ]]; then
130
tmpconfig="$HOME_HOST/lima-config-tmp"
131
mkdir -p "${tmpconfig}"
132
defer "rm -rf \"$tmpconfig\""
133
tmpfile="${tmpconfig}/${NAME}.yaml"
134
cp "$FILE" "${tmpfile}"
135
FILE="${tmpfile}"
136
FILE_HOST=$FILE
137
if [ "${OS_HOST}" = "Msys" ]; then
138
FILE_HOST="$(cygpath -w "$FILE")"
139
fi
140
141
INFO "Setup port forwarding rules for testing in \"${FILE}\""
142
"${scriptdir}/test-port-forwarding.pl" "${FILE}"
143
INFO "Validating \"$FILE_HOST\""
144
limactl validate "$FILE_HOST"
145
fi
146
147
INFO "Make sure template embedding copies \"$FILE_HOST\" exactly"
148
diff -u <(echo -n "base: $FILE_HOST" | limactl tmpl copy --embed - -) "$FILE_HOST"
149
150
function diagnose() {
151
NAME="$1"
152
set -x +e
153
tail "$HOME_HOST/.lima/${NAME}"/*.log
154
limactl shell "$NAME" systemctl --no-pager status
155
limactl shell "$NAME" systemctl --no-pager
156
mkdir -p failure-logs
157
cp -pf "$HOME_HOST/.lima/${NAME}"/*.log failure-logs/
158
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
159
set +x -e
160
}
161
162
export ftp_proxy=http://localhost:2121
163
164
INFO "Creating \"$NAME\" from \"$FILE_HOST\""
165
defer "limactl delete -f \"$NAME\""
166
167
if [[ -n ${CHECKS["disk"]} ]]; then
168
if ! limactl disk ls | grep -q "^data\s"; then
169
defer "limactl disk delete data"
170
limactl disk create data --size 10G
171
fi
172
fi
173
174
set -x
175
# shellcheck disable=SC2086
176
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS:-} "$FILE_HOST"
177
set +x
178
179
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
180
mkdir -p "/tmp/lima test dir with spaces"
181
echo "test file content" >"/tmp/lima test dir with spaces/test file"
182
fi
183
184
INFO "Starting \"$NAME\""
185
set -x
186
if ! limactl start "$NAME"; then
187
ERROR "Failed to start \"$NAME\""
188
diagnose "$NAME"
189
exit 1
190
fi
191
192
limactl shell "$NAME" uname -a
193
194
limactl shell "$NAME" cat /etc/os-release
195
set +x
196
197
INFO "Testing that host home is not wiped out"
198
[ -e "$HOME_HOST/.lima" ]
199
200
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
201
INFO 'Testing that "/tmp/lima test dir with spaces" is not wiped out'
202
[ "$(cat "/tmp/lima test dir with spaces/test file")" = "test file content" ]
203
[ "$(limactl shell "$NAME" cat "/tmp/lima test dir with spaces/test file")" = "test file content" ]
204
fi
205
206
if [[ -n ${CHECKS["provision-data"]} ]]; then
207
INFO 'Testing that /etc/sysctl.d/99-inotify.conf was created successfully on provision'
208
limactl shell "$NAME" grep -q fs.inotify.max_user_watches /etc/sysctl.d/99-inotify.conf
209
fi
210
211
if [[ -n ${CHECKS["provision-yq"]} ]]; then
212
INFO 'Testing that /tmp/param-yq.json was created successfully on provision'
213
limactl shell "$NAME" grep -q '"YQ": "yq"' /tmp/param-yq.json
214
fi
215
216
if [[ -n ${CHECKS["param-env-variables"]} ]]; then
217
INFO 'Testing that PARAM env variables are exported to all types of provisioning scripts and probes'
218
limactl shell "$NAME" test -e /tmp/param-ansible
219
limactl shell "$NAME" test -e /tmp/param-boot
220
limactl shell "$NAME" test -e /tmp/param-dependency
221
limactl shell "$NAME" test -e /tmp/param-probe
222
limactl shell "$NAME" test -e /tmp/param-system
223
limactl shell "$NAME" test -e /tmp/param-user
224
fi
225
226
if [[ -n ${CHECKS["set-user"]} ]]; then
227
INFO 'Testing that user settings can be provided by lima.yaml'
228
limactl shell "$NAME" grep "^john:x:4711:4711:John Doe:/home/john-john:/usr/bin/bash" /etc/passwd
229
fi
230
231
if [[ -n ${CHECKS["proxy-settings"]} ]]; then
232
INFO "Testing proxy settings are imported"
233
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
234
# Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
235
# by the gateway address, and the value is set immediately without a restart
236
gatewayIp=$(limactl shell "$NAME" ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
237
expected="FTP_PROXY=http://${gatewayIp}:2121"
238
INFO "FTP_PROXY: expected=${expected} got=${got}"
239
if [ "$got" != "$expected" ]; then
240
ERROR "proxy environment variable not set to correct value"
241
exit 1
242
fi
243
fi
244
245
INFO "Testing limactl copy command"
246
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/lima-test-templates.XXXXXX)"
247
defer "rm -rf \"$tmpdir\""
248
tmpfile="$tmpdir/lima-hostname"
249
rm -f "$tmpfile"
250
tmpfile_host=$tmpfile
251
if [ "${OS_HOST}" = "Msys" ]; then
252
tmpfile_host="$(cygpath -w "$tmpfile")"
253
fi
254
limactl cp "$NAME":/etc/hostname "$tmpfile_host"
255
expected="$(limactl shell "$NAME" cat /etc/hostname)"
256
got="$(cat "$tmpfile")"
257
INFO "/etc/hostname: expected=${expected}, got=${got}"
258
if [ "$got" != "$expected" ]; then
259
ERROR "copy command did not fetch the file"
260
exit 1
261
fi
262
263
INFO "Testing limactl command with escaped characters"
264
limactl shell "$NAME" bash -c "$(echo -e '\n\techo foo\n\techo bar')"
265
266
INFO "Testing limactl command with quotes"
267
limactl shell "$NAME" bash -c "echo 'foo \"bar\"'"
268
269
if [[ -n ${CHECKS["systemd"]} ]]; then
270
set -x
271
# agetty segfaults on Ubuntu 25.04 (x86_64)
272
# > __strncmp_evex () at ../sysdeps/x86_64/multiarch/strcmp-evex.S:316
273
# Should be fixed in Ubuntu 25.10 with util-linux >= 2.41
274
# https://github.com/lima-vm/lima/pull/3643#issuecomment-3006788732
275
if limactl shell "$NAME" systemctl -q is-failed serial-getty@ttyS0.service; then
276
limactl shell "$NAME" sudo systemctl reset-failed serial-getty@ttyS0.service
277
fi
278
if ! limactl shell "$NAME" systemctl is-system-running --wait; then
279
ERROR '"systemctl is-system-running" failed'
280
diagnose "$NAME"
281
if [[ -z ${CHECKS["systemd-strict"]} ]]; then
282
INFO 'Ignoring "systemctl is-system-running" failure'
283
else
284
exit 1
285
fi
286
fi
287
set +x
288
fi
289
290
if [[ -n ${CHECKS["mount-home"]} ]]; then
291
"${scriptdir}"/test-mount-home.sh "$NAME"
292
fi
293
294
if [[ -n ${CHECKS["preserve-env"]} ]]; then
295
"${scriptdir}"/test-preserve-env.sh "$NAME"
296
fi
297
298
# Use GHCR to avoid hitting Docker Hub rate limit
299
nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
300
alpine_image="ghcr.io/containerd/alpine:3.14.0"
301
302
if [[ -n ${CHECKS["container-engine"]} ]]; then
303
sudo=""
304
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
305
if [[ "$(limactl ls --json "${NAME}" | jq -r .vmType)" == "wsl2" ]]; then
306
sudo="sudo"
307
fi
308
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
309
set -x
310
if ! limactl shell "$NAME" $sudo $CONTAINER_ENGINE info; then
311
limactl shell "$NAME" cat /var/log/cloud-init-output.log
312
ERROR "\"${CONTAINER_ENGINE} info\" failed"
313
exit 1
314
fi
315
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
316
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
317
318
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
319
320
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
321
set +x
322
if [[ -n ${CHECKS["mount-home"]} ]]; then
323
hometmp="$HOME_HOST/lima-container-engine-test-tmp"
324
hometmpguest="$HOME_GUEST/lima-container-engine-test-tmp"
325
# test for https://github.com/lima-vm/lima/issues/187
326
INFO "Testing home bind mount (\"$hometmp\")"
327
rm -rf "$hometmp"
328
mkdir -p "$hometmp"
329
defer "rm -rf \"$hometmp\""
330
set -x
331
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${alpine_image}
332
echo "random-content-${RANDOM}" >"$hometmp/random"
333
expected="$(cat "$hometmp/random")"
334
got="$(limactl shell "$NAME" $sudo $CONTAINER_ENGINE run --rm -v "$hometmpguest/random":/mnt/foo ${alpine_image} cat /mnt/foo)"
335
INFO "$hometmp/random: expected=${expected}, got=${got}"
336
if [ "$got" != "$expected" ]; then
337
ERROR "Home directory is not shared?"
338
exit 1
339
fi
340
set +x
341
fi
342
fi
343
344
if [[ -n ${CHECKS["port-forwards"]} ]]; then
345
INFO "Testing port forwarding rules using netcat"
346
set -x
347
if [ "${NAME}" = "archlinux" ]; then
348
limactl shell "$NAME" sudo pacman -Syu --noconfirm openbsd-netcat
349
fi
350
if [ "${NAME}" = "debian" ]; then
351
limactl shell "$NAME" sudo apt-get install -y netcat-openbsd
352
fi
353
if [ "${NAME}" == "fedora" ]; then
354
limactl shell "$NAME" sudo dnf install -y nc
355
fi
356
if [ "${NAME}" = "opensuse" ]; then
357
limactl shell "$NAME" sudo zypper in -y netcat-openbsd
358
fi
359
if limactl shell "$NAME" command -v dnf; then
360
limactl shell "$NAME" sudo dnf install -y nc
361
fi
362
"${scriptdir}/test-port-forwarding.pl" "${NAME}"
363
364
if [[ -n ${CHECKS["container-engine"]} || ${NAME} == "alpine"* ]]; then
365
INFO "Testing that \"${CONTAINER_ENGINE} run\" binds to 0.0.0.0 and is forwarded to the host (non-default behavior, configured via test-port-forwarding.pl)"
366
if [ "$(uname)" = "Darwin" ]; then
367
# macOS runners seem to use `localhost` as the hostname, so the perl lookup just returns `127.0.0.1`
368
hostip=$(system_profiler SPNetworkDataType -json | jq -r 'first(.SPNetworkDataType[] | select(.ip_address) | .ip_address) | first')
369
else
370
hostip=$(perl -MSocket -MSys::Hostname -E 'say inet_ntoa(scalar gethostbyname(hostname()))')
371
fi
372
if [ -n "${hostip}" ]; then
373
sudo=""
374
if [[ ${NAME} == "alpine"* ]]; then
375
arch=$(limactl info | jq -r .defaultTemplate.arch)
376
nerdctl=$(limactl info | jq -r ".defaultTemplate.containerd.archives[] | select(.arch==\"$arch\").location")
377
curl -Lso nerdctl-full.tgz "${nerdctl}"
378
limactl shell "$NAME" sudo apk add containerd
379
limactl shell "$NAME" sudo rc-service containerd start
380
limactl shell "$NAME" sudo tar xzf "${PWD}/nerdctl-full.tgz" -C /usr/local
381
rm nerdctl-full.tgz
382
sudo="sudo"
383
fi
384
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
385
if [[ "$(limactl ls --json "${NAME}" | jq -r .vmType)" == "wsl2" ]]; then
386
sudo="sudo"
387
fi
388
limactl shell "$NAME" $sudo $CONTAINER_ENGINE info
389
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
390
391
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 8888:80 ${nginx_image}
392
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://${hostip}:8888; do sleep 3; done"
393
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
394
395
if [ "$(uname)" = "Darwin" ]; then
396
# Only macOS can bind to port 80 without root
397
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:80:80 ${nginx_image}
398
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://localhost:80; do sleep 3; done"
399
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
400
fi
401
fi
402
if [[ ${NAME} != "alpine"* && ${NAME} != "wsl2"* ]] && command -v w3m >/dev/null; then
403
INFO "Testing https://github.com/lima-vm/lima/issues/3685 ([gRPC portfwd] client connection is not closed immediately when server closed the connection)"
404
# Skip the test on Alpine, as systemd-run is missing
405
# Skip the test on WSL2, as port forwarding is half broken https://github.com/lima-vm/lima/pull/3686#issuecomment-3034842616
406
limactl shell "$NAME" systemd-run --user python3 -m http.server 3685
407
# curl is not enough to reproduce https://github.com/lima-vm/lima/issues/3685
408
# `w3m -dump` exits with status code 0 even on "Can't load" error.
409
timeout 30s bash -euxc "until w3m -dump http://localhost:3685 | grep -v \"w3m: Can't load\"; do sleep 3; done"
410
fi
411
fi
412
set +x
413
fi
414
415
if [[ -n ${CHECKS["static-port-forwards"]} ]]; then
416
INFO "Testing static port forwarding functionality"
417
"${scriptdir}/test-plain-static-port-forward.sh" "$NAME"
418
"${scriptdir}/test-nonplain-static-port-forward.sh" "$NAME"
419
INFO "All static port forwarding tests passed!"
420
fi
421
422
if [[ -n ${CHECKS["vmnet"]} ]]; then
423
INFO "Testing vmnet functionality"
424
guestip="$(limactl shell "$NAME" ip -4 -j addr show dev lima0 | jq -r '.[0].addr_info[0].local')"
425
INFO "Pinging the guest IP ${guestip}"
426
set -x
427
ping -c 3 "$guestip"
428
set +x
429
INFO "Benchmarking with iperf3"
430
set -x
431
limactl shell "$NAME" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y iperf3
432
limactl shell "$NAME" iperf3 -s -1 -D
433
${IPERF3} -c "$guestip"
434
set +x
435
# NOTE: we only test the shared interface here, as the bridged interface cannot be used on GHA (and systemd-networkd-wait-online.service will fail)
436
fi
437
438
if [[ -n ${CHECKS["disk"]} ]]; then
439
INFO "Testing disk is attached"
440
set -x
441
if ! limactl shell "$NAME" lsblk --output NAME,MOUNTPOINT | grep -q "/mnt/lima-data"; then
442
ERROR "Disk is not mounted"
443
exit 1
444
fi
445
set +x
446
fi
447
448
if [[ -n ${CHECKS["restart"]} ]]; then
449
INFO "Create file in the guest home directory and verify that it still exists after a restart"
450
# shellcheck disable=SC2016
451
limactl shell "$NAME" sh -c 'touch $HOME/sweet-home'
452
if [[ -n ${CHECKS["disk"]} ]]; then
453
INFO "Create file in disk and verify that it still exists when it is reattached"
454
limactl shell "$NAME" sudo sh -c 'touch /mnt/lima-data/sweet-disk'
455
fi
456
457
INFO "Stopping \"$NAME\""
458
limactl stop "$NAME"
459
sleep 3
460
461
if [[ -n ${CHECKS["disk"]} ]]; then
462
INFO "Resize disk and verify that partition and fs size are increased"
463
limactl disk resize data --size 11G
464
fi
465
466
export ftp_proxy=my.proxy:8021
467
INFO "Restarting \"$NAME\""
468
if ! limactl start "$NAME"; then
469
ERROR "Failed to start \"$NAME\""
470
diagnose "$NAME"
471
exit 1
472
fi
473
474
INFO "Make sure proxy setting is updated"
475
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
476
expected="FTP_PROXY=my.proxy:8021"
477
INFO "FTP_PROXY: expected=${expected} got=${got}"
478
if [ "$got" != "$expected" ]; then
479
ERROR "proxy environment variable not set to correct value"
480
exit 1
481
fi
482
483
# shellcheck disable=SC2016
484
if ! limactl shell "$NAME" sh -c 'test -f $HOME/sweet-home'; then
485
ERROR "Guest home directory does not persist across restarts"
486
exit 1
487
fi
488
489
if [[ -n ${CHECKS["disk"]} ]]; then
490
if ! limactl shell "$NAME" sh -c 'test -f /mnt/lima-data/sweet-disk'; then
491
ERROR "Disk does not persist across restarts"
492
exit 1
493
fi
494
if ! limactl shell "$NAME" sh -c 'df -h /mnt/lima-data/ --output=size | grep -q 11G'; then
495
ERROR "Disk FS does not resized after restart"
496
exit 1
497
fi
498
fi
499
fi
500
501
if [[ -n ${CHECKS["user-v2"]} ]]; then
502
INFO "Testing user-v2 network"
503
secondvm="$NAME-1"
504
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE_HOST" --name "$secondvm"
505
if ! limactl start "$secondvm"; then
506
ERROR "Failed to start \"$secondvm\""
507
diagnose "$secondvm"
508
exit 1
509
fi
510
secondvmDNS="lima-$secondvm.internal"
511
INFO "DNS of $secondvm is $secondvmDNS"
512
set -x
513
if ! limactl shell "$NAME" ping -c 1 "$secondvmDNS"; then
514
ERROR "Failed to do vm->vm communication via user-v2"
515
INFO "Stopping \"$secondvm\""
516
limactl stop "$secondvm"
517
INFO "Deleting \"$secondvm\""
518
limactl delete "$secondvm"
519
exit 1
520
fi
521
INFO "Stopping \"$secondvm\""
522
limactl stop "$secondvm"
523
INFO "Deleting \"$secondvm\""
524
limactl delete "$secondvm"
525
set +x
526
fi
527
if [[ -n ${CHECKS["snapshot-online"]} ]]; then
528
INFO "Testing online snapshots"
529
limactl shell "$NAME" sh -c 'echo foo > /tmp/test'
530
limactl snapshot create "$NAME" --tag snap1
531
got=$(limactl snapshot list "$NAME" --quiet)
532
expected="snap1"
533
INFO "snapshot list: expected=${expected} got=${got}"
534
if [ "$got" != "$expected" ]; then
535
ERROR "snapshot list did not return expected value"
536
exit 1
537
fi
538
limactl shell "$NAME" sh -c 'echo bar > /tmp/test'
539
limactl snapshot apply "$NAME" --tag snap1
540
got=$(limactl shell "$NAME" cat /tmp/test)
541
expected="foo"
542
INFO "snapshot apply: expected=${expected} got=${got}"
543
if [ "$got" != "$expected" ]; then
544
ERROR "snapshot apply did not restore snapshot"
545
exit 1
546
fi
547
limactl snapshot delete "$NAME" --tag snap1
548
limactl shell "$NAME" rm /tmp/test
549
fi
550
if [[ -n ${CHECKS["snapshot-offline"]} ]]; then
551
INFO "Testing offline snapshots"
552
limactl stop "$NAME"
553
sleep 3
554
limactl snapshot create "$NAME" --tag snap2
555
got=$(limactl snapshot list "$NAME" --quiet)
556
expected="snap2"
557
INFO "snapshot list: expected=${expected} got=${got}"
558
if [ "$got" != "$expected" ]; then
559
ERROR "snapshot list did not return expected value"
560
exit 1
561
fi
562
limactl snapshot apply "$NAME" --tag snap2
563
limactl snapshot delete "$NAME" --tag snap2
564
limactl start "$NAME"
565
fi
566
if [[ -n ${CHECKS["clone"]} ]]; then
567
INFO "Testing cloning"
568
limactl stop "$NAME"
569
sleep 3
570
# [hostagent] could not attach disk \"data\", in use by instance \"test-misc-clone\"
571
limactl clone --set '.additionalDisks = null' "$NAME" "${NAME}-clone"
572
limactl start "${NAME}-clone"
573
[ "$(limactl shell "${NAME}-clone" hostname)" = "lima-${NAME}-clone" ]
574
limactl start "$NAME"
575
fi
576
577
if [[ $NAME == "fedora" && "$(limactl ls --json "$NAME" | jq -r .vmType)" == "vz" ]]; then
578
"${scriptdir}"/test-selinux.sh "$NAME"
579
fi
580
581
INFO "Stopping \"$NAME\""
582
limactl stop "$NAME"
583
sleep 3
584
585
INFO "Deleting \"$NAME\""
586
limactl delete "$NAME"
587
588
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
589
rm -rf "/tmp/lima test dir with spaces"
590
fi
591
592