Skip to content

[Virt] Removes EFI boot for cloning tests on s390x #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: s390x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,16 @@ def pytest_cmdline_main(config):


def add_polarion_parameters_to_user_properties(item: Item, matrix_name: str) -> None:
values = re.findall("(#.*?#)", item.name) # Extract all substrings enclosed in '#' from item.name
for value in values:
value = value.strip("#")
for param in py_config[matrix_name]:
if isinstance(param, dict):
param = [*param][0]
if matrix_config := py_config.get(matrix_name):
values = re.findall("(#.*?#)", item.name) # Extract all substrings enclosed in '#' from item.name
for value in values:
value = value.strip("#")
for param in matrix_config:
if isinstance(param, dict):
param = [*param][0]

if value == param:
item.user_properties.append((f"polarion-parameter-{matrix_name}", value))
if value == param:
item.user_properties.append((f"polarion-parameter-{matrix_name}", value))


def add_test_id_markers(item: Item, marker_name: str) -> None:
Expand Down Expand Up @@ -485,6 +486,9 @@ def pytest_collection_modifyitems(session, config, items):
add_tier2_marker(item=item)

mark_tests_by_team(item=item)

# All tests are verified on X86_64 platforms, adding `x86_64` to all tests
item.add_marker(marker="x86_64")
# Collect only 'upgrade_custom' tests when running pytest with --upgrade_custom
keep, discard = filter_upgrade_tests(items=items, config=config)
items[:] = keep
Expand Down Expand Up @@ -619,24 +623,24 @@ def _update_os_related_config():
# with runtime windows_os_matrix value(s).
# Some tests extract a single OS from the matrix and may fail if running with
# passed values from cli
py_config["system_windows_os_matrix"] = py_config["windows_os_matrix"]
py_config["system_rhel_os_matrix"] = py_config["rhel_os_matrix"]
if windows_os_matrix := py_config.get("windows_os_matrix"):
py_config["system_windows_os_matrix"] = windows_os_matrix

if rhel_os_matrix := py_config.get("rhel_os_matrix"):
py_config["system_rhel_os_matrix"] = rhel_os_matrix

# Update OS matrix list with the latest OS if running with os_group
if session.config.getoption("latest_rhel"):
py_config["rhel_os_matrix"] = [utilities.infra.generate_latest_os_dict(os_list=py_config["rhel_os_matrix"])]
if session.config.getoption("latest_windows"):
py_config["windows_os_matrix"] = [
utilities.infra.generate_latest_os_dict(os_list=py_config["windows_os_matrix"])
]
if session.config.getoption("latest_centos"):
py_config["centos_os_matrix"] = [
utilities.infra.generate_latest_os_dict(os_list=py_config["centos_os_matrix"])
]
if session.config.getoption("latest_fedora"):
py_config["fedora_os_matrix"] = [
utilities.infra.generate_latest_os_dict(os_list=py_config["fedora_os_matrix"])
]
if session.config.getoption("latest_rhel") and rhel_os_matrix:
py_config["rhel_os_matrix"] = [utilities.infra.generate_latest_os_dict(os_list=rhel_os_matrix)]

if session.config.getoption("latest_windows") and windows_os_matrix:
py_config["windows_os_matrix"] = [utilities.infra.generate_latest_os_dict(os_list=windows_os_matrix)]

if session.config.getoption("latest_centos") and (centos_os_matrix := py_config.get("centos_os_matrix")):
py_config["centos_os_matrix"] = [utilities.infra.generate_latest_os_dict(os_list=centos_os_matrix)]

if session.config.getoption("latest_fedora") and (fedora_os_matrix := py_config.get("fedora_os_matrix")):
py_config["fedora_os_matrix"] = [utilities.infra.generate_latest_os_dict(os_list=fedora_os_matrix)]

