diff options
author | Gaige B Paulsen <gaige@cluetrust.com> | 2025-01-26 15:00:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-27 06:00:56 +1000 |
commit | 0a0ab13f84e3930e203a412ae08c127b282ab675 (patch) | |
tree | b52db22cfa3fc0994c0d3a2ccf20e34b32203e55 /plugins/module_utils | |
parent | fda50fe09d21b365264c6213bc5883201c460a29 (diff) | |
download | vyos.vyos-0a0ab13f84e3930e203a412ae08c127b282ab675.tar.gz vyos.vyos-0a0ab13f84e3930e203a412ae08c127b282ab675.zip |
T7006: update to fix interface tests (#374)
* T7008: update to fix interface tests
* T7006: fix: tests for interfaces
* T7006: further work on interfaces
* test: attempt to fix codecov on branch
* test: unwind cli_config loops for 1.4
* fix: vif handling in replace,override,delete
* fix: vif handling and docs
Diffstat (limited to 'plugins/module_utils')
-rw-r--r-- | plugins/module_utils/network/vyos/config/interfaces/interfaces.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py index 62e4f922..a9d9307c 100644 --- a/plugins/module_utils/network/vyos/config/interfaces/interfaces.py +++ b/plugins/module_utils/network/vyos/config/interfaces/interfaces.py @@ -275,7 +275,9 @@ class Interfaces(ConfigBase): commands.append( self._compute_commands(key=key, interface=want_copy["name"], remove=True), ) - if have_copy["enabled"] is False and not ('enabled' in want_copy and want_copy["enabled"] is False): + if have_copy["enabled"] is False and not ( + "enabled" in want_copy and want_copy["enabled"] is False + ): commands.append( self._compute_commands(key="enabled", value=True, interface=want_copy["name"]), ) @@ -284,43 +286,48 @@ class Interfaces(ConfigBase): for have_vif in have_vifs: want_vif = search_obj_in_list(have_vif["vlan_id"], want_vifs, key="vlan_id") if not want_vif: - want_vif = { - "vlan_id": have_vif["vlan_id"], - "enabled": True, - } - - for key in dict_delete(have_vif, want_vif).keys(): - if key == "enabled": - continue commands.append( self._compute_commands( - key=key, + key="", interface=want_copy["name"], - vif=want_vif["vlan_id"], + vif=have_vif["vlan_id"], remove=True, ), ) - if have_vif["enabled"] is False: + continue + + for key in dict_delete(have_vif, want_vif).keys(): + if key == "enabled": + continue commands.append( self._compute_commands( - key="enabled", - value=True, + key=key, interface=want_copy["name"], vif=want_vif["vlan_id"], + remove=True, ), ) return commands def _compute_commands(self, interface, key, vif=None, value=None, remove=False): - intf_context = "interfaces {0} {1}".format(get_interface_type(interface), interface) + interface_type = get_interface_type(interface) + if not interface_type: + self._module.fail_json( + msg="interface {0} is not a valid interface type".format(interface), + ) + intf_context = "interfaces {0} {1}".format(interface_type, interface) set_cmd = "set {0}".format(intf_context) del_cmd = "delete {0}".format(intf_context) if vif: set_cmd = set_cmd + (" vif {0}".format(vif)) del_cmd = del_cmd + (" vif {0}".format(vif)) - - if key == "enabled": + if key == "" or key is None: + if not remove: + command = "{0}".format(set_cmd) + else: + command = "{0}".format(del_cmd) + elif key == "enabled": if not value: command = "{0} disable".format(set_cmd) else: |