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