Skip to content

Commit fc9c1a6

Browse files
committed
add fedora42 vmtests
1 parent 7a0d7a7 commit fc9c1a6

File tree

5 files changed

+188
-30
lines changed

5 files changed

+188
-30
lines changed

.github/workflows/tests-vmtests-imagecreator.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ jobs:
119119
run: |
120120
set -eux
121121
122-
# Download the test RPM and tools file.
123-
./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -t 3.0 -s true
122+
# Download the test RPM and tools file for azurelinux
123+
./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d azurelinux -t 3.0 -s true
124+
# Download the test RPM and tools file for fedora
125+
./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d fedora -t 42 -s true
124126
125127
126128
- name: Run image creator tests
@@ -129,13 +131,20 @@ jobs:
129131
130132
pushd ./repo/test/vmtests
131133
132-
sudo make test-imagecreator \
134+
sudo make test-imagecreator-azurelinux \
133135
IMAGE_CREATOR_BIN="../../toolkit/out/tools/imagecreator" \
134136
TOOLS_TAR="../../toolkit/tools/internal/testutils/testrpms/build/tools-azurelinux-3.0.tar.gz" \
135137
RPM_SOURCES="../../toolkit/tools/internal/testutils/testrpms/downloadedrpms/azurelinux/3.0" \
136138
IMAGE_CUSTOMIZER_BINARY_PATH="../../toolkit/out/tools/imagecustomizer" \
137139
SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519
138140
141+
sudo make test-imagecreator-fedora \
142+
IMAGE_CREATOR_BIN="../../toolkit/out/tools/imagecreator" \
143+
TOOLS_TAR="../../toolkit/tools/internal/testutils/testrpms/build/tools-fedora-42.tar.gz" \
144+
RPM_SOURCES="../../toolkit/tools/internal/testutils/testrpms/downloadedrpms/fedora/42" \
145+
IMAGE_CUSTOMIZER_BINARY_PATH="../../toolkit/out/tools/imagecustomizer" \
146+
SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519
147+
139148
- uses: actions/upload-artifact@v4
140149
if: ${{ !cancelled() }}
141150
with:

test/vmtests/Makefile

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,26 @@ test-imagecustomizer:
9999
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
100100
./vmtests/imagecustomizer/test_min_change.py
101101

102-
.PHONY: test-imagecreator
103-
test-imagecreator:
102+
.PHONY: test-osmodifier
103+
test-osmodifier:
104+
${PYTEST} \
105+
--image-customizer-container-url="${IMAGE_CUSTOMIZER_CONTAINER_TAG}" \
106+
--osmodifier-binary="${OSMODIFIER_BIN}" \
107+
--logs-dir="${LOGS_DIR}" \
108+
--input-image="${INPUT_IMAGE}" \
109+
--ssh-private-key="${SSH_PRIVATE_KEY_FILE}" \
110+
$(if $(filter y,$(KEEP_ENVIRONMENT)),--keep-environment) \
111+
--log-cli-level=DEBUG \
112+
--show-capture=all \
113+
--tb=short \
114+
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
115+
./vmtests/osmodifier/test_osmodifier.py
116+
117+
.PHONY: run-imagecustomizer
118+
run-imagecustomizer: image-customizer-container test-imagecustomizer
119+
120+
.PHONY: test-imagecreator-azurelinux
121+
test-imagecreator-azurelinux:
104122
${PYTEST} \
105123
--image-creator-binary-path="${IMAGE_CREATOR_BIN}" \
106124
--rpm-sources="${RPM_SOURCES}" \
@@ -114,26 +132,23 @@ test-imagecreator:
114132
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
115133
./vmtests/imagecreator/test_imagecreator.py
116134

117-
.PHONY: test-osmodifier
118-
test-osmodifier:
135+
.PHONY: test-imagecreator-fedora
136+
test-imagecreator-fedora:
119137
${PYTEST} \
120-
--image-customizer-container-url="${IMAGE_CUSTOMIZER_CONTAINER_TAG}" \
121-
--osmodifier-binary="${OSMODIFIER_BIN}" \
122-
--logs-dir="${LOGS_DIR}" \
123-
--input-image="${INPUT_IMAGE}" \
138+
--image-creator-binary-path="${IMAGE_CREATOR_BIN}" \
139+
--rpm-sources="${RPM_SOURCES}" \
140+
--tools-tar="${TOOLS_TAR}" \
141+
--image-customizer-binary-path="${IMAGE_CUSTOMIZER_BINARY_PATH}" \
124142
--ssh-private-key="${SSH_PRIVATE_KEY_FILE}" \
125143
$(if $(filter y,$(KEEP_ENVIRONMENT)),--keep-environment) \
126144
--log-cli-level=DEBUG \
127145
--show-capture=all \
128146
--tb=short \
129147
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
130-
./vmtests/osmodifier/test_osmodifier.py
131-
132-
.PHONY: run-imagecustomizer
133-
run-imagecustomizer: image-customizer-container test-imagecustomizer
148+
./vmtests/imagecreator/test_imagecreator_fedora.py
134149

