[IUO] Fix runbook URL test failures#4741
Conversation
📝 WalkthroughWalkthroughAdds a session-scoped pytest fixture ChangesAAQ Prometheus Rule Testing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
AI Features
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4741 +/- ##
==========================================
+ Coverage 98.63% 98.67% +0.03%
==========================================
Files 25 25
Lines 2420 2484 +64
==========================================
+ Hits 2387 2451 +64
Misses 33 33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/observability/runbook_url/conftest.py`:
- Around line 60-61: The call to sample.json() can raise JSONDecodeError and
escape the sampler retry loop; wrap the sample.json() extraction into a
try/except that catches requests.exceptions.JSONDecodeError (or ValueError for
older requests) around the line creating runbook_urls (the {entry["html_url"]
for entry in sample.json()} expression), log or ignore the decode error and
continue the loop so the TimeoutExpiredError retry logic (the existing except
handling) can retry, and only return runbook_urls when JSON parsing succeeds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c8611c94-c7b5-4fcf-ac3b-81777cf4b293
📒 Files selected for processing (4)
tests/conftest.pytests/observability/runbook_url/conftest.pytests/observability/runbook_url/test_runbook_url.pyutilities/constants.py
f413348 to
bdbe8df
Compare
bdbe8df to
b992e20
Compare
|
/build-and-push-container |
|
Clean rebase detected — no code changes compared to previous head ( |
|
New container for quay.io/openshift-cnv/openshift-virtualization-tests:pr-4741 published |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/conftest.py`:
- Around line 1340-1342: The fixture aaq_enabled currently assumes
hyperconverged_resource_scope_session is always present and will raise
AttributeError when that fixture is None; update the aaq_enabled fixture
signature to accept installing_cnv (like other fixtures) and guard against a
None hyperconverged_resource_scope_session by returning False (or a safe
default) when hyperconverged_resource_scope_session is None, otherwise return
hyperconverged_resource_scope_session.instance.spec.get("enableApplicationAwareQuota",
False); reference the aaq_enabled fixture and
hyperconverged_resource_scope_session to locate and change the code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 30c834f2-1297-4685-8071-079031dec556
📒 Files selected for processing (4)
tests/conftest.pytests/observability/runbook_url/conftest.pytests/observability/runbook_url/test_runbook_url.pyutilities/constants.py
…upport Replace status code check with data validation in available_runbook_urls fixture to handle non-200 responses that still contain valid data. Add AAQ prometheus rule support to test_no_new_prometheus_rules so clusters with AAQ enabled don't fail the assertion. Signed-off-by: Ohad <orevah@redhat.com> assisted by: claude code claude-opus-4-6
b992e20 to
2455627
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/observability/runbook_url/conftest.py`:
- Around line 60-70: The code builds runbook_urls using a set comprehension from
sample.json() which can raise TypeError/KeyError when the JSON is not the
expected list-of-dicts or when entries lack "html_url"; modify the block around
sample.json() in conftest.py so you first parse the payload into a variable
(resp = sample.json()), validate that resp is an iterable/list, then iterate
entries and only add entry["html_url"] when entry is a dict and "html_url" in
entry; catch and handle TypeError/KeyError (and ValueError already handled) by
logging the failure with runbooks_api_url, sample.status_code and content-type
via LOGGER and continue the sampler loop so retries are preserved (referencing
sample, runbook_urls, runbooks_api_url, LOGGER).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6190730e-69a9-40ec-8826-0fb68e4c3a75
📒 Files selected for processing (4)
tests/conftest.pytests/observability/runbook_url/conftest.pytests/observability/runbook_url/test_runbook_url.pyutilities/constants.py
| if sample: | ||
| try: | ||
| runbook_urls = {entry["html_url"] for entry in sample.json()} | ||
| except ValueError: | ||
| LOGGER.error( | ||
| f"Failed to decode JSON from '{runbooks_api_url}', " | ||
| f"status: {sample.status_code}, content-type: {sample.headers.get('Content-Type')}" | ||
| ) | ||
| continue | ||
| if runbook_urls: | ||
| return runbook_urls |
There was a problem hiding this comment.
HIGH: Validate JSON payload shape before extracting html_url.
At Line 62, valid-but-unexpected JSON (e.g., dict payload or entries without html_url) can raise TypeError/KeyError, escape the sampler loop, and bypass retry behavior.
Proposed fix
if sample:
try:
- runbook_urls = {entry["html_url"] for entry in sample.json()}
+ payload = sample.json()
except ValueError:
LOGGER.error(
f"Failed to decode JSON from '{runbooks_api_url}', "
f"status: {sample.status_code}, content-type: {sample.headers.get('Content-Type')}"
)
continue
+ if not isinstance(payload, list):
+ LOGGER.error(
+ f"Unexpected JSON payload type from '{runbooks_api_url}': "
+ f"{type(payload).__name__}, status: {sample.status_code}"
+ )
+ continue
+ runbook_urls = {
+ entry.get("html_url")
+ for entry in payload
+ if isinstance(entry, dict) and entry.get("html_url")
+ }
if runbook_urls:
return runbook_urls🧰 Tools
🪛 Ruff (0.15.12)
[warning] 64-67: Use logging.exception instead of logging.error
Replace with exception
(TRY400)
[warning] 65-66: Logging statement uses f-string
(G004)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/observability/runbook_url/conftest.py` around lines 60 - 70, The code
builds runbook_urls using a set comprehension from sample.json() which can raise
TypeError/KeyError when the JSON is not the expected list-of-dicts or when
entries lack "html_url"; modify the block around sample.json() in conftest.py so
you first parse the payload into a variable (resp = sample.json()), validate
that resp is an iterable/list, then iterate entries and only add
entry["html_url"] when entry is a dict and "html_url" in entry; catch and handle
TypeError/KeyError (and ValueError already handled) by logging the failure with
runbooks_api_url, sample.status_code and content-type via LOGGER and continue
the sampler loop so retries are preserved (referencing sample, runbook_urls,
runbooks_api_url, LOGGER).
|
/retest all Auto-triggered: Files in this PR were modified by merged PR #4658. Overlapping filesutilities/constants.py |
Short description:
Replace status code check with data validation in available_runbook_urls fixture to handle non-200 responses that still contain valid data. Add AAQ prometheus rule support to test_no_new_prometheus_rules so clusters with AAQ enabled don't fail the assertion.
Signed-off-by: Ohad Revah orevah@redhat.com
assisted by: claude code claude-opus-4-6
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
jira-ticket:
Summary by CodeRabbit
Tests
Chores