data_collector_dict = set_data_collector_values()
shutil.rmtree(
Expand Down
50 changes: 50 additions & 0 deletions docs/ARCHITECTURE_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Test Images Architecture Support

The tests can dynamically select test images based on the system's architecture.
This is controlled by the environment variable `OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH`.
Note: to run on the default architecture `x86_64`, there's no need to set the environment variable.

Supported architectures include:

- `x86_64` (default)
- `arm64`
- `s390x` (currently work in progress)

Ensure the environment variable is set correctly before running the tests:

```bash
export OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH=<desired-architecture>
```

## Test markers and global_config
To run tests on a specific architecture, add the path to the relevant `global_config` file and add `-m <architecture>` to the pytest command.

For example:

```bash
pytest --tc-file=tests/global_config_x86.py
pytest -m arm64 --tc-file=tests/global_config_arm64.py ...
pytest -m s390x --tc-file=tests/global_config_s390x.py ...
```

Note: to run on the default architecture `x86_64`, there's no need to set any architecture-specific markers.

## Adding new images or new architecture support
Images for different architectures are managed under [constants.py](../utilities/constants.py) - `ArchImages`
The data structures are defined under [images.py](../libs/infra/images.py)

### Adding new images
To add a new image:
- Add the image name under the relevant dataclass under [images.py](../libs/infra/images.py)
- Add the image name to the `ArchImages` under the relevant architecture and OS under [constants.py](../utilities/constants.py)
- Add the image to the image mapping under [os_utils.py](../utilities/os_utils.py); refer to existing images for the format

### Adding new architecture support
To add a new architecture:
- Add the architecture name to the `ARCHITECTURE_SUPPORT` list under [ARCHITECTURE_SUPPORT.md](ARCHITECTURE_SUPPORT.md)
- Add a new pytest marker for the architecture
- Add a new pytest global config file for the architecture under [tests/global_config_<architecture>.py](../tests/global_config_<architecture>.py)
- The file should contain the relevant os matrix(es); see [global_config_x86.py](../tests/global_config_x86.py) for an example
- Add the architecture name as a constant under [constants.py](../utilities/constants.py)
- Add the architecture name to the list of supported architectures under [get_test_images_arch_class](../utilities/constants.py)
- Add the architecture name to the `ArchImages` under the relevant architecture and OS under [constants.py](../utilities/constants.py)
18 changes: 2 additions & 16 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,8 @@ or by saving the kubeconfig file under `~/.kube/config`

## Test Images Architecture Support

The tests can dynamically select test images based on the system's architecture. This is controlled by the environment variable `OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH`. Supported architectures include:

- `x86_64` (default)

### Usage
The architecture-specific test images class is selected automatically based on the `OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH` environment variable. If the variable is not set, the default architecture `x86_64` is used.

Ensure the environment variable is set correctly before running the tests:

```bash
export OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH=<desired-architecture>
```

If an unsupported architecture is specified, a `ValueError` will be raised.

Images for different architectures are managed under [utilities/constants.py](../utilities/constants.py) - `ArchImages`
The tests can dynamically select test images based on the system's architecture.
Please refer to [ARCHITECTURE_SUPPORT.md](ARCHITECTURE_SUPPORT.md) for more details.


## Python and dependencies
Expand Down
Empty file added libs/infra/__init__.py
Empty file.
97 changes: 97 additions & 0 deletions libs/infra/images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from dataclasses import dataclass

BASE_IMAGES_DIR = "cnv-tests"


@dataclass
class Cirros:
RAW_IMG: str | None = None
RAW_IMG_GZ: str | None = None
RAW_IMG_XZ: str | None = None
QCOW2_IMG: str | None = None
QCOW2_IMG_GZ: str | None = None
QCOW2_IMG_XZ: str | None = None
DISK_DEMO: str | None = None
DIR: str = f"{BASE_IMAGES_DIR}/cirros-images"
DEFAULT_DV_SIZE: str = "1Gi"
DEFAULT_MEMORY_SIZE: str = "64M"


@dataclass
class Rhel:
RHEL7_8_IMG: str | None = None
RHEL7_9_IMG: str | None = None
RHEL8_0_IMG: str | None = None
RHEL8_2_IMG: str | None = None
RHEL8_8_IMG: str | None = None
RHEL8_9_IMG: str | None = None
RHEL8_10_IMG: str | None = None
RHEL9_3_IMG: str | None = None
RHEL9_4_IMG: str | None = None
RHEL9_5_IMG: str | None = None
RHEL9_6_IMG: str | None = None
RHEL8_REGISTRY_GUEST_IMG: str = "registry.redhat.io/rhel8/rhel-guest-image"
RHEL9_REGISTRY_GUEST_IMG: str = "registry.redhat.io/rhel9/rhel-guest-image"
# TODO: change back to registry.redhat.io when rhel10 is available
RHEL10_REGISTRY_GUEST_IMG: str = "registry.stage.redhat.io/rhel10/rhel-guest-image"
DIR: str = f"{BASE_IMAGES_DIR}/rhel-images"
DEFAULT_DV_SIZE: str = "20Gi"
DEFAULT_MEMORY_SIZE: str = "1.5Gi"
LATEST_RELEASE_STR: str | None = None


@dataclass
class Windows:
WIN10_IMG: str | None = None
WIN10_WSL2_IMG: str | None = None
WIN10_ISO_IMG: str | None = None
WIN2k16_IMG: str | None = None
WIN2k19_IMG: str | None = None
WIN2k25_IMG: str | None = None
WIN2k19_HA_IMG: str | None = None
WIN11_IMG: str | None = None
WIN11_WSL2_IMG: str | None = None
WIN11_ISO_IMG: str | None = None
WIN19_RAW: str | None = None
WIN2022_IMG: str | None = None
WIN2022_ISO_IMG: str | None = None
WIN2025_ISO_IMG: str | None = None
DIR: str = f"{BASE_IMAGES_DIR}/windows-images"
UEFI_WIN_DIR: str = f"{DIR}/uefi"
HA_DIR: str = f"{DIR}/HA-images"
ISO_WIN10_DIR: str = f"{DIR}/install_iso/win10"
ISO_WIN11_DIR: str = f"{DIR}/install_iso/win11"
ISO_WIN2022_DIR: str = f"{DIR}/install_iso/win2022"
ISO_WIN2025_DIR: str = f"{DIR}/install_iso/win2025"
DEFAULT_DV_SIZE: str = "70Gi"
DEFAULT_MEMORY_SIZE: str = "8Gi"
DEFAULT_MEMORY_SIZE_WSL: str = "12Gi"
DEFAULT_CPU_CORES: int = 4
DEFAULT_CPU_THREADS: int = 2
LATEST_RELEASE_STR: str | None = None


@dataclass
class Fedora:
FEDORA41_IMG: str | None = None
FEDORA_CONTAINER_IMAGE: str | None = None
DISK_DEMO: str | None = None
DIR: str = f"{BASE_IMAGES_DIR}/fedora-images"
DEFAULT_DV_SIZE: str = "10Gi"
DEFAULT_MEMORY_SIZE: str = "1Gi"
LATEST_RELEASE_STR: str | None = None


@dataclass
class Centos:
CENTOS_STREAM_9_IMG: str | None = None
DIR: str = f"{BASE_IMAGES_DIR}/centos-images"
DEFAULT_DV_SIZE: str = "15Gi"
LATEST_RELEASE_STR: str | None = None


@dataclass
class Cdi:
QCOW2_IMG: str | None = None
DIR: str = f"{BASE_IMAGES_DIR}/cdi-test-images"
DEFAULT_DV_SIZE: str = "1Gi"
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ markers =
# Cluster markers
## Architecture support
arm64: Tests that can run on ARM-based cluster
x86_64: Tests that can run on x86_64-based cluster
s390x: Tests that can run on s390x-based cluster

## Hardware requirements
special_infra: Tests that requires special infrastructure. e.g. sriov, gpu etc.
Expand Down Expand Up @@ -91,7 +93,6 @@ addopts =
-p no:logging
--basetemp=/tmp/pytest
--strict-markers
--tc-file=tests/global_config.py
--tc-format=python
--show-progress
--order-dependencies
Expand Down
21 changes: 14 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@
POD_SECURITY_NAMESPACE_LABELS,
PREFERENCE_STR,
RHEL9_PREFERENCE,
RHEL9_PREFERENCE_S390X,
RHEL_WITH_INSTANCETYPE_AND_PREFERENCE,
RHSM_SECRET_NAME,
S390X,
SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME,
TIMEOUT_3MIN,
TIMEOUT_4MIN,
Expand Down Expand Up @@ -147,6 +149,7 @@
get_hyperconverged_resource,
get_infrastructure,
get_node_selector_dict,
get_nodes_cpu_architecture,
get_nodes_cpu_model,
get_nodes_with_label,
get_pods,
Expand Down Expand Up @@ -1906,12 +1909,14 @@ def rhel_latest_os_params():
"""This fixture is needed as during collection pytest_testconfig is empty.
os_params or any globals using py_config in conftest cannot be used.
"""
latest_rhel_dict = py_config["latest_rhel_os_dict"]
return {
"rhel_image_path": f"{get_test_artifact_server_url()}{latest_rhel_dict['image_path']}",
"rhel_dv_size": latest_rhel_dict["dv_size"],
"rhel_template_labels": latest_rhel_dict["template_labels"],
}
if latest_rhel_dict := py_config.get("latest_rhel_os_dict"):
return {
"rhel_image_path": f"{get_test_artifact_server_url()}{latest_rhel_dict['image_path']}",
"rhel_dv_size": latest_rhel_dict["dv_size"],
"rhel_template_labels": latest_rhel_dict["template_labels"],
}

raise ValueError("Failed to get latest RHEL OS parameters")


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -2500,7 +2505,9 @@ def rhel_vm_with_instancetype_and_preference_for_cloning(namespace, unprivileged
namespace=namespace.name,
client=unprivileged_client,
vm_instance_type=VirtualMachineClusterInstancetype(name=U1_SMALL),
vm_preference=VirtualMachineClusterPreference(name=RHEL9_PREFERENCE),
vm_preference=VirtualMachineClusterPreference(
name=RHEL9_PREFERENCE_S390X if get_nodes_cpu_architecture() == S390X else RHEL9_PREFERENCE
),
os_flavor=OS_FLAVOR_RHEL,
) as vm:
running_vm(vm=vm)
Expand Down
Loading