Skip to content

Commit 22d86cc

Browse files
committed
Enable Integration tests in Windows CI
Signed-off-by: Arthur Sengileyev <[email protected]>
1 parent 26a3821 commit 22d86cc

File tree

6 files changed

+96
-55
lines changed

6 files changed

+96
-55
lines changed

Diff for: .github/workflows/test.yml

+11-20
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ jobs:
129129
- name: Enable WSL2
130130
run: |
131131
wsl --set-default-version 2
132-
# Manually install the latest kernel from MSI
133-
Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile "wsl_update_x64.msi"
134-
$pwd = (pwd).Path
135-
Start-Process msiexec.exe -Wait -ArgumentList "/I $pwd\wsl_update_x64.msi /quiet"
132+
wsl --shutdown
136133
wsl --update
137134
wsl --status
135+
wsl --version
138136
wsl --list --online
139137
- name: Install WSL2 distro
140138
timeout-minutes: 1
@@ -160,22 +158,15 @@ jobs:
160158
run: go test -v ./...
161159
- name: Make
162160
run: make
163-
# FIXME: Windows CI began to fail on Oct 21, 2024.
164-
# Something seems to have changed between win22/20241006.1 and win22/20241015.1.
165-
# https://github.com/lima-vm/lima/issues/2775
166-
# - name: Smoke test
167-
# # Make sure the path is set properly and then run limactl
168-
# run: |
169-
# $env:Path = 'C:\Program Files\Git\usr\bin;' + $env:Path
170-
# Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $env:Path
171-
# .\_output\bin\limactl.exe start template://experimental/wsl2
172-
# # TODO: run the full integration tests
173-
# - name: Debug
174-
# if: always()
175-
# run: type C:\Users\runneradmin\.lima\wsl2\ha.stdout.log
176-
# - name: Debug
177-
# if: always()
178-
# run: type C:\Users\runneradmin\.lima\wsl2\ha.stderr.log
161+
- name: Integration tests (WSL2, Windows host)
162+
run: |
163+
$env:Path = "$pwd\_output\bin;" + 'C:\Program Files\Git\usr\bin;' + $env:Path
164+
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $env:Path
165+
$env:MSYS2_ENV_CONV_EXCL='HOME_HOST;HOME_GUEST'
166+
$env:HOME_HOST=$(cygpath.exe "$env:USERPROFILE")
167+
$env:HOME_GUEST="/mnt$env:HOME_HOST"
168+
$env:LIMACTL_CREATE_ARGS='--vm-type=wsl2 --mount-type=wsl2 --containerd=system'
169+
bash.exe -c "./hack/test-templates.sh templates/experimental/wsl2.yaml"
179170
180171
qemu:
181172
name: "Integration tests (QEMU, macOS host)"

Diff for: hack/common.inc.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
2323
exit 1
2424
fi
2525

26-
: "${LIMA_HOME:=$HOME/.lima}"
26+
: "${LIMA_HOME:=${HOME_HOST:-$HOME}/.lima}"
2727
_IPERF3=iperf3
2828
# iperf3-darwin does some magic on macOS to avoid "No route on host" on macOS 15
2929
# https://github.com/lima-vm/socket_vmnet/issues/85

Diff for: hack/test-mount-home.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ if [ "$#" -ne 1 ]; then
1111
fi
1212

1313
NAME="$1"
14-
hometmp="$HOME/lima-test-tmp"
14+
hometmp="${HOME_HOST:-$HOME}/lima-test-tmp"
15+
hometmpguest="${HOME_GUEST:-$HOME}/lima-test-tmp"
1516
INFO "Testing home access (\"$hometmp\")"
1617
rm -rf "$hometmp"
1718
mkdir -p "$hometmp"
1819
defer "rm -rf \"$hometmp\""
1920
echo "random-content-${RANDOM}" >"$hometmp/random"
2021
expected="$(cat "$hometmp/random")"
21-
got="$(limactl shell "$NAME" cat "$hometmp/random")"
22+
got="$(limactl shell "$NAME" cat "$hometmpguest/random")"
2223
INFO "$hometmp/random: expected=${expected}, got=${got}"
2324
if [ "$got" != "$expected" ]; then
2425
ERROR "Home directory is not shared?"

Diff for: hack/test-port-forwarding.pl

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
sleep 5;
130130

131131
# Record current log size, so we can skip prior output
132-
$ENV{LIMA_HOME} ||= "$ENV{HOME}/.lima";
132+
$ENV{HOME_HOST} ||= "$ENV{HOME}";
133+
$ENV{LIMA_HOME} ||= "$ENV{HOME_HOST}/.lima";
133134
my $ha_log = "$ENV{LIMA_HOME}/$instance/ha.stderr.log";
134135
my $ha_log_size = -s $ha_log or die;
135136

