From cd19e03acb3be6067751360586ef08c8f1938671 Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 09:47:20 +0300 Subject: [PATCH 1/6] refactor(constants): final cleanup of old constants imports Remove all re-exports from utilities/constants/__init__.py except Images. Migrate remaining callers to direct submodule imports, move NODE_STR from aaq.py to cluster.py, and update docs and analyzer test fixtures. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- conftest.py | 8 +- docs/ARCHITECTURE_SUPPORT.md | 12 +- docs/DEVELOPER_GUIDE.md | 2 +- docs/QUARANTINE_GUIDELINES.md | 2 +- libs/storage/config.py | 5 +- libs/vm/factory.py | 3 +- libs/vm/vm.py | 2 +- .../tests/test_pytest_marker_analyzer.py | 4 +- .../test_after_cluster_deploy_sanity.py | 8 +- tests/conftest.py | 80 +- tests/global_config.py | 52 +- tests/global_config_amd64.py | 4 +- tests/global_config_arm64.py | 12 +- tests/global_config_aro.py | 2 +- tests/global_config_aws.py | 3 +- tests/global_config_gcnv.py | 2 +- tests/global_config_gcp.py | 2 +- tests/global_config_ibm_spectrum_sc.py | 2 +- tests/global_config_lvms.py | 6 +- tests/global_config_multiarch.py | 8 +- tests/global_config_nfs.py | 2 +- tests/global_config_oci.py | 6 +- tests/global_config_rh_it.py | 2 +- tests/global_config_s390x.py | 6 +- tests/global_config_sno.py | 6 +- tests/global_config_sno_hpp.py | 7 +- tests/observability/metrics/utils.py | 2 +- tests/scale/test_scale_benchmark.py | 8 +- tests/storage/disk_preallocation/utils.py | 2 +- tests/storage/hpp/test_hpp_node_placement.py | 2 +- tests/utils.py | 20 +- utilities/architecture.py | 2 +- utilities/constants/__init__.py | 824 +----------------- utilities/constants/aaq.py | 1 - utilities/constants/cluster.py | 3 +- utilities/unittests/README.md | 2 +- 36 files changed, 192 insertions(+), 922 deletions(-) diff --git a/conftest.py b/conftest.py index 1dc2625140..0792568486 100644 --- a/conftest.py +++ b/conftest.py @@ -32,13 +32,13 @@ import utilities.infra # noqa from libs.storage.config import StorageClassConfig from utilities.bitwarden import get_cnv_tests_secret_by_name -from utilities.constants import ( - AMD_64, +from utilities.constants.architecture import AMD_64 +from utilities.constants.namespaces import NamespacesNames +from utilities.constants.pytest import ( QUARANTINED, SETUP_ERROR, - TIMEOUT_5MIN, - NamespacesNames, ) +from utilities.constants.timeouts import TIMEOUT_5MIN from utilities.data_collector import ( collect_default_cnv_must_gather_with_vm_gather, get_data_collector_dir, diff --git a/docs/ARCHITECTURE_SUPPORT.md b/docs/ARCHITECTURE_SUPPORT.md index 1230666388..b8edaa211d 100644 --- a/docs/ARCHITECTURE_SUPPORT.md +++ b/docs/ARCHITECTURE_SUPPORT.md @@ -28,13 +28,13 @@ pytest -m s390x ... Note: to run on the default architecture `amd64`, 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) +Images for different architectures are managed under [images.py](../utilities/constants/images.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 name to the `ArchImages` under the relevant architecture and OS under [images.py](../utilities/constants/images.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 @@ -43,6 +43,6 @@ To add a new architecture: - Add a new pytest marker for the architecture - Add a new pytest global config file for the architecture under [tests/global_config_.py](../tests/global_config_.py) - The file should contain the relevant OS matrix(es); see [global_config_amd64.py](../tests/global_config_amd64.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) +- Add the architecture name as a constant under [architecture.py](../utilities/constants/architecture.py) +- Add the architecture name to `SUPPORTED_CPU_ARCHITECTURES` under [architecture.py](../utilities/constants/architecture.py) +- Add the architecture name to the `ArchImages` under the relevant architecture and OS under [images.py](../utilities/constants/images.py) diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index fbe8ca6f86..218bb9dca7 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -9,7 +9,7 @@ The project is structured as follows: - [utilities](../utilities): Base directory for utility functions - Each module contains a set of utility functions related to a specific topic, for example: - [infra](../utilities/infra.py): Infrastructure-related (cluster resources) utility functions - - [constants](../utilities/constants.py): Constants used in the project + - [constants](../utilities/constants/): Constants package — import from the relevant submodule (e.g. `from utilities.constants.timeouts import TIMEOUT_5MIN`). - [docs](../docs): Documentation - [py_config](../tests/global_config.py) contains tests-specific configuration which can be controlled from the command line. Please refer to [pytest-testconfig](https://github.com/wojole/pytest-testconfig) for more information. diff --git a/docs/QUARANTINE_GUIDELINES.md b/docs/QUARANTINE_GUIDELINES.md index face3fde35..4ebcf8d57e 100644 --- a/docs/QUARANTINE_GUIDELINES.md +++ b/docs/QUARANTINE_GUIDELINES.md @@ -92,7 +92,7 @@ Apply pytest's `xfail` marker with `run=False`, for example: ```python import pytest -from utilities.constants import QUARANTINED +from utilities.constants.pytest import QUARANTINED @pytest.mark.xfail( diff --git a/libs/storage/config.py b/libs/storage/config.py index 48dbdbd461..17b70ab981 100644 --- a/libs/storage/config.py +++ b/libs/storage/config.py @@ -5,7 +5,10 @@ from ocp_resources.datavolume import DataVolume -from utilities.constants import HPP_CAPABILITIES, StorageClassNames +from utilities.constants.storage import ( + HPP_CAPABILITIES, + StorageClassNames, +) from utilities.storage import HppCsiStorageClass LOGGER = logging.getLogger(__name__) diff --git a/libs/vm/factory.py b/libs/vm/factory.py index 9187be46c0..65a207b4a3 100644 --- a/libs/vm/factory.py +++ b/libs/vm/factory.py @@ -6,7 +6,8 @@ from libs.vm.spec import CPU, Devices, Domain, Memory, Metadata, Template, VMISpec, VMSpec from libs.vm.vm import BaseVirtualMachine, container_image, containerdisk_storage from utilities import constants -from utilities.constants import MULTIARCH, OS_FLAVOR_FEDORA +from utilities.constants.architecture import MULTIARCH +from utilities.constants.images import OS_FLAVOR_FEDORA def fedora_vm( diff --git a/libs/vm/vm.py b/libs/vm/vm.py index 31b8706062..910313f376 100644 --- a/libs/vm/vm.py +++ b/libs/vm/vm.py @@ -27,7 +27,7 @@ ) from tests.network.libs import cloudinit from utilities import infra -from utilities.constants import CLOUD_INIT_DISK_NAME +from utilities.constants.virt import CLOUD_INIT_DISK_NAME from utilities.virt import get_oc_image_info, vm_console_run_commands if TYPE_CHECKING: diff --git a/scripts/tests_analyzer/tests/test_pytest_marker_analyzer.py b/scripts/tests_analyzer/tests/test_pytest_marker_analyzer.py index 3750a5041f..c81151041e 100644 --- a/scripts/tests_analyzer/tests/test_pytest_marker_analyzer.py +++ b/scripts/tests_analyzer/tests/test_pytest_marker_analyzer.py @@ -2874,7 +2874,7 @@ class TestImportContinuationSafety: def test_import_continuation_line_is_safe(self, tmp_path: Path) -> None: """Import continuation lines do not trigger conservative fallback.""" source = ( - "from utilities.constants import (\n" + "from utilities.constants.timeouts import (\n" " TIMEOUT_1MIN,\n" " TIMEOUT_2MIN,\n" ")\n" @@ -2886,7 +2886,7 @@ def test_import_continuation_line_is_safe(self, tmp_path: Path) -> None: "--- a/utilities/example.py\n" "+++ b/utilities/example.py\n" "@@ -1,3 +1,4 @@\n" - " from utilities.constants import (\n" + " from utilities.constants.timeouts import (\n" " TIMEOUT_1MIN,\n" "+ TIMEOUT_2MIN,\n" " )\n" diff --git a/tests/after_cluster_deploy_sanity/test_after_cluster_deploy_sanity.py b/tests/after_cluster_deploy_sanity/test_after_cluster_deploy_sanity.py index 76375102ec..d63d21c313 100644 --- a/tests/after_cluster_deploy_sanity/test_after_cluster_deploy_sanity.py +++ b/tests/after_cluster_deploy_sanity/test_after_cluster_deploy_sanity.py @@ -11,7 +11,13 @@ from ocp_utilities.infra import assert_nodes_in_healthy_condition, assert_nodes_schedulable from timeout_sampler import TimeoutSampler -from utilities.constants import KUBELET_READY_CONDITION, TIMEOUT_1MIN, TIMEOUT_5MIN, TIMEOUT_5SEC, TIMEOUT_10MIN +from utilities.constants.monitoring import KUBELET_READY_CONDITION +from utilities.constants.timeouts import ( + TIMEOUT_1MIN, + TIMEOUT_5MIN, + TIMEOUT_5SEC, + TIMEOUT_10MIN, +) from utilities.hco import get_installed_hco_csv, wait_for_hco_conditions from utilities.infra import wait_for_pods_running from utilities.operator import wait_for_cluster_operator_stabilize diff --git a/tests/conftest.py b/tests/conftest.py index ab0fb7ca92..233fd03adb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,55 +77,73 @@ from utilities.artifactory import get_artifactory_header, get_http_image_url, get_test_artifact_server_url from utilities.bitwarden import get_cnv_tests_secret_by_name from utilities.cluster import cache_admin_client, get_oc_whoami_username -from utilities.constants import ( +from utilities.constants import Images +from utilities.constants.aaq import ( AAQ_NAMESPACE_LABEL, - ARM_64, ARQ_QUOTA_HARD_SPEC, +) +from utilities.constants.architecture import ( + ARM_64, + S390X, +) +from utilities.constants.cluster import ( AUDIT_LOGS_PATH, + CNV_TEST_SERVICE_ACCOUNT, + KUBECONFIG, + KUBERNETES_ARCH_LABEL, + NODE_ROLE_KUBERNETES_IO, + NODE_TYPE_WORKER_LABEL, + OC_ADM_LOGS_COMMAND, + POD_SECURITY_NAMESPACE_LABELS, + RHSM_SECRET_NAME, + UTILITY, + WORKER_NODE_LABEL_KEY, + WORKERS_TYPE, +) +from utilities.constants.components import ( CDI_KUBEVIRT_HYPERCONVERGED, CLUSTER, - CNV_TEST_SERVICE_ACCOUNT, - CNV_VM_SSH_KEY_PATH, - ES_NONE, - EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS, + KUBEMACPOOL_MAC_CONTROLLER_MANAGER, + RHEL9_STR, + VIRTCTL_CLI_DOWNLOADS, +) +from utilities.constants.hco import ( FEATURE_GATES, HCO_SUBSCRIPTION, HOTFIX_STR, + SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME, + UpgradeStreams, +) +from utilities.constants.images import OS_FLAVOR_RHEL +from utilities.constants.instance_types import ( + EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS, INSTANCE_TYPE_STR, + PREFERENCE_STR, +) +from utilities.constants.namespaces import NamespacesNames +from utilities.constants.networking import ( KMP_ENABLED_LABEL, KMP_VM_ASSIGNMENT_LABEL, - KUBECONFIG, - KUBEMACPOOL_MAC_CONTROLLER_MANAGER, KUBEMACPOOL_MAC_RANGE_CONFIG, - KUBERNETES_ARCH_LABEL, LINUX_BRIDGE, - MIGRATION_POLICY_VM_LABEL, - NODE_HUGE_PAGES_1GI_KEY, - NODE_ROLE_KUBERNETES_IO, - NODE_TYPE_WORKER_LABEL, - OC_ADM_LOGS_COMMAND, - OS_FLAVOR_RHEL, OVS_BRIDGE, - POD_SECURITY_NAMESPACE_LABELS, - PREFERENCE_STR, - RHEL9_STR, - RHSM_SECRET_NAME, - S390X, - SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME, +) +from utilities.constants.pytest import ( + UNPRIVILEGED_PASSWORD, + UNPRIVILEGED_USER, +) +from utilities.constants.storage import StorageClassNames +from utilities.constants.timeouts import ( TIMEOUT_3MIN, TIMEOUT_4MIN, TIMEOUT_5MIN, - UNPRIVILEGED_PASSWORD, - UNPRIVILEGED_USER, - UTILITY, - VIRTCTL_CLI_DOWNLOADS, +) +from utilities.constants.virt import ( + CNV_VM_SSH_KEY_PATH, + ES_NONE, + MIGRATION_POLICY_VM_LABEL, + NODE_HUGE_PAGES_1GI_KEY, VIRTIO, - WORKER_NODE_LABEL_KEY, - WORKERS_TYPE, - Images, - NamespacesNames, - StorageClassNames, - UpgradeStreams, ) from utilities.cpu import ( find_common_cpu_model_for_live_migration, diff --git a/tests/global_config.py b/tests/global_config.py index 608052f976..774d518d93 100644 --- a/tests/global_config.py +++ b/tests/global_config.py @@ -7,42 +7,56 @@ from utilities.architecture import get_cluster_architecture from utilities.artifactory import BASE_ARTIFACTORY_LOCATION -from utilities.constants import ( +from utilities.constants import Images +from utilities.constants.aaq import ( AAQ_VIRTUAL_RESOURCES, AAQ_VMI_POD_USAGE, - ALL_CNV_CRDS, +) +from utilities.constants.architecture import MULTIARCH +from utilities.constants.components import ( ALL_CNV_DAEMONSETS, ALL_CNV_DEPLOYMENTS, ALL_CNV_PODS, ALL_HCO_RELATED_OBJECTS, - BREW_REGISTRY_SOURCE, - CENTOS_STREAM9_PREFERENCE, - CENTOS_STREAM10_PREFERENCE, CNV_OPERATORS, CNV_PROMETHEUS_RULES, HCO_CATALOG_SOURCE, - HPP_CAPABILITIES, - LINUX_BRIDGE, - MONITORING_METRICS, - MULTIARCH, - OS_FLAVOR_FEDORA, - OVS_BRIDGE, + VM_CONSOLE_PROXY_CLUSTER_RESOURCES, + VM_CONSOLE_PROXY_NAMESPACE_RESOURCES, +) +from utilities.constants.hco import ( + ALL_CNV_CRDS, PRODUCTION_CATALOG_SOURCE, + TLS_CUSTOM_POLICY, + TLS_OLD_POLICY, +) +from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.instance_types import ( + CENTOS_STREAM9_PREFERENCE, + CENTOS_STREAM10_PREFERENCE, RHEL8_PREFERENCE, RHEL9_PREFERENCE, RHEL10_PREFERENCE, + U1_MEDIUM_STR, +) +from utilities.constants.monitoring import MONITORING_METRICS +from utilities.constants.namespaces import NamespacesNames +from utilities.constants.networking import ( + LINUX_BRIDGE, + OVS_BRIDGE, +) +from utilities.constants.storage import ( + BREW_REGISTRY_SOURCE, + HPP_CAPABILITIES, + StorageClassNames, +) +from utilities.constants.tekton import ( TEKTON_AVAILABLE_PIPELINEREF, TEKTON_AVAILABLE_TASKS, +) +from utilities.constants.timeouts import ( TIMEOUT_5MIN, TIMEOUT_5SEC, - TLS_CUSTOM_POLICY, - TLS_OLD_POLICY, - U1_MEDIUM_STR, - VM_CONSOLE_PROXY_CLUSTER_RESOURCES, - VM_CONSOLE_PROXY_NAMESPACE_RESOURCES, - Images, - NamespacesNames, - StorageClassNames, ) from utilities.storage import HppCsiStorageClass diff --git a/tests/global_config_amd64.py b/tests/global_config_amd64.py index 20d9595a53..3f8bbc8c19 100644 --- a/tests/global_config_amd64.py +++ b/tests/global_config_amd64.py @@ -1,9 +1,9 @@ from typing import Any -from utilities.constants import ( +from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.instance_types import ( CENTOS_STREAM9_PREFERENCE, CENTOS_STREAM10_PREFERENCE, - OS_FLAVOR_FEDORA, RHEL8_PREFERENCE, RHEL9_PREFERENCE, RHEL10_PREFERENCE, diff --git a/tests/global_config_arm64.py b/tests/global_config_arm64.py index 0f36ed8398..26c790fa0b 100644 --- a/tests/global_config_arm64.py +++ b/tests/global_config_arm64.py @@ -2,15 +2,17 @@ from ocp_resources.datavolume import DataVolume -from utilities.constants import ( - ARM_64, +from utilities.constants import Images +from utilities.constants.architecture import ARM_64 +from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.instance_types import ( CENTOS_STREAM10_PREFERENCE, EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS, - HPP_CAPABILITIES, - OS_FLAVOR_FEDORA, PREFERENCE_STR, RHEL10_PREFERENCE, - Images, +) +from utilities.constants.storage import ( + HPP_CAPABILITIES, StorageClassNames, ) from utilities.storage import HppCsiStorageClass diff --git a/tests/global_config_aro.py b/tests/global_config_aro.py index f9d834cb0f..3260d8939d 100644 --- a/tests/global_config_aro.py +++ b/tests/global_config_aro.py @@ -3,7 +3,7 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_aws.py b/tests/global_config_aws.py index 3f25cdf30e..39dded0f81 100644 --- a/tests/global_config_aws.py +++ b/tests/global_config_aws.py @@ -3,7 +3,8 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import Images, StorageClassNames +from utilities.constants import Images +from utilities.constants.storage import StorageClassNames global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_gcnv.py b/tests/global_config_gcnv.py index 7668dda817..8906aa142f 100644 --- a/tests/global_config_gcnv.py +++ b/tests/global_config_gcnv.py @@ -3,7 +3,7 @@ from ocp_resources.datavolume import DataVolume from pytest_testconfig import load_python -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_gcp.py b/tests/global_config_gcp.py index 9155a582fa..bf78e1cb56 100644 --- a/tests/global_config_gcp.py +++ b/tests/global_config_gcp.py @@ -3,7 +3,7 @@ from ocp_resources.datavolume import DataVolume from pytest_testconfig import load_python -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_ibm_spectrum_sc.py b/tests/global_config_ibm_spectrum_sc.py index e4c3de150c..95116c5401 100644 --- a/tests/global_config_ibm_spectrum_sc.py +++ b/tests/global_config_ibm_spectrum_sc.py @@ -3,7 +3,7 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_lvms.py b/tests/global_config_lvms.py index 9977129a2f..087ba11f8d 100644 --- a/tests/global_config_lvms.py +++ b/tests/global_config_lvms.py @@ -3,7 +3,11 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import ACCESS_MODE, VOLUME_MODE, StorageClassNames +from utilities.constants.storage import ( + ACCESS_MODE, + VOLUME_MODE, + StorageClassNames, +) global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_multiarch.py b/tests/global_config_multiarch.py index acba8653ed..287ba9965f 100644 --- a/tests/global_config_multiarch.py +++ b/tests/global_config_multiarch.py @@ -2,17 +2,19 @@ from ocp_resources.datavolume import DataVolume -from utilities.constants import ( +from utilities.constants.architecture import ( AMD_64, ARM_64, +) +from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.instance_types import ( CENTOS_STREAM9_PREFERENCE, CENTOS_STREAM10_PREFERENCE, - OS_FLAVOR_FEDORA, RHEL8_PREFERENCE, RHEL9_PREFERENCE, RHEL10_PREFERENCE, - StorageClassNames, ) +from utilities.constants.storage import StorageClassNames global config diff --git a/tests/global_config_nfs.py b/tests/global_config_nfs.py index 0e5edcde77..cf90288e8c 100644 --- a/tests/global_config_nfs.py +++ b/tests/global_config_nfs.py @@ -3,7 +3,7 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_oci.py b/tests/global_config_oci.py index 845ae5fbe4..c0b3acb5a8 100644 --- a/tests/global_config_oci.py +++ b/tests/global_config_oci.py @@ -3,7 +3,11 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import ACCESS_MODE, VOLUME_MODE, StorageClassNames +from utilities.constants.storage import ( + ACCESS_MODE, + VOLUME_MODE, + StorageClassNames, +) global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_rh_it.py b/tests/global_config_rh_it.py index 08e6bdb53c..0b6435a391 100644 --- a/tests/global_config_rh_it.py +++ b/tests/global_config_rh_it.py @@ -3,7 +3,7 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import StorageClassNames +from utilities.constants.storage import StorageClassNames global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_s390x.py b/tests/global_config_s390x.py index d170d788a0..94027e7f20 100644 --- a/tests/global_config_s390x.py +++ b/tests/global_config_s390x.py @@ -1,12 +1,12 @@ from typing import Any -from utilities.constants import ( +from utilities.constants.architecture import S390X +from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.instance_types import ( CENTOS_STREAM9_PREFERENCE, EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS, - OS_FLAVOR_FEDORA, PREFERENCE_STR, RHEL9_PREFERENCE, - S390X, ) global config diff --git a/tests/global_config_sno.py b/tests/global_config_sno.py index 34c166ed06..044f7e5f0c 100644 --- a/tests/global_config_sno.py +++ b/tests/global_config_sno.py @@ -3,7 +3,11 @@ import pytest_testconfig from ocp_resources.datavolume import DataVolume -from utilities.constants import ACCESS_MODE, VOLUME_MODE, StorageClassNames +from utilities.constants.storage import ( + ACCESS_MODE, + VOLUME_MODE, + StorageClassNames, +) global config global_config = pytest_testconfig.load_python(py_file="tests/global_config.py", encoding="utf-8") diff --git a/tests/global_config_sno_hpp.py b/tests/global_config_sno_hpp.py index 61824351a0..d4645ea659 100644 --- a/tests/global_config_sno_hpp.py +++ b/tests/global_config_sno_hpp.py @@ -2,7 +2,12 @@ import pytest_testconfig -from utilities.constants import ALL_CNV_DAEMONSETS, ALL_CNV_DEPLOYMENTS, ALL_CNV_PODS, HPP_CAPABILITIES +from utilities.constants.components import ( + ALL_CNV_DAEMONSETS, + ALL_CNV_DEPLOYMENTS, + ALL_CNV_PODS, +) +from utilities.constants.storage import HPP_CAPABILITIES from utilities.storage import HppCsiStorageClass global config diff --git a/tests/observability/metrics/utils.py b/tests/observability/metrics/utils.py index 4b58c03474..60dbf3c9ca 100644 --- a/tests/observability/metrics/utils.py +++ b/tests/observability/metrics/utils.py @@ -35,7 +35,7 @@ get_test_artifact_server_url, ) from utilities.constants import Images -from utilities.constants.aaq import NODE_STR +from utilities.constants.cluster import NODE_STR from utilities.constants.components import ( VIRT_CONTROLLER, VIRT_HANDLER, diff --git a/tests/scale/test_scale_benchmark.py b/tests/scale/test_scale_benchmark.py index 159f0b3f74..773eba28a6 100644 --- a/tests/scale/test_scale_benchmark.py +++ b/tests/scale/test_scale_benchmark.py @@ -31,14 +31,16 @@ get_artifactory_config_map, get_artifactory_secret, ) -from utilities.constants import ( - NODE_STR, +from utilities.constants.cluster import NODE_STR +from utilities.constants.images import ( OS_FLAVOR_FEDORA, OS_FLAVOR_RHEL, OS_FLAVOR_WINDOWS, +) +from utilities.constants.storage import StorageClassNames +from utilities.constants.timeouts import ( TIMEOUT_1MIN, TIMEOUT_30MIN, - StorageClassNames, ) from utilities.infra import ( create_ns, diff --git a/tests/storage/disk_preallocation/utils.py b/tests/storage/disk_preallocation/utils.py index 604d6ff009..817f1749b8 100644 --- a/tests/storage/disk_preallocation/utils.py +++ b/tests/storage/disk_preallocation/utils.py @@ -6,7 +6,7 @@ from ocp_resources.resource import NamespacedResource from timeout_sampler import TimeoutExpiredError, TimeoutSampler -from utilities.constants import TIMEOUT_2MIN +from utilities.constants.timeouts import TIMEOUT_2MIN if TYPE_CHECKING: from ocp_resources.cdi_config import CDIConfig diff --git a/tests/storage/hpp/test_hpp_node_placement.py b/tests/storage/hpp/test_hpp_node_placement.py index 4026369595..791ecf4b2e 100644 --- a/tests/storage/hpp/test_hpp_node_placement.py +++ b/tests/storage/hpp/test_hpp_node_placement.py @@ -14,7 +14,7 @@ VM_NAME, edit_hpp_with_node_selector, ) -from utilities.constants.aaq import NODE_STR +from utilities.constants.cluster import NODE_STR from utilities.storage import check_disk_count_in_vm LOGGER = logging.getLogger(__name__) diff --git a/tests/utils.py b/tests/utils.py index 874dcc7633..b6a5489ab3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -34,12 +34,17 @@ get_http_image_url, get_test_artifact_server_url, ) -from utilities.constants import ( - DISK_SERIAL, - NODE_HUGE_PAGES_1GI_KEY, +from utilities.constants import Images +from utilities.constants.cluster import RHSM_SECRET_NAME +from utilities.constants.images import ( OS_FLAVOR_WIN_CONTAINER_DISK, OS_FLAVOR_WINDOWS, - RHSM_SECRET_NAME, +) +from utilities.constants.instance_types import ( + U1_LARGE, + WINDOWS_2K22_PREFERENCE, +) +from utilities.constants.timeouts import ( TCP_TIMEOUT_30SEC, TIMEOUT_1MIN, TIMEOUT_1SEC, @@ -50,10 +55,11 @@ TIMEOUT_10SEC, TIMEOUT_15SEC, TIMEOUT_30MIN, - U1_LARGE, +) +from utilities.constants.virt import ( + DISK_SERIAL, + NODE_HUGE_PAGES_1GI_KEY, WIN_2K22, - WINDOWS_2K22_PREFERENCE, - Images, ) from utilities.data_collector import get_data_collector_dir, write_to_file from utilities.exceptions import ResourceValueError diff --git a/utilities/architecture.py b/utilities/architecture.py index df57329dc4..2a2974bf01 100644 --- a/utilities/architecture.py +++ b/utilities/architecture.py @@ -23,7 +23,7 @@ def get_cluster_architecture() -> set[str]: """ # Lazy import to avoid circular dependency # TODO: remove when/if utilities modules are refactored - from utilities.constants import KUBERNETES_ARCH_LABEL # noqa: PLC0415 + from utilities.constants.cluster import KUBERNETES_ARCH_LABEL # noqa: PLC0415 # Needed for CI if arch := os.environ.get("OPENSHIFT_VIRTUALIZATION_TEST_IMAGES_ARCH"): diff --git a/utilities/constants/__init__.py b/utilities/constants/__init__.py index 58f6024f64..edf3008844 100644 --- a/utilities/constants/__init__.py +++ b/utilities/constants/__init__.py @@ -1,818 +1,16 @@ -# Compatibility shim: re-exports every public name from submodules so that -# existing `from utilities.constants import X` statements continue to work -# while the per-team import migration is in progress. -# This file will be emptied once all callers use direct submodule imports. +# Compatibility shim: re-exports `Images` only. # -# NOTE: `Images` is computed at the very bottom of this file (not in images.py) -# to avoid a circular import: the original computation called -# get_cluster_architecture() at module level, which does a lazy -# `from utilities.constants import KUBERNETES_ARCH_LABEL` inside -# utilities.architecture. With the package structure that lazy import would fail -# if triggered while the package is still being initialised. Placing the -# computation after all submodule imports guarantees that KUBERNETES_ARCH_LABEL -# (from cluster.py) is already in the namespace when get_cluster_architecture() runs. -from libs.infra.images import BASE_IMAGES_DIR +# `Images` is computed here (not in images.py) to avoid a circular import: +# get_cluster_architecture() is called at module level and historically imported +# from this package. Placing the computation here keeps images.py free of +# utilities/ dependencies beyond libs/. +# +# All other constants must be imported from their submodule directly, e.g.: +# from utilities.constants.cluster import KUBERNETES_ARCH_LABEL +# from utilities.constants.timeouts import TIMEOUT_5MIN from utilities.architecture import get_cluster_architecture as _get_cluster_architecture -from utilities.constants.aaq import ( - AAQ_NAMESPACE_LABEL, - AAQ_VIRTUAL_RESOURCES, - AAQ_VMI_POD_USAGE, - ARQ_QUOTA_HARD_SPEC, - LIMITS_CPU_STR, - LIMITS_MEMORY_STR, - NODE_STR, - POD_LIMITS_CPU, - POD_LIMITS_MEMORY, - POD_REQUESTS_CPU, - POD_REQUESTS_MEMORY, - PODS_STR, - QUOTA_FOR_ONE_VMI, - QUOTA_FOR_POD, - REQUESTS_CPU_STR, - REQUESTS_CPU_VMI_STR, - REQUESTS_INSTANCES_VMI_STR, - REQUESTS_MEMORY_STR, - REQUESTS_MEMORY_VMI_STR, - VM_CPU_CORES, - VM_MEMORY_GUEST, -) -from utilities.constants.architecture import ( - AMD, - AMD_64, - ARM_64, - INTEL, - LINUX_AMD_64, - MULTIARCH, - S390X, - SUPPORTED_CPU_ARCHITECTURES, - SUPPORTED_MULTIARCH_OPTIONS, - X86_64, -) -from utilities.constants.cluster import ( - AUDIT_LOGS_PATH, - BASE_EXCEPTIONS_DICT, - CNV_TEST_RUN_IN_PROGRESS, - CNV_TEST_RUN_IN_PROGRESS_NS, - CNV_TEST_SERVICE_ACCOUNT, - CNV_TESTS_CONTAINER, - COUNT_FIVE, - CPU_MODEL_LABEL_PREFIX, - CREATE_STR, - DELETE_STR, - GET_STR, - KUBECONFIG, - KUBERNETES_ARCH_LABEL, - LS_COMMAND, - NODE_ROLE_KUBERNETES_IO, - NODE_TYPE_WORKER_LABEL, - OC_ADM_LOGS_COMMAND, - POD_SECURITY_NAMESPACE_LABELS, - RHSM_SECRET_NAME, - TSC_FREQUENCY, - UPDATE_STR, - UTILITY, - VALUE_STR, - VERSION_LABEL_KEY, - WORKER_NODE_LABEL_KEY, - WORKERS_TYPE, -) -from utilities.constants.components import ( - AAQ_OPERATOR, - ALL_CNV_DAEMONSETS, - ALL_CNV_DEPLOYMENTS, - ALL_CNV_PODS, - ALL_HCO_RELATED_OBJECTS, - BRIDGE_MARKER, - CDI_APISERVER, - CDI_DEPLOYMENT, - CDI_KUBEVIRT_HYPERCONVERGED, - CDI_OPERATOR, - CDI_STR, - CDI_UPLOADPROXY, - CLUSTER, - CLUSTER_NETWORK_ADDONS_OPERATOR, - CNAO_OPERATOR, - CNV_OPERATORS, - CNV_PODS_NO_HPP_CSI_HPP_POOL, - CNV_PROMETHEUS_RULES, - CONFIGMAP_STR, - CONSOLE_PLUGIN_STR, - CONSOLECLIDOWNLOAD_STR, - CONSOLEQUICKSTART_STR, - CREATING_VIRTUAL_MACHINE, - CREATING_VIRTUAL_MACHINE_FROM_VOLUME, - DEPLOYMENT_STR, - GRAFANA_DASHBOARD_KUBEVIRT_TOP_CONSUMERS, - HCO_BEARER_AUTH, - HCO_CATALOG_SOURCE, - HCO_OPERATOR, - HCO_PART_OF_LABEL_VALUE, - HCO_WEBHOOK, - HOSTPATH_PROVISIONER, - HOSTPATH_PROVISIONER_CSI, - HOSTPATH_PROVISIONER_OPERATOR, - HPP_POOL, - HYPERCONVERGED_CLUSTER, - HYPERCONVERGED_CLUSTER_CLI_DOWNLOAD, - HYPERCONVERGED_CLUSTER_OPERATOR, - HYPERCONVERGED_CLUSTER_OPERATOR_METRICS, - IMAGESTREAM_STR, - KUBE_CNI_LINUX_BRIDGE_PLUGIN, - KUBEMACPOOL_CERT_MANAGER, - KUBEMACPOOL_MAC_CONTROLLER_MANAGER, - KUBEMACPOOL_PROMETHEUS_RULE, - KUBEVIRT_APISERVER_PROXY, - KUBEVIRT_APISERVER_PROXY_NP, - KUBEVIRT_CLUSTER_CRITICAL, - KUBEVIRT_CONSOLE_PLUGIN, - KUBEVIRT_CONSOLE_PLUGIN_NP, - KUBEVIRT_CONSOLE_PLUGIN_SERVICE, - KUBEVIRT_HCO_NAME, - KUBEVIRT_HYPERCONVERGED_OPERATOR_METRICS, - KUBEVIRT_HYPERCONVERGED_PROMETHEUS_RULE, - KUBEVIRT_IPAM_CONTROLLER_MANAGER, - KUBEVIRT_KUBEVIRT_HYPERCONVERGED, - KUBEVIRT_MIGRATION_CONTROLLER, - KUBEVIRT_MIGRATION_OPERATOR, - KUBEVIRT_OPERATOR, - KUBEVIRT_PLUGIN, - KUBEVIRT_STR, - KUBEVIRT_UI_CONFIG, - KUBEVIRT_UI_CONFIG_READER, - KUBEVIRT_UI_CONFIG_READER_ROLE_BINDING, - KUBEVIRT_UI_FEATURES, - KUBEVIRT_USER_SETTINGS, - MANAGED_BY_LABEL_VALUE_OLM, - MIGCONTROLLER_KUBEVIRT_HYPERCONVERGED, - NETWORKADDONSCONFIG_STR, - NETWORKPOLICY_STR, - NGINX_CONF, - POD_STR, - PRIORITYCLASS_STR, - PROMETHEUS_RULES_STR, - PROMETHEUSRULE_STR, - RHEL8_GUEST, - RHEL9_GUEST, - RHEL9_STR, - RHEL10_GUEST, - RHEL10_STR, - ROLE_STR, - ROLEBINDING_STR, - ROUTE_STR, - SECRET_STR, - SERVICE_STR, - SERVICEACCOUNT_STR, - SERVICEMONITOR_STR, - SSP_KUBEVIRT_HYPERCONVERGED, - SSP_OPERATOR, - SSP_STR, - UPLOAD_BOOT_SOURCE, - VIRT_API, - VIRT_CONTROLLER, - VIRT_EXPORTPROXY, - VIRT_HANDLER, - VIRT_LAUNCHER, - VIRT_OPERATOR, - VIRT_PLATFORM_AUTOPILOT, - VIRT_SYNCHRONIZATION_CONTROLLER, - VIRT_TEMPLATE_VALIDATOR, - VIRTCTL_CLI_DOWNLOADS, - VIRTIO_WIN, - VM_CONSOLE_PROXY_CLUSTER_RESOURCES, - VM_CONSOLE_PROXY_NAMESPACE_RESOURCES, - WINDOWS_BOOTSOURCE_PIPELINE, -) -from utilities.constants.cpu_models import ( - EXCLUDED_CPU_MODELS, - EXCLUDED_CPU_MODELS_S390X, - EXCLUDED_OLD_CPU_MODELS, -) -from utilities.constants.hco import ( - ALL_CNV_CRDS, - COMMON_TEMPLATES_KEY_NAME, - DATA_IMPORT_CRON_ENABLE, - DATA_SOURCE_NAME, - DATA_SOURCE_NAMESPACE, - DEFAULT_HCO_CONDITIONS, - DEFAULT_KUBEVIRT_CONDITIONS, - DEFAULT_RESOURCE_CONDITIONS, - ENABLE_COMMON_BOOT_IMAGE_IMPORT, - EXPECTED_STATUS_CONDITIONS, - FEATURE_GATES, - HCO_DEFAULT_CPU_MODEL_KEY, - HCO_SUBSCRIPTION, - HOTFIX_STR, - IMAGE_CRON_STR, - PRODUCTION_CATALOG_SOURCE, - RESOURCE_REQUIREMENTS_KEY_HCO_CR, - SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME, - TLS_CUSTOM_POLICY, - TLS_OLD_POLICY, - TLS_SECURITY_PROFILE, - VM_CLONE_CRD, - VM_CRD, - VM_EXPORT_CRD, - UpgradeStreams, -) -from utilities.constants.images import ( - ALPINE_VERSION, - CIRROS_DISK_DEMO, - CIRROS_QCOW2_IMG, - DEFAULT_FEDORA_REGISTRY_URL, - FEDORA_DISK_DEMO, - OS_FLAVOR_ALPINE, - OS_FLAVOR_CIRROS, - OS_FLAVOR_FEDORA, - OS_FLAVOR_RHEL, - OS_FLAVOR_WIN_CONTAINER_DISK, - OS_FLAVOR_WINDOWS, - ArchImages, -) -from utilities.constants.instance_types import ( - CENTOS_STREAM9_PREFERENCE, - CENTOS_STREAM10_PREFERENCE, - EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS, - FLAVOR_STR, - INSTANCE_TYPE_STR, - LINUX_STR, - OS_STR, - PREFERENCE_STR, - RHEL8_PREFERENCE, - RHEL9_PREFERENCE, - RHEL10_PREFERENCE, - RHEL_WITH_INSTANCETYPE_AND_PREFERENCE, - U1_LARGE, - U1_MEDIUM_STR, - U1_SMALL, - WINDOWS_2K22_PREFERENCE, - WINDOWS_11_PREFERENCE, - WORKLOAD_STR, -) -from utilities.constants.monitoring import ( - CRITICAL_STR, - FIRING_STATE, - INFO_STR, - KUBELET_READY_CONDITION, - KUBEVIRT_HCO_HYPERCONVERGED_CR_EXISTS, - KUBEVIRT_HYPERCONVERGED_OPERATOR_HEALTH_STATUS, - KUBEVIRT_VMI_MEMORY_ACTUAL_BALLOON_BYTES, - KUBEVIRT_VMI_MEMORY_DOMAIN_BYTES, - KUBEVIRT_VMI_MEMORY_PGMAJFAULT_TOTAL, - KUBEVIRT_VMI_MEMORY_PGMINFAULT_TOTAL, - KUBEVIRT_VMI_MEMORY_SWAP_IN_TRAFFIC_BYTES, - KUBEVIRT_VMI_MEMORY_SWAP_OUT_TRAFFIC_BYTES, - KUBEVIRT_VMI_MEMORY_UNUSED_BYTES, - KUBEVIRT_VMI_MEMORY_USABLE_BYTES, - KUBEVIRT_VMI_NETWORK_RECEIVE_BYTES_TOTAL, - KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_DROPPED_TOTAL, - KUBEVIRT_VMI_NETWORK_TRANSMIT_BYTES_TOTAL, - KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_DROPPED_TOTAL, - KUBEVIRT_VMI_STORAGE_FLUSH_REQUESTS_TOTAL, - KUBEVIRT_VMI_STORAGE_FLUSH_TIMES_SECONDS_TOTAL, - KUBEVIRT_VMI_STORAGE_IOPS_READ_TOTAL, - KUBEVIRT_VMI_STORAGE_IOPS_WRITE_TOTAL, - KUBEVIRT_VMI_STORAGE_READ_TRAFFIC_BYTES_TOTAL, - KUBEVIRT_VMI_STORAGE_WRITE_TRAFFIC_BYTES_TOTAL, - KUBEVIRT_VMI_VCPU_WAIT_SECONDS_TOTAL, - MONITORING_METRICS, - NONE_STRING, - OPERATOR_HEALTH_IMPACT_VALUES, - PENDING_STR, - PROMETHEUS_K8S, - WARNING_STR, -) -from utilities.constants.namespaces import NamespacesNames -from utilities.constants.networking import ( - ACTIVE_BACKUP, - FLAT_OVERLAY_STR, - IP_FAMILY_POLICY_PREFER_DUAL_STACK, - IPV4_STR, - IPV6_STR, - KMP_ENABLED_LABEL, - KMP_VM_ASSIGNMENT_LABEL, - KUBEMACPOOL_MAC_RANGE_CONFIG, - LINUX_BRIDGE, - NET_UTIL_CONTAINER_IMAGE, - OVS_BRIDGE, - POD_CONTAINER_SPEC, - POD_SECURITY_CONTEXT_SPEC, - PORT_80, - PUBLIC_DNS_SERVER_IP, - SECURITY_CONTEXT, - SRIOV, - SSH_PORT_22, -) -from utilities.constants.oadp import ( - BACKUP_STORAGE_LOCATION, - FILE_NAME_FOR_BACKUP, - TEXT_TO_TEST, -) -from utilities.constants.os_matrix import ( - CONTAINER_DISK_IMAGE_PATH_STR, - DATA_SOURCE_STR, - DV_SIZE_STR, - IMAGE_NAME_STR, - IMAGE_PATH_STR, - LATEST_RELEASE_STR, - OS_VERSION_STR, - TEMPLATE_LABELS_STR, -) -from utilities.constants.pytest import ( - DEPENDENCY_SCOPE_SESSION, - QUARANTINED, - SANITY_TESTS_FAILURE, - SETUP_ERROR, - UNPRIVILEGED_PASSWORD, - UNPRIVILEGED_USER, -) -from utilities.constants.storage import ( - ACCESS_MODE, - BIND_IMMEDIATE_ANNOTATION, - BREW_REGISTRY_SOURCE, - CAPACITY, - CDI_CONFIGMAPS, - CDI_LABEL, - CDI_SECRETS, - CDI_UPLOAD, - CDI_UPLOAD_TMP_PVC, - HOTPLUG_DISK_SCSI_BUS, - HOTPLUG_DISK_SERIAL, - HOTPLUG_DISK_VIRTIO_BUS, - HPP_CAPABILITIES, - OUTDATED, - PVC, - REGISTRY_STR, - SOURCE_POD, - USED, - VOLUME_MODE, - WILDCARD_CRON_EXPRESSION, - StorageClassNames, -) -from utilities.constants.tekton import ( - TEKTON_AVAILABLE_PIPELINEREF, - TEKTON_AVAILABLE_TASKS, - WINDOWS_CUSTOMIZE_STR, - WINDOWS_EFI_INSTALLER_STR, -) -from utilities.constants.timeouts import ( - TCP_TIMEOUT_30SEC, - TIMEOUT_1MIN, - TIMEOUT_1SEC, - TIMEOUT_2MIN, - TIMEOUT_3MIN, - TIMEOUT_4MIN, - TIMEOUT_5MIN, - TIMEOUT_5SEC, - TIMEOUT_6MIN, - TIMEOUT_8MIN, - TIMEOUT_9MIN, - TIMEOUT_10MIN, - TIMEOUT_10SEC, - TIMEOUT_11MIN, - TIMEOUT_12MIN, - TIMEOUT_15MIN, - TIMEOUT_15SEC, - TIMEOUT_20MIN, - TIMEOUT_20SEC, - TIMEOUT_25MIN, - TIMEOUT_30MIN, - TIMEOUT_30SEC, - TIMEOUT_40MIN, - TIMEOUT_50MIN, - TIMEOUT_60MIN, - TIMEOUT_75MIN, - TIMEOUT_90SEC, - TIMEOUT_180MIN, -) -from utilities.constants.virt import ( - CLOUD_INIT_DISK_NAME, - CLOUD_INIT_NO_CLOUD, - CNV_SUPPLEMENTAL_TEMPLATES_URL, - CNV_VM_SSH_KEY_PATH, - DISK_SERIAL, - DV_DISK, - EIGHT_CPU_SOCKETS, - ES_LIVE_MIGRATE_IF_POSSIBLE, - ES_NONE, - EVICTIONSTRATEGY, - FIVE_GI_MEMORY, - FOUR_CPU_SOCKETS, - FOUR_GI_MEMORY, - HYPERV_FEATURES_LABELS_DOM_XML, - HYPERV_FEATURES_LABELS_VM_YAML, - KERNEL_DRIVER, - LIVE_MIGRATE, - MIGRATION_POLICY_VM_LABEL, - NODE_HUGE_PAGES_1GI_KEY, - ONE_CPU_CORE, - ONE_CPU_THREAD, - OS_PROC_NAME, - REGEDIT_PROC_NAME, - ROOTDISK, - SIX_CPU_SOCKETS, - SIX_GI_MEMORY, - STRESS_CPU_MEM_IO_COMMAND, - TEN_CPU_SOCKETS, - TEN_GI_MEMORY, - TWELVE_GI_MEMORY, - TWO_CPU_CORES, - TWO_CPU_SOCKETS, - TWO_CPU_THREADS, - VIRTCTL, - VIRTIO, - WIN_2K19, - WIN_2K22, - WIN_2K25, - WIN_10, - WIN_11, -) +from utilities.constants.images import ArchImages -__all__ = [ - "AAQ_NAMESPACE_LABEL", - "AAQ_OPERATOR", - "AAQ_VIRTUAL_RESOURCES", - "AAQ_VMI_POD_USAGE", - "ACCESS_MODE", - "ACTIVE_BACKUP", - "ALL_CNV_CRDS", - "ALL_CNV_DAEMONSETS", - "ALL_CNV_DEPLOYMENTS", - "ALL_CNV_PODS", - "ALL_HCO_RELATED_OBJECTS", - "ALPINE_VERSION", - "AMD", - "AMD_64", - "ARM_64", - "ARQ_QUOTA_HARD_SPEC", - "AUDIT_LOGS_PATH", - "BACKUP_STORAGE_LOCATION", - "BASE_EXCEPTIONS_DICT", - "BASE_IMAGES_DIR", - "BIND_IMMEDIATE_ANNOTATION", - "BREW_REGISTRY_SOURCE", - "BRIDGE_MARKER", - "CAPACITY", - "CDI_APISERVER", - "CDI_CONFIGMAPS", - "CDI_DEPLOYMENT", - "CDI_KUBEVIRT_HYPERCONVERGED", - "CDI_LABEL", - "CDI_OPERATOR", - "CDI_SECRETS", - "CDI_STR", - "CDI_UPLOAD", - "CDI_UPLOADPROXY", - "CDI_UPLOAD_TMP_PVC", - "CENTOS_STREAM9_PREFERENCE", - "CENTOS_STREAM10_PREFERENCE", - "CIRROS_DISK_DEMO", - "CIRROS_QCOW2_IMG", - "CLOUD_INIT_DISK_NAME", - "CLOUD_INIT_NO_CLOUD", - "CLUSTER", - "CLUSTER_NETWORK_ADDONS_OPERATOR", - "CNAO_OPERATOR", - "CNV_OPERATORS", - "CNV_PODS_NO_HPP_CSI_HPP_POOL", - "CNV_PROMETHEUS_RULES", - "CNV_SUPPLEMENTAL_TEMPLATES_URL", - "CNV_TESTS_CONTAINER", - "CNV_TEST_RUN_IN_PROGRESS", - "CNV_TEST_RUN_IN_PROGRESS_NS", - "CNV_TEST_SERVICE_ACCOUNT", - "CNV_VM_SSH_KEY_PATH", - "COMMON_TEMPLATES_KEY_NAME", - "CONFIGMAP_STR", - "CONSOLECLIDOWNLOAD_STR", - "CONSOLEQUICKSTART_STR", - "CONSOLE_PLUGIN_STR", - "CONTAINER_DISK_IMAGE_PATH_STR", - "COUNT_FIVE", - "CPU_MODEL_LABEL_PREFIX", - "CREATE_STR", - "CREATING_VIRTUAL_MACHINE", - "CREATING_VIRTUAL_MACHINE_FROM_VOLUME", - "CRITICAL_STR", - "DATA_IMPORT_CRON_ENABLE", - "DATA_SOURCE_NAME", - "DATA_SOURCE_NAMESPACE", - "DATA_SOURCE_STR", - "DEFAULT_FEDORA_REGISTRY_URL", - "DEFAULT_HCO_CONDITIONS", - "DEFAULT_KUBEVIRT_CONDITIONS", - "DEFAULT_RESOURCE_CONDITIONS", - "DELETE_STR", - "DEPENDENCY_SCOPE_SESSION", - "DEPLOYMENT_STR", - "DISK_SERIAL", - "DV_DISK", - "DV_SIZE_STR", - "EIGHT_CPU_SOCKETS", - "ENABLE_COMMON_BOOT_IMAGE_IMPORT", - "ES_LIVE_MIGRATE_IF_POSSIBLE", - "ES_NONE", - "EVICTIONSTRATEGY", - "EXCLUDED_CPU_MODELS", - "EXCLUDED_CPU_MODELS_S390X", - "EXCLUDED_OLD_CPU_MODELS", - "EXPECTED_CLUSTER_INSTANCE_TYPE_LABELS", - "EXPECTED_STATUS_CONDITIONS", - "FEATURE_GATES", - "FEDORA_DISK_DEMO", - "FILE_NAME_FOR_BACKUP", - "FIRING_STATE", - "FIVE_GI_MEMORY", - "FLAT_OVERLAY_STR", - "FLAVOR_STR", - "FOUR_CPU_SOCKETS", - "FOUR_GI_MEMORY", - "GET_STR", - "GRAFANA_DASHBOARD_KUBEVIRT_TOP_CONSUMERS", - "HCO_BEARER_AUTH", - "HCO_CATALOG_SOURCE", - "HCO_DEFAULT_CPU_MODEL_KEY", - "HCO_OPERATOR", - "HCO_PART_OF_LABEL_VALUE", - "HCO_SUBSCRIPTION", - "HCO_WEBHOOK", - "HOSTPATH_PROVISIONER", - "HOSTPATH_PROVISIONER_CSI", - "HOSTPATH_PROVISIONER_OPERATOR", - "HOTFIX_STR", - "HOTPLUG_DISK_SCSI_BUS", - "HOTPLUG_DISK_SERIAL", - "HOTPLUG_DISK_VIRTIO_BUS", - "HPP_CAPABILITIES", - "HPP_POOL", - "HYPERCONVERGED_CLUSTER", - "HYPERCONVERGED_CLUSTER_CLI_DOWNLOAD", - "HYPERCONVERGED_CLUSTER_OPERATOR", - "HYPERCONVERGED_CLUSTER_OPERATOR_METRICS", - "HYPERV_FEATURES_LABELS_DOM_XML", - "HYPERV_FEATURES_LABELS_VM_YAML", - "IMAGESTREAM_STR", - "IMAGE_CRON_STR", - "IMAGE_NAME_STR", - "IMAGE_PATH_STR", - "INFO_STR", - "INSTANCE_TYPE_STR", - "INTEL", - "IPV4_STR", - "IPV6_STR", - "IP_FAMILY_POLICY_PREFER_DUAL_STACK", - "KERNEL_DRIVER", - "KMP_ENABLED_LABEL", - "KMP_VM_ASSIGNMENT_LABEL", - "KUBECONFIG", - "KUBELET_READY_CONDITION", - "KUBEMACPOOL_CERT_MANAGER", - "KUBEMACPOOL_MAC_CONTROLLER_MANAGER", - "KUBEMACPOOL_MAC_RANGE_CONFIG", - "KUBEMACPOOL_PROMETHEUS_RULE", - "KUBERNETES_ARCH_LABEL", - "KUBEVIRT_APISERVER_PROXY", - "KUBEVIRT_APISERVER_PROXY_NP", - "KUBEVIRT_CLUSTER_CRITICAL", - "KUBEVIRT_CONSOLE_PLUGIN", - "KUBEVIRT_CONSOLE_PLUGIN_NP", - "KUBEVIRT_CONSOLE_PLUGIN_SERVICE", - "KUBEVIRT_HCO_HYPERCONVERGED_CR_EXISTS", - "KUBEVIRT_HCO_NAME", - "KUBEVIRT_HYPERCONVERGED_OPERATOR_HEALTH_STATUS", - "KUBEVIRT_HYPERCONVERGED_OPERATOR_METRICS", - "KUBEVIRT_HYPERCONVERGED_PROMETHEUS_RULE", - "KUBEVIRT_IPAM_CONTROLLER_MANAGER", - "KUBEVIRT_KUBEVIRT_HYPERCONVERGED", - "KUBEVIRT_MIGRATION_CONTROLLER", - "KUBEVIRT_MIGRATION_OPERATOR", - "KUBEVIRT_OPERATOR", - "KUBEVIRT_PLUGIN", - "KUBEVIRT_STR", - "KUBEVIRT_UI_CONFIG", - "KUBEVIRT_UI_CONFIG_READER", - "KUBEVIRT_UI_CONFIG_READER_ROLE_BINDING", - "KUBEVIRT_UI_FEATURES", - "KUBEVIRT_USER_SETTINGS", - "KUBEVIRT_VMI_MEMORY_ACTUAL_BALLOON_BYTES", - "KUBEVIRT_VMI_MEMORY_DOMAIN_BYTES", - "KUBEVIRT_VMI_MEMORY_PGMAJFAULT_TOTAL", - "KUBEVIRT_VMI_MEMORY_PGMINFAULT_TOTAL", - "KUBEVIRT_VMI_MEMORY_SWAP_IN_TRAFFIC_BYTES", - "KUBEVIRT_VMI_MEMORY_SWAP_OUT_TRAFFIC_BYTES", - "KUBEVIRT_VMI_MEMORY_UNUSED_BYTES", - "KUBEVIRT_VMI_MEMORY_USABLE_BYTES", - "KUBEVIRT_VMI_NETWORK_RECEIVE_BYTES_TOTAL", - "KUBEVIRT_VMI_NETWORK_RECEIVE_PACKETS_DROPPED_TOTAL", - "KUBEVIRT_VMI_NETWORK_TRANSMIT_BYTES_TOTAL", - "KUBEVIRT_VMI_NETWORK_TRANSMIT_PACKETS_DROPPED_TOTAL", - "KUBEVIRT_VMI_STORAGE_FLUSH_REQUESTS_TOTAL", - "KUBEVIRT_VMI_STORAGE_FLUSH_TIMES_SECONDS_TOTAL", - "KUBEVIRT_VMI_STORAGE_IOPS_READ_TOTAL", - "KUBEVIRT_VMI_STORAGE_IOPS_WRITE_TOTAL", - "KUBEVIRT_VMI_STORAGE_READ_TRAFFIC_BYTES_TOTAL", - "KUBEVIRT_VMI_STORAGE_WRITE_TRAFFIC_BYTES_TOTAL", - "KUBEVIRT_VMI_VCPU_WAIT_SECONDS_TOTAL", - "KUBE_CNI_LINUX_BRIDGE_PLUGIN", - "LATEST_RELEASE_STR", - "LIMITS_CPU_STR", - "LIMITS_MEMORY_STR", - "LINUX_AMD_64", - "LINUX_BRIDGE", - "LINUX_STR", - "LIVE_MIGRATE", - "LS_COMMAND", - "MANAGED_BY_LABEL_VALUE_OLM", - "MIGCONTROLLER_KUBEVIRT_HYPERCONVERGED", - "MIGRATION_POLICY_VM_LABEL", - "MONITORING_METRICS", - "MULTIARCH", - "NETWORKADDONSCONFIG_STR", - "NETWORKPOLICY_STR", - "NET_UTIL_CONTAINER_IMAGE", - "NGINX_CONF", - "NODE_HUGE_PAGES_1GI_KEY", - "NODE_ROLE_KUBERNETES_IO", - "NODE_STR", - "NODE_TYPE_WORKER_LABEL", - "NONE_STRING", - "OC_ADM_LOGS_COMMAND", - "ONE_CPU_CORE", - "ONE_CPU_THREAD", - "OPERATOR_HEALTH_IMPACT_VALUES", - "OS_FLAVOR_ALPINE", - "OS_FLAVOR_CIRROS", - "OS_FLAVOR_FEDORA", - "OS_FLAVOR_RHEL", - "OS_FLAVOR_WINDOWS", - "OS_FLAVOR_WIN_CONTAINER_DISK", - "OS_PROC_NAME", - "OS_STR", - "OS_VERSION_STR", - "OUTDATED", - "OVS_BRIDGE", - "PENDING_STR", - "PODS_STR", - "POD_CONTAINER_SPEC", - "POD_LIMITS_CPU", - "POD_LIMITS_MEMORY", - "POD_REQUESTS_CPU", - "POD_REQUESTS_MEMORY", - "POD_SECURITY_CONTEXT_SPEC", - "POD_SECURITY_NAMESPACE_LABELS", - "POD_STR", - "PORT_80", - "PREFERENCE_STR", - "PRIORITYCLASS_STR", - "PRODUCTION_CATALOG_SOURCE", - "PROMETHEUSRULE_STR", - "PROMETHEUS_K8S", - "PROMETHEUS_RULES_STR", - "PUBLIC_DNS_SERVER_IP", - "PVC", - "QUARANTINED", - "QUOTA_FOR_ONE_VMI", - "QUOTA_FOR_POD", - "REGEDIT_PROC_NAME", - "REGISTRY_STR", - "REQUESTS_CPU_STR", - "REQUESTS_CPU_VMI_STR", - "REQUESTS_INSTANCES_VMI_STR", - "REQUESTS_MEMORY_STR", - "REQUESTS_MEMORY_VMI_STR", - "RESOURCE_REQUIREMENTS_KEY_HCO_CR", - "RHEL8_GUEST", - "RHEL8_PREFERENCE", - "RHEL9_GUEST", - "RHEL9_PREFERENCE", - "RHEL9_STR", - "RHEL10_GUEST", - "RHEL10_PREFERENCE", - "RHEL10_STR", - "RHEL_WITH_INSTANCETYPE_AND_PREFERENCE", - "RHSM_SECRET_NAME", - "ROLEBINDING_STR", - "ROLE_STR", - "ROOTDISK", - "ROUTE_STR", - "S390X", - "SANITY_TESTS_FAILURE", - "SECRET_STR", - "SECURITY_CONTEXT", - "SERVICEACCOUNT_STR", - "SERVICEMONITOR_STR", - "SERVICE_STR", - "SETUP_ERROR", - "SIX_CPU_SOCKETS", - "SIX_GI_MEMORY", - "SOURCE_POD", - "SRIOV", - "SSH_PORT_22", - "SSP_CR_COMMON_TEMPLATES_LIST_KEY_NAME", - "SSP_KUBEVIRT_HYPERCONVERGED", - "SSP_OPERATOR", - "SSP_STR", - "STRESS_CPU_MEM_IO_COMMAND", - "SUPPORTED_CPU_ARCHITECTURES", - "SUPPORTED_MULTIARCH_OPTIONS", - "TCP_TIMEOUT_30SEC", - "TEKTON_AVAILABLE_PIPELINEREF", - "TEKTON_AVAILABLE_TASKS", - "TEMPLATE_LABELS_STR", - "TEN_CPU_SOCKETS", - "TEN_GI_MEMORY", - "TEXT_TO_TEST", - "TIMEOUT_1MIN", - "TIMEOUT_1SEC", - "TIMEOUT_2MIN", - "TIMEOUT_3MIN", - "TIMEOUT_4MIN", - "TIMEOUT_5MIN", - "TIMEOUT_5SEC", - "TIMEOUT_6MIN", - "TIMEOUT_8MIN", - "TIMEOUT_9MIN", - "TIMEOUT_10MIN", - "TIMEOUT_10SEC", - "TIMEOUT_11MIN", - "TIMEOUT_12MIN", - "TIMEOUT_15MIN", - "TIMEOUT_15SEC", - "TIMEOUT_20MIN", - "TIMEOUT_20SEC", - "TIMEOUT_25MIN", - "TIMEOUT_30MIN", - "TIMEOUT_30SEC", - "TIMEOUT_40MIN", - "TIMEOUT_50MIN", - "TIMEOUT_60MIN", - "TIMEOUT_75MIN", - "TIMEOUT_90SEC", - "TIMEOUT_180MIN", - "TLS_CUSTOM_POLICY", - "TLS_OLD_POLICY", - "TLS_SECURITY_PROFILE", - "TSC_FREQUENCY", - "TWELVE_GI_MEMORY", - "TWO_CPU_CORES", - "TWO_CPU_SOCKETS", - "TWO_CPU_THREADS", - "U1_LARGE", - "U1_MEDIUM_STR", - "U1_SMALL", - "UNPRIVILEGED_PASSWORD", - "UNPRIVILEGED_USER", - "UPDATE_STR", - "UPLOAD_BOOT_SOURCE", - "USED", - "UTILITY", - "VALUE_STR", - "VERSION_LABEL_KEY", - "VIRTCTL", - "VIRTCTL_CLI_DOWNLOADS", - "VIRTIO", - "VIRTIO_WIN", - "VIRT_API", - "VIRT_CONTROLLER", - "VIRT_EXPORTPROXY", - "VIRT_HANDLER", - "VIRT_LAUNCHER", - "VIRT_OPERATOR", - "VIRT_PLATFORM_AUTOPILOT", - "VIRT_SYNCHRONIZATION_CONTROLLER", - "VIRT_TEMPLATE_VALIDATOR", - "VM_CLONE_CRD", - "VM_CONSOLE_PROXY_CLUSTER_RESOURCES", - "VM_CONSOLE_PROXY_NAMESPACE_RESOURCES", - "VM_CPU_CORES", - "VM_CRD", - "VM_EXPORT_CRD", - "VM_MEMORY_GUEST", - "VOLUME_MODE", - "WARNING_STR", - "WILDCARD_CRON_EXPRESSION", - "WINDOWS_2K22_PREFERENCE", - "WINDOWS_11_PREFERENCE", - "WINDOWS_BOOTSOURCE_PIPELINE", - "WINDOWS_CUSTOMIZE_STR", - "WINDOWS_EFI_INSTALLER_STR", - "WIN_2K19", - "WIN_2K22", - "WIN_2K25", - "WIN_10", - "WIN_11", - "WORKERS_TYPE", - "WORKER_NODE_LABEL_KEY", - "WORKLOAD_STR", - "X86_64", - "ArchImages", - "Images", - "NamespacesNames", - "StorageClassNames", - "UpgradeStreams", -] +__all__ = ["ArchImages", "Images"] -# Computed after all submodule imports so that KUBERNETES_ARCH_LABEL (from cluster.py) -# is already in the utilities.constants namespace when get_cluster_architecture() -# triggers its lazy `from utilities.constants import KUBERNETES_ARCH_LABEL`. -# TODO: remove this when utilities modules are refactored Images = getattr(ArchImages, next(iter(_get_cluster_architecture())).upper()) diff --git a/utilities/constants/aaq.py b/utilities/constants/aaq.py index cb276bf9a9..efeca85ce3 100644 --- a/utilities/constants/aaq.py +++ b/utilities/constants/aaq.py @@ -6,7 +6,6 @@ AAQ_VIRTUAL_RESOURCES = "VirtualResources" AAQ_VMI_POD_USAGE = "VmiPodUsage" -NODE_STR = "node" AAQ_NAMESPACE_LABEL = {"application-aware-quota/enable-gating": ""} VM_CPU_CORES = 2 diff --git a/utilities/constants/cluster.py b/utilities/constants/cluster.py index 429bfb7da0..78f768fd61 100644 --- a/utilities/constants/cluster.py +++ b/utilities/constants/cluster.py @@ -1,7 +1,7 @@ """Cluster infrastructure constants. Covers Kubernetes node labels (architecture, worker role, CPU model prefix, TSC -frequency, version), pod security namespace labels, Kubernetes API verb strings, +frequency, version), generic node dict keys (NODE_STR), pod security namespace labels, Kubernetes API verb strings, environment variables (KUBECONFIG, WORKERS_TYPE), CNV test run markers, service account names, the base network-exception dictionary, and audit-log command strings. @@ -24,6 +24,7 @@ # Node / selector labels KUBERNETES_ARCH_LABEL = f"{Resource.ApiGroup.KUBERNETES_IO}/arch" +NODE_STR = "node" NODE_TYPE_WORKER_LABEL = {"node-type": "worker"} NODE_ROLE_KUBERNETES_IO = "node-role.kubernetes.io" WORKER_NODE_LABEL_KEY = f"{NODE_ROLE_KUBERNETES_IO}/worker" diff --git a/utilities/unittests/README.md b/utilities/unittests/README.md index 5c53092094..4cc218ed68 100644 --- a/utilities/unittests/README.md +++ b/utilities/unittests/README.md @@ -142,7 +142,7 @@ def test_with_external_mock(self, mock_external): - artifactory.py - bitwarden.py - console.py -- constants.py +- constants/ (package) - cpu.py - data_collector.py - data_utils.py From 0587493244d6c37295743095d00e048ba543988e Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 11:05:20 +0300 Subject: [PATCH 2/6] test(constants): fix unittests to use submodule imports Replace broken sys.path + import constants hack with direct imports from utilities.constants. after the package restructure. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- utilities/unittests/test_constants.py | 230 ++++++++++++++++---------- 1 file changed, 142 insertions(+), 88 deletions(-) diff --git a/utilities/unittests/test_constants.py b/utilities/unittests/test_constants.py index 804d8775e9..03c3ff3427 100644 --- a/utilities/unittests/test_constants.py +++ b/utilities/unittests/test_constants.py @@ -1,125 +1,179 @@ -# Generated using Claude cli - -"""Unit tests for constants module""" - -import sys -from pathlib import Path - -# Add utilities to Python path for imports -sys.path.insert(0, str(Path(__file__).parent.parent)) - -import constants +"""Unit tests for constants package.""" + +from utilities.constants.architecture import ( + AMD_64, + ARM_64, + MULTIARCH, + S390X, + SUPPORTED_CPU_ARCHITECTURES, + SUPPORTED_MULTIARCH_OPTIONS, + X86_64, +) +from utilities.constants.components import ( + BRIDGE_MARKER, + CLUSTER_NETWORK_ADDONS_OPERATOR, + HCO_OPERATOR, + HCO_WEBHOOK, + HOSTPATH_PROVISIONER, + HOSTPATH_PROVISIONER_CSI, + HOSTPATH_PROVISIONER_OPERATOR, + HYPERCONVERGED_CLUSTER, +) +from utilities.constants.hco import DATA_IMPORT_CRON_ENABLE +from utilities.constants.images import ( + OS_FLAVOR_CIRROS, + OS_FLAVOR_FEDORA, + OS_FLAVOR_RHEL, + OS_FLAVOR_WINDOWS, + ArchImages, +) +from utilities.constants.instance_types import ( + CENTOS_STREAM9_PREFERENCE, + RHEL9_PREFERENCE, + U1_LARGE, + U1_SMALL, + WORKLOAD_STR, +) +from utilities.constants.monitoring import ( + KUBEVIRT_HYPERCONVERGED_OPERATOR_HEALTH_STATUS, + PENDING_STR, +) +from utilities.constants.networking import ( + LINUX_BRIDGE, + OVS_BRIDGE, +) +from utilities.constants.os_matrix import ( + DV_SIZE_STR, + IMAGE_NAME_STR, + OS_VERSION_STR, +) +from utilities.constants.timeouts import ( + TCP_TIMEOUT_30SEC, + TIMEOUT_1MIN, + TIMEOUT_1SEC, + TIMEOUT_5MIN, + TIMEOUT_10MIN, + TIMEOUT_30MIN, + TIMEOUT_60MIN, +) +from utilities.constants.virt import ( + FIVE_GI_MEMORY, + FOUR_GI_MEMORY, + ONE_CPU_CORE, + ONE_CPU_THREAD, + SIX_GI_MEMORY, + TEN_GI_MEMORY, + TWELVE_GI_MEMORY, + TWO_CPU_CORES, + TWO_CPU_SOCKETS, + TWO_CPU_THREADS, + WIN_10, + WIN_11, +) class TestConstants: - """Test cases for constants module""" + """Test cases for constants package.""" def test_architecture_constants(self): - """Test architecture constants are defined""" - assert constants.AMD_64 == "amd64" - assert constants.ARM_64 == "arm64" - assert constants.S390X == "s390x" - assert constants.X86_64 == "x86_64" - assert constants.MULTIARCH == "multiarch" - assert constants.SUPPORTED_MULTIARCH_OPTIONS == {"amd64", "arm64"} - assert constants.SUPPORTED_CPU_ARCHITECTURES == {"amd64", "arm64", "s390x"} + """Test architecture constants are defined.""" + assert AMD_64 == "amd64" + assert ARM_64 == "arm64" + assert S390X == "s390x" + assert X86_64 == "x86_64" + assert MULTIARCH == "multiarch" + assert SUPPORTED_MULTIARCH_OPTIONS == {"amd64", "arm64"} + assert SUPPORTED_CPU_ARCHITECTURES == {"amd64", "arm64", "s390x"} def test_timeout_constants(self): - """Test timeout constants are defined""" - assert constants.TIMEOUT_1SEC == 1 - assert constants.TIMEOUT_1MIN == 60 - assert constants.TIMEOUT_5MIN == 5 * 60 - assert constants.TIMEOUT_10MIN == 10 * 60 - assert constants.TIMEOUT_30MIN == 30 * 60 - assert constants.TIMEOUT_60MIN == 60 * 60 + """Test timeout constants are defined.""" + assert TIMEOUT_1SEC == 1 + assert TIMEOUT_1MIN == 60 + assert TIMEOUT_5MIN == 5 * 60 + assert TIMEOUT_10MIN == 10 * 60 + assert TIMEOUT_30MIN == 30 * 60 + assert TIMEOUT_60MIN == 60 * 60 def test_tcp_timeout_constants(self): - """Test TCP timeout constants are defined""" - assert constants.TCP_TIMEOUT_30SEC == 30.0 + """Test TCP timeout constants are defined.""" + assert TCP_TIMEOUT_30SEC == 30.0 def test_memory_constants(self): - """Test memory constants are defined""" - assert constants.FOUR_GI_MEMORY == "4Gi" - assert constants.FIVE_GI_MEMORY == "5Gi" - assert constants.SIX_GI_MEMORY == "6Gi" - assert constants.TEN_GI_MEMORY == "10Gi" - assert constants.TWELVE_GI_MEMORY == "12Gi" + """Test memory constants are defined.""" + assert FOUR_GI_MEMORY == "4Gi" + assert FIVE_GI_MEMORY == "5Gi" + assert SIX_GI_MEMORY == "6Gi" + assert TEN_GI_MEMORY == "10Gi" + assert TWELVE_GI_MEMORY == "12Gi" def test_cpu_constants(self): - """Test CPU constants are defined""" - assert constants.ONE_CPU_CORE == 1 - assert constants.ONE_CPU_THREAD == 1 - assert constants.TWO_CPU_CORES == 2 - assert constants.TWO_CPU_SOCKETS == 2 - assert constants.TWO_CPU_THREADS == 2 + """Test CPU constants are defined.""" + assert ONE_CPU_CORE == 1 + assert ONE_CPU_THREAD == 1 + assert TWO_CPU_CORES == 2 + assert TWO_CPU_SOCKETS == 2 + assert TWO_CPU_THREADS == 2 def test_state_constants(self): - """Test state constants are defined""" - assert constants.PENDING_STR == "pending" + """Test state constants are defined.""" + assert PENDING_STR == "pending" def test_cnv_operator_constants(self): - """Test CNV operator constants are defined""" - # Check for CNV related namespaces/operators - assert constants.HCO_OPERATOR == "hco-operator" - assert constants.HCO_WEBHOOK == "hco-webhook" - assert constants.HYPERCONVERGED_CLUSTER == "hyperconverged-cluster" + """Test CNV operator constants are defined.""" + assert HCO_OPERATOR == "hco-operator" + assert HCO_WEBHOOK == "hco-webhook" + assert HYPERCONVERGED_CLUSTER == "hyperconverged-cluster" def test_storage_classes(self): - """Test storage classes are defined""" - # Check if storage class constants exist - assert constants.HOSTPATH_PROVISIONER == "hostpath-provisioner" - assert constants.HOSTPATH_PROVISIONER_CSI == "hostpath-provisioner-csi" - assert constants.HOSTPATH_PROVISIONER_OPERATOR == "hostpath-provisioner-operator" + """Test storage classes are defined.""" + assert HOSTPATH_PROVISIONER == "hostpath-provisioner" + assert HOSTPATH_PROVISIONER_CSI == "hostpath-provisioner-csi" + assert HOSTPATH_PROVISIONER_OPERATOR == "hostpath-provisioner-operator" def test_operator_health_impact_values(self): - """Test operator health impact values are defined""" - # Check for operator health related metrics - assert ( - constants.KUBEVIRT_HYPERCONVERGED_OPERATOR_HEALTH_STATUS == "kubevirt_hyperconverged_operator_health_status" - ) + """Test operator health impact values are defined.""" + assert KUBEVIRT_HYPERCONVERGED_OPERATOR_HEALTH_STATUS == "kubevirt_hyperconverged_operator_health_status" def test_images_class_exists(self): - """Test that ArchImages class exists""" - assert hasattr(constants, "ArchImages") - assert hasattr(constants.ArchImages, "AMD64") + """Test that ArchImages class exists.""" + assert hasattr(ArchImages, "AMD64") def test_data_import_cron_constants(self): - """Test data import cron related constants are defined""" - assert constants.DATA_IMPORT_CRON_ENABLE.startswith("metadata->annotations->") + """Test data import cron related constants are defined.""" + assert DATA_IMPORT_CRON_ENABLE.startswith("metadata->annotations->") def test_os_related_constants(self): - """Test OS related constants are defined""" - assert constants.OS_FLAVOR_RHEL == "rhel" - assert constants.OS_FLAVOR_FEDORA == "fedora" - assert constants.OS_FLAVOR_WINDOWS == "win" - assert constants.OS_FLAVOR_CIRROS == "cirros" + """Test OS related constants are defined.""" + assert OS_FLAVOR_RHEL == "rhel" + assert OS_FLAVOR_FEDORA == "fedora" + assert OS_FLAVOR_WINDOWS == "win" + assert OS_FLAVOR_CIRROS == "cirros" def test_windows_os_constants(self): - """Test Windows OS constants are defined""" - assert constants.WIN_10 == "win10" - assert constants.WIN_11 == "win11" + """Test Windows OS constants are defined.""" + assert WIN_10 == "win10" + assert WIN_11 == "win11" def test_workload_constants(self): - """Test workload constants are defined""" - # Check for workload related constants - assert constants.WORKLOAD_STR == "workload" + """Test workload constants are defined.""" + assert WORKLOAD_STR == "workload" def test_network_constants(self): - """Test network constants are defined""" - assert constants.LINUX_BRIDGE == "linux-bridge" - assert constants.OVS_BRIDGE == "ovs-bridge" - assert constants.BRIDGE_MARKER == "bridge-marker" - assert constants.CLUSTER_NETWORK_ADDONS_OPERATOR == "cluster-network-addons-operator" + """Test network constants are defined.""" + assert LINUX_BRIDGE == "linux-bridge" + assert OVS_BRIDGE == "ovs-bridge" + assert BRIDGE_MARKER == "bridge-marker" + assert CLUSTER_NETWORK_ADDONS_OPERATOR == "cluster-network-addons-operator" def test_instance_type_constants(self): - """Test instance type and preference constants are defined""" - assert constants.U1_SMALL == "u1.small" - assert constants.U1_LARGE == "u1.large" - assert constants.RHEL9_PREFERENCE == "rhel.9" - assert constants.CENTOS_STREAM9_PREFERENCE == "centos.stream9" + """Test instance type and preference constants are defined.""" + assert U1_SMALL == "u1.small" + assert U1_LARGE == "u1.large" + assert RHEL9_PREFERENCE == "rhel.9" + assert CENTOS_STREAM9_PREFERENCE == "centos.stream9" def test_os_matrix_constants(self): - """Test OS matrix parameter key constants are defined""" - assert constants.IMAGE_NAME_STR == "image_name" - assert constants.OS_VERSION_STR == "os_version" - assert constants.DV_SIZE_STR == "dv_size" + """Test OS matrix parameter key constants are defined.""" + assert IMAGE_NAME_STR == "image_name" + assert OS_VERSION_STR == "os_version" + assert DV_SIZE_STR == "dv_size" From abb523308ed0827727bc0f9281a88638f0e91c95 Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 12:40:43 +0300 Subject: [PATCH 3/6] docs: add CODE_ORGANIZATION guide Document where constants, utilities, and fixtures live and how to import them. Link from AGENTS.md and existing contributor docs. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- AGENTS.md | 7 +- docs/ARCHITECTURE_SUPPORT.md | 3 + docs/CODE_ORGANIZATION.md | 162 +++++++++++++++++++++++++++++++++ docs/CODING_AND_STYLE_GUIDE.md | 10 +- docs/DEVELOPER_GUIDE.md | 5 +- 5 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 docs/CODE_ORGANIZATION.md diff --git a/AGENTS.md b/AGENTS.md index e986e2cdae..0fee0483da 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -51,12 +51,14 @@ Before writing ANY new code: ### Utility Module Placement -When adding functions to `utilities/`, place them in the correct module: +When adding functions to `utilities/`, place them in the correct module. See +[Code Organization](docs/CODE_ORGANIZATION.md) for constants import rules and the fixtures package layout. - **`utilities/cluster.py`** — cluster-wide operations (oc commands, node operations, cluster state) - **`utilities/infra.py`** — infrastructure helpers (SSH, networking infrastructure, pod operations) - **`utilities/virt.py`** — VM lifecycle, VMI operations, migration helpers - **`utilities/storage.py`** — storage operations (PVC, DataVolume, StorageClass) +- **`utilities/constants/.py`** — shared constants; import from the submodule, not the package root (except `Images`) **NEVER** add functions to the wrong utility module — match the domain. @@ -214,7 +216,7 @@ When reviewing quarantine PRs, verify the **quarantine mechanism matches the fai - **Tests belong under the feature they test** - do NOT create standalone directories for cross-cutting concerns. If a test measures VM downtime during migration over a specific network type, it belongs under that network type's directory (e.g., `tests/network/l2_bridge/`), not a separate top-level directory. - **Test file naming REQUIRED** - ALWAYS use `test_.py` format - **Local helpers location** - place helper utils in `/utils.py` -- **Local fixtures location** - place in `/conftest.py` +- **Local fixtures location** - place in `/conftest.py` for feature-local fixtures, or `tests/fixtures//` for shared fixtures (see [Code Organization](docs/CODE_ORGANIZATION.md#fixtures-testsfixtures-and-conftestpy)) - **Move to shared location** - move to `utilities/` or `tests/conftest.py` ONLY when used by different team directories ### Internal API Stability @@ -261,6 +263,7 @@ uv run tox -e utilities-unittests ## Related Documentation +- [`docs/CODE_ORGANIZATION.md`](docs/CODE_ORGANIZATION.md) — Constants, utilities, and fixtures layout and import rules - [`docs/QUARANTINE_GUIDELINES.md`](QUARANTINE_GUIDELINES.md) — Test quarantine and de-quarantine procedures - [`docs/SOFTWARE_TEST_DESCRIPTION.md`](SOFTWARE_TEST_DESCRIPTION.md) — STD docstring format and requirements - [`docs/CODING_AND_STYLE_GUIDE.md`](docs/CODING_AND_STYLE_GUIDE.md) — Detailed coding and style conventions diff --git a/docs/ARCHITECTURE_SUPPORT.md b/docs/ARCHITECTURE_SUPPORT.md index b8edaa211d..c8552274f4 100644 --- a/docs/ARCHITECTURE_SUPPORT.md +++ b/docs/ARCHITECTURE_SUPPORT.md @@ -28,6 +28,9 @@ pytest -m s390x ... Note: to run on the default architecture `amd64`, there's no need to set any architecture-specific markers. ## Adding new images or new architecture support + +See [Code Organization — Constants](CODE_ORGANIZATION.md#constants-utilitiesconstants) for import rules and the constants module map. + Images for different architectures are managed under [images.py](../utilities/constants/images.py) — `ArchImages`. The data structures are defined under [images.py](../libs/infra/images.py). diff --git a/docs/CODE_ORGANIZATION.md b/docs/CODE_ORGANIZATION.md new file mode 100644 index 0000000000..4267a9bf2d --- /dev/null +++ b/docs/CODE_ORGANIZATION.md @@ -0,0 +1,162 @@ +# Code Organization + +Where shared constants, utility functions, and pytest fixtures belong, and how to import them. + +For general coding style see [CODING_AND_STYLE_GUIDE.md](CODING_AND_STYLE_GUIDE.md). For enforceable +AI/review rules see [AGENTS.md](../AGENTS.md). + +## Shared principles + +- **Thematic modules** — one concern per file; no catch-all modules. +- **Search first** — before adding anything, check existing `utilities/`, `libs/`, and `tests/` code. +- **Absolute imports** — always `from utilities.… import …`, never relative imports. +- **Submodule imports** — import from the specific module that owns the symbol; do not rely on + package-level re-exports except where documented below. +- **No helpers in conftest** — `conftest.py` and `test_*.py` contain fixtures and tests only; + helpers belong in `utilities/`, `libs/`, or feature `utils.py` files. + +--- + +## Constants (`utilities/constants/`) + +Test and utility code shares string literals, timeouts, resource names, and configuration values +through the `utilities/constants/` package. Each file is a thematic submodule. + +### Import policy + +```python +# Preferred — import from the owning submodule +from utilities.constants.timeouts import TIMEOUT_5MIN +from utilities.constants.cluster import KUBERNETES_ARCH_LABEL + +# Exception — Images only (computed at package import time; see below) +from utilities.constants import Images +``` + +- Do **not** use `from utilities.constants import X` for any name other than `Images`. +- Do **not** add re-exports to `utilities/constants/__init__.py` (except `Images` and `ArchImages`). + +### Adding a new constant + +1. Read submodule docstrings (`Covers` / `Not here` sections) to pick the right file. +2. Add the constant there; update the module docstring if the scope changes. +3. Submodule files must **not** import from other `utilities/constants/` submodules — only from + `libs/`, `ocp_resources`, or the standard library. +4. Import the constant at call sites from the submodule directly. +5. Keep single-use values local to the test or feature module instead of adding them to the package. + +### `Images` exception + +`Images` is resolved in `utilities/constants/__init__.py` based on cluster architecture. +This avoids a circular import between `utilities/architecture.py` and the constants package. +Use `from utilities.constants import Images` only for this alias. For `ArchImages`, OS flavor +strings, and other image constants, import from `utilities/constants/images.py`. + +Architecture-specific image setup is described in [ARCHITECTURE_SUPPORT.md](ARCHITECTURE_SUPPORT.md). + +### Module map + +| Submodule | Use for | +| --- | --- | +| `aaq.py` | Application-Aware Quota resource names, quota field keys, namespace labels, quota spec dicts | +| `architecture.py` | CPU architecture strings (`AMD_64`, `ARM_64`, …), vendor identifiers, supported architecture sets | +| `cluster.py` | Kubernetes node labels, `NODE_STR`, API verb strings, env vars, pod security labels, audit-log commands | +| `components.py` | CNV operator/pod/deployment/service **name strings** and Kubernetes kind strings (`kubectl get /`) | +| `cpu_models.py` | CPU model exclusion lists for guest compatibility | +| `hco.py` | HCO status conditions, upgrade streams, TLS profiles, feature gate keys, CNV CRD list | +| `images.py` | `ArchImages`, OS flavor strings, image disk names, `DEFAULT_FEDORA_REGISTRY_URL` | +| `instance_types.py` | Instance type and VM preference name strings (`U1_*`, `RHEL*_PREFERENCE`, `WINDOWS_*_PREFERENCE`) | +| `monitoring.py` | Alert severities, operator health metrics, KubeVirt VMI metric names, Prometheus service name | +| `namespaces.py` | `NamespacesNames` — well-known OpenShift and CNV namespace strings | +| `networking.py` | SR-IOV, bridge types, ports, KubeMacPool config, bonding, network test pod specs | +| `oadp.py` | OADP test file names, backup storage location names | +| `os_matrix.py` | Common-templates test matrix **parameter keys** (`IMAGE_NAME_STR`, `DV_SIZE_STR`, …) | +| `pytest.py` | Pytest exit codes, quarantine strings, fixture scope strings, unprivileged test credentials | +| `storage.py` | `StorageClassNames`, CDI/HPP labels, hotplug constants, DataVolume source types, DataImportCron values | +| `tekton.py` | Tekton pipeline ref and task name strings for Windows VM automation | +| `timeouts.py` | `TIMEOUT_*` integers and `TCP_TIMEOUT_30SEC` | +| `virt.py` | Virtctl commands, migration/eviction values, Windows version tags, CPU/memory topology, VM hardware constants | + +Each submodule docstring lists what belongs there and what belongs elsewhere. + +--- + +## Utility functions (`utilities/`) + +Shared non-fixture logic lives under `utilities/`. Monolithic modules are being split into +thematic subpackages over time (same model as `utilities/constants/`). + +### Placement + +| Location | Use for | +| --- | --- | +| `utilities/cluster.py` | Cluster-wide operations (oc commands, node operations, cluster state) | +| `utilities/infra.py` | Infrastructure helpers (SSH, networking infrastructure, pod operations) | +| `utilities/virt.py` | VM lifecycle, VMI operations, migration helpers | +| `utilities/storage.py` | Storage operations (PVC, DataVolume, StorageClass) | +| Other `utilities/*.py` | Domain-specific helpers (HCO, monitoring, artifactory, …) | + +When a module grows into a package (e.g. `utilities/virt/`), add functions to the submodule +that matches the concern and import from there: + +```python +from utilities.virt.migration import migrate_vm_and_verify +``` + +Small single-purpose modules (`exceptions.py`, `logger.py`, …) may remain as single files +until splitting improves clarity. + +**Never** add functions to the wrong domain module — match the table above. + +--- + +## Fixtures (`tests/fixtures/` and `conftest.py`) + +Pytest fixtures provide test setup and teardown. Fixture **definitions** for shared use are +moving into `tests/fixtures/`; `conftest.py` files register plugins and hold feature-local +fixtures only. + +### Hierarchy + +| File / directory | Role | +| --- | --- | +| [`conftest.py`](../conftest.py) | Pytest hooks, session configuration, `pytest_plugins` registration | +| [`tests/conftest.py`](../tests/conftest.py) | Cross-team fixtures still being consolidated | +| `tests///conftest.py` | Feature-local fixtures when needed | +| `tests/fixtures//.py` | Shared fixture implementations | + +### `tests/fixtures/` package + +Shared fixtures are defined in Python modules under `tests/fixtures/`, grouped by team and topic: + +``` +tests/fixtures/ + network/ + l2_bridge.py + cluster.py +``` + +Register new fixture modules in the root `conftest.py` `pytest_plugins` list: + +```python +pytest_plugins = [ + "tests.fixtures.network.l2_bridge", + "tests.fixtures.network.cluster", +] +``` + +Add a new entry when introducing a fixture module used across multiple test directories. + +### Rules + +- **`conftest.py` is for fixtures only** — no helper functions, utility functions, or classes. +- **Fixture names are nouns** — describe what the fixture provides (`vm_with_disk`), not an action + (`create_vm_with_disk`). +- **One action per fixture** — split combined setup into separate fixtures composed by tests or + `@pytest.mark.usefixtures`. +- **Return or yield the resource** — even setup-only fixtures should yield the created object. +- **Use `@pytest.mark.usefixtures`** when the test does not use the fixture return value. +- **Feature-local helpers** — place in `/utils.py`, not in `conftest.py`. + +Fixture scope, ordering, and logging rules are in [AGENTS.md](../AGENTS.md) and +[CODING_AND_STYLE_GUIDE.md](CODING_AND_STYLE_GUIDE.md). diff --git a/docs/CODING_AND_STYLE_GUIDE.md b/docs/CODING_AND_STYLE_GUIDE.md index 203023d128..7e622be49b 100644 --- a/docs/CODING_AND_STYLE_GUIDE.md +++ b/docs/CODING_AND_STYLE_GUIDE.md @@ -61,12 +61,16 @@ Only add comments when necessary. For example, when using complex regex. - Tests are to be placed in `test_.py` file; this is where the actual tests are written. `` describes the functionality tested in this test file. - If helper utils are needed, they should be placed in the test's subdirectory. -- If specific fixtures are needed, they should be placed in a `conftest.py` file under the test's subdirectory. +- If specific fixtures are needed, they should be placed in a `conftest.py` file under the test's subdirectory, or in [`tests/fixtures/`](../tests/fixtures/) when shared across teams — see [Code Organization](CODE_ORGANIZATION.md#fixtures-testsfixtures-and-conftestpy). ## conftest -- Top level [conftest.py](../conftest.py) contains pytest native fixtures. + +See [Code Organization](CODE_ORGANIZATION.md#fixtures-testsfixtures-and-conftestpy) for the full fixture layout. + +- Top level [conftest.py](../conftest.py) contains pytest hooks and `pytest_plugins` registration. - General tests [conftest.py](../tests/conftest.py) contains fixtures that are used in multiple tests by multiple teams. -- If needed, create new `conftest.py` files in the relevant directories. +- Shared fixture implementations belong in [`tests/fixtures//.py`](../tests/fixtures/) and are registered via `pytest_plugins` in the root `conftest.py`. +- If needed, create new `conftest.py` files in the relevant directories for feature-local fixtures only. ## Fixtures diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index 218bb9dca7..b2179abdaa 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -9,8 +9,9 @@ The project is structured as follows: - [utilities](../utilities): Base directory for utility functions - Each module contains a set of utility functions related to a specific topic, for example: - [infra](../utilities/infra.py): Infrastructure-related (cluster resources) utility functions - - [constants](../utilities/constants/): Constants package — import from the relevant submodule (e.g. `from utilities.constants.timeouts import TIMEOUT_5MIN`). -- [docs](../docs): Documentation + - [constants](../utilities/constants/): Shared constants package — see [Code Organization](CODE_ORGANIZATION.md#constants-utilitiesconstants) + - [tests/fixtures](../tests/fixtures/): Shared pytest fixture implementations — see [Code Organization](CODE_ORGANIZATION.md#fixtures-testsfixtures-and-conftestpy) +- [docs](../docs): Documentation — including [Code Organization](CODE_ORGANIZATION.md) for constants, utilities, and fixtures - [py_config](../tests/global_config.py) contains tests-specific configuration which can be controlled from the command line. Please refer to [pytest-testconfig](https://github.com/wojole/pytest-testconfig) for more information. From 74de320eea0db7100009a5c1adc80cde56f902ea Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 12:52:54 +0300 Subject: [PATCH 4/6] refactor(constants): export only Images from package __init__ Drop ArchImages from __all__; use private _ArchImages import for Images computation. Update callers to import ArchImages from images.py. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- docs/CODE_ORGANIZATION.md | 2 +- libs/vm/factory.py | 8 ++++---- utilities/constants/__init__.py | 7 ++++--- utilities/os_utils.py | 2 +- utilities/pytest_utils.py | 5 ++--- utilities/unittests/test_pytest_utils.py | 16 ++++++++-------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/CODE_ORGANIZATION.md b/docs/CODE_ORGANIZATION.md index 4267a9bf2d..8de0dccec8 100644 --- a/docs/CODE_ORGANIZATION.md +++ b/docs/CODE_ORGANIZATION.md @@ -34,7 +34,7 @@ from utilities.constants import Images ``` - Do **not** use `from utilities.constants import X` for any name other than `Images`. -- Do **not** add re-exports to `utilities/constants/__init__.py` (except `Images` and `ArchImages`). +- Do **not** add re-exports to `utilities/constants/__init__.py` (except `Images`). ### Adding a new constant diff --git a/libs/vm/factory.py b/libs/vm/factory.py index 65a207b4a3..423f8c55a8 100644 --- a/libs/vm/factory.py +++ b/libs/vm/factory.py @@ -5,9 +5,9 @@ from libs.vm.spec import CPU, Devices, Domain, Memory, Metadata, Template, VMISpec, VMSpec from libs.vm.vm import BaseVirtualMachine, container_image, containerdisk_storage -from utilities import constants +from utilities.constants import Images from utilities.constants.architecture import MULTIARCH -from utilities.constants.images import OS_FLAVOR_FEDORA +from utilities.constants.images import OS_FLAVOR_FEDORA, ArchImages def fedora_vm( @@ -33,9 +33,9 @@ def fedora_vm( def fedora_image(arch: str | None = None) -> str: if arch: - images = getattr(constants.ArchImages, arch.upper()) + images = getattr(ArchImages, arch.upper()) else: - images = constants.Images + images = Images return container_image(base_image=images.Fedora.FEDORA_CONTAINER_IMAGE, arch=arch) diff --git a/utilities/constants/__init__.py b/utilities/constants/__init__.py index edf3008844..881e863970 100644 --- a/utilities/constants/__init__.py +++ b/utilities/constants/__init__.py @@ -8,9 +8,10 @@ # All other constants must be imported from their submodule directly, e.g.: # from utilities.constants.cluster import KUBERNETES_ARCH_LABEL # from utilities.constants.timeouts import TIMEOUT_5MIN +# from utilities.constants.images import ArchImages from utilities.architecture import get_cluster_architecture as _get_cluster_architecture -from utilities.constants.images import ArchImages +from utilities.constants.images import ArchImages as _ArchImages -__all__ = ["ArchImages", "Images"] +__all__ = ["Images"] -Images = getattr(ArchImages, next(iter(_get_cluster_architecture())).upper()) +Images = getattr(_ArchImages, next(iter(_get_cluster_architecture())).upper()) diff --git a/utilities/os_utils.py b/utilities/os_utils.py index 703c367082..c878160650 100644 --- a/utilities/os_utils.py +++ b/utilities/os_utils.py @@ -193,7 +193,7 @@ def generate_os_matrix_dict( if not os_base_class: raise ValueError( f"Unsupported OS: {os_name}. " - "Make sure it is supported under `utilities.constants.ArchImages` class for cluster architecture." + "Make sure it is supported under `utilities.constants.images.ArchImages` for cluster architecture." ) latest_os_release = getattr(os_base_class, "LATEST_RELEASE_STR", None) diff --git a/utilities/pytest_utils.py b/utilities/pytest_utils.py index 9315bef045..cd958fac6d 100644 --- a/utilities/pytest_utils.py +++ b/utilities/pytest_utils.py @@ -634,10 +634,9 @@ def update_cpu_arch_related_config(cpu_arch_option: str) -> None: # TODO: remove this when utilities modules are refactored import utilities.constants as constants_module # noqa: PLC0415 + from utilities.constants.images import ArchImages # noqa: PLC0415 - # Due to the way the constants module is structured, there's no way to set correctly Images value there - # This is due to change when constants (and other utilities modules) are refactored - constants_module.Images = getattr(constants_module.ArchImages, arch.upper()) + constants_module.Images = getattr(ArchImages, arch.upper()) if py_config["cluster_type"] == MULTIARCH: generate_common_template_matrix_dicts(os_dict=py_config["os_matrix"][arch], cpu_arch=arch) diff --git a/utilities/unittests/test_pytest_utils.py b/utilities/unittests/test_pytest_utils.py index ba3fc1a419..4bf8407760 100644 --- a/utilities/unittests/test_pytest_utils.py +++ b/utilities/unittests/test_pytest_utils.py @@ -1968,7 +1968,7 @@ def test_single_arch_option_sets_cpu_arch( mock_py_config = {"cluster_type": "amd64"} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.AMD64 = MagicMock() @@ -1996,7 +1996,7 @@ def test_empty_option_uses_cluster_architecture( mock_py_config = {"cluster_type": "arm64"} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.ARM64 = MagicMock() @@ -2030,7 +2030,7 @@ def test_multiarch_cluster_uses_os_matrix_arch( } with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.AMD64 = MagicMock() @@ -2058,7 +2058,7 @@ def test_s390x_architecture_sets_images( mock_py_config = {"cluster_type": "s390x"} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_s390x_images = MagicMock() @@ -2088,7 +2088,7 @@ def test_arm64_option_sets_images( mock_py_config = {"cluster_type": "amd64"} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arm64_images = MagicMock() @@ -2116,7 +2116,7 @@ def test_non_multiarch_amd64_cluster_uses_py_config_no_cpu_arch( mock_py_config = {"cluster_type": "amd64", "rhel_os_list": ["rhel-9-6"]} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.AMD64 = MagicMock() @@ -2143,7 +2143,7 @@ def test_non_amd64_cluster_uses_py_config_with_cpu_arch( mock_py_config = {"cluster_type": "arm64", "rhel_os_list": ["rhel-9-6"]} with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.ARM64 = MagicMock() @@ -2198,7 +2198,7 @@ def test_multiarch_cluster_arm64_uses_correct_os_matrix( } with ( patch("utilities.pytest_utils.py_config", mock_py_config), - patch("utilities.constants.ArchImages") as mock_arch_images, + patch("utilities.constants.images.ArchImages") as mock_arch_images, patch("utilities.constants.Images"), ): mock_arch_images.ARM64 = MagicMock() From 6d04d6295f92659249a901e62f951b258f4883a7 Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 14:40:27 +0300 Subject: [PATCH 5/6] test(constants): cover aaq, oadp, and tekton submodules Add unit tests for constants split into separate modules so utilities coverage stays above the project threshold. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- utilities/unittests/test_constants.py | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/utilities/unittests/test_constants.py b/utilities/unittests/test_constants.py index 03c3ff3427..984793ac5f 100644 --- a/utilities/unittests/test_constants.py +++ b/utilities/unittests/test_constants.py @@ -1,5 +1,13 @@ """Unit tests for constants package.""" +from utilities.constants.aaq import ( + AAQ_NAMESPACE_LABEL, + AAQ_VIRTUAL_RESOURCES, + AAQ_VMI_POD_USAGE, + ARQ_QUOTA_HARD_SPEC, + QUOTA_FOR_ONE_VMI, + QUOTA_FOR_POD, +) from utilities.constants.architecture import ( AMD_64, ARM_64, @@ -42,11 +50,22 @@ LINUX_BRIDGE, OVS_BRIDGE, ) +from utilities.constants.oadp import ( + BACKUP_STORAGE_LOCATION, + FILE_NAME_FOR_BACKUP, + TEXT_TO_TEST, +) from utilities.constants.os_matrix import ( DV_SIZE_STR, IMAGE_NAME_STR, OS_VERSION_STR, ) +from utilities.constants.tekton import ( + TEKTON_AVAILABLE_PIPELINEREF, + TEKTON_AVAILABLE_TASKS, + WINDOWS_CUSTOMIZE_STR, + WINDOWS_EFI_INSTALLER_STR, +) from utilities.constants.timeouts import ( TCP_TIMEOUT_30SEC, TIMEOUT_1MIN, @@ -177,3 +196,37 @@ def test_os_matrix_constants(self): assert IMAGE_NAME_STR == "image_name" assert OS_VERSION_STR == "os_version" assert DV_SIZE_STR == "dv_size" + + def test_aaq_constants(self): + """Test Application-Aware Quota constants are defined.""" + assert AAQ_VIRTUAL_RESOURCES == "VirtualResources" + assert AAQ_VMI_POD_USAGE == "VmiPodUsage" + assert AAQ_NAMESPACE_LABEL == {"application-aware-quota/enable-gating": ""} + assert QUOTA_FOR_POD["pods"] == "1" + assert QUOTA_FOR_ONE_VMI["requests.instances/vmi"] == "1" + assert ARQ_QUOTA_HARD_SPEC == {**QUOTA_FOR_POD, **QUOTA_FOR_ONE_VMI} + + def test_oadp_constants(self): + """Test OADP backup test constants are defined.""" + assert FILE_NAME_FOR_BACKUP == "file_before_backup.txt" + assert TEXT_TO_TEST == "text" + assert BACKUP_STORAGE_LOCATION == "dpa-1" + + def test_tekton_constants(self): + """Test Tekton pipeline and task name constants are defined.""" + assert WINDOWS_EFI_INSTALLER_STR == "windows-efi-installer" + assert WINDOWS_CUSTOMIZE_STR == "windows-customize" + assert TEKTON_AVAILABLE_PIPELINEREF == [ + WINDOWS_EFI_INSTALLER_STR, + WINDOWS_CUSTOMIZE_STR, + ] + assert TEKTON_AVAILABLE_TASKS == [ + "modify-data-object", + "create-vm-from-manifest", + "wait-for-vmi-status", + "cleanup-vm", + "disk-virt-sysprep", + "disk-virt-customize", + "modify-windows-iso-file", + "disk-uploader", + ] From 450b58221d7a199e9dbaac4efc33446f9358fff4 Mon Sep 17 00:00:00 2001 From: vsibirsk Date: Wed, 1 Jul 2026 18:59:16 +0300 Subject: [PATCH 6/6] fix(vm): resolve Images at runtime in fedora_image Direct import froze the architecture image set at module load, so --cpu-arch overrides from update_cpu_arch_related_config were ignored when no explicit arch was passed. Assisted-by: Cursor Agent (Composer 2.5) Signed-off-by: vsibirsk --- libs/vm/factory.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/vm/factory.py b/libs/vm/factory.py index 423f8c55a8..b99139a533 100644 --- a/libs/vm/factory.py +++ b/libs/vm/factory.py @@ -5,7 +5,7 @@ from libs.vm.spec import CPU, Devices, Domain, Memory, Metadata, Template, VMISpec, VMSpec from libs.vm.vm import BaseVirtualMachine, container_image, containerdisk_storage -from utilities.constants import Images +from utilities import constants as constants_module from utilities.constants.architecture import MULTIARCH from utilities.constants.images import OS_FLAVOR_FEDORA, ArchImages @@ -32,10 +32,7 @@ def fedora_vm( def fedora_image(arch: str | None = None) -> str: - if arch: - images = getattr(ArchImages, arch.upper()) - else: - images = Images + images = getattr(ArchImages, arch.upper()) if arch else constants_module.Images return container_image(base_image=images.Fedora.FEDORA_CONTAINER_IMAGE, arch=arch)