-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix IndexError if no virt-launcher pod #2225
Conversation
WalkthroughThe changes in this pull request focus on enhancing error handling within the Changes
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
Report bugs in Issues The following are automatically added:
Available user actions:
Supported /retest check runs
Supported labels
|
884b20e
to
97bff1f
Compare
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
🧹 Outside diff range and nitpick comments (2)
ocp_resources/virtual_machine_instance.py (2)
78-80
: LGTM! Consider enhancing the error message.The error handling is correctly placed before any list indexing operations, preventing the IndexError. However, the error message could be more specific about the cause.
Consider this enhanced error message:
- raise ResourceNotFoundError(f"VIRT launcher POD not found for {self.kind}:{self.name}") + raise ResourceNotFoundError( + f"No virt-launcher pod found for {self.kind} '{self.name}'. " + f"The pod might not have been created yet or was terminated." + )
Line range hint
133-147
: Consider enhancing error logging in wait_until_running.The error handling flow is good, but the debug information could be more comprehensive.
Consider adding VMI status logging:
try: self.wait_for_status(status=self.Status.RUNNING, timeout=timeout, stop_status=stop_status) except TimeoutExpiredError as sampler_ex: if not logs: raise try: + self.logger.error(f"VMI status: {self.instance.status}") virt_pod = self.virt_launcher_pod self.logger.error(f"Status of virt-launcher pod {virt_pod.name}: {virt_pod.status}") self.logger.debug(f"{virt_pod.name} *****LOGS*****") self.logger.debug(virt_pod.log(container="compute")) except ResourceNotFoundError as virt_pod_ex: - self.logger.error(virt_pod_ex) + self.logger.error( + f"Failed to get virt-launcher pod logs: {virt_pod_ex}. " + f"This might indicate that the pod creation failed or was delayed." + ) raise sampler_ex
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
ocp_resources/virtual_machine_instance.py
(1 hunks)
🔇 Additional comments (1)
ocp_resources/virtual_machine_instance.py (1)
Line range hint 3-3
: Verify usage of virt_launcher_pod property.
Let's verify other methods that might need similar error handling when accessing the virt_launcher_pod property.
✅ Verification successful
Let me analyze the usage of virt_launcher_pod
to verify if similar error handling is needed in other methods.
The error handling for virt_launcher_pod
property is already properly implemented
The property virt_launcher_pod
already has appropriate error handling:
- Raises
ResourceNotFoundError
when no pods are found - Handles migration scenarios by correctly selecting the target pod
- All methods using this property (
execute_virsh_command
,get_uid
, etc.) will automatically inherit this error handling
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all usages of virt_launcher_pod property to verify error handling
# Search for methods accessing virt_launcher_pod
ast-grep --pattern 'self.virt_launcher_pod'
# Search for direct property access
rg '\bvirt_launcher_pod\b' -A 2 -B 2
Length of output: 3130
Script:
#!/bin/bash
# Let's examine the implementation of virt_launcher_pod property and its error handling
ast-grep --pattern $'@property\n def virt_launcher_pod(self):\n $$$'
# Also check the error handling in the methods that use it
ast-grep --pattern $'def execute_virsh_command(self, $_):\n $$$'
Length of output: 2396
/verified |
/cherry-pick v4.16 v4.17 |
Cherry-picked PR fix IndexError if no virt-launcher pod into v4.17 |
Cherry-picked PR fix IndexError if no virt-launcher pod into v4.16 |
Short description:
raise
ResourceNotFoundError
with meaningful message instead ofIndexError
More details:
Encountered issue when calling for
wait_until_running()
method...
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:
Summary by CodeRabbit