Diff for: hack/test-templates.sh

+76-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22
set -eu -o pipefail
33

4+
# will prevent msys2 converting Linux path arguments into Windows paths before passing to limactl
5+
export MSYS2_ARG_CONV_EXCL='*'
6+
47
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
58
# shellcheck source=common.inc.sh
69
source "${scriptdir}/common.inc.sh"
@@ -12,16 +15,27 @@ fi
1215

1316
FILE="$1"
1417
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
1528

16-
INFO "Validating \"$FILE\""
17-
limactl validate "$FILE"
29+
INFO "Validating \"$FILE_HOST\""
30+
limactl validate "$FILE_HOST"
1831

1932
# --cpus=1 is needed for running vz on GHA: https://github.com/lima-vm/lima/pull/1511#issuecomment-1574937888
2033
LIMACTL_CREATE=(limactl --tty=false create --cpus=1 --memory=1)
2134

2235
CONTAINER_ENGINE="nerdctl"
2336

2437
declare -A CHECKS=(
38+
["proxy-settings"]="1"
2539
["systemd"]="1"
2640
["systemd-strict"]="1"
2741
["mount-home"]="1"
@@ -69,6 +83,13 @@ case "$NAME" in
6983
"docker")
7084
CONTAINER_ENGINE="docker"
7185
;;
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+
;;
7293
esac
7394

7495
if limactl ls -q | grep -q "$NAME"; then
@@ -80,7 +101,7 @@ fi
80101
# TODO: skip downloading and converting the image here.
81102
# Probably `limactl create` should have "dry run" mode that just generates `lima.yaml`.
82103
# 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"
84105
case "$(yq '.networks[].lima' "${LIMA_HOME}/${NAME}-tmp/lima.yaml")" in
85106
"shared")
86107
CHECKS["vmnet"]=1
@@ -93,32 +114,38 @@ esac
93114
limactl rm -f "${NAME}-tmp"
94115

95116
if [[ -n ${CHECKS["port-forwards"]} ]]; then
96-
tmpconfig="$HOME/lima-config-tmp"
117+
tmpconfig="$HOME_HOST/lima-config-tmp"
97118
mkdir -p "${tmpconfig}"
98119
defer "rm -rf \"$tmpconfig\""
99120
tmpfile="${tmpconfig}/${NAME}.yaml"
100121
cp "$FILE" "${tmpfile}"
101122
FILE="${tmpfile}"
123+
FILE_HOST=$FILE
124+
if [ "${OS_HOST}" = "Msys" ]; then
125+
FILE_HOST="$(cygpath -w "$FILE")"
126+
fi
127+
102128
INFO "Setup port forwarding rules for testing in \"${FILE}\""
103129
"${scriptdir}/test-port-forwarding.pl" "${FILE}"
104-
limactl validate "$FILE"
130+
INFO "Validating \"$FILE_HOST\""
131+
limactl validate "$FILE_HOST"
105132
fi
106133

