Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/hack/test-templates.sh
2608 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
LIMACTL_CREATE=(limactl --tty=false create)
38
39
CONTAINER_ENGINE="nerdctl"
40
41
declare -A CHECKS=(
42
["proxy-settings"]="1"
43
["systemd"]="1"
44
["mount-home"]="1"
45
["container-engine"]="1"
46
["restart"]="1"
47
# snapshot tests are too flaky (especially with archlinux)
48
["snapshot-online"]=""
49
["snapshot-offline"]=""
50
["clone"]=""
51
["port-forwards"]="1"
52
["vmnet"]=""
53
["disk"]=""
54
["user-v2"]=""
55
["mount-path-with-spaces"]=""
56
["provision-data"]=""
57
["provision-yq"]=""
58
["param-env-variables"]=""
59
["set-user"]=""
60
["preserve-env"]="1"
61
["static-port-forwards"]=""
62
["ssh-over-vsock"]=""
63
)
64
65
case "$NAME" in
66
"default")
67
# CI failure:
68
# "[hostagent] failed to confirm whether /c/Users/runneradmin [remote] is successfully mounted"
69
[ "${OS_HOST}" = "Msys" ] && CHECKS["mount-home"]=
70
[ "${OS_HOST}" = "Darwin" ] && CHECKS["ssh-over-vsock"]="1"
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
"test-misc")
83
CHECKS["disk"]=1
84
CHECKS["snapshot-online"]="1"
85
CHECKS["snapshot-offline"]="1"
86
CHECKS["clone"]="1"
87
CHECKS["mount-path-with-spaces"]="1"
88
CHECKS["provision-data"]="1"
89
CHECKS["provision-yq"]="1"
90
CHECKS["param-env-variables"]="1"
91
CHECKS["set-user"]="1"
92
CHECKS["static-port-forwards"]="1"
93
;;
94
"docker")
95
CONTAINER_ENGINE="docker"
96
;;
97
"wsl2")
98
# TODO https://github.com/lima-vm/lima/issues/3268
99
CHECKS["proxy-settings"]=
100
;;
101
esac
102
103
if limactl ls -q "$NAME" 2>/dev/null; then
104
ERROR "Instance $NAME already exists"
105
exit 1
106
fi
107
108
case "$(limactl tmpl yq "$FILE_HOST" '.networks[].lima')" in
109
"shared")
110
CHECKS["vmnet"]=1
111
;;
112
"user-v2")
113
CHECKS["port-forwards"]=""
114
CHECKS["user-v2"]=1
115
;;
116
esac
117
118
if [[ -n ${CHECKS["port-forwards"]} ]]; then
119
tmpconfig="$HOME_HOST/lima-config-tmp"
120
mkdir -p "${tmpconfig}"
121
defer "rm -rf \"$tmpconfig\""
122
tmpfile="${tmpconfig}/${NAME}.yaml"
123
cp "$FILE" "${tmpfile}"
124
FILE="${tmpfile}"
125
FILE_HOST=$FILE
126
if [ "${OS_HOST}" = "Msys" ]; then
127
FILE_HOST="$(cygpath -w "$FILE")"
128
fi
129
130
INFO "Setup port forwarding rules for testing in \"${FILE}\""
131
"${scriptdir}/test-port-forwarding.pl" "${FILE}"
132
INFO "Validating \"$FILE_HOST\""
133
limactl validate "$FILE_HOST"
134
fi
135
136
INFO "Make sure template embedding copies \"$FILE_HOST\" exactly"
137
diff -u <(echo -n "base: $FILE_HOST" | limactl tmpl copy --embed - -) "$FILE_HOST"
138
139
function diagnose() {
140
NAME="$1"
141
set -x +e
142
tail "$HOME_HOST/.lima/${NAME}"/*.log
143
limactl shell "$NAME" systemctl --no-pager status
144
limactl shell "$NAME" systemctl --no-pager
145
mkdir -p failure-logs
146
cp -pf "$HOME_HOST/.lima/${NAME}"/*.log failure-logs/
147
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
148
limactl shell "$NAME" sh -c "command -v journalctl >/dev/null && sudo journalctl --no-pager" >failure-logs/journal.log
149
set +x -e
150
}
151
152
export ftp_proxy=http://localhost:2121
153
154
INFO "Creating \"$NAME\" from \"$FILE_HOST\""
155
defer "limactl delete -f \"$NAME\""
156
157
if [[ -n ${CHECKS["disk"]} ]]; then
158
if [[ -z "$(limactl disk ls data --json 2>/dev/null)" ]]; then
159
defer "limactl disk delete data"
160
limactl disk create data --size 10G
161
fi
162
if ! limactl disk ls | grep -q "^swap\s"; then
163
defer "limactl disk delete swap"
164
limactl disk create swap --size 2G
165
fi
166
fi
167
168
set -x
169
# shellcheck disable=SC2086
170
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS:-} "$FILE_HOST"
171
set +x
172
173
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
174
mkdir -p "/tmp/lima test dir with spaces"
175
echo "test file content" >"/tmp/lima test dir with spaces/test file"
176
fi
177
178
INFO "Starting \"$NAME\""
179
set -x
180
if ! limactl start "$NAME"; then
181
ERROR "Failed to start \"$NAME\""
182
diagnose "$NAME"
183
exit 1
184
fi
185
186
limactl shell "$NAME" uname -a
187
188
limactl shell "$NAME" cat /etc/os-release
189
set +x
190
191
INFO "Testing that host home is not wiped out"
192
[ -e "$HOME_HOST/.lima" ]
193
194
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
195
INFO 'Testing that "/tmp/lima test dir with spaces" is not wiped out'
196
[ "$(cat "/tmp/lima test dir with spaces/test file")" = "test file content" ]
197
[ "$(limactl shell "$NAME" cat "/tmp/lima test dir with spaces/test file")" = "test file content" ]
198
fi
199
200
if [[ -n ${CHECKS["provision-data"]} ]]; then
201
INFO 'Testing that /etc/sysctl.d/99-inotify.conf was created successfully on provision'
202
limactl shell "$NAME" grep -q fs.inotify.max_user_watches /etc/sysctl.d/99-inotify.conf
203
fi
204
205
if [[ -n ${CHECKS["provision-yq"]} ]]; then
206
INFO 'Testing that /tmp/param-yq.json was created successfully on provision'
207
limactl shell "$NAME" grep -q '"YQ": "yq"' /tmp/param-yq.json
208
fi
209
210
if [[ -n ${CHECKS["param-env-variables"]} ]]; then
211
INFO 'Testing that PARAM env variables are exported to all types of provisioning scripts and probes'
212
limactl shell "$NAME" test -e /tmp/param-ansible
213
limactl shell "$NAME" test -e /tmp/param-boot
214
limactl shell "$NAME" test -e /tmp/param-dependency
215
limactl shell "$NAME" test -e /tmp/param-probe
216
limactl shell "$NAME" test -e /tmp/param-system
217
limactl shell "$NAME" test -e /tmp/param-user
218
fi
219
220
if [[ -n ${CHECKS["set-user"]} ]]; then
221
INFO 'Testing that user settings can be provided by lima.yaml'
222
limactl shell "$NAME" grep "^john:x:4711:4711:John Doe:/home/john-john:/usr/bin/bash" /etc/passwd
223
fi
224
225
if [[ -n ${CHECKS["proxy-settings"]} ]]; then
226
INFO "Testing proxy settings are imported"
227
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
228
# Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
229
# by the gateway address, and the value is set immediately without a restart
230
gatewayIp=$(limactl shell "$NAME" ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
231
expected="FTP_PROXY=http://${gatewayIp}:2121"
232
INFO "FTP_PROXY: expected=${expected} got=${got}"
233
if [ "$got" != "$expected" ]; then
234
ERROR "proxy environment variable not set to correct value"
235
exit 1
236
fi
237
fi
238
239
INFO "Testing limactl copy command"
240
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/lima-test-templates.XXXXXX)"
241
defer "rm -rf \"$tmpdir\""
242
tmpfile="$tmpdir/lima-hostname"
243
rm -f "$tmpfile"
244
tmpfile_host=$tmpfile
245
if [ "${OS_HOST}" = "Msys" ]; then
246
tmpfile_host="$(cygpath -w "$tmpfile")"
247
fi
248
limactl cp "$NAME":/etc/hostname "$tmpfile_host"
249
expected="$(limactl shell "$NAME" cat /etc/hostname)"
250
got="$(cat "$tmpfile")"
251
INFO "/etc/hostname: expected=${expected}, got=${got}"
252
if [ "$got" != "$expected" ]; then
253
ERROR "copy command did not fetch the file"
254
exit 1
255
fi
256
257
INFO "Testing limactl copy command with scp backend"
258
tmpfile_scp="$tmpdir/lima-hostname-scp"
259
rm -f "$tmpfile_scp"
260
tmpfile_scp_host=$tmpfile_scp
261
if [ "${OS_HOST}" = "Msys" ]; then
262
tmpfile_scp_host="$(cygpath -w "$tmpfile_scp")"
263
fi
264
limactl cp --backend=scp "$NAME":/etc/hostname "$tmpfile_scp_host"
265
expected="$(limactl shell "$NAME" cat /etc/hostname)"
266
got="$(cat "$tmpfile_scp")"
267
INFO "/etc/hostname (scp): expected=${expected}, got=${got}"
268
if [ "$got" != "$expected" ]; then
269
ERROR "copy command with scp backend did not fetch the file"
270
exit 1
271
fi
272
273
if command -v rsync >/dev/null && limactl shell "$NAME" command -v rsync >/dev/null 2>&1; then
274
INFO "Testing limactl copy command with rsync backend"
275
tmpfile_rsync="$tmpdir/lima-hostname-rsync"
276
rm -f "$tmpfile_rsync"
277
tmpfile_rsync_host=$tmpfile_rsync
278
if [ "${OS_HOST}" = "Msys" ]; then
279
tmpfile_rsync_host="$(cygpath -w "$tmpfile_rsync")"
280
fi
281
limactl cp --backend=rsync "$NAME":/etc/hostname "$tmpfile_rsync_host"
282
expected="$(limactl shell "$NAME" cat /etc/hostname)"
283
got="$(cat "$tmpfile_rsync")"
284
INFO "/etc/hostname (rsync): expected=${expected}, got=${got}"
285
if [ "$got" != "$expected" ]; then
286
ERROR "copy command with rsync backend did not fetch the file"
287
exit 1
288
fi
289
290
INFO "Testing limactl copy command with rsync backend (verbose, recursive)"
291
testdir="$tmpdir/test-rsync-dir"
292
mkdir -p "$testdir"
293
echo "test content" >"$testdir/testfile.txt"
294
limactl cp --backend=rsync -r -v "$testdir" "$NAME":/tmp/
295
if ! limactl shell "$NAME" test -f /tmp/test-rsync-dir/testfile.txt; then
296
ERROR "rsync recursive copy failed"
297
exit 1
298
fi
299
rsync_content="$(limactl shell "$NAME" cat /tmp/test-rsync-dir/testfile.txt)"
300
if [ "$rsync_content" != "test content" ]; then
301
ERROR "rsync file content mismatch"
302
exit 1
303
fi
304
else
305
INFO "Skipping rsync backend test (rsync not available on host or guest)"
306
fi
307
308
INFO "Testing limactl command with escaped characters"
309
limactl shell "$NAME" bash -c "$(echo -e '\n\techo foo\n\techo bar')"
310
311
INFO "Testing limactl command with quotes"
312
limactl shell "$NAME" bash -c "echo 'foo \"bar\"'"
313
314
if [[ -n ${CHECKS["systemd"]} ]]; then
315
set -x
316
if ! limactl shell "$NAME" systemctl is-system-running --wait; then
317
ERROR '"systemctl is-system-running" failed'
318
diagnose "$NAME"
319
exit 1
320
fi
321
set +x
322
fi
323
324
if [[ -n ${CHECKS["mount-home"]} ]]; then
325
"${scriptdir}"/test-mount-home.sh "$NAME"
326
fi
327
328
if [[ -n ${CHECKS["ssh-over-vsock"]} ]]; then
329
if [[ "$(limactl ls "${NAME}" --yq .vmType)" == "vz" ]]; then
330
INFO "Testing SSH over vsock"
331
set -x
332
log_file="$HOME_HOST/.lima/${NAME}/ha.stdout.log"
333
334
# Helper function to check vsock events in the log file
335
# $1: event_type to check for
336
check_vsock_event() {
337
local event_type="$1"
338
if jq -e --arg type "$event_type" 'select(.status.vsock.type == $type)' "$log_file" >/dev/null 2>&1; then
339
return 0
340
fi
341
return 1
342
}
343
344
INFO "Testing .ssh.overVsock=true configuration"
345
limactl stop "${NAME}"
346
# Detection of the SSH server on VSOCK may fail; however, a failing log indicates that controlling detection via the environment variable works as expected.
347
limactl start --set '.ssh.overVsock=true' "${NAME}"
348
if ! check_vsock_event "started" && ! check_vsock_event "failed"; then
349
set +x
350
diagnose "${NAME}"
351
ERROR ".ssh.overVsock=true did not enable vsock forwarder"
352
exit 1
353
fi
354
INFO 'Testing .ssh.overVsock=null configuration'
355
limactl stop "${NAME}"
356
# Detection of the SSH server on VSOCK may fail; however, a failing log indicates that controlling detection via the environment variable works as expected.
357
limactl start --set '.ssh.overVsock=null' "${NAME}"
358
if ! check_vsock_event "started" && ! check_vsock_event "failed"; then
359
set +x
360
diagnose "${NAME}"
361
ERROR ".ssh.overVsock=null did not enable vsock forwarder"
362
exit 1
363
fi
364
INFO "Testing .ssh.overVsock=false configuration"
365
limactl stop "${NAME}"
366
limactl start --set '.ssh.overVsock=false' "${NAME}"
367
if ! check_vsock_event "skipped"; then
368
set +x
369
diagnose "${NAME}"
370
ERROR ".ssh.overVsock=false did not disable vsock forwarder"
371
exit 1
372
fi
373
set +x
374
fi
375
fi
376
377
# Use GHCR and ECR to avoid hitting Docker Hub rate limit
378
nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
379
alpine_image="ghcr.io/containerd/alpine:3.14.0"
380
coredns_image="public.ecr.aws/eks-distro/coredns/coredns:v1.12.2-eks-1-31-latest"
381
382
if [[ -n ${CHECKS["container-engine"]} ]]; then
383
sudo=""
384
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
385
if [[ "$(limactl ls "${NAME}" --yq .vmType)" == "wsl2" ]]; then
386
sudo="sudo"
387
fi
388
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
389
set -x
390
if ! limactl shell "$NAME" $sudo $CONTAINER_ENGINE info; then
391
limactl shell "$NAME" cat /var/log/cloud-init-output.log
392
ERROR "\"${CONTAINER_ENGINE} info\" failed"
393
exit 1
394
fi
395
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
396
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
397
398
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
399
400
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
401
402
if [ "${OS_HOST}" != "Msys" ]; then
403
# TODO: support UDP on Windows
404
INFO "Run a coredns container with port forwarding 127.0.0.1:10053/udp"
405
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${coredns_image}
406
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name coredns -p 127.0.0.1:10053:53/udp ${coredns_image}
407
dig @127.0.0.1 -p 10053 lima-vm.io
408
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f coredns
409
fi
410
411
set +x
412
if [[ -n ${CHECKS["mount-home"]} ]]; then
413
hometmp="$HOME_HOST/lima-container-engine-test-tmp"
414
hometmpguest="$HOME_GUEST/lima-container-engine-test-tmp"
415
# test for https://github.com/lima-vm/lima/issues/187
416
INFO "Testing home bind mount (\"$hometmp\")"
417
rm -rf "$hometmp"
418
mkdir -p "$hometmp"
419
defer "rm -rf \"$hometmp\""
420
set -x
421
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${alpine_image}
422
echo "random-content-${RANDOM}" >"$hometmp/random"
423
expected="$(cat "$hometmp/random")"
424
got="$(limactl shell "$NAME" $sudo $CONTAINER_ENGINE run --rm -v "$hometmpguest/random":/mnt/foo ${alpine_image} cat /mnt/foo)"
425
INFO "$hometmp/random: expected=${expected}, got=${got}"
426
if [ "$got" != "$expected" ]; then
427
ERROR "Home directory is not shared?"
428
exit 1
429
fi
430
set +x
431
fi
432
fi
433
434
if [[ -n ${CHECKS["port-forwards"]} ]]; then
435
PORT_FORWARDING_CONNECTION_TIMEOUT=1
436
INFO "Testing port forwarding rules using netcat and socat with connection timeout ${PORT_FORWARDING_CONNECTION_TIMEOUT}s"
437
set -x
438
if [[ ${NAME} == "alpine"* ]]; then
439
limactl shell "${NAME}" sudo apk add socat
440
fi
441
if [[ ${NAME} == "archlinux" ]]; then
442
limactl shell "${NAME}" sudo pacman -Syu --noconfirm openbsd-netcat socat
443
fi
444
if [[ ${NAME} == "debian" || ${NAME} == "default" || ${NAME} == "docker" || ${NAME} == "test-misc" ]]; then
445
limactl shell "${NAME}" sudo apt-get install -y netcat-openbsd socat
446
fi
447
if [[ ${NAME} == "fedora" || ${NAME} == "wsl2" ]]; then
448
limactl shell "${NAME}" sudo dnf install -y nc socat
449
fi
450
if [[ ${NAME} == "opensuse" ]]; then
451
limactl shell "${NAME}" sudo zypper in -y netcat-openbsd socat
452
fi
453
if limactl shell "${NAME}" command -v dnf; then
454
limactl shell "${NAME}" sudo dnf install -y nc socat
455
fi
456
if "${scriptdir}/test-port-forwarding.pl" "${NAME}" socat $PORT_FORWARDING_CONNECTION_TIMEOUT; then
457
INFO "Port forwarding rules work"
458
else
459
ERROR "Port forwarding rules do not work with socat"
460
diagnose "$NAME"
461
exit 1
462
fi
463
464
if [[ -n ${CHECKS["container-engine"]} || ${NAME} == "alpine"* ]]; then
465
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)"
466
if [ "$(uname)" = "Darwin" ]; then
467
# macOS runners seem to use `localhost` as the hostname, so the perl lookup just returns `127.0.0.1`
468
hostip=$(system_profiler SPNetworkDataType -json | jq -r 'first(.SPNetworkDataType[] | select(.ip_address) | .ip_address) | first')
469
else
470
hostip=$(perl -MSocket -MSys::Hostname -E 'say inet_ntoa(scalar gethostbyname(hostname()))')
471
fi
472
if [ -n "${hostip}" ]; then
473
sudo=""
474
if [[ ${NAME} == "alpine"* ]]; then
475
arch=$(limactl info | jq -r .defaultTemplate.arch)
476
nerdctl=$(limactl info | jq -r ".defaultTemplate.containerd.archives[] | select(.arch==\"$arch\").location")
477
curl -Lso nerdctl-full.tgz "${nerdctl}"
478
limactl shell "$NAME" sudo apk add containerd
479
limactl shell "$NAME" sudo rc-service containerd start
480
limactl shell "$NAME" sudo tar xzf "${PWD}/nerdctl-full.tgz" -C /usr/local
481
rm nerdctl-full.tgz
482
sudo="sudo"
483
fi
484
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
485
if [[ "$(limactl ls "${NAME}" --yq .vmType)" == "wsl2" ]]; then
486
sudo="sudo"
487
fi
488
limactl shell "$NAME" $sudo $CONTAINER_ENGINE info
489
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
490
491
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 8888:80 ${nginx_image}
492
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://${hostip}:8888; do sleep 3; done"
493
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
494
495
if [ "$(uname)" = "Darwin" ]; then
496
# Only macOS can bind to port 80 without root
497
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:80:80 ${nginx_image}
498
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://localhost:80; do sleep 3; done"
499
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
500
fi
501
fi
502
if [[ ${NAME} != "alpine"* ]] && command -v w3m >/dev/null; then
503
INFO "Testing https://github.com/lima-vm/lima/issues/3685 ([gRPC portfwd] client connection is not closed immediately when server closed the connection)"
504
# Skip the test on Alpine, as systemd-run is missing
505
# Skip the test on WSL2, as port forwarding is half broken https://github.com/lima-vm/lima/pull/3686#issuecomment-3034842616
506
limactl shell "$NAME" systemd-run --user python3 -m http.server 3685
507
# curl is not enough to reproduce https://github.com/lima-vm/lima/issues/3685
508
# `w3m -dump` exits with status code 0 even on "Can't load" error.
509
timeout 30s bash -euxc "until w3m -dump http://localhost:3685 | grep -v \"w3m: Can't load\"; do sleep 3; done"
510
fi
511
fi
512
set +x
513
fi
514
515
if [[ -n ${CHECKS["vmnet"]} ]]; then
516
INFO "Testing vmnet functionality"
517
guestip="$(limactl shell "$NAME" ip -4 -j addr show dev lima0 | jq -r '.[0].addr_info[0].local')"
518
INFO "Pinging the guest IP ${guestip}"
519
set -x
520
ping -c 3 "$guestip"
521
set +x
522
INFO "Benchmarking with iperf3"
523
set -x
524
limactl shell "$NAME" sudo DEBIAN_FRONTEND=noninteractive apt-get install -y iperf3
525
limactl shell "$NAME" iperf3 -s -1 -D
526
${IPERF3} -c "$guestip"
527
set +x
528
# 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)
529
fi
530
531
if [[ -n ${CHECKS["disk"]} ]]; then
532
INFO "Testing disk is attached"
533
set -x
534
if ! limactl shell "$NAME" lsblk --output NAME,MOUNTPOINT | grep -q "/mnt/lima-data"; then
535
ERROR "Disk is not mounted"
536
exit 1
537
fi
538
if ! limactl shell "$NAME" lsblk --output NAME,MOUNTPOINT | grep -q "\[SWAP\]"; then
539
ERROR "Disk is not mounted"
540
exit 1
541
fi
542
set +x
543
fi
544
545
if [[ -n ${CHECKS["restart"]} ]]; then
546
INFO "Create file in the guest home directory and verify that it still exists after a restart"
547
# shellcheck disable=SC2016
548
limactl shell "$NAME" sh -c 'touch $HOME/sweet-home'
549
if [[ -n ${CHECKS["disk"]} ]]; then
550
INFO "Create file in disk and verify that it still exists when it is reattached"
551
limactl shell "$NAME" sudo sh -c 'touch /mnt/lima-data/sweet-disk'
552
fi
553
554
INFO "Stopping \"$NAME\""
555
limactl stop "$NAME"
556
sleep 3
557
558
if [[ -n ${CHECKS["disk"]} ]]; then
559
INFO "Resize disk and verify that partition and fs size are increased"
560
limactl disk resize data --size 11G
561
fi
562
563
export ftp_proxy=my.proxy:8021
564
INFO "Restarting \"$NAME\""
565
if ! limactl start "$NAME"; then
566
ERROR "Failed to start \"$NAME\""
567
diagnose "$NAME"
568
exit 1
569
fi
570
571
INFO "Make sure proxy setting is updated"
572
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
573
expected="FTP_PROXY=my.proxy:8021"
574
INFO "FTP_PROXY: expected=${expected} got=${got}"
575
if [ "$got" != "$expected" ]; then
576
ERROR "proxy environment variable not set to correct value"
577
exit 1
578
fi
579
580
# shellcheck disable=SC2016
581
if ! limactl shell "$NAME" sh -c 'test -f $HOME/sweet-home'; then
582
ERROR "Guest home directory does not persist across restarts"
583
exit 1
584
fi
585
586
if [[ -n ${CHECKS["disk"]} ]]; then
587
if ! limactl shell "$NAME" sh -c 'test -f /mnt/lima-data/sweet-disk'; then
588
ERROR "Disk does not persist across restarts"
589
exit 1
590
fi
591
if ! limactl shell "$NAME" sh -c 'df -h /mnt/lima-data/ --output=size | grep -q 11G'; then
592
ERROR "Disk FS does not resized after restart"
593
exit 1
594
fi
595
fi
596
fi
597
598
if [[ -n ${CHECKS["user-v2"]} ]]; then
599
INFO "Testing user-v2 network"
600
secondvm="$NAME-1"
601
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE_HOST" --name "$secondvm"
602
if ! limactl start "$secondvm"; then
603
ERROR "Failed to start \"$secondvm\""
604
diagnose "$secondvm"
605
exit 1
606
fi
607
secondvmDNS="lima-$secondvm.internal"
608
INFO "DNS of $secondvm is $secondvmDNS"
609
set -x
610
if ! limactl shell "$NAME" ping -c 1 "$secondvmDNS"; then
611
ERROR "Failed to do vm->vm communication via user-v2"
612
INFO "Stopping \"$secondvm\""
613
limactl stop "$secondvm"
614
INFO "Deleting \"$secondvm\""
615
limactl delete "$secondvm"
616
exit 1
617
fi
618
INFO "Stopping \"$secondvm\""
619
limactl stop "$secondvm"
620
INFO "Deleting \"$secondvm\""
621
limactl delete "$secondvm"
622
set +x
623
fi
624
if [[ -n ${CHECKS["snapshot-online"]} ]]; then
625
INFO "Testing online snapshots"
626
limactl shell "$NAME" sh -c 'echo foo > /tmp/test'
627
limactl snapshot create "$NAME" --tag snap1
628
got=$(limactl snapshot list "$NAME" --quiet)
629
expected="snap1"
630
INFO "snapshot list: expected=${expected} got=${got}"
631
if [ "$got" != "$expected" ]; then
632
ERROR "snapshot list did not return expected value"
633
exit 1
634
fi
635
limactl shell "$NAME" sh -c 'echo bar > /tmp/test'
636
limactl snapshot apply "$NAME" --tag snap1
637
got=$(limactl shell "$NAME" cat /tmp/test)
638
expected="foo"
639
INFO "snapshot apply: expected=${expected} got=${got}"
640
if [ "$got" != "$expected" ]; then
641
ERROR "snapshot apply did not restore snapshot"
642
exit 1
643
fi
644
limactl snapshot delete "$NAME" --tag snap1
645
limactl shell "$NAME" rm /tmp/test
646
fi
647
if [[ -n ${CHECKS["snapshot-offline"]} ]]; then
648
INFO "Testing offline snapshots"
649
limactl stop "$NAME"
650
sleep 3
651
limactl snapshot create "$NAME" --tag snap2
652
got=$(limactl snapshot list "$NAME" --quiet)
653
expected="snap2"
654
INFO "snapshot list: expected=${expected} got=${got}"
655
if [ "$got" != "$expected" ]; then
656
ERROR "snapshot list did not return expected value"
657
exit 1
658
fi
659
limactl snapshot apply "$NAME" --tag snap2
660
limactl snapshot delete "$NAME" --tag snap2
661
limactl start "$NAME"
662
fi
663
if [[ -n ${CHECKS["clone"]} ]]; then
664
INFO "Testing cloning"
665
limactl stop "$NAME"
666
sleep 3
667
# [hostagent] could not attach disk \"data\", in use by instance \"test-misc-clone\"
668
limactl clone --set '.additionalDisks = null' "$NAME" "${NAME}-clone"
669
limactl start "${NAME}-clone"
670
[ "$(limactl shell "${NAME}-clone" hostname)" = "lima-${NAME}-clone" ]
671
limactl start "$NAME"
672
fi
673
674
if [[ $NAME == "fedora" && "$(limactl ls "${NAME}" --yq .vmType)" == "vz" ]]; then
675
"${scriptdir}"/test-selinux.sh "$NAME"
676
fi
677
678
INFO "Stopping \"$NAME\""
679
limactl stop "$NAME"
680
sleep 3
681
682
INFO "Deleting \"$NAME\""
683
limactl delete "$NAME"
684
685
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
686
rm -rf "/tmp/lima test dir with spaces"
687
fi
688
689
if [[ -n ${CHECKS["static-port-forwards"]} ]]; then
690
INFO "Testing static port forwarding functionality"
691
"${scriptdir}/test-plain-static-port-forward.sh" "$NAME"
692
"${scriptdir}/test-nonplain-static-port-forward.sh" "$NAME"
693
INFO "All static port forwarding tests passed!"
694
fi
695
696