135150
.PHONY: run-imagecreator
136-
run-imagecreator: ${IMAGE_CREATOR_BIN} test-imagecreator
151+
run-imagecreator: ${IMAGE_CREATOR_BIN} test-imagecreator-azurelinux test-imagecreator-fedora
137152

138153
.PHONY: run-osmodifier
139154
run-osmodifier: ${OSMODIFIER_BIN} test-osmodifier

test/vmtests/vmtests/imagecreator/test_imagecreator.py

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def run_image_creator_test(
8989
base_ssh_config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("ssh-base-config.yaml")
9090
customizer_config_path_obj = add_ssh_to_config(base_ssh_config_path, username, ssh_public_key, close_list)
9191

92+
# add previewFeatures section if distro is Fedora
93+
if distro.lower() == "fedora":
94+
with open(customizer_config_path_obj, "a") as config_fd:
95+
config_fd.write("\npreviewFeatures:\n - fedora-42\n") # Assuming Fedora 42 for this test
96+
9297
run_image_customizer_binary(
9398
image_customizer_binary_path,
9499
initial_output_image_path,
@@ -185,36 +190,113 @@ def run_image_creator_test(
185190
logging.info(f"Attempting to connect to VM via SSH")
186191
logging.info(f"Username: {username}")
187192

188-
with vm.create_ssh_client(ssh_private_key_path, test_temp_dir, username) as ssh_client:
189-
logging.info(f"SSH connection established successfully!")
190-
# Run the test
191-
logging.info(f"Running basic checks on the VM")
192-
run_basic_checks(ssh_client, test_temp_dir)
193-
logging.info(f"Basic checks completed successfully!")
193+
try:
194+
with vm.create_ssh_client(ssh_private_key_path, test_temp_dir, username) as ssh_client:
195+
logging.info("SSH connection established successfully!")
196+
# Test SSH connectivity and shell access
197+
result = ssh_client.run("whoami")
198+
if result.exit_code != 0:
199+
logging.error("Failed to execute basic SSH command")
200+
logging.error(f"Command output: {result.stdout}")
201+
logging.error(f"Command error: {result.stderr}")
202+
raise RuntimeError("SSH connection test failed")
203+
204+
# Run the test
205+
logging.info("Running basic checks on the VM")
206+
if distro.lower() == "fedora":
207+
run_basic_checks_fedora(ssh_client, test_temp_dir)
208+
else:
209+
run_basic_checks_azurelinux(ssh_client, test_temp_dir)
210+
logging.info("Basic checks completed successfully!")
211+
except Exception as e:
212+
logging.error(f"Failed to establish or verify SSH connection: {str(e)}")
213+
logging.error("VM Console output:")
214+
with open(vm_console_log_file_path, "r") as f:
215+
logging.error(f.read())
216+
raise
217+
218+
219+
def _verify_common_packages(ssh_client: SshClient) -> None:
220+
"""Verify packages that should be present in all distributions."""
221+
packages_to_check = ["kernel", "systemd", "bash"]
222+
for package in packages_to_check:
223+
logging.info(f"Checking package: {package}")
224+
result = ssh_client.run(f"rpm -q {package}")
225+
try:
226+
result.check_exit_code()
227+
except Exception as e:
228+
logging.error(f"Failed to verify package {package}: {str(e)}")
229+
logging.error(f"Command output: {result.stdout}")
230+
logging.error(f"Command error: {result.stderr}")
231+
raise
232+
233+
234+
def run_basic_checks_fedora(
235+
ssh_client: SshClient,
236+
test_temp_dir: Path,
237+
) -> None:
238+
"""Run basic checks specific to Fedora images."""
239+
ssh_client.run("cat /proc/cmdline").check_exit_code()
194240

241+
os_release_path = test_temp_dir.joinpath("os-release")
242+
ssh_client.get_file(Path("/etc/os-release"), os_release_path)
195243

196-
def run_basic_checks(
244+
with open(os_release_path, "r") as os_release_fd:
245+
os_release_text = os_release_fd.read()
246+
logging.info("OS Release content:")
247+
logging.info(os_release_text)
248+
249+
# Verify Fedora-specific os-release content
250+
assert "ID=fedora" in os_release_text
251+
assert 'VERSION="42 (Adams)"' in os_release_text
252+
253+
# Check common packages
254+
logging.info("Checking essential packages...")
255+
_verify_common_packages(ssh_client)
256+
257+
# Check Fedora-specific bootloader packages
258+
logging.info("Checking bootloader packages...")
259+
try:
260+
result = ssh_client.run("rpm -q grub2-efi-x64")
261+
result.check_exit_code()
262+
except Exception:
263+
logging.warning("grub2-efi-x64 not found, trying grub2-pc...")
264+
result = ssh_client.run("rpm -q grub2-pc")
265+
try:
266+
result.check_exit_code()
267+
except Exception as e:
268+
logging.error(f"Failed to find any grub2 package: {str(e)}")
269+
logging.error(f"Command error: {result.stderr}")
270+
raise
271+
272+
273+
def run_basic_checks_azurelinux(
197274
ssh_client: SshClient,
198275
test_temp_dir: Path,
199276
) -> None:
200-
277+
"""Run basic checks specific to Azure Linux images."""
201278
ssh_client.run("cat /proc/cmdline").check_exit_code()
202279

203280
os_release_path = test_temp_dir.joinpath("os-release")
204281
ssh_client.get_file(Path("/etc/os-release"), os_release_path)
205282

206283
with open(os_release_path, "r") as os_release_fd:
207284
os_release_text = os_release_fd.read()
285+
logging.info("OS Release content:")
286+
logging.info(os_release_text)
208287

209-
# Since imagecreator creates new images, we expect Azure Linux 3.0
288+
# Verify Azure Linux-specific os-release content
210289
assert "ID=azurelinux" in os_release_text
211290
assert 'VERSION_ID="3.0"' in os_release_text
212291

213-
# Check that essential packages are installed
214-
ssh_client.run("rpm -q kernel").check_exit_code()
215-
ssh_client.run("rpm -q systemd").check_exit_code()
216-
ssh_client.run("rpm -q grub2").check_exit_code()
217-
ssh_client.run("rpm -q bash").check_exit_code()
292+
# Check common packages
293+
logging.info("Checking essential packages...")
294+
_verify_common_packages(ssh_client)
295+
296+
# Check Azure Linux bootloader package
297+
logging.info("Checking bootloader packages...")
298+
result = ssh_client.run("rpm -q grub2")
299+
result.check_exit_code()
218300

219301

220302
@pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
import logging
5+
import platform
6+
from pathlib import Path
7+
from typing import List, Tuple
8+
9+
import libvirt # type: ignore
10+
import pytest
11+
12+
from ..utils.closeable import Closeable
13+
from .test_imagecreator import IMAGECREATOR_TEST_CONFIGS_DIR, run_image_creator_test
14+
15+
16+
@pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination")
17+
def test_create_image_efi_qcow_output_fedora(
18+
image_creator_binary_path: Path,
19+
rpm_sources: List[Path],
20+
tools_tar: Path,
21+
ssh_key: Tuple[str, Path],
22+
test_temp_dir: Path,
23+
test_instance_name: str,
24+
logs_dir: Path,
25+
libvirt_conn: libvirt.virConnect,
26+
close_list: List[Closeable],
27+
image_customizer_binary_path: Path,
28+
) -> None:
29+
config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("fedora.yaml")
30+
output_format = "qcow2"
31+
32+
# debug message
33+
logging.debug("Running test_create_image_efi_qcow_output_fedora")
34+
35+
run_image_creator_test(
36+
image_creator_binary_path,
37+
rpm_sources,
38+
tools_tar,
39+
config_path,
40+
output_format,
41+
ssh_key,
42+
test_temp_dir,
43+
test_instance_name,
44+
logs_dir,
45+
libvirt_conn,
46+
close_list,
47+
image_customizer_binary_path,
48+
"fedora",
49+
"42",
50+
)

toolkit/tools/pkg/imagecreatorlib/testdata/fedora.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ os:
4949
- libxkbcommon
5050
- shim-x64
5151
- kernel
52+
# Add dnf to support dnf based package installation in imagecustomizer
53+
- dnf
5254

0 commit comments

Comments
 (0)