Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/install_upgrade_operators/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)
Comment on lines +56 to +64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you apply it for all other other tests using ALL_CNV_DEPLOYMENT or the deployment matrix? its a good opportunity



@pytest.fixture(scope="session")
def iib_build_info(cnv_source, cnv_image_url, admin_client):
"""Queries Version Explorer for IIB build info.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
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}"
)