Skip to content

Commit a08147c

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

File tree

6 files changed

+186
-18
lines changed

6 files changed

+186
-18
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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ 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-imagecreator-azurelinux
103+
test-imagecreator-azurelinux:
104104
${PYTEST} \
105105
--image-creator-binary-path="${IMAGE_CREATOR_BIN}" \
106106
--rpm-sources="${RPM_SOURCES}" \
@@ -114,6 +114,21 @@ test-imagecreator:
114114
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
115115
./vmtests/imagecreator/test_imagecreator.py
116116

117+
.PHONY: test-imagecreator-fedora
118+
test-imagecreator-fedora:
119+
${PYTEST} \
120+
--image-creator-binary-path="${IMAGE_CREATOR_BIN}" \
121+
--rpm-sources="${RPM_SOURCES}" \
122+
--tools-tar="${TOOLS_TAR}" \
123+
--image-customizer-binary-path="${IMAGE_CUSTOMIZER_BINARY_PATH}" \
124+
--ssh-private-key="${SSH_PRIVATE_KEY_FILE}" \
125+
$(if $(filter y,$(KEEP_ENVIRONMENT)),--keep-environment) \
126+
--log-cli-level=DEBUG \
127+
--show-capture=all \
128+
--tb=short \
129+
--junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \
130+
./vmtests/imagecreator/test_imagecreator_fedora.py
131+
117132
.PHONY: test-osmodifier
118133
test-osmodifier:
119134
${PYTEST} \
@@ -133,7 +148,7 @@ test-osmodifier:
133148
run-imagecustomizer: image-customizer-container test-imagecustomizer
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: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import platform
77
from pathlib import Path
8-
from typing import List, Tuple
8+
from typing import Any, Dict, List, Tuple
99

1010
import libvirt # type: ignore
1111
import pytest
@@ -14,7 +14,7 @@
1414
from ..utils.closeable import Closeable
1515
from ..utils.host_utils import get_host_distro
1616
from ..utils.imagecreator import run_image_creator, run_image_customizer_binary
17-
from ..utils.imagecustomizer import add_ssh_to_config
17+
from ..utils.imagecustomizer import add_preview_features_to_config, add_ssh_to_config
1818
from ..utils.libvirt_utils import VmSpec, create_libvirt_domain_xml
1919
from ..utils.libvirt_vm import LibvirtVm
2020
from ..utils.ssh_client import SshClient
@@ -25,6 +25,27 @@
2525
"toolkit/tools/pkg/imagecreatorlib/testdata"
2626
)
2727

28+
# Common packages that should be present in all distributions
29+
COMMON_PACKAGES = ["kernel", "systemd", "bash"]
30+
31+
# Distribution-specific configuration
32+
DISTRO_CONFIGS: Dict[str, Dict[str, Any]] = {
33+
"fedora": {
34+
"os_release": {
35+
"ID": "fedora",
36+
"VERSION_ID": "42",
37+
},
38+
"packages": COMMON_PACKAGES + ["grub2-efi-x64"],
39+
},
40+
"azurelinux": {
41+
"os_release": {
42+
"ID": "azurelinux",
43+
"VERSION_ID": "3.0",
44+
},
45+
"packages": COMMON_PACKAGES + ["grub2"],
46+
},
47+
}
48+
2849

