From 03373cac8fd0d203dc4907fb420e505c5dcad9b9 Mon Sep 17 00:00:00 2001 From: Nishan Acharya Date: Mon, 4 Aug 2025 23:09:07 +0200 Subject: [PATCH] refactor: improve architecture detection and feature support handling in tests Signed-off-by: Nishan Acharya --- tests/containers/architecture_support.py | 11 +++++++ tests/containers/architecture_utils.py | 31 +++++++++++++++++++ .../workbenches/jupyterlab/jupyterlab_test.py | 18 +++++------ 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 tests/containers/architecture_support.py create mode 100644 tests/containers/architecture_utils.py diff --git a/tests/containers/architecture_support.py b/tests/containers/architecture_support.py new file mode 100644 index 0000000000..b4fba478bf --- /dev/null +++ b/tests/containers/architecture_support.py @@ -0,0 +1,11 @@ +"""Centralized configuration for architecture-specific feature limitations.""" + +ARCHITECTURE_LIMITATIONS = { + "s390x": {"pdf_export": False, "pdf_export_reason": "TexLive and Pandoc dependencies not available on s390x"}, + "x86_64": {"pdf_export": True, "pdf_export_reason": "Full support available"}, + "aarch64": {"pdf_export": True, "pdf_export_reason": "Full support available"}, + "ppc64le": {"pdf_export": True, "pdf_export_reason": "Full support available"}, +} + +# Architecture mapping from uname -m to common names +ARCHITECTURE_NAMES = {"x86_64": "x86_64", "aarch64": "arm64", "ppc64le": "ppc64le", "s390x": "s390x"} diff --git a/tests/containers/architecture_utils.py b/tests/containers/architecture_utils.py new file mode 100644 index 0000000000..b2f8f3f401 --- /dev/null +++ b/tests/containers/architecture_utils.py @@ -0,0 +1,31 @@ +"""Architecture detection utilities for container tests.""" + +import pytest + +from tests.containers import docker_utils +from tests.containers.architecture_support import ARCHITECTURE_LIMITATIONS +from tests.containers.workbenches.workbench_image_test import WorkbenchContainer + + +@pytest.fixture(scope="function") +def container_architecture(jupyterlab_image): + """Cache architecture detection per test function.""" + container = WorkbenchContainer(image=jupyterlab_image.name, user=4321, group_add=[0]) + container.start(wait_for_readiness=False) + try: + exit_code, arch_output = container.exec(["uname", "-m"]) + if exit_code == 0: + return arch_output.decode().strip() + return None + finally: + docker_utils.NotebookContainer(container).stop(timeout=0) + + +def is_feature_supported(architecture: str, feature: str) -> bool: + """Check if a feature is supported on the given architecture.""" + return ARCHITECTURE_LIMITATIONS.get(architecture, {}).get(feature, True) + + +def get_architecture_limitation_reason(architecture: str, feature: str) -> str: + """Get the reason why a feature is not supported on the given architecture.""" + return ARCHITECTURE_LIMITATIONS.get(architecture, {}).get(f"{feature}_reason", "Unknown limitation") diff --git a/tests/containers/workbenches/jupyterlab/jupyterlab_test.py b/tests/containers/workbenches/jupyterlab/jupyterlab_test.py index 8d43af2dda..00587b4b0f 100644 --- a/tests/containers/workbenches/jupyterlab/jupyterlab_test.py +++ b/tests/containers/workbenches/jupyterlab/jupyterlab_test.py @@ -8,6 +8,10 @@ import requests from tests.containers import conftest, docker_utils +from tests.containers.architecture_utils import ( + get_architecture_limitation_reason, + is_feature_supported, +) from tests.containers.workbenches.workbench_image_test import WorkbenchContainer @@ -56,16 +60,12 @@ def test_spinner_html_loaded(self, jupyterlab_image: conftest.Image) -> None: @allure.issue("RHOAIENG-16568") @allure.description("Check that PDF export is working correctly") - def test_pdf_export(self, jupyterlab_image: conftest.Image) -> None: + def test_pdf_export(self, jupyterlab_image: conftest.Image, container_architecture) -> None: + # Skip if PDF export is not supported on this architecture + if not is_feature_supported(container_architecture, "pdf_export"): + reason = get_architecture_limitation_reason(container_architecture, "pdf_export") + pytest.skip(f"PDF export functionality is not supported on {container_architecture} architecture: {reason}") container = WorkbenchContainer(image=jupyterlab_image.name, user=4321, group_add=[0]) - # Skip if we're running on s390x architecture - container.start(wait_for_readiness=False) - try: - exit_code, arch_output = container.exec(["uname", "-m"]) - if exit_code == 0 and arch_output.decode().strip() == "s390x": - pytest.skip("PDF export functionality is not supported on s390x architecture") - finally: - docker_utils.NotebookContainer(container).stop(timeout=0) test_file_name = "test.ipybn" test_file_content = """{ "cells": [