-
Notifications
You must be signed in to change notification settings - Fork 54
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(robot): fix Test Longhorn dynamic provisioned RWX volume recovery #2168
Conversation
WalkthroughThe changes in this pull request involve updates to the Changes
Possibly related PRs
Suggested reviewers
Poem
Warning Rate limit exceeded@chriscchien has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 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
CodeRabbit Configuration File (
|
longhorn/longhorn-9822 Signed-off-by: Chris <[email protected]>
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: 5
🧹 Outside diff range and nitpick comments (2)
e2e/libs/keywords/sharemanager_keywords.py (2)
59-59
: Rename unused loop variablei
to_
The loop variable
i
is not used within the loop body. It's idiomatic in Python to rename unused variables to_
to indicate that they are intentionally unused.Apply this diff to rename the variable:
-for i in range(retry_count): +for _ in range(retry_count):🧰 Tools
🪛 Ruff (0.7.0)
59-59: Loop control variable
i
not used within loop bodyRename unused
i
to_i
(B007)
74-74
: Rename unused loop variablei
to_
The loop variable
i
is not used within the loop body. Renaming it to_
indicates that it is intentionally unused.Apply this diff to rename the variable:
-for i in range(retry_count): +for _ in range(retry_count):🧰 Tools
🪛 Ruff (0.7.0)
74-74: Loop control variable
i
not used within loop bodyRename unused
i
to_i
(B007)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
e2e/keywords/sharemanager.resource
(1 hunks)e2e/libs/keywords/sharemanager_keywords.py
(2 hunks)e2e/tests/negative/component_resilience.robot
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.7.0)
e2e/libs/keywords/sharemanager_keywords.py
59-59: Loop control variable i
not used within loop body
Rename unused i
to _i
(B007)
62-62: Comparison to None
should be cond is None
Replace with cond is None
(E711)
68-68: Do not assert False
(python -O
removes these calls), raise AssertionError()
Replace assert False
(B011)
74-74: Loop control variable i
not used within loop body
Rename unused i
to _i
(B007)
79-79: Do not assert False
(python -O
removes these calls), raise AssertionError()
Replace assert False
(B011)
🔇 Additional comments (4)
e2e/keywords/sharemanager.resource (2)
29-32
: LGTM! Complementary change for pod-based approach.
The keyword rename from "Wait for sharemanager" to "Wait for sharemanager pod" maintains consistency with the pod-based testing approach.
24-27
: LGTM! The keyword change aligns with PR objectives.
The rename from "Delete sharemanager" to "Delete sharemanager pod" makes the operation more explicit and matches the PR's goal of testing pod deletion instead of CRD deletion.
Let's verify the implementation of the new method:
✅ Verification successful
Implementation verified and aligns with test requirements
The implementation in e2e/libs/keywords/sharemanager_keywords.py
correctly handles the pod deletion and recreation:
- Deletes the sharemanager pod using
delete_pod
in the longhorn-system namespace - Tracks the pod recreation by comparing creation timestamps
- Uses proper retry mechanism with configurable count and interval
- Integrates with the test case "Test Longhorn dynamic provisioned RWX volume recovery" which verifies volume recovery after component deletion
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the implementation of delete_sharemanager_pod_and_wait_for_recreation
# Search for the implementation to ensure it handles pod deletion correctly
ast-grep --pattern 'def delete_sharemanager_pod_and_wait_for_recreation($$$)'
Length of output: 79
Script:
#!/bin/bash
# Let's try searching with ripgrep for the implementation
rg -A 10 "delete_sharemanager_pod_and_wait_for_recreation"
# Also search for any Python/Robot Framework files that might contain this implementation
fd -e py -e robot -e resource | xargs rg "delete_sharemanager_pod_and_wait_for_recreation"
Length of output: 2008
Script:
#!/bin/bash
# Let's verify the related functions used in the implementation
rg -A 5 "def (get_pod|delete_pod|get_retry_count_and_interval)"
# Also check if there are any tests using this functionality
rg "Test Longhorn dynamic provisioned RWX volume recovery" -A 10
Length of output: 6919
e2e/tests/negative/component_resilience.robot (1)
177-178
: LGTM! The change improves the testing approach.
The modification to delete the sharemanager pod instead of the CRD is a better approach because:
- It tests a more realistic failure scenario
- It's less disruptive as it only affects a single sharemanager instance
- It maintains the CRD definition while verifying the pod recovery mechanism
e2e/libs/keywords/sharemanager_keywords.py (1)
10-10
: Import statements approved
The import of get_pod
and delete_pod
is necessary for the new functionality and is correctly implemented.
if creation_time > last_creation_time: | ||
return | ||
|
||
assert False, f"sharemanager pod {sharemanager_pod_name} not recreated" |
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.
Replace assert False
with raising an exception
Using assert False
is not reliable because assertions can be disabled with optimization flags (e.g., python -O
). Instead, raise an AssertionError
or a more specific exception to ensure the error is always reported.
Apply this diff to raise an exception:
-assert False, f"sharemanager pod {sharemanager_pod_name} not recreated"
+raise AssertionError(f"sharemanager pod {sharemanager_pod_name} not recreated")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
assert False, f"sharemanager pod {sharemanager_pod_name} not recreated" | |
raise AssertionError(f"sharemanager pod {sharemanager_pod_name} not recreated") |
🧰 Tools
🪛 Ruff (0.7.0)
68-68: Do not assert False
(python -O
removes these calls), raise AssertionError()
Replace assert False
(B011)
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system") | ||
last_creation_time = sharemanager_pod.metadata.creation_timestamp |
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.
Handle possible None
return value from get_pod
get_pod
may return None
if the pod does not exist. Attempting to access sharemanager_pod.metadata.creation_timestamp
when sharemanager_pod
is None
will raise an AttributeError
. Ensure that sharemanager_pod
is not None
before accessing its attributes.
Apply this diff to add a check for None
:
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system")
+if sharemanager_pod is None:
+ raise Exception(f"Pod {sharemanager_pod_name} not found in namespace longhorn-system")
last_creation_time = sharemanager_pod.metadata.creation_timestamp
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system") | |
last_creation_time = sharemanager_pod.metadata.creation_timestamp | |
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system") | |
if sharemanager_pod is None: | |
raise Exception(f"Pod {sharemanager_pod_name} not found in namespace longhorn-system") | |
last_creation_time = sharemanager_pod.metadata.creation_timestamp |
for i in range(retry_count): | ||
time.sleep(retry_interval) | ||
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system") | ||
if sharemanager_pod == None: |
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.
🛠️ Refactor suggestion
Use is None
instead of == None
for None
comparison
In Python, the preferred way to compare to None
is to use is None
for correctness and readability.
Apply this diff to fix the comparison:
-if sharemanager_pod == None:
+if sharemanager_pod is None:
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if sharemanager_pod == None: | |
if sharemanager_pod is None: |
🧰 Tools
🪛 Ruff (0.7.0)
62-62: Comparison to None
should be cond is None
Replace with cond is None
(E711)
|
||
def wait_for_share_manager_running(self, name): | ||
return self.sharemanager.wait_for_running(name) | ||
assert False, f"sharemanager pod {sharemanager_pod_name} not running" |
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.
Replace assert False
with raising an exception
Using assert False
is not recommended as assertions can be skipped. Raise an AssertionError
or a more appropriate exception instead.
Apply this diff to raise an exception:
-assert False, f"sharemanager pod {sharemanager_pod_name} not running"
+raise AssertionError(f"sharemanager pod {sharemanager_pod_name} not running")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
assert False, f"sharemanager pod {sharemanager_pod_name} not running" | |
raise AssertionError(f"sharemanager pod {sharemanager_pod_name} not running") |
🧰 Tools
🪛 Ruff (0.7.0)
79-79: Do not assert False
(python -O
removes these calls), raise AssertionError()
Replace assert False
(B011)
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system") | ||
if sharemanager_pod.status.phase == "Running": |
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.
Handle possible None
return value from get_pod
If get_pod
returns None
, accessing sharemanager_pod.status.phase
will raise an AttributeError
. Check if sharemanager_pod
is not None
before accessing its attributes.
Apply this diff to handle None
values:
sharemanager_pod = get_pod(sharemanager_pod_name, "longhorn-system")
+if sharemanager_pod is None:
+ continue
if sharemanager_pod.status.phase == "Running":
return
Committable suggestion skipped: line range outside the PR's diff.
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.
LGTM
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.
LGTM
Which issue(s) this PR fixes:
longhorn/longhorn#9822
What this PR does / why we need it:
Update test case
Test Longhorn dynamic provisioned RWX volume recovery
to delete sharemanager pod instead of delete the sharemanager CRD during testing."Special notes for your reviewer:
Test report: https://ci.longhorn.io/job/private/job/longhorn-e2e-test/1971/
Additional documentation or context
N/A
Summary by CodeRabbit
New Features
Bug Fixes
Documentation