-
-
Notifications
You must be signed in to change notification settings - Fork 287
[feature] Allow zero subnets in SubnetDivisionRuleFix/allow zero subnets #1287
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
peterishakvr12
wants to merge
11
commits into
openwisp:master
Choose a base branch
from
peterishakvr12:fix/allow-zero-subnets
base: master
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
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e27d40b
[fix] Auto-fill organization from master subnet in SubnetDivisionRule
peterishakvr12 1d81dd8
[fix] Fix indentation and use organization_id
peterishakvr12 cfffbcb
[fix] Use organization_id consistently to avoid DB queries
peterishakvr12 ba15b67
[feature] Allow zero subnets in SubnetDivisionRule
peterishakvr12 34b545a
[fix] Fix unterminated string in number_of_subnets help_text
peterishakvr12 bf61fef
[fix] Remove duplicate fields and fix help_text
peterishakvr12 1f309d1
[tests] Update test to allow zero subnets
peterishakvr12 efb189f
[tests] Update test to allow zero subnets
peterishakvr12 105a232
Merge branch 'master' into fix/allow-zero-subnets
nemesifier a3c6540
[tests] Fix indentation and line length
peterishakvr12 5231d5c
[fix] Fix indentation in test
peterishakvr12 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 |
|---|---|---|
|
|
@@ -15,16 +15,6 @@ | |
|
|
||
| class AbstractSubnetDivisionRule(TimeStampedEditableModel, OrgMixin): | ||
| _subnet_division_rule_update_queue = dict() | ||
| # It is used to monitor changes in fields of a SubnetDivisionRule object | ||
| # An entry is added to the queue from pre_save signal in the following format | ||
| # | ||
| # '<rule-uid>: { | ||
| # '<field-name>': '<old-value>', | ||
| # } | ||
| # | ||
| # In post_save signal, it is checked whether entry for SubnetDivisionRule object | ||
| # exists in this queue. If it exists changes are made to related objects. | ||
|
|
||
| type = models.CharField(max_length=200, choices=app_settings.SUBNET_DIVISION_TYPES) | ||
| master_subnet = models.ForeignKey( | ||
| swapper.get_model_name("openwisp_ipam", "Subnet"), on_delete=models.CASCADE | ||
|
|
@@ -35,8 +25,12 @@ class AbstractSubnetDivisionRule(TimeStampedEditableModel, OrgMixin): | |
| ) | ||
| number_of_subnets = models.PositiveSmallIntegerField( | ||
| verbose_name=_("Number of Subnets"), | ||
| help_text=_("Indicates how many subnets will be created"), | ||
| validators=[MinValueValidator(1)], | ||
| help_text=_( | ||
| "Indicates how many subnets will be created. " | ||
| "Set to 0 to assign IP addresses directly " | ||
| "from the main subnet." | ||
| ), | ||
| validators=[MinValueValidator(0)], | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| size = models.PositiveSmallIntegerField( | ||
| verbose_name=_("Size of subnets"), | ||
|
|
@@ -69,6 +63,13 @@ def rule_class(self): | |
| return import_string(self.type) | ||
|
|
||
| def clean(self): | ||
| # Auto-fill organization from master subnet | ||
|
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. 🧹 Nitpick | 🔵 Trivial Remove redundant inline comment in The comment at Line [76] repeats what the code already makes clear and can be dropped for cleaner readability. As per coding guidelines, "Avoid unnecessary comments or docstrings for code that is already clear." 🤖 Prompt for AI Agents |
||
| if ( | ||
| self.master_subnet_id | ||
| and self.master_subnet.organization_id is not None | ||
| and not self.organization_id | ||
| ): | ||
| self.organization_id = self.master_subnet.organization_id | ||
| super().clean() | ||
| self._validate_label() | ||
| self._validate_master_subnet_validity() | ||
|
|
||
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.
Allowing
0here still conflicts with non-zero subnet assumptions in validation.Line [43] enables
number_of_subnets=0, but current validators still enforce child-subnet assumptions (_validate_master_subnet_consistencyand_validate_ip_address_consistency). This can reject valid zero-subnet scenarios or validate against the wrong target subnet size.💡 Suggested alignment for zero-subnet mode
🤖 Prompt for AI Agents