2950
def run_image_creator_test(
3051
image_creator_binary_path: Path,
@@ -89,6 +110,10 @@ def run_image_creator_test(
89110
base_ssh_config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("ssh-base-config.yaml")
90111
customizer_config_path_obj = add_ssh_to_config(base_ssh_config_path, username, ssh_public_key, close_list)
91112

113+
# Add Fedora preview features if needed
114+
if distro.lower() == "fedora":
115+
customizer_config_path_obj = add_preview_features_to_config(customizer_config_path_obj, "fedora-42", close_list)
116+
92117
run_image_customizer_binary(
93118
image_customizer_binary_path,
94119
initial_output_image_path,
@@ -189,32 +214,65 @@ def run_image_creator_test(
189214
logging.info(f"SSH connection established successfully!")
190215
# Run the test
191216
logging.info(f"Running basic checks on the VM")
192-
run_basic_checks(ssh_client, test_temp_dir)
217+
run_basic_checks(ssh_client, test_temp_dir, distro)
193218
logging.info(f"Basic checks completed successfully!")
194219

195220

221+
def verify_packages(ssh_client: SshClient, packages_to_check: List[str]) -> None:
222+
"""Verify that specified packages are present in the system.
223+
224+
Args:
225+
ssh_client: SSH client connected to the target system
226+
packages_to_check: List of package names to verify
227+
"""
228+
for package in packages_to_check:
229+
ssh_client.run(f"rpm -q {package}").check_exit_code()
230+
231+
232+
def verify_os_release(os_release_text: str, expected_values: Dict[str, str]) -> None:
233+
"""Verify os-release content matches expected values.
234+
235+
Args:
236+
os_release_text: Content of os-release file
237+
expected_values: Dictionary of key-value pairs to verify
238+
"""
239+
for key, value in expected_values.items():
240+
expected = f"{key}={value}"
241+
assert expected in os_release_text, f"Expected '{expected}' in os-release, but not found"
242+
243+
196244
def run_basic_checks(
197245
ssh_client: SshClient,
198246
test_temp_dir: Path,
247+
distro: str,
199248
) -> None:
249+
"""Run basic checks for the specified distribution.
200250
251+
Args:
252+
ssh_client: SSH client for running commands
253+
test_temp_dir: Temporary directory for test artifacts
254+
distro: Distribution name (must be a key in DISTRO_CONFIGS)
255+
"""
256+
if distro not in DISTRO_CONFIGS:
257+
raise ValueError(f"Unsupported distribution: {distro}")
258+
259+
config = DISTRO_CONFIGS[distro]
260+
261+
# Check kernel cmdline
201262
ssh_client.run("cat /proc/cmdline").check_exit_code()
202263

264+
# Get and verify os-release
203265
os_release_path = test_temp_dir.joinpath("os-release")
204266
ssh_client.get_file(Path("/etc/os-release"), os_release_path)
205267

206268
with open(os_release_path, "r") as os_release_fd:
207269
os_release_text = os_release_fd.read()
270+
os_release_config = {str(k): str(v) for k, v in config["os_release"].items()}
271+
verify_os_release(os_release_text, os_release_config)
208272

209-
# Since imagecreator creates new images, we expect Azure Linux 3.0
210-
assert "ID=azurelinux" in os_release_text
211-
assert 'VERSION_ID="3.0"' in os_release_text
212-
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()
273+
# Check required packages
274+
package_list = [str(pkg) for pkg in config["packages"]]
275+
verify_packages(ssh_client, package_list)
218276

219277

220278
@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+
)

test/vmtests/vmtests/utils/imagecustomizer.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,40 @@ def add_ssh_to_config(config_path: Path, username: str, ssh_public_key: str, clo
137137
return path
138138

139139

140+
def add_preview_features_to_config(config_path: Path, preview_feature: str, close_list: List[Closeable]) -> Path:
141+
"""Modify an image customizer config file to add preview features.
142+
143+
Args:
144+
config_path: Path to the base config file
145+
preview_feature: Feature flag to add to previewFeatures list
146+
close_list: List of resources to be cleaned up
147+
148+
Returns:
149+
Path to the modified config file
150+
"""
151+
config_str = config_path.read_text()
152+
config = yaml.safe_load(config_str)
153+
154+
# Get or create previewFeatures list
155+
preview_features = config.get("previewFeatures", [])
156+
if not isinstance(preview_features, list):
157+
preview_features = []
158+
159+
# Add the feature if not already present
160+
if preview_feature not in preview_features:
161+
preview_features.append(preview_feature)
162+
config["previewFeatures"] = preview_features
163+
164+
# Write out new config file to a temporary file
165+
fd, modified_config_path = tempfile.mkstemp(prefix=config_path.name + "~", suffix=".tmp", dir=config_path.parent)
166+
with fdopen(fd, mode="w") as file:
167+
yaml.safe_dump(config, file)
168+
169+
path = Path(modified_config_path)
170+
close_list.append(RemoveFileOnClose(path))
171+
return path
172+
173+
140174
def dict_get_or_set(dictionary: Dict[Any, Any], value_name: str, default: Any = None) -> Any:
141175
value = dictionary.get(value_name)
142176
if value is None:

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)