From 866985ce0461dd7a820b007f8a6044890e774504 Mon Sep 17 00:00:00 2001 From: Ohad Date: Tue, 11 Aug 2026 15:22:09 +0300 Subject: [PATCH] Convert SCC annotation tests to dynamic subtests Combine test_deployments_missing_required_scc_annotation and test_deployments_with_incorrect_required_scc into a single test using subtests over discovered_cnv_deployments. Remove the required_scc_deployment_check fixture. Xfail virt-template deployments while CNV-94717 is open. assisted by: claude code claude-opus-4-6 Signed-off-by: Ohad --- tests/install_upgrade_operators/conftest.py | 12 ++++ .../scc/test_cnv_deployment_required_scc.py | 56 ++++++------------- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/tests/install_upgrade_operators/conftest.py b/tests/install_upgrade_operators/conftest.py index 34a640102d..c67ca3d0b3 100644 --- a/tests/install_upgrade_operators/conftest.py +++ b/tests/install_upgrade_operators/conftest.py @@ -52,6 +52,18 @@ LOGGER = logging.getLogger(__name__) +@pytest.fixture(scope="session") +def discovered_cnv_deployments(admin_client, hco_namespace): + """Discover all CNV deployments from the cluster.""" + return list( + Deployment.get( + client=admin_client, + namespace=hco_namespace.name, + label_selector="app.kubernetes.io/part-of=hyperconverged-cluster", + ) + ) + + @pytest.fixture(scope="session") def iib_build_info(cnv_source, cnv_image_url, admin_client): """Queries Version Explorer for IIB build info. diff --git a/tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py b/tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py index abcabaa50e..1286996dbb 100644 --- a/tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py +++ b/tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py @@ -3,52 +3,28 @@ """ import pytest -from ocp_resources.deployment import Deployment -from utilities.constants.components import ( - ALL_CNV_DEPLOYMENTS, - HPP_POOL, -) +from utilities.constants.components import HPP_POOL +from utilities.jira import is_jira_open REQUIRED_SCC_ANNOTATION = "openshift.io/required-scc" REQUIRED_SCC_VALUE = "restricted-v2" +VIRT_TEMPLATE_PREFIXES = ("virt-template-apiserver", "virt-template-controller") pytestmark = [pytest.mark.s390x, pytest.mark.skip_must_gather_collection] -@pytest.fixture(scope="module") -def required_scc_deployment_check(admin_client, hco_namespace): - missing_required_scc_annotation = [] - incorrect_required_scc_annotation_value = {} - - for name in ALL_CNV_DEPLOYMENTS: - if name.startswith(HPP_POOL): - continue - dp = Deployment(client=admin_client, name=name, namespace=hco_namespace.name) - scc = dp.instance.spec.template.metadata.annotations.get(REQUIRED_SCC_ANNOTATION) - - if scc is None: - missing_required_scc_annotation.append(dp.name) - elif scc != REQUIRED_SCC_VALUE: - incorrect_required_scc_annotation_value[dp.name] = scc - - return { - "missing_required_scc_annotation": missing_required_scc_annotation, - "incorrect_required_scc_annotation_value": incorrect_required_scc_annotation_value, - } - - @pytest.mark.polarion("CNV-11964") -def test_deployments_missing_required_scc_annotation(required_scc_deployment_check): - assert not required_scc_deployment_check["missing_required_scc_annotation"], ( - f"Deployments missing {REQUIRED_SCC_ANNOTATION} annotation: " - f"{required_scc_deployment_check['missing_required_scc_annotation']}" - ) - - -@pytest.mark.polarion("CNV-11965") -def test_deployments_with_incorrect_required_scc(required_scc_deployment_check): - assert not required_scc_deployment_check["incorrect_required_scc_annotation_value"], ( - f"Deployments incorrect {REQUIRED_SCC_ANNOTATION} annotation : " - f"{required_scc_deployment_check['incorrect_required_scc_annotation_value']}" - ) +def test_deployment_required_scc(subtests, discovered_cnv_deployments): + assert discovered_cnv_deployments, "No CNV deployments were discovered in the HCO namespace" + for deployment in discovered_cnv_deployments: + with subtests.test(msg=deployment.name): + if deployment.name.startswith(HPP_POOL): + continue + if deployment.name.startswith(VIRT_TEMPLATE_PREFIXES) and is_jira_open(jira_id="CNV-94717"): + pytest.xfail(f"{deployment.name} missing required-scc annotation (CNV-94717)") + scc = deployment.instance.spec.template.metadata.annotations.get(REQUIRED_SCC_ANNOTATION) + assert scc, f"Deployment {deployment.name} missing {REQUIRED_SCC_ANNOTATION} annotation" + assert scc == REQUIRED_SCC_VALUE, ( + f"Deployment {deployment.name}: {REQUIRED_SCC_ANNOTATION}={scc}, expected: {REQUIRED_SCC_VALUE}" + )