1
1
#! /usr/bin/env bash
2
2
set -eu -o pipefail
3
3
4
+ # will prevent msys2 converting Linux path arguments into Windows paths before passing to limactl
5
+ export MSYS2_ARG_CONV_EXCL=' *'
6
+
4
7
scriptdir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
5
8
# shellcheck source=common.inc.sh
6
9
source " ${scriptdir} /common.inc.sh"
12
15
13
16
FILE=" $1 "
14
17
NAME=" $( basename -s .yaml " $FILE " ) "
18
+ OS_HOST=" $( uname -o) "
19
+
20
+ # On Windows $HOME of the bash runner, %USERPROFILE% of the host machine and mpunting point in the guest machine
21
+ # are all different folders. This will handle path differences, when values are expilictly set.
22
+ HOME_HOST=${HOME_HOST:- $HOME }
23
+ HOME_GUEST=${HOME_GUEST:- $HOME }
24
+ FILE_HOST=$FILE
25
+ if [ " ${OS_HOST} " = " Msys" ]; then
26
+ FILE_HOST=" $( cygpath -w " $FILE " ) "
27
+ fi
15
28
16
- INFO " Validating \" $FILE \" "
17
- limactl validate " $FILE "
29
+ INFO " Validating \" $FILE_HOST \" "
30
+ limactl validate " $FILE_HOST "
18
31
19
32
# --cpus=1 is needed for running vz on GHA: https://github.com/lima-vm/lima/pull/1511#issuecomment-1574937888
20
33
LIMACTL_CREATE=(limactl --tty=false create --cpus=1 --memory=1)
21
34
22
35
CONTAINER_ENGINE=" nerdctl"
23
36
24
37
declare -A CHECKS=(
38
+ [" proxy-settings" ]=" 1"
25
39
[" systemd" ]=" 1"
26
40
[" systemd-strict" ]=" 1"
27
41
[" mount-home" ]=" 1"
@@ -69,6 +83,13 @@ case "$NAME" in
69
83
" docker" )
70
84
CONTAINER_ENGINE=" docker"
71
85
;;
86
+ " wsl2" )
87
+ # TODO https://github.com/lima-vm/lima/issues/3267
88
+ CHECKS[" systemd" ]=
89
+ # TODO https://github.com/lima-vm/lima/issues/3268
90
+ CHECKS[" proxy-settings" ]=
91
+ CHECKS[" port-forwards" ]=
92
+ ;;
72
93
esac
73
94
74
95
if limactl ls -q | grep -q " $NAME " ; then
80
101
# TODO: skip downloading and converting the image here.
81
102
# Probably `limactl create` should have "dry run" mode that just generates `lima.yaml`.
82
103
# shellcheck disable=SC2086
83
- " ${LIMACTL_CREATE[@]} " ${LIMACTL_CREATE_ARGS} --set " .additionalDisks=null" --name=" ${NAME} -tmp" " $FILE "
104
+ " ${LIMACTL_CREATE[@]} " ${LIMACTL_CREATE_ARGS} --set " .additionalDisks=null" --name=" ${NAME} -tmp" " $FILE_HOST "
84
105
case " $( yq ' .networks[].lima' " ${LIMA_HOME} /${NAME} -tmp/lima.yaml" ) " in
85
106
" shared" )
86
107
CHECKS[" vmnet" ]=1
@@ -93,32 +114,38 @@ esac
93
114
limactl rm -f " ${NAME} -tmp"
94
115
95
116
if [[ -n ${CHECKS["port-forwards"]} ]]; then
96
- tmpconfig=" $HOME /lima-config-tmp"
117
+ tmpconfig=" $HOME_HOST /lima-config-tmp"
97
118
mkdir -p " ${tmpconfig} "
98
119
defer " rm -rf \" $tmpconfig \" "
99
120
tmpfile=" ${tmpconfig} /${NAME} .yaml"
100
121
cp " $FILE " " ${tmpfile} "
101
122
FILE=" ${tmpfile} "
123
+ FILE_HOST=$FILE
124
+ if [ " ${OS_HOST} " = " Msys" ]; then
125
+ FILE_HOST=" $( cygpath -w " $FILE " ) "
126
+ fi
127
+
102
128
INFO " Setup port forwarding rules for testing in \" ${FILE} \" "
103
129
" ${scriptdir} /test-port-forwarding.pl" " ${FILE} "
104
- limactl validate " $FILE "
130
+ INFO " Validating \" $FILE_HOST \" "
131
+ limactl validate " $FILE_HOST "
105
132
fi
106
133
107
134
function diagnose() {
108
135
NAME=" $1 "
109
136
set -x +e
110
- tail " $HOME /.lima/${NAME} " /* .log
137
+ tail " $HOME_HOST /.lima/${NAME} " /* .log
111
138
limactl shell " $NAME " systemctl --no-pager status
112
139
limactl shell " $NAME " systemctl --no-pager
113
140
mkdir -p failure-logs
114
- cp -pf " $HOME /.lima/${NAME} " /* .log failure-logs/
141
+ cp -pf " $HOME_HOST /.lima/${NAME} " /* .log failure-logs/
115
142
limactl shell " $NAME " sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
116
143
set +x -e
117
144
}
118
145
119
146
export ftp_proxy=http://localhost:2121
120
147
121
- INFO " Creating \" $NAME \" from \" $FILE \" "
148
+ INFO " Creating \" $NAME \" from \" $FILE_HOST \" "
122
149
defer " limactl delete -f \" $NAME \" "
123
150
124
151
if [[ -n ${CHECKS["disk"]} ]]; then
130
157
131
158
set -x
132
159
# shellcheck disable=SC2086
133
- " ${LIMACTL_CREATE[@]} " ${LIMACTL_CREATE_ARGS} " $FILE "
160
+ " ${LIMACTL_CREATE[@]} " ${LIMACTL_CREATE_ARGS} " $FILE_HOST "
134
161
set +x
135
162
136
163
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
@@ -152,7 +179,7 @@ limactl shell "$NAME" cat /etc/os-release
152
179
set +x
153
180
154
181
INFO " Testing that host home is not wiped out"
155
- [ -e " $HOME /.lima" ]
182
+ [ -e " $HOME_HOST /.lima" ]
156
183
157
184
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
158
185
INFO ' Testing that "/tmp/lima test dir with spaces" is not wiped out'
@@ -179,23 +206,26 @@ if [[ -n ${CHECKS["set-user"]} ]]; then
179
206
limactl shell " $NAME " grep " ^john:x:4711:4711:John Doe:/home/john-john" /etc/passwd
180
207
fi
181
208
182
- INFO " Testing proxy settings are imported"
183
- got=$( limactl shell " $NAME " env | grep FTP_PROXY)
184
- # Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
185
- # by the gateway address, and the value is set immediately without a restart
186
- gatewayIp=$( limactl shell " $NAME " ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
187
- expected=" FTP_PROXY=http://${gatewayIp} :2121"
188
- INFO " FTP_PROXY: expected=${expected} got=${got} "
189
- if [ " $got " != " $expected " ]; then
190
- ERROR " proxy environment variable not set to correct value"
191
- exit 1
209
+ if [[ -n ${CHECKS["proxy-settings"]} ]]; then
210
+ INFO " Testing proxy settings are imported"
211
+ got=$( limactl shell " $NAME " env | grep FTP_PROXY)
212
+ # Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
213
+ # by the gateway address, and the value is set immediately without a restart
214
+ gatewayIp=$( limactl shell " $NAME " ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
215
+ expected=" FTP_PROXY=http://${gatewayIp} :2121"
216
+ INFO " FTP_PROXY: expected=${expected} got=${got} "
217
+ if [ " $got " != " $expected " ]; then
218
+ ERROR " proxy environment variable not set to correct value"
219
+ exit 1
220
+ fi
192
221
fi
193
222
194
223
INFO " Testing limactl copy command"
195
224
tmpdir=" $( mktemp -d " ${TMPDIR:-/ tmp} " /lima-test-templates.XXXXXX) "
196
225
defer " rm -rf \" $tmpdir \" "
197
226
tmpfile=" $tmpdir /lima-hostname"
198
227
rm -f " $tmpfile "
228
+ # TODO support Windows path https://github.com/lima-vm/lima/issues/3215
199
229
limactl cp " $NAME " :/etc/hostname " $tmpfile "
200
230
expected=" $( limactl shell " $NAME " cat /etc/hostname) "
201
231
got=" $( cat " $tmpfile " ) "
@@ -234,32 +264,38 @@ nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
234
264
alpine_image=" ghcr.io/containerd/alpine:3.14.0"
235
265
236
266
if [[ -n ${CHECKS["container-engine"]} ]]; then
267
+ sudo=" "
268
+ # Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
269
+ if [[ " $( limactl ls --json " ${NAME} " | jq -r .vmType) " == " wsl2" ]]; then
270
+ sudo=" sudo"
271
+ fi
237
272
INFO " Run a nginx container with port forwarding 127.0.0.1:8080"
238
273
set -x
239
- if ! limactl shell " $NAME " $CONTAINER_ENGINE info; then
240
- limactl shell " $NAME " sudo cat /var/log/cloud-init-output.log
274
+ if ! limactl shell " $NAME " $sudo $ CONTAINER_ENGINE info; then
275
+ limactl shell " $NAME " cat /var/log/cloud-init-output.log
241
276
ERROR " \" ${CONTAINER_ENGINE} info\" failed"
242
277
exit 1
243
278
fi
244
- limactl shell " $NAME " $CONTAINER_ENGINE pull --quiet ${nginx_image}
245
- limactl shell " $NAME " $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
279
+ limactl shell " $NAME " $sudo $ CONTAINER_ENGINE pull --quiet ${nginx_image}
280
+ limactl shell " $NAME " $sudo $ CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
246
281
247
282
timeout 3m bash -euxc " until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
248
283
249
- limactl shell " $NAME " $CONTAINER_ENGINE rm -f nginx
284
+ limactl shell " $NAME " $sudo $ CONTAINER_ENGINE rm -f nginx
250
285
set +x
251
286
if [[ -n ${CHECKS["mount-home"]} ]]; then
252
- hometmp=" $HOME /lima-container-engine-test-tmp"
287
+ hometmp=" $HOME_HOST /lima-container-engine-test-tmp"
288
+ hometmpguest=" $HOME_GUEST /lima-container-engine-test-tmp"
253
289
# test for https://github.com/lima-vm/lima/issues/187
254
290
INFO " Testing home bind mount (\" $hometmp \" )"
255
291
rm -rf " $hometmp "
256
292
mkdir -p " $hometmp "
257
293
defer " rm -rf \" $hometmp \" "
258
294
set -x
259
- limactl shell " $NAME " $CONTAINER_ENGINE pull --quiet ${alpine_image}
295
+ limactl shell " $NAME " $sudo $ CONTAINER_ENGINE pull --quiet ${alpine_image}
260
296
echo " random-content-${RANDOM} " > " $hometmp /random"
261
297
expected=" $( cat " $hometmp /random" ) "
262
- got=" $( limactl shell " $NAME " $CONTAINER_ENGINE run --rm -v " $hometmp /random" :/mnt/foo ${alpine_image} cat /mnt/foo) "
298
+ got=" $( limactl shell " $NAME " $sudo $ CONTAINER_ENGINE run --rm -v " $hometmpguest /random" :/mnt/foo ${alpine_image} cat /mnt/foo) "
263
299
INFO " $hometmp /random: expected=${expected} , got=${got} "
264
300
if [ " $got " != " $expected " ]; then
265
301
ERROR " Home directory is not shared?"
@@ -284,6 +320,9 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
284
320
if [ " ${NAME} " = " opensuse" ]; then
285
321
limactl shell " $NAME " sudo zypper in -y netcat-openbsd
286
322
fi
323
+ if limactl shell " $NAME " command -v dnf; then
324
+ limactl shell " $NAME " sudo dnf install -y nc
325
+ fi
287
326
" ${scriptdir} /test-port-forwarding.pl" " ${NAME} "
288
327
289
328
if [[ -n ${CHECKS["container-engine"]} || ${NAME} == " alpine" * ]]; then
@@ -306,6 +345,10 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
306
345
rm nerdctl-full.tgz
307
346
sudo=" sudo"
308
347
fi
348
+ # Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
349
+ if [[ " $( limactl ls --json " ${NAME} " | jq -r .vmType) " == " wsl2" ]]; then
350
+ sudo=" sudo"
351
+ fi
309
352
limactl shell " $NAME " $sudo $CONTAINER_ENGINE info
310
353
limactl shell " $NAME " $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
311
354
@@ -360,7 +403,8 @@ if [[ -n ${CHECKS["restart"]} ]]; then
360
403
fi
361
404
362
405
INFO " Stopping \" $NAME \" "
363
- limactl stop " $NAME "
406
+ # TODO https://github.com/lima-vm/lima/issues/3221
407
+ limactl stop " $NAME " || [ " ${OS_HOST} " = " Msys" ]
364
408
sleep 3
365
409
366
410
if [[ -n ${CHECKS["disk"]} ]]; then
406
450
if [[ -n ${CHECKS["user-v2"]} ]]; then
407
451
INFO " Testing user-v2 network"
408
452
secondvm=" $NAME -1"
409
- " ${LIMACTL_CREATE[@]} " --set " .additionalDisks=null" " $FILE " --name " $secondvm "
453
+ " ${LIMACTL_CREATE[@]} " --set " .additionalDisks=null" " $FILE_HOST " --name " $secondvm "
410
454
if ! limactl start " $secondvm " ; then
411
455
ERROR " Failed to start \" $secondvm \" "
412
456
diagnose " $secondvm "
@@ -474,7 +518,8 @@ if [[ $NAME == "fedora" && "$(limactl ls --json "$NAME" | jq -r .vmType)" == "vz
474
518
fi
475
519
476
520
INFO " Stopping \" $NAME \" "
477
- limactl stop " $NAME "
521
+ # TODO https://github.com/lima-vm/lima/issues/3221
522
+ limactl stop " $NAME " || [ " ${OS_HOST} " = " Msys" ]
478
523
sleep 3
479
524
480
525
INFO " Deleting \" $NAME \" "
0 commit comments