-
Notifications
You must be signed in to change notification settings - Fork 34
Add test to validate openshift.io/required-scc annotation for all HCO deployments #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
""" WalkthroughA new test module was added to verify that all HyperConverged Operator (HCO) deployments have the "openshift.io/required-scc" annotation set to "restricted-v2". The tests use pytest fixtures to collect deployments, check for missing or incorrect annotations, and assert compliance, with traceability via Polarion IDs. Changes
Possibly related issues
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Report bugs in Issues The following are automatically added:
Available user actions:
PR will be approved when the following conditions are met:
Approvers and Reviewers
Supported /retest check runs
Supported labels
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)
utilities/infra.py (1)
is_jira_open
(854-867)tests/conftest.py (2)
hco_namespace
(1027-1029)namespace
(648-662)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: build-container
- GitHub Check: tox
🔇 Additional comments (5)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (5)
1-14
: LGTM! Good module structure and clear constants.The file header, imports, and constant definitions are well-organized. The constants
REQUIRED_SCC_ANNOTATION
andREQUIRED_SCC_VALUE
make the code maintainable and clear.
16-21
: LGTM! Well-structured fixture with appropriate scope.The fixture correctly creates Deployment objects and sorts them for consistent test execution. The module scope is appropriate for this type of resource collection.
45-50
: LGTM! Clear test with appropriate assertions.The test function properly asserts that no deployments are missing the required annotation and provides informative error messages. The Polarion marker ensures proper traceability.
53-58
: LGTM! Complementary test with clear validation.This test correctly validates that deployments with the annotation have the correct value. Together with the previous test, it provides comprehensive coverage of the annotation requirement.
30-31
:✅ Verification successful
Verify the JIRA conditional logic.
The conditional skip logic for
VIRT_EXPORTPROXY
deployments when JIRA CNV-62807 is open appears correct, but should be verified to ensureVIRT_EXPORTPROXY
contains the expected deployment names.
🏁 Script executed:
#!/bin/bash # Description: Verify the VIRT_EXPORTPROXY constant contains expected deployment names # Expected: Should find the constant definition and show its value rg -A 5 "VIRT_EXPORTPROXY.*=" utilities/constants.pyLength of output: 278
VIRT_EXPORTPROXY constant verified
VIRT_EXPORTPROXY is defined as the string
"virt-exportproxy"
, which matches the deployment name checked bydp.name in VIRT_EXPORTPROXY
. The skip logic for CNV-62807 therefore behaves as intended.
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py
Outdated
Show resolved
Hide resolved
/wip |
/wip cancel |
f02c4f8
to
4e4f6d9
Compare
/verified |
D/S test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1)
24-24
:⚠️ Potential issueAddress the unaddressed unsafe attribute access issue.
This line still has the same unsafe chained attribute access issue that was flagged in previous reviews. If any intermediate attribute (
spec
,template
,metadata
, orannotations
) isNone
, this will raise anAttributeError
.Apply the previously suggested fix to make the code more robust:
- scc = dp.instance.spec.template.metadata.annotations.get(REQUIRED_SCC_ANNOTATION) + try: + annotations = dp.instance.spec.template.metadata.annotations or {} + scc = annotations.get(REQUIRED_SCC_ANNOTATION) + except AttributeError: + # If any intermediate attribute is missing, treat as missing annotation + missing_required_scc_annotation.append(dp.name) + continue
🧹 Nitpick comments (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (1)
15-16
: Add docstrings to address static analysis warnings.Consider adding docstrings to the fixture and test functions to improve code documentation and address pylint warnings.
@pytest.fixture(scope="module") def required_scc_deployment_check(admin_client, hco_namespace): + """ + Fixture to check SCC annotations on CNV deployments. + + Returns: + dict: Contains lists of deployments missing or having incorrect SCC annotations. + """ missing_required_scc_annotation = [] @pytest.mark.polarion("CNV-11964") def test_deployments_missing_required_scc_annotation(required_scc_deployment_check): + """Test that all CNV deployments have the required SCC annotation.""" assert not required_scc_deployment_check["missing_required_scc_annotation"], ( @pytest.mark.polarion("CNV-11965") def test_deployments_with_incorrect_required_scc(required_scc_deployment_check): + """Test that all CNV deployments have the correct SCC annotation value.""" assert not required_scc_deployment_check["incorrect_required_scc_annotation_value"], (Also applies to: 38-38, 46-46
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 16-16: Missing function or method docstring
(C0116)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)
tests/conftest.py (3)
admin_client
(303-307)hco_namespace
(1029-1031)namespace
(650-664)tests/network/user_defined_network/test_user_defined_network.py (1)
client
(89-98)
🪛 Pylint (3.3.7)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py
[error] 7-7: Unable to import 'ocp_resources.deployment'
(E0401)
[convention] 16-16: Missing function or method docstring
(C0116)
[convention] 38-38: Missing function or method docstring
(C0116)
[warning] 38-38: Redefining name 'required_scc_deployment_check' from outer scope (line 16)
(W0621)
[convention] 46-46: Missing function or method docstring
(C0116)
[warning] 46-46: Redefining name 'required_scc_deployment_check' from outer scope (line 16)
(W0621)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: can-be-merged
- GitHub Check: tox
- GitHub Check: build-container
- GitHub Check: can-be-merged
🔇 Additional comments (2)
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py (2)
26-29
: Good fix for the annotation categorization logic.The logic now correctly separates deployments with missing annotations from those with incorrect values, addressing the previous concern about adding deployments to both lists.
37-42
: Well-structured test functions with clear assertions.The test functions properly use the fixture data and provide clear error messages that will help identify which deployments are non-compliant. The Polarion markers ensure proper test traceability.
Also applies to: 45-50
🧰 Tools
🪛 Pylint (3.3.7)
[convention] 38-38: Missing function or method docstring
(C0116)
[warning] 38-38: Redefining name 'required_scc_deployment_check' from outer scope (line 16)
(W0621)
/approve |
tests/install_upgrade_operators/security/scc/test_cnv_deployment_required_scc.py
Show resolved
Hide resolved
/lgtm |
New container for quay.io/openshift-cnv/openshift-virtualization-tests:latest published |
Short description:
Refer : kubevirt/hyperconverged-cluster-operator#3284
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:
https://issues.redhat.com/browse/CNV-60087
Summary by CodeRabbit