-
Notifications
You must be signed in to change notification settings - Fork 383
fix(server): remove and add nat config back if applicable during resize server job #6675
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
Open
phot0n
wants to merge
1
commit into
frappe:develop
Choose a base branch
from
phot0n:nat-fx-resize
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||||||||||||||||||||||
| class ResizeServerJob(PressJob): | ||||||||||||||||||||||||||
| @flow | ||||||||||||||||||||||||||
| def execute(self): | ||||||||||||||||||||||||||
| self.remove_nat_config_if_applicable() | ||||||||||||||||||||||||||
| self.stop_virtual_machine() | ||||||||||||||||||||||||||
| self.wait_for_virtual_machine_to_stop() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -28,9 +29,21 @@ def execute(self): | |||||||||||||||||||||||||
| self.wait_for_virtual_machine_to_start() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| self.wait_for_server_to_be_accessible() | ||||||||||||||||||||||||||
| self.add_nat_config_if_applicable() | ||||||||||||||||||||||||||
| self.set_additional_config() | ||||||||||||||||||||||||||
| self.increase_disk_size() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||
| def remove_nat_config_if_applicable(self): | ||||||||||||||||||||||||||
| if self.server_type not in ("Server", "Database Server") or ( | ||||||||||||||||||||||||||
| not self.server_doc.nat_server and self.server_doc.ip | ||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| play = self.server_doc._remove_nat_iptables() | ||||||||||||||||||||||||||
| if not play or play.status != "Success": | ||||||||||||||||||||||||||
| raise Exception("Failed to remove NAT configuration") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||
| def stop_virtual_machine(self): | ||||||||||||||||||||||||||
| with suppress(Exception): | ||||||||||||||||||||||||||
|
|
@@ -95,6 +108,17 @@ def wait_for_server_to_be_accessible(self): | |||||||||||||||||||||||||
| if not play or play.status != "Success": | ||||||||||||||||||||||||||
| self.defer_current_task() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||
| def add_nat_config_if_applicable(self): | ||||||||||||||||||||||||||
| if self.server_type not in ("Server", "Database Server") or ( | ||||||||||||||||||||||||||
| not self.server_doc.nat_server and self.server_doc.ip | ||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||
|
Comment on lines
+111
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: press/press/doctype/press_job/jobs/resize_server.py
Line: 111-116
Comment:
Same edge-case guard applies to `add_nat_config_if_applicable`.
```suggestion
@task
def add_nat_config_if_applicable(self):
if self.server_type not in ("Server", "Database Server") or (
not self.server_doc.nat_server
):
return
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe i should only add this if it was removed in the previous block? |
||||||||||||||||||||||||||
| play = self.server_doc._install_nat_iptables() | ||||||||||||||||||||||||||
| if not play or play.status != "Success": | ||||||||||||||||||||||||||
| raise Exception("Failed to add NAT configuration") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||
| def set_additional_config(self): | ||||||||||||||||||||||||||
| if self.server_type not in ["Server", "Database Server"]: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The condition
not self.server_doc.nat_server and self.server_doc.ipskips NAT operations only when a server has no NAT server and has a direct IP. If both fields are falsy (e.g. a pending or mis-configured server), the AND evaluates toFalse, so the code proceeds to run the Ansible NAT playbook against a server with nonat_serverset — this will likely fail and block the resize. A simpler, safer check is to skip whenevernat_serveris not set.Prompt To Fix With AI