Fix VM preference resolution in downward metrics fixture#4016
Fix VM preference resolution in downward metrics fixture#4016aditi-sharma-1 wants to merge 1 commit intoRedHatQE:mainfrom
Conversation
This change updates the preferred_preference_for_rhel_version fixture. When the cluster architecture is s390x, it checks for an architecture-specific VirtualMachineClusterPreference (for example, rhel.9.s390x). If the architecture preference does not exist (for example, rhel.8 on s390x), the logic falls back to the base preference(rhel.8). Behavior for other architectures remains unchanged. Signed-off-by: Aditi Sharma <Aditi.Sharma@ibm.com>
📝 WalkthroughWalkthroughTest file updated to support S390X cluster architecture detection. New imports added for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/infrastructure/vhostmd/test_downwardmetrics_virtio.py (1)
132-141: 🧹 Nitpick | 🔵 TrivialOPTIONAL: Improve error message to show all attempted preference names.
The fallback logic is correct—
S390Xis properly defined as the string constant"s390x"inutilities/constants.pyand works correctly in both the comparison (line 132) and f-string interpolation (line 134). The code correctly implements the documented behavior where RHEL 8 lacks an s390x-specific preference while RHEL 9/10 have them.One optional improvement: when the fallback fails on s390x clusters, the error only mentions the base
preference_name, not the s390x-specific name that was tried first. This makes debugging harder. Consider tracking attempted names for clarity:Suggested improvement
`@pytest.fixture`() def preferred_preference_for_rhel_version(rhel_version, unprivileged_client): preference_name = re.sub(r"(\D+)(\d+)", r"\1.\2", rhel_version) + attempted_names = [preference_name] if get_cluster_architecture() == S390X: + s390x_preference_name = f"{preference_name}.{S390X}" + attempted_names.insert(0, s390x_preference_name) preference_object = VirtualMachineClusterPreference( - name=f"{preference_name}.{S390X}", client=unprivileged_client + name=s390x_preference_name, client=unprivileged_client ) if preference_object.exists: return preference_object preference_object = VirtualMachineClusterPreference(name=preference_name, client=unprivileged_client) if preference_object.exists: return preference_object - raise ResourceNotFoundError(f"VirtualMachineClusterPreference {preference_name} not found") + raise ResourceNotFoundError(f"VirtualMachineClusterPreference not found. Attempted: {attempted_names}")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/infrastructure/vhostmd/test_downwardmetrics_virtio.py` around lines 132 - 141, The ResourceNotFoundError message should include all preference names that were attempted; update the logic around VirtualMachineClusterPreference (the S390X branch and the fallback) to collect attempted names (e.g., f"{preference_name}.{S390X}" when get_cluster_architecture() == S390X and preference_name) and, if neither exists, raise ResourceNotFoundError with a message listing both attempted names so callers can see which specific s390x and base preference lookups failed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/infrastructure/vhostmd/test_downwardmetrics_virtio.py`:
- Around line 132-141: The ResourceNotFoundError message should include all
preference names that were attempted; update the logic around
VirtualMachineClusterPreference (the S390X branch and the fallback) to collect
attempted names (e.g., f"{preference_name}.{S390X}" when
get_cluster_architecture() == S390X and preference_name) and, if neither exists,
raise ResourceNotFoundError with a message listing both attempted names so
callers can see which specific s390x and base preference lookups failed.
| @pytest.fixture() | ||
| def preferred_preference_for_rhel_version(rhel_version, unprivileged_client): | ||
| preference_name = re.sub(r"(\D+)(\d+)", r"\1.\2", rhel_version) | ||
| if get_cluster_architecture() == S390X: |
There was a problem hiding this comment.
please use get_cluster_architecture fixture
This change updates the preferred_preference_for_rhel_version fixture. When the cluster architecture is s390x, it checks for an architecture-specific VirtualMachineClusterPreference (for example, rhel.9.s390x). If the architecture preference does not exist (for example, rhel.8 on s390x), the logic falls back to the base preference (rhel.8).
Behavior for other architectures remains unchanged.
Short description:
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
New Features
Tests