Skip to content

Commit daca909

Browse files
authored
Add test to validate openshift.io/required-scc annotation for all HCO deployments (#1110)
Signed-off-by: Geetika Kapoor <[email protected]>
1 parent b084519 commit daca909

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test to verify all HCO deployments have 'openshift.io/required-scc' annotation.
4+
"""
5+
6+
import pytest
7+
from ocp_resources.deployment import Deployment
8+
9+
from utilities.constants import ALL_CNV_DEPLOYMENTS_NO_HPP_POOL
10+
11+
REQUIRED_SCC_ANNOTATION = "openshift.io/required-scc"
12+
REQUIRED_SCC_VALUE = "restricted-v2"
13+
14+
15+
@pytest.fixture(scope="module")
16+
def required_scc_deployment_check(admin_client, hco_namespace):
17+
missing_required_scc_annotation = []
18+
incorrect_required_scc_annotation_value = {}
19+
20+
for dp in (
21+
Deployment(client=admin_client, name=name, namespace=hco_namespace.name)
22+
for name in ALL_CNV_DEPLOYMENTS_NO_HPP_POOL
23+
):
24+
scc = dp.instance.spec.template.metadata.annotations.get(REQUIRED_SCC_ANNOTATION)
25+
26+
if scc is None:
27+
missing_required_scc_annotation.append(dp.name)
28+
elif scc != REQUIRED_SCC_VALUE:
29+
incorrect_required_scc_annotation_value[dp.name] = scc
30+
31+
return {
32+
"missing_required_scc_annotation": missing_required_scc_annotation,
33+
"incorrect_required_scc_annotation_value": incorrect_required_scc_annotation_value,
34+
}
35+
36+
37+
@pytest.mark.polarion("CNV-11964")
38+
def test_deployments_missing_required_scc_annotation(required_scc_deployment_check):
39+
assert not required_scc_deployment_check["missing_required_scc_annotation"], (
40+
f"Deployments missing {REQUIRED_SCC_ANNOTATION} annotation: "
41+
f"{required_scc_deployment_check['missing_required_scc_annotation']}"
42+
)
43+
44+
45+
@pytest.mark.polarion("CNV-11965")
46+
def test_deployments_with_incorrect_required_scc(required_scc_deployment_check):
47+
assert not required_scc_deployment_check["incorrect_required_scc_annotation_value"], (
48+
f"Deployments incorrect {REQUIRED_SCC_ANNOTATION} annotation : "
49+
f"{required_scc_deployment_check['incorrect_required_scc_annotation_value']}"
50+
)

0 commit comments

Comments
 (0)