Fix IOS vlan list causing a vlan deletion in remediation#265
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Cisco IOS remediation edge case where collapsed VLAN definitions (e.g. vlan 69,381 / vlan 10-12) could be treated as a single config object and incorrectly negated as no vlan x,y, causing destructive churn. It adds a Cisco IOS post-load callback to normalize these lines into one vlan <id> block per VLAN so diffs/remediations remain per-VLAN and surgical.
Changes:
- Added a Cisco IOS post-load callback to split collapsed comma/range VLAN ID lists into individual
vlan <id>blocks at load time. - Added unit tests covering list/range splitting and non-destructive remediation behaviors.
- Documented the new IOS normalization behavior and noted the fix in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_driver_cisco_ios.py | Adds regression and behavior tests for VLAN list/range splitting and non-destructive remediation outputs. |
| hier_config/platforms/cisco_ios/driver.py | Implements VLAN list expansion/splitting via a new post-load callback for IOS/IOS-XE. |
| docs/drivers.md | Documents IOS VLAN id list splitting behavior and rationale. |
| CHANGELOG.md | Notes the IOS collapsed VLAN remediation fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+55
| def _expand_vlan_id_list(spec: str) -> list[int]: | ||
| """Expand a VLAN id spec like ``69,381`` or ``10-12,20`` into a list of ints.""" | ||
| ids: list[int] = [] | ||
| for part in spec.split(","): | ||
| if "-" in part: | ||
| low, high = part.split("-") | ||
| ids.extend(range(int(low), int(high) + 1)) | ||
| else: | ||
| ids.append(int(part)) | ||
| return ids |
Comment on lines
+67
to
+73
| for vlan in tuple(config.get_children(re_search=r"^vlan \d[\d,\-]*$")): | ||
| spec = vlan.text.split(maxsplit=1)[1] | ||
| if not any(separator in spec for separator in (",", "-")): | ||
| continue | ||
| for vlan_id in _expand_vlan_id_list(spec): | ||
| config.add_child(f"vlan {vlan_id}") | ||
| vlan.delete() |
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #264.
Splits collapsed Cisco IOS VLAN lines (e.g.
vlan 69,381) into onevlan <id>block each at load time, so they diff per-VLAN instead of producing a destructiveno vlan 69,381. Used the existing ProCurvepost_load_callbackas an example on how to resolve this.Added tests for the existing broken case and new cases.