summaryrefslogtreecommitdiff
path: root/plugins/module_utils/network
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-08-21 12:26:57 +0300
committerGitHub <noreply@github.com>2026-08-21 12:26:57 +0300
commitfb4efdb9252b965be5c2ceaa0c969c179cf3f7cd (patch)
treee2d5443155d812f185f5f76dce2bea86e9432ad2 /plugins/module_utils/network
parentfcf2e1c1d851da4c71a2289889b55dd738cfa43f (diff)
downloadvyos.vyos-fb4efdb9252b965be5c2ceaa0c969c179cf3f7cd.tar.gz
vyos.vyos-fb4efdb9252b965be5c2ceaa0c969c179cf3f7cd.zip
T8516: add vyos_l3_interfaces unit tests; delete only L3 attributes in deleted/overridden (#458)
* T8516: add unit tests for vyos_l3_interfaces module * T8516: fix copyright header to use VyOS Networks attribution Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Changelog * Misc fixes * Misc changes * T8516: bugfixes * T8516: changelog - bugfixes added * T8516: Update changelog Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * T8516: Docstring fix Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * T8516: docstring fix Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * T8516: restore _state_deleted docstring, align test docstring and fixture - restore the _state_deleted docstring lost in the L2-safeguard change, now documenting the address-only delete semantics - overridden test docstring said "delete interface stanzas" but the module now emits address-only deletes; align wording - quote loopback interface name in fixture for consistency with vyos_interfaces_config.cfg * T8516: drop out-of-scope config and generated-docs changes Reviewer request (gaige): top-level instruction files (.coderabbit.yaml, AGENTS.md) belong in separate PRs. Also revert unrelated generated-docs drift in vyos_config / vyos_bgp_global rst files. All four files are now identical to main. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: omnom62 <75066712+omnom62@users.noreply.github.com> Co-authored-by: omnom62 <omnom62@outlook.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'plugins/module_utils/network')
-rw-r--r--plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
index a23494cd..f7b76af9 100644
--- a/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
+++ b/plugins/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py
@@ -256,6 +256,10 @@ class L3_interfaces(ConfigBase):
def _state_deleted(self, want, have):
"""The command generator when state is deleted
+ Deletes only the L3 address attributes (base interface and VIFs)
+ owned by this module, never the interface subtree, so L2 settings
+ are preserved.
+
:rtype: A list
:returns: the commands necessary to remove the current configuration
of the provided objects
@@ -266,14 +270,33 @@ class L3_interfaces(ConfigBase):
if have_copy is not None:
if all(v in (None, {}, []) for k, v in want_copy.items() if k != "name"):
- commands.append(
- self._compute_commands(
- key=None,
- value=None,
- interface=want_copy["name"],
- remove=True,
- ),
- )
+ # Only delete L3 attributes we own — do not touch L2 config
+ have_vifs = have_copy.pop("vifs", []) or []
+
+ for addr_family in ("ipv4", "ipv6"):
+ for addr in have_copy.get(addr_family) or []:
+ commands.append(
+ self._compute_commands(
+ key="address",
+ value=addr["address"],
+ interface=want_copy["name"],
+ remove=True,
+ ),
+ )
+
+ for have_vif in have_vifs:
+ for addr_family in ("ipv4", "ipv6"):
+ for addr in have_vif.get(addr_family) or []:
+ commands.append(
+ self._compute_commands(
+ key="address",
+ value=addr["address"],
+ interface=want_copy["name"],
+ vif=have_vif["vlan_id"],
+ remove=True,
+ ),
+ )
+
return commands
want_vifs = want_copy.pop("vifs", [])