fix: use return value from download_virtctl_from_cluster()#388
Conversation
When virtctl already exists in PATH, download_virtctl_from_cluster() returns early without writing to shared_dir. The fixture ignored the return value and checked shared_dir/virtctl, which didn't exist. Use the function's return value directly, which handles all cases: PATH lookup, cached binary, fresh download.
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan Review Summary by QodoFix virtctl_binary fixture to use function return value
WalkthroughsDescription• Use return value from download_virtctl_from_cluster() instead of hardcoding path • Handles all virtctl lookup cases: PATH, cached binary, fresh download • Remove redundant existence checks and duplicate add_to_path() call • Fix false ValueError when virtctl exists in PATH Diagramflowchart LR
A["virtctl_binary fixture"] -->|calls| B["download_virtctl_from_cluster"]
B -->|returns| C["virtctl_path"]
C -->|used directly| D["fixture returns path"]
E["Removed: hardcoded path check"] -.->|eliminated| F["false ValueError"]
File Changes1. conftest.py
|
Code Review by Qodo
1. Wrong virtctl chosen
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
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. |
| with filelock.FileLock(lock_file, timeout=600): | ||
| if not virtctl_path.is_file() or not os.access(virtctl_path, os.X_OK): | ||
| download_virtctl_from_cluster(client=ocp_admin_client, download_dir=shared_dir) | ||
| # Validate binary was downloaded successfully | ||
| if not virtctl_path.is_file() or not os.access(virtctl_path, os.X_OK): | ||
| raise ValueError(f"Failed to download or make executable virtctl at {virtctl_path}") | ||
| virtctl_path = download_virtctl_from_cluster(client=ocp_admin_client, download_dir=shared_dir) |
There was a problem hiding this comment.
1. Wrong virtctl chosen 🐞 Bug ✓ Correctness
virtctl_binary now always calls download_virtctl_from_cluster(), which prefers any PATH-installed virtctl over the cluster-versioned shared_dir cache, defeating the fixture’s version-based cache invalidation and risking a virtctl/cluster incompatibility.
Agent Prompt
### Issue description
`virtctl_binary` is intended to use a cluster-versioned cache directory to ensure the virtctl binary matches the current cluster version. After this PR, `download_virtctl_from_cluster()` may return a PATH-installed virtctl before checking the versioned cache directory, which bypasses version-based cache invalidation and can use an incompatible virtctl.
### Issue Context
- `conftest.py` derives `shared_dir` from `get_cluster_version_str(...)` specifically for cache invalidation.
- `utilities/virtctl.py::_check_existing_virtctl()` checks `shutil.which('virtctl')` before checking `download_dir / 'virtctl'`.
### Fix Focus Areas
- Update cache selection order (or add an opt-in flag) so `virtctl_binary` prefers the versioned `download_dir` binary over an arbitrary PATH binary.
- Ensure PATH is still updated to include the chosen binary’s parent directory.
- conftest.py[505-516]
- utilities/virtctl.py[17-38]
- utilities/virtctl.py[211-246]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
virtctl_binaryfixture to use the return value fromdownload_virtctl_from_cluster()instead of hardcodingshared_dir / "virtctl"shared_dir, causing a falseValueErroradd_to_path()call (handled internally by the function)Test plan
Summary by CodeRabbit