Skip to content

Fix IOS vlan list causing a vlan deletion in remediation#265

Merged
jtdub merged 1 commit into
netdevops:masterfrom
nopg:u/nopg/2064-ios-vlan-list
Jul 4, 2026
Merged

Fix IOS vlan list causing a vlan deletion in remediation#265
jtdub merged 1 commit into
netdevops:masterfrom
nopg:u/nopg/2064-ios-vlan-list

Conversation

@nopg

@nopg nopg commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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 destructive no vlan 69,381. Used the existing ProCurve post_load_callback as an example on how to resolve this.
Added tests for the existing broken case and new cases.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@jtdub jtdub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jtdub jtdub merged commit d881053 into netdevops:master Jul 4, 2026
5 checks passed
@jtdub jtdub mentioned this pull request Jul 4, 2026
jtdub added a commit that referenced this pull request Jul 4, 2026
Bump version to 3.6.1 and finalize CHANGELOG:
- Move Unreleased entries under [3.6.1] - 2026-07-04
- Fix duplicate "Fixed" heading; recategorize Renovate config as Changed
- Add PR references (#265, #266)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collapsed VLAN lines can produce a destructive "no vlan x,y" remediation in Cisco IOS

3 participants