Skip to content

Commit fa83ebb

Browse files
authored
infra: align tests to fit multiarch needs (#4788)
Update multiarch matrix generation so preference and DataSource names match architecture-specific cluster naming for RHEL, Fedora, and CentOS. ##### Short description: ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: rrmngmnt's package manager auto-detection uses which to find the package manager binary which is not available in centos-stream10 and hence some of tests didn't work. 8e0f430 is to fix it. ##### jira-ticket: https://redhat.atlassian.net/browse/CNV-64577 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Extended support for ARM_64 architecture with CentOS Stream 10 preference configuration * Enhanced architecture preference handling to provide more flexible configuration options * **Bug Fixes** * Improved QEMU guest agent presence detection methodology * **Tests** * Expanded test coverage for instance-type OS matrix generation with parametrized test cases * Added validation for architecture-specific configurations and preference handling <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Geetika Kapoor <gkapoor@redhat.com>
1 parent 68ed541 commit fa83ebb

7 files changed

Lines changed: 171 additions & 123 deletions

File tree

tests/global_config_multiarch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"centos_os_list": ["centos-stream-9"],
5959
"instance_type_rhel_os_list": [RHEL10_PREFERENCE],
6060
"instance_type_fedora_os_list": [OS_FLAVOR_FEDORA],
61+
"instance_type_centos_os_list": [CENTOS_STREAM10_PREFERENCE],
6162
},
6263
}
6364

