Skip to content

Commit 722afea

Browse files
authored
Add OSModifier vmtests into github workflow (#363)
<!-- Description: Please provide a summary of the changes and the motivation behind them. --> a successful build: https://github.com/microsoft/azure-linux-image-tools/actions/runs/16946893526/job/48030310797 --- ### **Checklist** - [ ] Tests added/updated - [ ] Documentation updated (if needed) - [ ] Code conforms to style guidelines --------- Signed-off-by: Elaine Zhao <[email protected]>
1 parent f6cb22b commit 722afea

File tree

4 files changed

+226
-7
lines changed

4 files changed

+226
-7
lines changed

.github/workflows/binary-build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ jobs:
205205
uses: actions/upload-artifact@v4
206206
with:
207207
name: imagecreator-binary-${{ inputs.arch }}
208-
path: repo/toolkit/out/imagecreator.tar.gz
208+
path: repo/toolkit/out/imagecreator.tar.gz
209+
210+
- name: Upload osmodifier artifact
211+
uses: actions/upload-artifact@v4
212+
with:
213+
name: osmodifier-${{ inputs.arch }}
214+
path: repo/toolkit/out/tools/osmodifier

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,30 @@ jobs:
143143
with:
144144
hostArch: arm64
145145
hostDistro: ubuntu2404
146+
147+
tests-vmtests-osmodifier-azl3-amd64:
148+
name: VMTests suite osmodifier AZL3 AMD64
149+
if: ${{ inputs.runVMTests }}
150+
needs: binary-build-amd64
151+
uses: ./.github/workflows/tests-vmtests-osmodifier.yml
152+
with:
153+
hostArch: amd64
154+
hostDistro: azl3
155+
156+
tests-vmtests-osmodifier-ubuntu2404-amd64:
157+
name: VMTests suite osmodifier Ubuntu24.04 AMD64
158+
if: ${{ inputs.runVMTests }}
159+
needs: binary-build-amd64
160+
uses: ./.github/workflows/tests-vmtests-osmodifier.yml
161+
with:
162+
hostArch: amd64
163+
hostDistro: ubuntu2404
164+
165+
tests-vmtests-osmodifier-ubuntu2404-arm64:
166+
name: VMTests suite osmodifier Ubuntu24.04 ARM64
167+
if: ${{ inputs.runVMTests }}
168+
needs: binary-build-arm64
169+
uses: ./.github/workflows/tests-vmtests-osmodifier.yml
170+
with:
171+
hostArch: arm64
172+
hostDistro: ubuntu2404
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
name: Tests VMTests suite for OSModifier
5+
6+
permissions:
7+
contents: read
8+
# Azure login.
9+
id-token: write
10+
11+
on:
12+
workflow_call:
13+
inputs:
14+
hostArch:
15+
required: true
16+
type: string
17+
hostDistro:
18+
required: true
19+
type: string
20+
21+
env:
22+
EXPECTED_GO_VERSION: "1.24.1"
23+
24+
jobs:
25+
tests-osmodifier:
26+
name: Tests VMTests suite
27+
runs-on:
28+
- self-hosted
29+
- 1ES.Pool=${{ inputs.hostDistro == 'azl3' && (inputs.hostArch == 'amd64' && 'maritimus-github-runner-azl3-amd64' || 'maritimus-github-runner-azl3-arm64') || (inputs.hostArch == 'amd64' && 'maritimus-github-runner-ubuntu2404-amd64' || 'maritimus-github-runner-ubuntu2404-arm64') }}
30+
permissions:
31+
contents: read
32+
# Azure login.
33+
id-token: write
34+
environment: public
35+
steps:
36+
- name: Setup Go toolchain
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: "${{ env.EXPECTED_GO_VERSION }}"
40+
41+
- name: Install prerequisites (AZL3)
42+
if: inputs.hostDistro == 'azl3'
43+
run: |
44+
set -eux
45+
46+
sudo tdnf install -y libvirt libvirt-daemon libvirt-daemon-config-network \
47+
libvirt-daemon-kvm libvirt-devel qemu-kvm qemu-img python3-libvirt \
48+
python3-devel edk2-ovmf \
49+
azure-cli
50+
51+
sudo tdnf list installed
52+
53+
sudo systemctl restart libvirtd
54+
sudo systemctl status libvirtd
55+
56+
- name: Install prerequisites (Ubuntu 24.04)
57+
if: inputs.hostDistro == 'ubuntu2404'
58+
run: |
59+
set -eux
60+
61+
sudo apt update -y
62+
sudo apt -y install python3-venv python3-pip python3-dev \
63+
libvirt-dev libvirt-daemon libvirt-daemon-system libvirt-clients \
64+
qemu-kvm virt-manager
65+
66+
# Install arm64 specific
67+
if [[ "$HOST_ARCH" == "arm64" ]]; then
68+
sudo apt -y install qemu-system-arm qemu-efi-aarch64 ovmf seabios
69+
fi
70+
71+
sudo apt list --installed
72+
73+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
74+
env:
75+
HOST_ARCH: ${{ inputs.hostArch }}
76+
77+
- name: Azure Login
78+
uses: azure/login@v2
79+
with:
80+
client-id: ${{ vars.AZURE_CLIENT_ID }}
81+
tenant-id: ${{ vars.AZURE_TENANT_ID }}
82+
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
83+
84+
- name: Checkout
85+
uses: actions/checkout@v4
86+
with:
87+
path: repo
88+
89+
- name: Download build artifacts
90+
uses: actions/download-artifact@v4
91+
with:
92+
path: out
93+
94+
- name: Import container
95+
id: importContainer
96+
run: |
97+
set -eux
98+
99+
CONTAINER_TAR_PATH="out/container-${{ inputs.hostArch }}/imagecustomizer.tar.gz"
100+
DOCKER_OUTPUT=$(sudo docker image load -i "$CONTAINER_TAR_PATH" 2>&1)
101+
CONTAINER_TAG=$(echo $DOCKER_OUTPUT | awk '{print $3}')
102+
103+
echo "containerTag=$CONTAINER_TAG" >> "$GITHUB_OUTPUT"
104+
env:
105+
HOST_ARCH: ${{ inputs.hostArch }}
106+
107+
- name: Verify osmodifier binary
108+
id: osmodifier_bin
109+
run: |
110+
set -eux
111+
112+
OSMODIFIER_BIN="$(realpath out/osmodifier-${{ inputs.hostArch }}/osmodifier)"
113+
[[ -f "$OSMODIFIER_BIN" ]] || { echo "osmodifier binary not found at $OSMODIFIER_BIN"; ls -la out/; exit 1; }
114+
chmod +x "$OSMODIFIER_BIN"
115+
echo "path=$OSMODIFIER_BIN" >> "$GITHUB_OUTPUT"
116+
117+
- name: Download base images
118+
run: |
119+
set -eux
120+
121+
./repo/.github/workflows/scripts/download-image.sh "$AZURE_STORAGE" "$AZURE_CONTAINER" "azure-linux/core-efi-vhdx-2.0-$HOST_ARCH" azl-core-efi-2.0
122+
./repo/.github/workflows/scripts/download-image.sh "$AZURE_STORAGE" "$AZURE_CONTAINER" "azure-linux/core-efi-vhdx-3.0-$HOST_ARCH" azl-core-efi-3.0
123+
env:
124+
HOST_ARCH: ${{ inputs.hostArch }}
125+
AZURE_STORAGE: ${{ vars.AZURE_STORAGE }}
126+
AZURE_CONTAINER: ${{ vars.AZURE_CONTAINER }}
127+
128+
- name: Setup input image
129+
id: setup_image
130+
run: |
131+
set -eux
132+
pushd repo/toolkit/tools
133+
134+
AZL2_IMAGE="../../../azl-core-efi-2.0/image.vhdx"
135+
AZL3_IMAGE="../../../azl-core-efi-3.0/image.vhdx"
136+
137+
echo "azl2_path=$AZL2_IMAGE" >> "$GITHUB_OUTPUT"
138+
echo "azl3_path=$AZL3_IMAGE" >> "$GITHUB_OUTPUT"
139+
140+
- name: Test setup
141+
run: |
142+
set -eux
143+
144+
pushd ./repo/test/vmtests
145+
146+
# Ensure an ssh key exists.
147+
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
148+
149+
make create-venv
150+
151+
- name: Run OSModifier tests - AZL 2.0
152+
if: ${{ inputs.hostArch == 'amd64' }} # Skip ARM64
153+
env:
154+
IMAGE_CUSTOMIZER_CONTAINER_TAG: ${{ steps.importContainer.outputs.containerTag }}
155+
OSMODIFIER_BIN: ${{ steps.osmodifier_bin.outputs.path }}
156+
INPUT_IMAGE: ${{ steps.setup_image.outputs.azl2_path }}
157+
run: |
158+
set -eux
159+
pushd ./repo/test/vmtests
160+
161+
sudo make test-osmodifier \
162+
IMAGE_CUSTOMIZER_CONTAINER_TAG="${IMAGE_CUSTOMIZER_CONTAINER_TAG}" \
163+
OSMODIFIER_BIN="${OSMODIFIER_BIN}" \
164+
INPUT_IMAGE="${INPUT_IMAGE}" \
165+
SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519
166+
167+
- name: Run OSModifier tests - AZL 3.0
168+
env:
169+
IMAGE_CUSTOMIZER_CONTAINER_TAG: ${{ steps.importContainer.outputs.containerTag }}
170+
OSMODIFIER_BIN: ${{ steps.osmodifier_bin.outputs.path }}
171+
INPUT_IMAGE: ${{ steps.setup_image.outputs.azl3_path }}
172+
run: |
173+
set -eux
174+
pushd ./repo/test/vmtests
175+
176+
sudo make test-osmodifier \
177+
IMAGE_CUSTOMIZER_CONTAINER_TAG="${IMAGE_CUSTOMIZER_CONTAINER_TAG}" \
178+
OSMODIFIER_BIN="${OSMODIFIER_BIN}" \
179+
INPUT_IMAGE="${INPUT_IMAGE}" \
180+
SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519
181+
182+
- uses: actions/upload-artifact@v4
183+
if: ${{ !cancelled() }}
184+
with:
185+
name: tests-results-osmodifier-${{ inputs.hostDistro }}-${{ inputs.hostArch }}
186+
path: repo/test/vmtests/out

test/vmtests/vmtests/osmodifier/test_osmodifier.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import platform
77
import tempfile
8-
from getpass import getuser
98
from pathlib import Path
109
from typing import List, Tuple
1110

@@ -22,6 +21,7 @@
2221
from ..utils.libvirt_utils import VmSpec, create_libvirt_domain_xml
2322
from ..utils.libvirt_vm import LibvirtVm
2423
from ..utils.ssh_client import SshClient
24+
from ..utils.user_utils import get_username
2525

2626

2727
@pytest.fixture(scope="session")
@@ -53,7 +53,7 @@ def setup_vm_with_osmodifier(
5353
target_boot_type = source_boot_type
5454

5555
output_image_path = session_temp_dir.joinpath("image." + output_format)
56-
username = getuser()
56+
username = get_username()
5757

5858
run_image_customizer(
5959
docker_client,
@@ -210,14 +210,14 @@ def test_modify_kernel_modules(
210210
module_load_path = "/etc/modules-load.d/modules-load.conf"
211211
module_options_path = "/etc/modprobe.d/module-options.conf"
212212

213-
load_content = ssh_client.run(f"cat {module_load_path} || true").stdout
213+
load_content = ssh_client.run(f"sudo cat {module_load_path} || true").stdout
214214
assert "vfio" in load_content
215215
assert "mlx5_ib" in load_content
216216

217-
disabled_content = ssh_client.run(f"cat {module_disabled_path} || true").stdout
217+
disabled_content = ssh_client.run(f"sudo cat {module_disabled_path} || true").stdout
218218
assert "blacklist mousedev" in disabled_content
219219

220-
options_content = ssh_client.run(f"cat {module_options_path} || true").stdout
220+
options_content = ssh_client.run(f"sudo cat {module_options_path} || true").stdout
221221
assert "options vfio" in options_content
222222
assert "enable_unsafe_noiommu_mode=Y" in options_content
223223
assert "disable_vga=Y" in options_content
@@ -238,7 +238,7 @@ def test_update_hostname(
238238
logs_dir / "test_hostname.log",
239239
)
240240

241-
actual_hostname = ssh_client.run("cat /etc/hostname").stdout.strip()
241+
actual_hostname = ssh_client.run("sudo cat /etc/hostname").stdout.strip()
242242
expected_hostname = "testname"
243243
assert actual_hostname == expected_hostname, f"Expected hostname '{expected_hostname}', got '{actual_hostname}'"
244244

0 commit comments

Comments
 (0)