107134
function diagnose() {
108135
NAME="$1"
109136
set -x +e
110-
tail "$HOME/.lima/${NAME}"/*.log
137+
tail "$HOME_HOST/.lima/${NAME}"/*.log
111138
limactl shell "$NAME" systemctl --no-pager status
112139
limactl shell "$NAME" systemctl --no-pager
113140
mkdir -p failure-logs
114-
cp -pf "$HOME/.lima/${NAME}"/*.log failure-logs/
141+
cp -pf "$HOME_HOST/.lima/${NAME}"/*.log failure-logs/
115142
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
116143
set +x -e
117144
}
118145

119146
export ftp_proxy=http://localhost:2121
120147

121-
INFO "Creating \"$NAME\" from \"$FILE\""
148+
INFO "Creating \"$NAME\" from \"$FILE_HOST\""
122149
defer "limactl delete -f \"$NAME\""
123150

124151
if [[ -n ${CHECKS["disk"]} ]]; then
@@ -130,7 +157,7 @@ fi
130157

131158
set -x
132159
# shellcheck disable=SC2086
133-
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} "$FILE"
160+
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} "$FILE_HOST"
134161
set +x
135162

136163
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
@@ -152,7 +179,7 @@ limactl shell "$NAME" cat /etc/os-release
152179
set +x
153180

154181
INFO "Testing that host home is not wiped out"
155-
[ -e "$HOME/.lima" ]
182+
[ -e "$HOME_HOST/.lima" ]
156183

157184
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
158185
INFO 'Testing that "/tmp/lima test dir with spaces" is not wiped out'
@@ -179,23 +206,26 @@ if [[ -n ${CHECKS["set-user"]} ]]; then
179206
limactl shell "$NAME" grep "^john:x:4711:4711:John Doe:/home/john-john" /etc/passwd
180207
fi
181208

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
192221
fi
193222

194223
INFO "Testing limactl copy command"
195224
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/lima-test-templates.XXXXXX)"
196225
defer "rm -rf \"$tmpdir\""
197226
tmpfile="$tmpdir/lima-hostname"
198227
rm -f "$tmpfile"
228+
# TODO support Windows path https://github.com/lima-vm/lima/issues/3215
199229
limactl cp "$NAME":/etc/hostname "$tmpfile"
200230
expected="$(limactl shell "$NAME" cat /etc/hostname)"
201231
got="$(cat "$tmpfile")"
@@ -234,32 +264,38 @@ nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
234264
alpine_image="ghcr.io/containerd/alpine:3.14.0"
235265

236266
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
237272
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
238273
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
241276
ERROR "\"${CONTAINER_ENGINE} info\" failed"
242277
exit 1
243278
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}
246281

247282
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
248283

249-
limactl shell "$NAME" $CONTAINER_ENGINE rm -f nginx
284+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
250285
set +x
251286
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"
253289
# test for https://github.com/lima-vm/lima/issues/187
254290
INFO "Testing home bind mount (\"$hometmp\")"
255291
rm -rf "$hometmp"
256292
mkdir -p "$hometmp"
257293
defer "rm -rf \"$hometmp\""
258294
set -x
259-
limactl shell "$NAME" $CONTAINER_ENGINE pull --quiet ${alpine_image}
295+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${alpine_image}
260296
echo "random-content-${RANDOM}" >"$hometmp/random"
261297
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)"
263299
INFO "$hometmp/random: expected=${expected}, got=${got}"
264300
if [ "$got" != "$expected" ]; then
265301
ERROR "Home directory is not shared?"
@@ -284,6 +320,9 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
284320
if [ "${NAME}" = "opensuse" ]; then
285321
limactl shell "$NAME" sudo zypper in -y netcat-openbsd
286322
fi
323+
if limactl shell "$NAME" command -v dnf; then
324+
limactl shell "$NAME" sudo dnf install -y nc
325+
fi
287326
"${scriptdir}/test-port-forwarding.pl" "${NAME}"
288327

289328
if [[ -n ${CHECKS["container-engine"]} || ${NAME} == "alpine"* ]]; then
@@ -306,6 +345,10 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
306345
rm nerdctl-full.tgz
307346
sudo="sudo"
308347
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
309352
limactl shell "$NAME" $sudo $CONTAINER_ENGINE info
310353
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
311354

@@ -360,7 +403,8 @@ if [[ -n ${CHECKS["restart"]} ]]; then
360403
fi
361404

362405
INFO "Stopping \"$NAME\""
363-
limactl stop "$NAME"
406+
# TODO https://github.com/lima-vm/lima/issues/3221
407+
limactl stop "$NAME" || [ "${OS_HOST}" = "Msys" ]
364408
sleep 3
365409

366410
if [[ -n ${CHECKS["disk"]} ]]; then
@@ -406,7 +450,7 @@ fi
406450
if [[ -n ${CHECKS["user-v2"]} ]]; then
407451
INFO "Testing user-v2 network"
408452
secondvm="$NAME-1"
409-
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE" --name "$secondvm"
453+
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE_HOST" --name "$secondvm"
410454
if ! limactl start "$secondvm"; then
411455
ERROR "Failed to start \"$secondvm\""
412456
diagnose "$secondvm"
@@ -474,7 +518,8 @@ if [[ $NAME == "fedora" && "$(limactl ls --json "$NAME" | jq -r .vmType)" == "vz
474518
fi
475519

476520
INFO "Stopping \"$NAME\""
477-
limactl stop "$NAME"
521+
# TODO https://github.com/lima-vm/lima/issues/3221
522+
limactl stop "$NAME" || [ "${OS_HOST}" = "Msys" ]
478523
sleep 3
479524

480525
INFO "Deleting \"$NAME\""

Diff for: pkg/osutil/user.go

+3
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ func LimaUser(limaVersion string, warn bool) *user.User {
144144
home, err := call([]string{"cygpath", limaUser.HomeDir})
145145
if err != nil {
146146
logrus.Debug(err)
147+
} else {
148+
home += ".linux"
147149
}
148150
if home == "" {
149151
drive := filepath.VolumeName(limaUser.HomeDir)
150152
home = filepath.ToSlash(limaUser.HomeDir)
151153
// replace C: with /c
152154
prefix := strings.ToLower(fmt.Sprintf("/%c", drive[0]))
153155
home = strings.Replace(home, drive, prefix, 1)
156+
home += ".linux"
154157
}
155158
if !regexPath.MatchString(limaUser.HomeDir) {
156159
warning := fmt.Sprintf("local home %q is not a valid Linux path (must match %q); using %q home instead",

0 commit comments

Comments
 (0)