tests/infrastructure/instance_types/supported_os/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def golden_image_windows_vm(
131131
vm_instance_type=VirtualMachineClusterInstancetype(client=unprivileged_client, name="u1.large"),
132132
vm_preference=VirtualMachineClusterPreference(
133133
client=unprivileged_client,
134-
name=windows_os_matrix__module__[os_name][DATA_SOURCE_STR].replace("win", "windows."),
134+
name=windows_os_matrix__module__[os_name][DATA_SOURCE_STR]
135+
.removesuffix(f"-{py_config.get('cpu_arch', '')}")
136+
.replace("win", "windows."),
135137
),
136138
data_volume_template=windows_data_volume_template.res,
137139
os_flavor=OS_FLAVOR_WIN_CONTAINER_DISK,

utilities/os_utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ def generate_os_matrix_dict(
255255

256256

257257
def generate_linux_instance_type_os_matrix(
258-
os_name: str, preferences: list[str], arch_suffix: str | None = None
258+
os_name: str,
259+
preferences: list[str],
260+
arch_suffix: str | None = None,
261+
add_arch_suffix: bool = True,
259262
) -> list[dict[str, dict[str, Any]]]:
260263
"""
261264
Generate a list of dictionaries representing the instance type matrix for a Linux OS type.
@@ -265,6 +268,9 @@ def generate_linux_instance_type_os_matrix(
265268
os_name (str): The name of the OS.
266269
preferences (list[str]): A list of preferences for the instance types. Preference format is "<os>.<version>".
267270
arch_suffix: Optional architecture suffix. Example: "s390x", "arm64" . Omit to keep original preference.
271+
add_arch_suffix: When True, append arch_suffix to the preference name. Set to False for OSes whose
272+
ClusterPreferences have no arch suffix (e.g. centos — "centos.stream10" exists,
273+
"centos.stream10.arm64" does not).
268274
269275
Returns:
270276
list[dict[str, dict[str, Any]]]: A list of dictionaries representing the instance type matrix.
@@ -285,10 +291,11 @@ def _format_data_source_name(preference_name: str) -> str:
285291
instance_types: list[dict[str, dict[str, Any]]] = []
286292

287293
for preference in preferences:
288-
arch_preference = f"{preference}.{arch_suffix}" if arch_suffix else preference
294+
arch_preference = f"{preference}.{arch_suffix}" if arch_suffix and add_arch_suffix else preference
295+
data_source_name = _format_data_source_name(preference_name=preference)
289296
preference_config: dict[str, Any] = {
290297
PREFERENCE_STR: arch_preference,
291-
DATA_SOURCE_NAME: _format_data_source_name(preference_name=preference),
298+
DATA_SOURCE_NAME: f"{data_source_name}-{arch_suffix}" if arch_suffix else data_source_name,
292299
}
293300

294301
if preference == latest_os:

utilities/pytest_utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,22 +508,31 @@ def generate_instance_type_matrix_dicts(os_dict: dict[str, Any], cpu_arch: str |
508508
"instance_type_rhel_os_list").
509509
cpu_arch: Optional architecture suffix.
510510
"""
511+
add_arch_suffix = cpu_arch != AMD_64
512+
511513
if instance_type_rhel_os_list := os_dict.get("instance_type_rhel_os_list"):
512514
py_config["instance_type_rhel_os_matrix"] = generate_linux_instance_type_os_matrix(
513-
os_name="rhel", preferences=instance_type_rhel_os_list, arch_suffix=cpu_arch
515+
os_name="rhel",
516+
preferences=instance_type_rhel_os_list,
517+
arch_suffix=cpu_arch,
518+
add_arch_suffix=add_arch_suffix,
514519
)
515520
py_config["latest_instance_type_rhel_os_dict"] = generate_latest_os_dict(
516521
os_matrix=py_config["instance_type_rhel_os_matrix"]
517522
)
518523
if instance_type_fedora_os_list := os_dict.get("instance_type_fedora_os_list"):
519524
py_config["instance_type_fedora_os_matrix"] = generate_linux_instance_type_os_matrix(
520-
os_name="fedora", preferences=instance_type_fedora_os_list, arch_suffix=cpu_arch
525+
os_name="fedora",
526+
preferences=instance_type_fedora_os_list,
527+
arch_suffix=cpu_arch,
528+
add_arch_suffix=add_arch_suffix,
521529
)
522530
if instance_type_centos_os_list := os_dict.get("instance_type_centos_os_list"):
523531
py_config["instance_type_centos_os_matrix"] = generate_linux_instance_type_os_matrix(
524532
os_name="centos.stream",
525533
preferences=instance_type_centos_os_list,
526-
arch_suffix=None,
534+
arch_suffix=cpu_arch,
535+
add_arch_suffix=False,
527536
)
528537

529538

utilities/unittests/test_os_utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88

9+
from utilities.constants import ARM_64, CENTOS_STREAM10_PREFERENCE, RHEL10_PREFERENCE
910
from utilities.exceptions import OsDictNotFoundError
1011
from utilities.os_utils import (
1112
CENTOS_OS_MAPPING,
@@ -332,6 +333,42 @@ def test_generate_instance_type_single_digit_versions(self):
332333
rhel9_item = next(item for item in result if "rhel-9" in item)
333334
assert rhel9_item["rhel-9"]["latest_released"] is True
334335

336+
def test_arch_suffix_applied_to_preference_and_data_source(self):
337+
"""arch_suffix is appended to both the preference name and the DataSource."""
338+
result = generate_linux_instance_type_os_matrix(
339+
os_name="rhel",
340+
preferences=[RHEL10_PREFERENCE],
341+
arch_suffix=ARM_64,
342+
)
343+
344+
config = result[0][f"{RHEL10_PREFERENCE}.{ARM_64}"]
345+
assert config["preference"] == f"{RHEL10_PREFERENCE}.{ARM_64}"
346+
assert config["DATA_SOURCE_NAME"] == f"rhel10-{ARM_64}"
347+
348+
def test_arch_suffix_omitted_from_preference_when_add_arch_suffix_false(self):
349+
"""add_arch_suffix=False keeps the preference plain while the DataSource still gets the arch suffix."""
350+
result = generate_linux_instance_type_os_matrix(
351+
os_name="centos.stream",
352+
preferences=[CENTOS_STREAM10_PREFERENCE],
353+
arch_suffix=ARM_64,
354+
add_arch_suffix=False,
355+
)
356+
357+
config = result[0][CENTOS_STREAM10_PREFERENCE]
358+
assert config["preference"] == CENTOS_STREAM10_PREFERENCE, "preference must not include arch suffix"
359+
assert config["DATA_SOURCE_NAME"] == f"centos-stream10-{ARM_64}", "DataSource must include arch suffix"
360+
361+
def test_add_arch_suffix_false_no_arch_suffix(self):
362+
"""add_arch_suffix=False with no arch_suffix is a no-op."""
363+
result_default = generate_linux_instance_type_os_matrix(
364+
os_name="centos.stream", preferences=[CENTOS_STREAM10_PREFERENCE]
365+
)
366+
result_no_arch = generate_linux_instance_type_os_matrix(
367+
os_name="centos.stream", preferences=[CENTOS_STREAM10_PREFERENCE], add_arch_suffix=False
368+
)
369+
370+
assert result_default == result_no_arch
371+
335372

336373
class TestOsMappingsConstants:
337374
"""Test cases for OS mapping constants"""

0 commit comments

Comments
 (0)