From 038a0e259b72057f75d685a8b2dd84f36fb18e6e Mon Sep 17 00:00:00 2001 From: Himaja Kesari Date: Fri, 3 Oct 2025 12:48:56 -0700 Subject: [PATCH 1/6] add fedora42 vmtests --- .github/workflows/build.yml | 6 ++ .../workflows/tests-vmtests-imagecreator.yml | 57 ++++++++++--- test/vmtests/Makefile | 21 ++++- .../vmtests/imagecreator/test_imagecreator.py | 80 ++++++++++++++++--- .../imagecreator/test_imagecreator_fedora.py | 50 ++++++++++++ test/vmtests/vmtests/utils/imagecustomizer.py | 34 ++++++++ .../testutils/testrpms/download-test-utils.sh | 8 +- .../pkg/imagecreatorlib/testdata/fedora.yaml | 2 + 8 files changed, 233 insertions(+), 25 deletions(-) create mode 100644 test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc6653da4..2d54e05de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -162,6 +162,8 @@ jobs: hostDistro: azl3 permissions: contents: read + # Azure login. + id-token: write tests-vmtests-imagecreator-ubuntu2404-amd64: name: VMTests suite image creator Ubuntu24.04 AMD64 @@ -173,6 +175,8 @@ jobs: hostDistro: ubuntu2404 permissions: contents: read + # Azure login. + id-token: write tests-vmtests-imagecreator-ubuntu2404-arm64: name: VMTests suite image creator Ubuntu24.04 ARM64 @@ -184,6 +188,8 @@ jobs: hostDistro: ubuntu2404 permissions: contents: read + # Azure login. + id-token: write tests-vmtests-osmodifier-azl3-amd64: name: VMTests suite osmodifier AZL3 AMD64 diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index 9f72de38a..95e0a227f 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -27,6 +27,9 @@ jobs: - 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') }} permissions: contents: read + # Azure login. + id-token: write + environment: public steps: - name: setup go 1.x uses: actions/setup-go@v6 @@ -114,27 +117,63 @@ jobs: ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" make create-venv - + + - name: Azure Login + uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0 + with: + client-id: ${{ vars.AZURE_CLIENT_ID }} + tenant-id: ${{ vars.AZURE_TENANT_ID }} + subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} + + - name: ACR Login + run: | + set -eux + # login to ACR + az acr login -n martimusexternal + - name: Download RPMS and tools file run: | set -eux - # Download the test RPM and tools file. - ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -t 3.0 -s true + # Download the test RPM and tools file for azurelinux + ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d azurelinux -t 3.0 -s true + + # Download the test RPM and tools file for fedora + CI=true ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d fedora -t 42 -s true - name: Run image creator tests run: | set -eux + # Define common paths and variables + TOOLKIT_DIR="../../toolkit" + TOOLS_DIR="$TOOLKIT_DIR/tools" + TESTRPMS_DIR="$TOOLS_DIR/internal/testutils/testrpms" + + # Binary paths + IMAGE_CREATOR_BIN="$TOOLKIT_DIR/out/tools/imagecreator" + IMAGE_CUSTOMIZER_BIN="$TOOLKIT_DIR/out/tools/imagecustomizer" + SSH_KEY="~/.ssh/id_ed25519" + + # Function to run tests for a specific distro + run_tests() { + local distro=$1 + local version=$2 + + sudo make test-imagecreator-$distro \ + IMAGE_CREATOR_BIN="$IMAGE_CREATOR_BIN" \ + TOOLS_TAR="$TESTRPMS_DIR/build/tools-$distro-$version.tar.gz" \ + RPM_SOURCES="$TESTRPMS_DIR/downloadedrpms/$distro/$version" \ + IMAGE_CUSTOMIZER_BINARY_PATH="$IMAGE_CUSTOMIZER_BIN" \ + SSH_PRIVATE_KEY_FILE=$SSH_KEY + } + pushd ./repo/test/vmtests - sudo make test-imagecreator \ - IMAGE_CREATOR_BIN="../../toolkit/out/tools/imagecreator" \ - TOOLS_TAR="../../toolkit/tools/internal/testutils/testrpms/build/tools-azurelinux-3.0.tar.gz" \ - RPM_SOURCES="../../toolkit/tools/internal/testutils/testrpms/downloadedrpms/azurelinux/3.0" \ - IMAGE_CUSTOMIZER_BINARY_PATH="../../toolkit/out/tools/imagecustomizer" \ - SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519 + # Run tests for each distro + run_tests "azurelinux" "3.0" + run_tests "fedora" "42" - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} diff --git a/test/vmtests/Makefile b/test/vmtests/Makefile index ae0ce60bf..a779c7054 100644 --- a/test/vmtests/Makefile +++ b/test/vmtests/Makefile @@ -99,8 +99,8 @@ test-imagecustomizer: --junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \ ./vmtests/imagecustomizer/test_min_change.py -.PHONY: test-imagecreator -test-imagecreator: +.PHONY: test-imagecreator-azurelinux +test-imagecreator-azurelinux: ${PYTEST} \ --image-creator-binary-path="${IMAGE_CREATOR_BIN}" \ --rpm-sources="${RPM_SOURCES}" \ @@ -114,6 +114,21 @@ test-imagecreator: --junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \ ./vmtests/imagecreator/test_imagecreator.py +.PHONY: test-imagecreator-fedora +test-imagecreator-fedora: + ${PYTEST} \ + --image-creator-binary-path="${IMAGE_CREATOR_BIN}" \ + --rpm-sources="${RPM_SOURCES}" \ + --tools-tar="${TOOLS_TAR}" \ + --image-customizer-binary-path="${IMAGE_CUSTOMIZER_BINARY_PATH}" \ + --ssh-private-key="${SSH_PRIVATE_KEY_FILE}" \ + $(if $(filter y,$(KEEP_ENVIRONMENT)),--keep-environment) \ + --log-cli-level=DEBUG \ + --show-capture=all \ + --tb=short \ + --junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \ + ./vmtests/imagecreator/test_imagecreator_fedora.py + .PHONY: test-osmodifier test-osmodifier: ${PYTEST} \ @@ -133,7 +148,7 @@ test-osmodifier: run-imagecustomizer: image-customizer-container test-imagecustomizer .PHONY: run-imagecreator -run-imagecreator: ${IMAGE_CREATOR_BIN} test-imagecreator +run-imagecreator: ${IMAGE_CREATOR_BIN} test-imagecreator-azurelinux test-imagecreator-fedora .PHONY: run-osmodifier run-osmodifier: ${OSMODIFIER_BIN} test-osmodifier diff --git a/test/vmtests/vmtests/imagecreator/test_imagecreator.py b/test/vmtests/vmtests/imagecreator/test_imagecreator.py index 764cb5ac4..8e060d944 100644 --- a/test/vmtests/vmtests/imagecreator/test_imagecreator.py +++ b/test/vmtests/vmtests/imagecreator/test_imagecreator.py @@ -5,7 +5,7 @@ import os import platform from pathlib import Path -from typing import List, Tuple +from typing import Any, Dict, List, Tuple import libvirt # type: ignore import pytest @@ -14,7 +14,7 @@ from ..utils.closeable import Closeable from ..utils.host_utils import get_host_distro from ..utils.imagecreator import run_image_creator, run_image_customizer_binary -from ..utils.imagecustomizer import add_ssh_to_config +from ..utils.imagecustomizer import add_preview_features_to_config, add_ssh_to_config from ..utils.libvirt_utils import VmSpec, create_libvirt_domain_xml from ..utils.libvirt_vm import LibvirtVm from ..utils.ssh_client import SshClient @@ -25,6 +25,27 @@ "toolkit/tools/pkg/imagecreatorlib/testdata" ) +# Common packages that should be present in all distributions +COMMON_PACKAGES = ["kernel", "systemd", "bash"] + +# Distribution-specific configuration +DISTRO_CONFIGS: Dict[str, Dict[str, Any]] = { + "fedora": { + "os_release": { + "ID": "fedora", + "VERSION_ID": "42", + }, + "packages": COMMON_PACKAGES + ["grub2-efi-x64"], + }, + "azurelinux": { + "os_release": { + "ID": "azurelinux", + "VERSION_ID": "3.0", + }, + "packages": COMMON_PACKAGES + ["grub2"], + }, +} + def run_image_creator_test( image_creator_binary_path: Path, @@ -89,6 +110,10 @@ def run_image_creator_test( base_ssh_config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("ssh-base-config.yaml") customizer_config_path_obj = add_ssh_to_config(base_ssh_config_path, username, ssh_public_key, close_list) + # Add Fedora preview features if needed + if distro.lower() == "fedora": + customizer_config_path_obj = add_preview_features_to_config(customizer_config_path_obj, "fedora-42", close_list) + run_image_customizer_binary( image_customizer_binary_path, initial_output_image_path, @@ -189,32 +214,63 @@ def run_image_creator_test( logging.info(f"SSH connection established successfully!") # Run the test logging.info(f"Running basic checks on the VM") - run_basic_checks(ssh_client, test_temp_dir) + run_basic_checks(ssh_client, test_temp_dir, distro) logging.info(f"Basic checks completed successfully!") +def verify_packages(ssh_client: SshClient, packages_to_check: List[str]) -> None: + """Verify that specified packages are present in the system. + + Args: + ssh_client: SSH client connected to the target system + packages_to_check: List of package names to verify + """ + for package in packages_to_check: + ssh_client.run(f"rpm -q {package}").check_exit_code() + + +def verify_os_release(os_release_text: str, expected_values: Dict[str, str]) -> None: + """Verify os-release content matches expected values. + + Args: + os_release_text: Content of os-release file + expected_values: Dictionary of key-value pairs to verify + """ + for key, value in expected_values.items(): + expected = f"{key}={value}" + assert expected in os_release_text, f"Expected '{expected}' in os-release, but not found" + + def run_basic_checks( ssh_client: SshClient, test_temp_dir: Path, + distro: str, ) -> None: + """Run basic checks for the specified distribution. + Args: + ssh_client: SSH client for running commands + test_temp_dir: Temporary directory for test artifacts + distro: Distribution name (must be a key in DISTRO_CONFIGS) + """ + if distro not in DISTRO_CONFIGS: + raise ValueError(f"Unsupported distribution: {distro}") + + config = DISTRO_CONFIGS[distro] + + # Check kernel cmdline ssh_client.run("cat /proc/cmdline").check_exit_code() + # Get and verify os-release os_release_path = test_temp_dir.joinpath("os-release") ssh_client.get_file(Path("/etc/os-release"), os_release_path) with open(os_release_path, "r") as os_release_fd: os_release_text = os_release_fd.read() + verify_os_release(os_release_text, config["os_release"]) - # Since imagecreator creates new images, we expect Azure Linux 3.0 - assert "ID=azurelinux" in os_release_text - assert 'VERSION_ID="3.0"' in os_release_text - - # Check that essential packages are installed - ssh_client.run("rpm -q kernel").check_exit_code() - ssh_client.run("rpm -q systemd").check_exit_code() - ssh_client.run("rpm -q grub2").check_exit_code() - ssh_client.run("rpm -q bash").check_exit_code() + # Check required packages + verify_packages(ssh_client, config["packages"]) @pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination") diff --git a/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py b/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py new file mode 100644 index 000000000..b0cd521d3 --- /dev/null +++ b/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py @@ -0,0 +1,50 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +import logging +import platform +from pathlib import Path +from typing import List, Tuple + +import libvirt # type: ignore +import pytest + +from ..utils.closeable import Closeable +from .test_imagecreator import IMAGECREATOR_TEST_CONFIGS_DIR, run_image_creator_test + + +@pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination") +def test_create_image_efi_qcow_output_fedora( + image_creator_binary_path: Path, + rpm_sources: List[Path], + tools_tar: Path, + ssh_key: Tuple[str, Path], + test_temp_dir: Path, + test_instance_name: str, + logs_dir: Path, + libvirt_conn: libvirt.virConnect, + close_list: List[Closeable], + image_customizer_binary_path: Path, +) -> None: + config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("fedora.yaml") + output_format = "qcow2" + + # debug message + logging.debug("Running test_create_image_efi_qcow_output_fedora") + + run_image_creator_test( + image_creator_binary_path, + rpm_sources, + tools_tar, + config_path, + output_format, + ssh_key, + test_temp_dir, + test_instance_name, + logs_dir, + libvirt_conn, + close_list, + image_customizer_binary_path, + "fedora", + "42", + ) diff --git a/test/vmtests/vmtests/utils/imagecustomizer.py b/test/vmtests/vmtests/utils/imagecustomizer.py index 55a176699..c944e7b2b 100644 --- a/test/vmtests/vmtests/utils/imagecustomizer.py +++ b/test/vmtests/vmtests/utils/imagecustomizer.py @@ -137,6 +137,40 @@ def add_ssh_to_config(config_path: Path, username: str, ssh_public_key: str, clo return path +def add_preview_features_to_config(config_path: Path, preview_feature: str, close_list: List[Closeable]) -> Path: + """Modify an image customizer config file to add preview features. + + Args: + config_path: Path to the base config file + preview_feature: Feature flag to add to previewFeatures list + close_list: List of resources to be cleaned up + + Returns: + Path to the modified config file + """ + config_str = config_path.read_text() + config = yaml.safe_load(config_str) + + # Get or create previewFeatures list + preview_features = config.get("previewFeatures", []) + if not isinstance(preview_features, list): + preview_features = [] + + # Add the feature if not already present + if preview_feature not in preview_features: + preview_features.append(preview_feature) + config["previewFeatures"] = preview_features + + # Write out new config file to a temporary file + fd, modified_config_path = tempfile.mkstemp(prefix=config_path.name + "~", suffix=".tmp", dir=config_path.parent) + with fdopen(fd, mode="w") as file: + yaml.safe_dump(config, file) + + path = Path(modified_config_path) + close_list.append(RemoveFileOnClose(path)) + return path + + def dict_get_or_set(dictionary: Dict[Any, Any], value_name: str, default: Any = None) -> Any: value = dictionary.get(value_name) if value is None: diff --git a/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh b/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh index fb634a31d..04840b381 100755 --- a/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh +++ b/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh @@ -5,7 +5,13 @@ SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" AZURELINUX_2_CONTAINER_IMAGE="mcr.microsoft.com/cbl-mariner/base/core:2.0" AZURELINUX_3_CONTAINER_IMAGE="mcr.microsoft.com/azurelinux/base/core:3.0" -FEDORA_42_CONTAINER_IMAGE="registry.fedoraproject.org/fedora:42" + +# Use ACR image in CI, public registry for local development +if [ "${CI:-}" = "true" ]; then + FEDORA_42_CONTAINER_IMAGE="martimusexternal.azurecr.io/fedora/fedora:42" +else + FEDORA_42_CONTAINER_IMAGE="registry.fedoraproject.org/fedora:42" +fi DISTRO="azurelinux" DISTRO_VERSION="3.0" diff --git a/toolkit/tools/pkg/imagecreatorlib/testdata/fedora.yaml b/toolkit/tools/pkg/imagecreatorlib/testdata/fedora.yaml index f921a004d..c742fadba 100644 --- a/toolkit/tools/pkg/imagecreatorlib/testdata/fedora.yaml +++ b/toolkit/tools/pkg/imagecreatorlib/testdata/fedora.yaml @@ -49,4 +49,6 @@ os: - libxkbcommon - shim-x64 - kernel + # Add dnf to support dnf based package installation in imagecustomizer + - dnf From b18b1ef5e9a9cf0acb12fdd3f5875ffc52871b72 Mon Sep 17 00:00:00 2001 From: Himaja Kesari Date: Thu, 9 Oct 2025 08:39:46 -0700 Subject: [PATCH 2/6] fix comments --- .../workflows/tests-vmtests-imagecreator.yml | 3 +- test/vmtests/Makefile | 2 +- ...ecreator.py => imagecreator_test_utils.py} | 160 ++++++++---------- .../test_imagecreator_azurelinux.py | 49 ++++++ .../imagecreator/test_imagecreator_fedora.py | 2 +- 5 files changed, 119 insertions(+), 97 deletions(-) rename test/vmtests/vmtests/imagecreator/{test_imagecreator.py => imagecreator_test_utils.py} (88%) create mode 100644 test/vmtests/vmtests/imagecreator/test_imagecreator_azurelinux.py diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index 95e0a227f..14aaa9000 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -154,7 +154,6 @@ jobs: # Binary paths IMAGE_CREATOR_BIN="$TOOLKIT_DIR/out/tools/imagecreator" IMAGE_CUSTOMIZER_BIN="$TOOLKIT_DIR/out/tools/imagecustomizer" - SSH_KEY="~/.ssh/id_ed25519" # Function to run tests for a specific distro run_tests() { @@ -166,7 +165,7 @@ jobs: TOOLS_TAR="$TESTRPMS_DIR/build/tools-$distro-$version.tar.gz" \ RPM_SOURCES="$TESTRPMS_DIR/downloadedrpms/$distro/$version" \ IMAGE_CUSTOMIZER_BINARY_PATH="$IMAGE_CUSTOMIZER_BIN" \ - SSH_PRIVATE_KEY_FILE=$SSH_KEY + SSH_PRIVATE_KEY_FILE=~/.ssh/id_ed25519 } pushd ./repo/test/vmtests diff --git a/test/vmtests/Makefile b/test/vmtests/Makefile index a779c7054..d65b12e98 100644 --- a/test/vmtests/Makefile +++ b/test/vmtests/Makefile @@ -112,7 +112,7 @@ test-imagecreator-azurelinux: --show-capture=all \ --tb=short \ --junitxml=./out/$(DATETIME_AS_VERSION)/report.xml \ - ./vmtests/imagecreator/test_imagecreator.py + ./vmtests/imagecreator/test_imagecreator_azurelinux.py .PHONY: test-imagecreator-fedora test-imagecreator-fedora: diff --git a/test/vmtests/vmtests/imagecreator/test_imagecreator.py b/test/vmtests/vmtests/imagecreator/imagecreator_test_utils.py similarity index 88% rename from test/vmtests/vmtests/imagecreator/test_imagecreator.py rename to test/vmtests/vmtests/imagecreator/imagecreator_test_utils.py index 8e060d944..ca684f6c1 100644 --- a/test/vmtests/vmtests/imagecreator/test_imagecreator.py +++ b/test/vmtests/vmtests/imagecreator/imagecreator_test_utils.py @@ -3,12 +3,10 @@ import logging import os -import platform from pathlib import Path from typing import Any, Dict, List, Tuple import libvirt # type: ignore -import pytest from ..utils import local_client from ..utils.closeable import Closeable @@ -47,6 +45,73 @@ } +def verify_packages(ssh_client: SshClient, packages_to_check: List[str]) -> None: + """Verify that specified packages are present in the system. + + Args: + ssh_client: SSH client connected to the target system + packages_to_check: List of package names to verify + """ + for package in packages_to_check: + ssh_client.run(f"rpm -q {package}").check_exit_code() + + +def verify_os_release(os_release_text: str, expected_values: Dict[str, str]) -> None: + """Verify os-release content matches expected values. + + Args: + os_release_text: Content of os-release file + expected_values: Dictionary of key-value pairs to verify + """ + + # Parse os-release into a dictionary + os_release_dict = {} + for line in os_release_text.splitlines(): + if "=" in line: + key, value = line.split("=", 1) + # Remove quotes if present + value = value.strip('"') + os_release_dict[key] = value + + for key, value in expected_values.items(): + if key not in os_release_dict: + raise AssertionError(f"Key '{key}' not found in os-release") + if os_release_dict[key] != value: + raise AssertionError(f"Value mismatch for '{key}': expected '{value}', got '{os_release_dict[key]}'") + + +def run_basic_checks( + ssh_client: SshClient, + test_temp_dir: Path, + distro: str, +) -> None: + """Run basic checks for the specified distribution. + + Args: + ssh_client: SSH client for running commands + test_temp_dir: Temporary directory for test artifacts + distro: Distribution name (must be a key in DISTRO_CONFIGS) + """ + if distro not in DISTRO_CONFIGS: + raise ValueError(f"Unsupported distribution: {distro}") + + config = DISTRO_CONFIGS[distro] + + # Check kernel cmdline + ssh_client.run("cat /proc/cmdline").check_exit_code() + + # Get and verify os-release + os_release_path = test_temp_dir.joinpath("os-release") + ssh_client.get_file(Path("/etc/os-release"), os_release_path) + + with open(os_release_path, "r") as os_release_fd: + os_release_text = os_release_fd.read() + verify_os_release(os_release_text, config["os_release"]) + + # Check required packages + verify_packages(ssh_client, config["packages"]) + + def run_image_creator_test( image_creator_binary_path: Path, rpm_sources: List[Path], @@ -216,94 +281,3 @@ def run_image_creator_test( logging.info(f"Running basic checks on the VM") run_basic_checks(ssh_client, test_temp_dir, distro) logging.info(f"Basic checks completed successfully!") - - -def verify_packages(ssh_client: SshClient, packages_to_check: List[str]) -> None: - """Verify that specified packages are present in the system. - - Args: - ssh_client: SSH client connected to the target system - packages_to_check: List of package names to verify - """ - for package in packages_to_check: - ssh_client.run(f"rpm -q {package}").check_exit_code() - - -def verify_os_release(os_release_text: str, expected_values: Dict[str, str]) -> None: - """Verify os-release content matches expected values. - - Args: - os_release_text: Content of os-release file - expected_values: Dictionary of key-value pairs to verify - """ - for key, value in expected_values.items(): - expected = f"{key}={value}" - assert expected in os_release_text, f"Expected '{expected}' in os-release, but not found" - - -def run_basic_checks( - ssh_client: SshClient, - test_temp_dir: Path, - distro: str, -) -> None: - """Run basic checks for the specified distribution. - - Args: - ssh_client: SSH client for running commands - test_temp_dir: Temporary directory for test artifacts - distro: Distribution name (must be a key in DISTRO_CONFIGS) - """ - if distro not in DISTRO_CONFIGS: - raise ValueError(f"Unsupported distribution: {distro}") - - config = DISTRO_CONFIGS[distro] - - # Check kernel cmdline - ssh_client.run("cat /proc/cmdline").check_exit_code() - - # Get and verify os-release - os_release_path = test_temp_dir.joinpath("os-release") - ssh_client.get_file(Path("/etc/os-release"), os_release_path) - - with open(os_release_path, "r") as os_release_fd: - os_release_text = os_release_fd.read() - verify_os_release(os_release_text, config["os_release"]) - - # Check required packages - verify_packages(ssh_client, config["packages"]) - - -@pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination") -def test_create_image_efi_qcow_output_azurelinux( - image_creator_binary_path: Path, - rpm_sources: List[Path], - tools_tar: Path, - ssh_key: Tuple[str, Path], - test_temp_dir: Path, - test_instance_name: str, - logs_dir: Path, - libvirt_conn: libvirt.virConnect, - close_list: List[Closeable], - image_customizer_binary_path: Path, -) -> None: - config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("minimal-os.yaml") - output_format = "qcow2" - # debug message - logging.debug("Running test_create_image_efi_qcow_output_azurelinux") - - run_image_creator_test( - image_creator_binary_path, - rpm_sources, - tools_tar, - config_path, - output_format, - ssh_key, - test_temp_dir, - test_instance_name, - logs_dir, - libvirt_conn, - close_list, - image_customizer_binary_path, - "azurelinux", - "3.0", - ) diff --git a/test/vmtests/vmtests/imagecreator/test_imagecreator_azurelinux.py b/test/vmtests/vmtests/imagecreator/test_imagecreator_azurelinux.py new file mode 100644 index 000000000..4bbcb7ce5 --- /dev/null +++ b/test/vmtests/vmtests/imagecreator/test_imagecreator_azurelinux.py @@ -0,0 +1,49 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +import logging +import platform +from pathlib import Path +from typing import List, Tuple + +import libvirt # type: ignore +import pytest + +from ..utils.closeable import Closeable +from .imagecreator_test_utils import IMAGECREATOR_TEST_CONFIGS_DIR, run_image_creator_test + + +@pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination") +def test_create_image_efi_qcow_output_azurelinux( + image_creator_binary_path: Path, + rpm_sources: List[Path], + tools_tar: Path, + ssh_key: Tuple[str, Path], + test_temp_dir: Path, + test_instance_name: str, + logs_dir: Path, + libvirt_conn: libvirt.virConnect, + close_list: List[Closeable], + image_customizer_binary_path: Path, +) -> None: + config_path = IMAGECREATOR_TEST_CONFIGS_DIR.joinpath("minimal-os.yaml") + output_format = "qcow2" + # debug message + logging.debug("Running test_create_image_efi_qcow_output_azurelinux") + + run_image_creator_test( + image_creator_binary_path, + rpm_sources, + tools_tar, + config_path, + output_format, + ssh_key, + test_temp_dir, + test_instance_name, + logs_dir, + libvirt_conn, + close_list, + image_customizer_binary_path, + "azurelinux", + "3.0", + ) diff --git a/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py b/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py index b0cd521d3..20fe9d704 100644 --- a/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py +++ b/test/vmtests/vmtests/imagecreator/test_imagecreator_fedora.py @@ -10,7 +10,7 @@ import pytest from ..utils.closeable import Closeable -from .test_imagecreator import IMAGECREATOR_TEST_CONFIGS_DIR, run_image_creator_test +from .imagecreator_test_utils import IMAGECREATOR_TEST_CONFIGS_DIR, run_image_creator_test @pytest.mark.skipif(platform.machine() != "x86_64", reason="arm64 is not supported for this combination") From ff27440007809a9f1f17ad1f388a637f3795d2d0 Mon Sep 17 00:00:00 2001 From: Himaja Kesari Date: Tue, 21 Oct 2025 15:30:28 -0700 Subject: [PATCH 3/6] resolve feedback --- .github/workflows/tests-vmtests-imagecreator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index 14aaa9000..a57fb520f 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -129,7 +129,7 @@ jobs: run: | set -eux # login to ACR - az acr login -n martimusexternal + az acr login -n $AZURE_CR_CACHE - name: Download RPMS and tools file run: | From 1e9e596db2b73208ec3d95ffee8c1529b06d0c6f Mon Sep 17 00:00:00 2001 From: Himaja Kesari Date: Tue, 21 Oct 2025 16:34:07 -0700 Subject: [PATCH 4/6] fix variable --- .github/workflows/tests-vmtests-imagecreator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index a57fb520f..1b66a6b6e 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -129,7 +129,7 @@ jobs: run: | set -eux # login to ACR - az acr login -n $AZURE_CR_CACHE + az acr login -n ${{ vars.AZURE_CR_CACHE }} - name: Download RPMS and tools file run: | From 90bda94ef778204dcab0a838c3722c0e72c7b7f8 Mon Sep 17 00:00:00 2001 From: Himaja Kesari Date: Wed, 22 Oct 2025 15:46:21 -0700 Subject: [PATCH 5/6] fix azure cr cache var --- .github/workflows/tests-vmtests-imagecreator.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index 1b66a6b6e..6dbedcab7 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -126,10 +126,12 @@ jobs: subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} - name: ACR Login + env: + AZURE_CR_CACHE: ${{ vars.AZURE_CR_CACHE }} run: | set -eux # login to ACR - az acr login -n ${{ vars.AZURE_CR_CACHE }} + az acr login -n "${AZURE_CR_CACHE}" - name: Download RPMS and tools file run: | From e8260bbe08050fb3a3aac26e500f3257272ad456 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:52:23 -0800 Subject: [PATCH 6/6] Pass container registry as parameter, use quay.io for Fedora defaults (#508) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses review comments R11 and R13 from PR #461: - **R11**: Remove hardcoded ACR URL from script; pass container registry as workflow parameter - **R13**: Use `quay.io/fedora/fedora:42` as default for local development (matches ACR cache source) ### Changes **`download-test-utils.sh`:** - Add `-r CONTAINER_REGISTRY` parameter to override Fedora container image URL - Default to `quay.io/fedora/fedora:42` instead of `registry.fedoraproject.org` - Remove `CI` environment variable detection logic **`tests-vmtests-imagecreator.yml`:** - Pass `${AZURE_CR_CACHE}` via new `-r` parameter for Fedora downloads ```bash # Before (hardcoded ACR in script) CI=true ./download-test-utils.sh -d fedora -t 42 -s true # After (registry passed from workflow) ./download-test-utils.sh -d fedora -t 42 -s true -r "${AZURE_CR_CACHE}" ``` --- ### **Checklist** - [ ] Tests added/updated - [ ] Documentation updated (if needed) - [x] Code conforms to style guidelines
Original prompt > https://github.com/microsoft/azure-linux-image-tools/pull/461/files help me resolve comments on R11 and R13
--- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: himaja-kesari <123194058+himaja-kesari@users.noreply.github.com> --- .../workflows/tests-vmtests-imagecreator.yml | 6 +++-- .../testutils/testrpms/download-test-utils.sh | 26 ++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests-vmtests-imagecreator.yml b/.github/workflows/tests-vmtests-imagecreator.yml index 6dbedcab7..417994688 100644 --- a/.github/workflows/tests-vmtests-imagecreator.yml +++ b/.github/workflows/tests-vmtests-imagecreator.yml @@ -134,14 +134,16 @@ jobs: az acr login -n "${AZURE_CR_CACHE}" - name: Download RPMS and tools file + env: + AZURE_CR_CACHE: ${{ vars.AZURE_CR_CACHE }} run: | set -eux # Download the test RPM and tools file for azurelinux ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d azurelinux -t 3.0 -s true - + # Download the test RPM and tools file for fedora - CI=true ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d fedora -t 42 -s true + ./repo/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh -d fedora -t 42 -s true -r "${AZURE_CR_CACHE}" - name: Run image creator tests diff --git a/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh b/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh index 04840b381..891996df5 100755 --- a/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh +++ b/toolkit/tools/internal/testutils/testrpms/download-test-utils.sh @@ -5,37 +5,39 @@ SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" AZURELINUX_2_CONTAINER_IMAGE="mcr.microsoft.com/cbl-mariner/base/core:2.0" AZURELINUX_3_CONTAINER_IMAGE="mcr.microsoft.com/azurelinux/base/core:3.0" - -# Use ACR image in CI, public registry for local development -if [ "${CI:-}" = "true" ]; then - FEDORA_42_CONTAINER_IMAGE="martimusexternal.azurecr.io/fedora/fedora:42" -else - FEDORA_42_CONTAINER_IMAGE="registry.fedoraproject.org/fedora:42" -fi +FEDORA_42_CONTAINER_IMAGE="quay.io/fedora/fedora:42" DISTRO="azurelinux" DISTRO_VERSION="3.0" IMAGE_CREATOR="false" +CONTAINER_REGISTRY="" -while getopts "d:t:s:" flag +while getopts "d:t:s:r:" flag do case "${flag}" in d) DISTRO="$OPTARG";; t) DISTRO_VERSION="$OPTARG";; s) IMAGE_CREATOR="$OPTARG";; + r) CONTAINER_REGISTRY="$OPTARG";; h) ;;& - ?) echo "Usage: download-test-utils.sh [-d DISTRO] [-t DISTRO_VERSION] [-s IMAGE_CREATOR]" + ?) echo "Usage: download-test-utils.sh [-d DISTRO] [-t DISTRO_VERSION] [-s IMAGE_CREATOR] [-r CONTAINER_REGISTRY]" echo "" echo "Args:" - echo " -d DISTRO The distribution to use (azurelinux or fedora). Default: azurelinux" - echo " -t DISTRO_VERSION The image version to download the RPMs for (2.0, 3.0 for Azure Linux or 42 for Fedora)." - echo " -s IMAGE_CREATOR If set to true, the script will create a tar.gz file with the tools and download the rpms needed to test imagecreator." + echo " -d DISTRO The distribution to use (azurelinux or fedora). Default: azurelinux" + echo " -t DISTRO_VERSION The image version to download the RPMs for (2.0, 3.0 for Azure Linux or 42 for Fedora)." + echo " -s IMAGE_CREATOR If set to true, the script will create a tar.gz file with the tools and download the rpms needed to test imagecreator." + echo " -r CONTAINER_REGISTRY Container registry URL to use for Fedora images (e.g., myacr.azurecr.io)." echo " -h Show help" exit 1;; esac done +# Override Fedora container image if a container registry is provided +if [[ -n "$CONTAINER_REGISTRY" ]]; then + FEDORA_42_CONTAINER_IMAGE="${CONTAINER_REGISTRY}/fedora/fedora:42" +fi + # Determine the tools file name based on the distro and image version BUILD_DIR="$SCRIPT_DIR/build" mkdir -p "$BUILD_DIR"