From 1a37697f2ec8046b9e646fbec9c250d4478188fe Mon Sep 17 00:00:00 2001 From: PadminiSivaraj Date: Fri, 25 Aug 2023 08:44:51 -0400 Subject: [PATCH 01/63] added vlan config features --- changelogs/fragments/fix_ios_vlans.yaml | 2 + docs/cisco.ios.ios_vlans_module.rst | 349 +++++++++++++++- .../network/ios/argspec/vlans/vlans.py | 8 + .../network/ios/config/vlans/vlans.py | 175 +++++--- .../network/ios/facts/vlans/vlans.py | 222 ++++++---- plugins/modules/ios_vlans.py | 384 +++++++++++++----- .../tests/cli/_parsed_vlan_config.cfg | 12 + .../cli/_populate_config_vlan_config.yaml | 15 + .../tests/cli/_remove_config_vlan_config.yaml | 14 + .../targets/ios_vlans/tests/cli/gathered.yaml | 18 + .../targets/ios_vlans/tests/cli/merged.yaml | 44 ++ .../ios_vlans/tests/cli/overridden.yaml | 46 +++ .../targets/ios_vlans/tests/cli/parsed.yaml | 14 + .../targets/ios_vlans/tests/cli/rendered.yaml | 25 ++ .../targets/ios_vlans/vars/main.yaml | 137 +++++++ .../modules/network/ios/test_ios_vlans.py | 223 +++++++++- 16 files changed, 1439 insertions(+), 249 deletions(-) create mode 100644 changelogs/fragments/fix_ios_vlans.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg create mode 100644 tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml diff --git a/changelogs/fragments/fix_ios_vlans.yaml b/changelogs/fragments/fix_ios_vlans.yaml new file mode 100644 index 000000000..0b3e759c6 --- /dev/null +++ b/changelogs/fragments/fix_ios_vlans.yaml @@ -0,0 +1,2 @@ +minor_changes: + - ios_vlans - added vlan config CLI feature \ No newline at end of file diff --git a/docs/cisco.ios.ios_vlans_module.rst b/docs/cisco.ios.ios_vlans_module.rst index 93b259513..6599431ae 100644 --- a/docs/cisco.ios.ios_vlans_module.rst +++ b/docs/cisco.ios.ios_vlans_module.rst @@ -139,7 +139,57 @@ Parameters
Private VLAN type
- + + + +
+ member + +
+ dictionary +
+ + + + +
Members of VLAN.
+ + + + + + +
+ vni + +
+ int +
+ + + + +
VXLAN VNI.
+ + + + + + +
+ evi + +
+ int +
+ + + + +
Ethernet Virtual Private Network (EVPN)
+ + + @@ -235,6 +285,21 @@ Parameters
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
+ + +
+ configuration + +
+ bool +
+ + + + +
When set to true, deals with vlan configuration CLIs
+ +
@@ -353,6 +418,46 @@ Examples # ------------------------------------------------------------------------------ # 10 + + + # Using merged (configuration: True) + + # Before state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + + + - name: Merge provided configuration with device configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: true + state: merged + + # After state: + # ------------ + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 901 + # member vni 50901 + # Using overridden # Before state: @@ -415,6 +520,45 @@ Examples # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 + +# Using overridden (configuration: True) + + # Before state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 901 + # member vni 50901 + + - name: Override device configuration of all VLANs with provided configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10102 + evi: 102 + - vlan_id: 102 + member: + vni: 10101 + evi: 101 + configuration: true + state: overridden + + # After state: + # ------------ + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 102 vni 10102 + # vlan configuration 102 + # member evpn-instance 101 vni 10101 + # Using replaced # Before state: @@ -575,6 +719,39 @@ Examples # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 + # Using deleted (configuration: True) + + # Before state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 901 + # member vni 50901 + + - name: Delete attributes of given VLANs + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + configuration: True + state: deleted + + # After state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 901 + # member vni 50901 + # Using Deleted without any config passed #"(NOTE: This will delete all of configured vlans attributes)" @@ -632,6 +809,40 @@ Examples # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 + # Using Deleted without any config passed (configuration: True) + #"(NOTE: This will delete all of configured vlans attributes)" + + # Before state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 202 + # member evpn-instance 202 vni 10202 + # vlan configuration 901 + # member vni 50901 + + - name: Delete attributes of ALL VLANs + cisco.ios.ios_vlans: + configuration: True + state: deleted + + # After state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # no vlan configuration 101 + # no vlan configuration 102 + # no vlan configuration 201 + # no vlan configuration 202 + # no vlan configuration 901 + # no vlan configuration 902 + # Using Gathered # Before state: @@ -761,6 +972,75 @@ Examples # ------------------------------------------------------------------------------ # 10 + # Using Gathered (configuration: True) + + # Before state: + # ------------- + # + # Leaf-01#show run nve | sec ^vlan configuration + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 201 + # member evpn-instance 201 vni 10201 + # vlan configuration 202 + # member evpn-instance 202 vni 10202 + # vlan configuration 901 + # member vni 50901 + + - name: Gather listed vlans with provided configurations + cisco.ios.ios_vlans: + config: + configuration: True + state: gathered + + # Module Execution Result: + # ------------------------ + # + # gathered = [ + # { + # "member": { + # "evi": 101, + # "vni": 10101 + # }, + # "vlan_id": 101 + # }, + # { + # "member": { + # "evi": 102, + # "vni": 10102 + # }, + # "vlan_id": 102 + # }, + # { + # "member": { + # "evi": 201, + # "vni": 10201 + # }, + # "vlan_id": 201 + # }, + # { + # "member": { + # "evi": 202, + # "vni": 10202 + # }, + # "vlan_id": 202 + # }, + # { + # "member": { + # "vni": 50901 + # }, + # "vlan_id": 901 + # }, + # { + # "member": { + # "vni": 50902 + # }, + # "vlan_id": 902 + # } + # ] + # Using Rendered - name: Render the commands for provided configuration @@ -802,6 +1082,31 @@ Examples # "shutdown" # ] + # Using Rendered (configuration: True) + + - name: Render the commands for provided configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + state: rendered + + # Module Execution Result: + # ------------------------ + # + # "rendered": [ + # "vlan configuration 101", + # "member evpn-instance 101 vni 10101", + # "vlan configuration 102", + # "member evpn-instance 102 vni 10102" + # ] + # Using Parsed # File: parsed.cfg @@ -896,7 +1201,49 @@ Examples # } # ] + # Using Parsed (configuration: True) + + # File: parsed.cfg + # ---------------- + # + # vlan configuration 101 + # member evpn-instance 101 vni 10101 + # vlan configuration 102 + # member evpn-instance 102 vni 10102 + # vlan configuration 901 + # member vni 50901 + - name: Parse the commands for provided configuration + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', './parsed.cfg') }}" + configuration: True + state: parsed + + # Module Execution Result: + # ------------------------ + # + # "parsed": [ + # { + # "member": { + # "evi": 101, + # "vni": 10101 + # }, + # "vlan_id": 101 + # }, + # { + # "member": { + # "evi": 102, + # "vni": 10102 + # }, + # "vlan_id": 102 + # }, + # { + # "member": { + # "vni": 50901 + # }, + # "vlan_id": 901 + # } + # ] Return Values ------------- diff --git a/plugins/module_utils/network/ios/argspec/vlans/vlans.py b/plugins/module_utils/network/ios/argspec/vlans/vlans.py index a3b0b6acd..9db593dcc 100644 --- a/plugins/module_utils/network/ios/argspec/vlans/vlans.py +++ b/plugins/module_utils/network/ios/argspec/vlans/vlans.py @@ -55,9 +55,17 @@ def __init__(self, **kwargs): "associated": {"type": "list", "elements": "int"}, }, }, + "member": { + "type": "dict", + "options": { + "vni": {"type": "int", "required": True}, + "evi": {"type": "int"}, + }, + }, }, "type": "list", }, + "configuration": {"type": "bool"}, "running_config": {"type": "str"}, "state": { "choices": [ diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 9d206f509..828151f38 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -44,6 +44,7 @@ def get_vlans_facts(self, data=None): :rtype: A dictionary :returns: The current configuration as a dictionary """ + facts, _warnings = Facts(self._module).get_facts( self.gather_subset, self.gather_network_resources, @@ -63,7 +64,12 @@ def execute_module(self): result = {"changed": False} commands = list() warnings = list() - + self.configuration = self._module.params["configuration"] + if not self.configuration: + self.have_now = list() + self.vlan_parent = "vlan {0}" + else: + self.vlan_parent = "vlan configuration {0}" if self.state in self.ACTION_STATES: existing_vlans_facts = self.get_vlans_facts() else: @@ -173,6 +179,7 @@ def _state_overridden(self, want, have): commands = [] want_local = want + self.have_now = have.copy() for each in have: count = 0 for every in want_local: @@ -260,12 +267,14 @@ def add_command_to_config_list(self, vlan_id, cmd, commands): commands.insert(0, vlan_id) if cmd not in commands: commands.append(cmd) - + def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] - vlan = "vlan {0}".format(want.get("vlan_id")) + config_cmds = [] + vlan = self.vlan_parent.format(want.get("vlan_id")) + def negate_have_config(want_diff, have_diff, vlan, commands): name = dict(have_diff).get("name") if name and not dict(want_diff).get("name"): @@ -303,69 +312,133 @@ def negate_have_config(want_diff, have_diff, vlan, commands): if have_diff and (self.state == "replaced" or self.state == "overridden"): negate_have_config(diff, have_diff, vlan, commands) - name = dict(diff).get("name") - state = dict(diff).get("state") - shutdown = dict(diff).get("shutdown") - mtu = dict(diff).get("mtu") - remote_span = dict(diff).get("remote_span") - private_vlan = dict(diff).get("private_vlan") - - if name: - self.add_command_to_config_list(vlan, "name {0}".format(name), commands) - if state: - self.add_command_to_config_list(vlan, "state {0}".format(state), commands) - if mtu: - self.add_command_to_config_list(vlan, "mtu {0}".format(mtu), commands) - if remote_span: - self.add_command_to_config_list(vlan, "remote-span", commands) - - if private_vlan: - private_vlan_type = dict(private_vlan).get("type") - private_vlan_associated = dict(private_vlan).get("associated") - if private_vlan_type: - self.add_command_to_config_list( - vlan, - "private-vlan {0}".format(private_vlan_type), - commands, + if not self.configuration: + name = dict(diff).get("name") + state = dict(diff).get("state") + shutdown = dict(diff).get("shutdown") + mtu = dict(diff).get("mtu") + remote_span = dict(diff).get("remote_span") + private_vlan = dict(diff).get("private_vlan") + + if name: + self.add_command_to_config_list(vlan, "name {0}".format(name), commands) + if state: + self.add_command_to_config_list(vlan, "state {0}".format(state), commands) + if mtu: + self.add_command_to_config_list(vlan, "mtu {0}".format(mtu), commands) + if remote_span: + self.add_command_to_config_list(vlan, "remote-span", commands) + + if private_vlan: + private_vlan_type = dict(private_vlan).get("type") + private_vlan_associated = dict(private_vlan).get("associated") + if private_vlan_type: + self.add_command_to_config_list( + vlan, + "private-vlan {0}".format(private_vlan_type), + commands, + ) + if private_vlan_associated: + associated_list = ",".join( + str(e) for e in private_vlan_associated + ) # Convert python list to string with elements separated by a comma + self.add_command_to_config_list( + vlan, + "private-vlan association {0}".format(associated_list), + commands, + ) + if shutdown == "enabled": + self.add_command_to_config_list(vlan, "shutdown", commands) + elif shutdown == "disabled": + self.add_command_to_config_list(vlan, "no shutdown", commands) + else: + member_dict = dict(diff).get("member") + if member_dict: + member_dict = dict(member_dict) + member_vni = member_dict.get("vni") + member_evi = member_dict.get("evi") + commands.extend( + self._remove_vlan_vni_evi_mapping( + want + ) ) - if private_vlan_associated: - associated_list = ",".join( - str(e) for e in private_vlan_associated - ) # Convert python list to string with elements separated by a comma - self.add_command_to_config_list( + commands.extend([ vlan, - "private-vlan association {0}".format(associated_list), - commands, - ) + self._get_member_cmds(member_dict), + ]) - if shutdown == "enabled": - self.add_command_to_config_list(vlan, "shutdown", commands) - elif shutdown == "disabled": - self.add_command_to_config_list(vlan, "no shutdown", commands) elif have_diff and (self.state == "replaced" or self.state == "overridden"): negate_have_config(diff, have_diff, vlan, commands) - return commands def _clear_config(self, want, have): # Delete the interface config based on the want and have config commands = [] - vlan = "vlan {0}".format(have.get("vlan_id")) + vlan = self.vlan_parent.format(have.get("vlan_id")) if ( have.get("vlan_id") - and "default" not in have.get("name") + and "default" not in have.get("name", "") and (have.get("vlan_id") != want.get("vlan_id") or self.state == "deleted") ): self.remove_command_from_config_list(vlan, "vlan", commands) - elif "default" not in have.get("name"): - if have.get("mtu") != want.get("mtu"): - self.remove_command_from_config_list(vlan, "mtu", commands) - if have.get("remote_span") != want.get("remote_span") and want.get("remote_span"): - self.remove_command_from_config_list(vlan, "remote-span", commands) - if have.get("shutdown") != want.get("shutdown") and want.get("shutdown"): - self.remove_command_from_config_list(vlan, "shutdown", commands) - if have.get("state") != want.get("state") and want.get("state"): - self.remove_command_from_config_list(vlan, "state", commands) + if self.configuration and self.state == "overridden": + self.have_now.remove(have) + if "default" not in have.get("name", ""): + if not self.configuration: + if have.get("mtu") != want.get("mtu"): + self.remove_command_from_config_list(vlan, "mtu", commands) + if have.get("remote_span") != want.get("remote_span") and want.get("remote_span"): + self.remove_command_from_config_list(vlan, "remote-span", commands) + if have.get("shutdown") != want.get("shutdown") and want.get("shutdown"): + self.remove_command_from_config_list(vlan, "shutdown", commands) + if have.get("state") != want.get("state") and want.get("state"): + self.remove_command_from_config_list(vlan, "state", commands) + return commands + def _remove_vlan_vni_evi_mapping(self, want_dict): + + commands = [] + have_copy = self.have_now.copy() + vlan = want_dict['vlan_id'] + for vlan_dict in have_copy: + if vlan_dict['vlan_id'] == vlan: + if 'member' in vlan_dict: + commands.extend([ + self.vlan_parent.format(vlan), + self._get_member_cmds( + vlan_dict.get('member', {}), + prefix = 'no' + ) + ]) + vlan_dict.pop('member') + if vlan_dict['vlan_id'] != vlan: + delete_member = False + if vlan_dict.get('member', {}).get('vni') == want_dict['member'].get('vni'): + delete_member = True + if vlan_dict.get('member', {}).get('evi') == want_dict['member'].get('evi'): + delete_member = True + if delete_member: + commands.extend([ + self.vlan_parent.format(vlan_dict['vlan_id']), + self._get_member_cmds( + vlan_dict.get('member', {}), + prefix = 'no' + ) + ]) + self.have_now.remove(vlan_dict) return commands + + def _get_member_cmds(self, member_dict, prefix=''): + cmd = '' + if prefix: + prefix = prefix + ' ' + member_vni = member_dict.get('vni') + member_evi = member_dict.get('evi') + + if member_evi: + cmd = prefix + "member evpn-instance {0} vni {1}".format(member_evi, member_vni) + elif member_vni: + cmd = prefix + "member vni {0}".format(member_vni) + + return cmd diff --git a/plugins/module_utils/network/ios/facts/vlans/vlans.py b/plugins/module_utils/network/ios/facts/vlans/vlans.py index 73f73a5a2..30b8c7e72 100644 --- a/plugins/module_utils/network/ios/facts/vlans/vlans.py +++ b/plugins/module_utils/network/ios/facts/vlans/vlans.py @@ -17,6 +17,7 @@ from copy import deepcopy +import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils @@ -42,14 +43,18 @@ def __init__(self, module, subspec="config", options="options"): self.generated_spec = utils.generate_dict(facts_argument_spec) - def get_vlans_data(self, connection): + def get_vlans_data(self, connection, configuration): """Checks device is L2/L3 and returns facts gracefully. Does not fail module. """ + if configuration: + cmd = "show running-config nve | sec ^vlan configuration" + else: + cmd = "show vlan" check_os_type = connection.get_device_info() if check_os_type.get("network_os_type") == "L3": return "" - return connection.get("show vlan") + return connection.get(cmd) def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for vlans @@ -59,14 +64,134 @@ def populate_facts(self, connection, ansible_facts, data=None): :rtype: dictionary :returns: facts """ + configuration = self._module.params["configuration"] + objs = [] + + if not data: + data = self.get_vlans_data(connection, configuration) + if not configuration: + objs = self.parse_vlan(data) + else: + objs = self.parse_vlan_config(data) + + facts = {} + if objs: + facts["vlans"] = [] + params = utils.validate_config(self.argument_spec, {"config": objs}) + + for cfg in params["config"]: + facts["vlans"].append(utils.remove_empties(cfg)) + ansible_facts["ansible_network_resources"].update(facts) + return ansible_facts + + def render_config(self, spec, conf, vlan_info): + """ + Render config as dictionary structure and delete keys + from spec for null values + + :param spec: The facts tree, generated from the argspec + :param conf: The configuration + :rtype: dictionary + :returns: The generated config + """ + config = deepcopy(spec) + + if vlan_info == "Name" and "VLAN Name" not in conf: + conf = list(filter(None, conf.split(" "))) + config["vlan_id"] = int(conf[0]) + config["name"] = conf[1] + state_idx = 2 + for i in range(2, len(conf)): # check for index where state starts + if conf[i] in ["suspended", "active"]: + state_idx = i + break + elif conf[i].split("/")[0] in ["sus", "act"]: + state_idx = i + break + config["name"] += " " + conf[i] + try: + if len(conf[state_idx].split("/")) > 1: + _state = conf[state_idx].split("/")[0] + if _state == "sus": + config["state"] = "suspend" + elif _state == "act": + config["state"] = "active" + config["shutdown"] = "enabled" + else: + if conf[state_idx] == "suspended": + config["state"] = "suspend" + elif conf[state_idx] == "active": + config["state"] = "active" + config["shutdown"] = "disabled" + except IndexError: + pass + elif vlan_info == "Type" and "VLAN Type" not in conf: + conf = list(filter(None, conf.split(" "))) + config["mtu"] = int(conf[3]) + elif vlan_info == "Remote": + if len(conf.split(",")) > 1 or conf.isdigit(): + remote_span_vlan = [] + if len(conf.split(",")) > 1: + remote_span_vlan = conf.split(",") + else: + remote_span_vlan.append(conf) + remote_span = [] + for each in remote_span_vlan: + split_sp_list = each.split("-") + if len(split_sp_list) > 1: # break range + for r_sp in range(int(split_sp_list[0]), int(split_sp_list[1]) + 1): + remote_span.append(r_sp) + else: + remote_span.append(int(each)) + config["remote_span"] = remote_span + + elif vlan_info == "Private" and "Primary Secondary" not in conf: + conf = list(filter(None, conf.split(" "))) + + pri_idx = 0 + sec_idx = 1 + priv_type_idx = 2 + + config["tmp_pvlans"] = { + "primary": conf[pri_idx], + "secondary": conf[sec_idx], + "sec_type": conf[priv_type_idx], + } + return utils.remove_empties(config) + + def parse_vlan_config(self, vlan_conf): + vlan_list = list() + + re1 = re.compile(r'^vlan configuration +(?P\d+)$') + re2 = re.compile(r'^member +(evpn\-instance +(?P\d+) )?vni (?P[\d\-]+)$') + + for line in vlan_conf.splitlines(): + line = line.strip() + m = re1.match(line) + if m: + vlan = m.groupdict()['vlan'] + vlan_dict = {'vlan_id':vlan} + continue + + m = re2.match(line) + if m: + group = m.groupdict() + vlan_dict.update({'member': {}}) + vlan_dict['member'].update({'vni': group['vni']}) + if group['evi']: + vlan_dict['member'].update({'evi': group['evi']}) + vlan_list.append(vlan_dict) + + return vlan_list + + def parse_vlan(self, data): objs = [] mtu_objs = [] remote_objs = [] final_objs = [] pvlan_objs = [] - if not data: - data = self.get_vlans_data(connection) + # operate on a collection of resource x config = data.split("\n") # Get individual vlan configs separately @@ -124,6 +249,7 @@ def populate_facts(self, connection, ansible_facts, data=None): pvlan_final = {} if len(pvlan_objs) > 0: # Sanitize and structure everything + for data in pvlan_objs: pvdata = data.get("tmp_pvlans") privlan = pvdata.get("primary") @@ -151,89 +277,7 @@ def populate_facts(self, connection, ansible_facts, data=None): if vlan_id == every.get("vlan_id"): every.update(data) - facts = {} if final_objs: - facts["vlans"] = [] - params = utils.validate_config(self.argument_spec, {"config": objs}) - - for cfg in params["config"]: - facts["vlans"].append(utils.remove_empties(cfg)) - ansible_facts["ansible_network_resources"].update(facts) - - return ansible_facts - - def render_config(self, spec, conf, vlan_info): - """ - Render config as dictionary structure and delete keys - from spec for null values - - :param spec: The facts tree, generated from the argspec - :param conf: The configuration - :rtype: dictionary - :returns: The generated config - """ - config = deepcopy(spec) - - if vlan_info == "Name" and "VLAN Name" not in conf: - conf = list(filter(None, conf.split(" "))) - config["vlan_id"] = int(conf[0]) - config["name"] = conf[1] - state_idx = 2 - for i in range(2, len(conf)): # check for index where state starts - if conf[i] in ["suspended", "active"]: - state_idx = i - break - elif conf[i].split("/")[0] in ["sus", "act"]: - state_idx = i - break - config["name"] += " " + conf[i] - try: - if len(conf[state_idx].split("/")) > 1: - _state = conf[state_idx].split("/")[0] - if _state == "sus": - config["state"] = "suspend" - elif _state == "act": - config["state"] = "active" - config["shutdown"] = "enabled" - else: - if conf[state_idx] == "suspended": - config["state"] = "suspend" - elif conf[state_idx] == "active": - config["state"] = "active" - config["shutdown"] = "disabled" - except IndexError: - pass - elif vlan_info == "Type" and "VLAN Type" not in conf: - conf = list(filter(None, conf.split(" "))) - config["mtu"] = int(conf[3]) - elif vlan_info == "Remote": - if len(conf.split(",")) > 1 or conf.isdigit(): - remote_span_vlan = [] - if len(conf.split(",")) > 1: - remote_span_vlan = conf.split(",") - else: - remote_span_vlan.append(conf) - remote_span = [] - for each in remote_span_vlan: - split_sp_list = each.split("-") - if len(split_sp_list) > 1: # break range - for r_sp in range(int(split_sp_list[0]), int(split_sp_list[1]) + 1): - remote_span.append(r_sp) - else: - remote_span.append(int(each)) - config["remote_span"] = remote_span - - elif vlan_info == "Private" and "Primary Secondary" not in conf: - conf = list(filter(None, conf.split(" "))) - - pri_idx = 0 - sec_idx = 1 - priv_type_idx = 2 - - config["tmp_pvlans"] = { - "primary": conf[pri_idx], - "secondary": conf[sec_idx], - "sec_type": conf[priv_type_idx], - } - - return utils.remove_empties(config) + return objs + else: + return {} diff --git a/plugins/modules/ios_vlans.py b/plugins/modules/ios_vlans.py index 2877e4318..2884514c4 100644 --- a/plugins/modules/ios_vlans.py +++ b/plugins/modules/ios_vlans.py @@ -95,6 +95,19 @@ - "List of private VLANs associated with the primary . Only works with `type: primary`." type: list elements: int + member: + description: + - Members of VLAN + type: dict + suboptions: + vni: + description: + - VxLan vni + type: int + evi: + description: + - Ethernet Virtual Private Network (EVPN) + type: int running_config: description: - This option is used only with state I(parsed). @@ -104,6 +117,10 @@ transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str + configuration: + description: + When set to true, deals with vlan configuration CLIs + type: bool state: description: - The state the configuration should be left in @@ -206,6 +223,44 @@ # ------------------------------------------------------------------------------ # 10 +# Using merged (configuration: True) + +# Before state: +# ------------- +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 + + +- name: Merge provided configuration with device configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: true + state: merged + +# After state: +# ------------ +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 901 +# member vni 50901 + # Using overridden # Before state: @@ -268,6 +323,45 @@ # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 + +# Using overridden (configuration: True) + +# Before state: +# ------------- +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 901 +# member vni 50901 + +- name: Override device configuration of all VLANs with provided configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10102 + evi: 102 + - vlan_id: 102 + member: + vni: 10101 + evi: 101 + configuration: true + state: overridden + +# After state: +# ------------ +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 102 vni 10102 +# vlan configuration 102 +# member evpn-instance 101 vni 10101 + # Using replaced # Before state: @@ -428,6 +522,39 @@ # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 +# Using deleted (configuration: True) + +# Before state: +# ------------- +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 901 +# member vni 50901 + +- name: Delete attributes of given VLANs + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + configuration: True + state: deleted + +# After state: +# ------------- +# +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 901 +# member vni 50901 + # Using Deleted without any config passed #"(NOTE: This will delete all of configured vlans attributes)" @@ -485,134 +612,108 @@ # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 -# Using Gathered +# Using Deleted without any config passed (configuration: True) +#"(NOTE: This will delete all of configured vlans attributes)" # Before state: # ------------- # -# vios_l2#show vlan -# VLAN Name Status Ports -# ---- -------------------------------- --------- ------------------------------- -# 1 default active Gi0/1, Gi0/2 -# 10 vlan_10 active -# 20 vlan_20 act/lshut -# 30 vlan_30 sus/lshut -# 1002 fddi-default act/unsup -# 1003 token-ring-default act/unsup -# 1004 fddinet-default act/unsup -# 1005 trnet-default act/unsup +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 202 +# member evpn-instance 202 vni 10202 +# vlan configuration 901 +# member vni 50901 + +- name: Delete attributes of ALL VLANs + cisco.ios.ios_vlans: + configuration: True + state: deleted + +# After state: +# ------------- # -# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 -# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ -# 1 enet 100001 1500 - - - - - 0 0 -# 10 enet 100010 1500 - - - - - 0 0 -# 20 enet 100020 610 - - - - - 0 0 -# 30 enet 100030 1500 - - - - - 0 0 -# 1002 fddi 101002 1500 - - - - - 0 0 -# 1003 tr 101003 1500 - - - - - 0 0 -# 1004 fdnet 101004 1500 - - - ieee - 0 0 -# 1005 trnet 101005 1500 - - - ibm - 0 0 +# Leaf-01#show run nve | sec ^vlan configuration +# no vlan configuration 101 +# no vlan configuration 102 +# no vlan configuration 201 +# no vlan configuration 202 +# no vlan configuration 901 +# no vlan configuration 902 + +# Using Gathered (configuration: True) + +# Before state: +# ------------- # -# Remote SPAN VLANs -# ------------------------------------------------------------------------------ -# 10 +# Leaf-01#show run nve | sec ^vlan configuration +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 201 +# member evpn-instance 201 vni 10201 +# vlan configuration 202 +# member evpn-instance 202 vni 10202 +# vlan configuration 901 +# member vni 50901 - name: Gather listed vlans with provided configurations cisco.ios.ios_vlans: config: + configuration: True state: gathered # Module Execution Result: # ------------------------ # -# "gathered": [ -# { -# "mtu": 1500, -# "name": "default", -# "shutdown": "disabled", -# "state": "active", -# "vlan_id": 1 -# }, -# { -# "mtu": 1500, -# "name": "VLAN0010", -# "shutdown": "disabled", -# "state": "active", -# "vlan_id": 10 +# gathered = [ +# { +# "member": { +# "evi": 101, +# "vni": 10101 # }, -# { -# "mtu": 1500, -# "name": "VLAN0020", -# "shutdown": "disabled", -# "state": "active", -# "vlan_id": 20 +# "vlan_id": 101 +# }, +# { +# "member": { +# "evi": 102, +# "vni": 10102 # }, -# { -# "mtu": 1500, -# "name": "VLAN0030", -# "shutdown": "disabled", -# "state": "active", -# "vlan_id": 30 +# "vlan_id": 102 +# }, +# { +# "member": { +# "evi": 201, +# "vni": 10201 # }, -# { -# "mtu": 1500, -# "name": "fddi-default", -# "shutdown": "enabled", -# "state": "active", -# "vlan_id": 1002 +# "vlan_id": 201 +# }, +# { +# "member": { +# "evi": 202, +# "vni": 10202 # }, -# { -# "mtu": 1500, -# "name": "token-ring-default", -# "shutdown": "enabled", -# "state": "active", -# "vlan_id": 1003 +# "vlan_id": 202 +# }, +# { +# "member": { +# "vni": 50901 # }, -# { -# "mtu": 1500, -# "name": "fddinet-default", -# "shutdown": "enabled", -# "state": "active", -# "vlan_id": 1004 +# "vlan_id": 901 +# }, +# { +# "member": { +# "vni": 50902 # }, -# { -# "mtu": 1500, -# "name": "trnet-default", -# "shutdown": "enabled", -# "state": "active", -# "vlan_id": 1005 -# } -# ] - -# After state: -# ------------ -# -# vios_l2#show vlan -# VLAN Name Status Ports -# ---- -------------------------------- --------- ------------------------------- -# 1 default active Gi0/1, Gi0/2 -# 10 vlan_10 active -# 20 vlan_20 act/lshut -# 30 vlan_30 sus/lshut -# 1002 fddi-default act/unsup -# 1003 token-ring-default act/unsup -# 1004 fddinet-default act/unsup -# 1005 trnet-default act/unsup -# -# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 -# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ -# 1 enet 100001 1500 - - - - - 0 0 -# 10 enet 100010 1500 - - - - - 0 0 -# 20 enet 100020 610 - - - - - 0 0 -# 30 enet 100030 1500 - - - - - 0 0 -# 1002 fddi 101002 1500 - - - - - 0 0 -# 1003 tr 101003 1500 - - - - - 0 0 -# 1004 fdnet 101004 1500 - - - ieee - 0 0 -# 1005 trnet 101005 1500 - - - ibm - 0 0 -# -# Remote SPAN VLANs -# ------------------------------------------------------------------------------ -# 10 +# "vlan_id": 902 +# } +# ] # Using Rendered @@ -655,6 +756,31 @@ # "shutdown" # ] +# Using Rendered (configuration: True) + +- name: Render the commands for provided configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + state: rendered + +# Module Execution Result: +# ------------------------ +# +# "rendered": [ +# "vlan configuration 101", +# "member evpn-instance 101 vni 10101", +# "vlan configuration 102", +# "member evpn-instance 102 vni 10102" +# ] + # Using Parsed # File: parsed.cfg @@ -748,6 +874,50 @@ # "vlan_id": 1005 # } # ] + +# Using Parsed (configuration: True) + +# File: parsed.cfg +# ---------------- +# +# vlan configuration 101 +# member evpn-instance 101 vni 10101 +# vlan configuration 102 +# member evpn-instance 102 vni 10102 +# vlan configuration 901 +# member vni 50901 + +- name: Parse the commands for provided configuration + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', './parsed.cfg') }}" + configuration: True + state: parsed + +# Module Execution Result: +# ------------------------ +# +# "parsed": [ +# { +# "member": { +# "evi": 101, +# "vni": 10101 +# }, +# "vlan_id": 101 +# }, +# { +# "member": { +# "evi": 102, +# "vni": 10102 +# }, +# "vlan_id": 102 +# }, +# { +# "member": { +# "vni": 50901 +# }, +# "vlan_id": 901 +# } +# ] """ RETURN = """ diff --git a/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg b/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg new file mode 100644 index 000000000..0c81de124 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg @@ -0,0 +1,12 @@ +vlan configuration 101 + member evpn-instance 101 vni 10101 +vlan configuration 102 + member evpn-instance 102 vni 10102 +vlan configuration 201 + member evpn-instance 201 vni 10201 +vlan configuration 202 + member evpn-instance 202 vni 10202 +vlan configuration 901 + member vni 50901 +vlan configuration 902 + member vni 50902 diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml new file mode 100644 index 000000000..d66b7eeea --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -0,0 +1,15 @@ +--- +- name: Setup + vars: + lines: + " + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 901 + member vni 50901 + " + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: "{{ lines }}" diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml new file mode 100644 index 000000000..ddf93d91c --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -0,0 +1,14 @@ +--- +- name: Remove configuration + vars: + lines: " + no vlan configuration 101 + no vlan configuration 102 + no vlan configuration 901 + no vlan configuration 201 + no vlan configuration 202 + no vlan configuration 902 + " + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: "{{ lines }}" diff --git a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml index 3c52d178a..ddc6a44a6 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml @@ -21,3 +21,21 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.ios.ios_vlans: + config: + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - gathered_vlan_config['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index 184a0317e..74be50327 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -60,3 +60,47 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 201 + member: + vni: 10201 + evi: 201 + - vlan_id: 902 + member: + vni: 50902 + configuration: True + state: merged + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - "{{ merged_vlan_config['before'] | symmetric_difference(result['before']) | length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - "{{ merged_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index 4e5468f95..9fc5c3177 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -46,3 +46,49 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml + + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Override device configuration of all vlans with provided configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 101 + member: + vni: 10102 + evi: 102 + - vlan_id: 102 + member: + vni: 10101 + evi: 101 + configuration: True + state: overridden + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - "{{ overridden_vlan_config['before'] | symmetric_difference(result['before']) | length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - "{{ overridden_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml index 042fef68b..78e700190 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml @@ -15,3 +15,17 @@ - result.changed == false - parsed['config']|symmetric_difference(result.parsed) == [] when: ansible_net_version != "15.6(2)T" + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', '_parsed_vlan_config.cfg') }}" + configuration: True + state: parsed + + - ansible.builtin.assert: + that: + - result.changed == false + - parsed_vlan_config['config']|symmetric_difference(result.parsed) == [] diff --git a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml index 38b0304c8..25afe1305 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml @@ -29,3 +29,28 @@ - result.changed == false - result.rendered|symmetric_difference(rendered.commands) == [] when: ansible_net_version != "15.6(2)T" + +- block: + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: True + state: rendered + + - ansible.builtin.assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered_vlan_config.commands) == [] diff --git a/tests/integration/targets/ios_vlans/vars/main.yaml b/tests/integration/targets/ios_vlans/vars/main.yaml index 72400621d..01f4a3a68 100644 --- a/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/tests/integration/targets/ios_vlans/vars/main.yaml @@ -93,6 +93,43 @@ merged: shutdown: enabled state: active vlan_id: 1005 +merged_vlan_config: + before: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - vlan configuration 201 + - member evpn-instance 201 vni 10201 + - vlan configuration 902 + - member vni 50902 + after: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 replaced: before: - mtu: 1500 @@ -278,6 +315,39 @@ overridden: shutdown: enabled state: active vlan_id: 1005 +overridden_vlan_config: + before: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - vlan configuration 101 + - no member evpn-instance 101 vni 10101 + - vlan configuration 102 + - no member evpn-instance 102 vni 10102 + - vlan configuration 101 + - member evpn-instance 102 vni 10102 + - vlan configuration 102 + - member evpn-instance 101 vni 10101 + - no vlan configuration 901 + + after: + - vlan_id: 101 + member: + evi: 102 + vni: 10102 + - vlan_id: 102 + member: + evi: 101 + vni: 10101 deleted: before: - mtu: 1500 @@ -350,6 +420,26 @@ deleted: shutdown: enabled state: active vlan_id: 1005 +deleted_vlan_config: + before: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - no vlan configuration 101 + - no vlan configuration 102 + - no vlan configuration 901 + + after: [] + gathered: config: - mtu: 1500 @@ -392,6 +482,20 @@ gathered: shutdown: enabled state: active vlan_id: 1005 + +gathered_vlan_config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + parsed: config: - mtu: 1500 @@ -435,6 +539,30 @@ parsed: state: active vlan_id: 1005 +parsed_vlan_config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 202 + member: + evi: 202 + vni: 10202 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 + rendered: commands: - vlan 10 @@ -452,6 +580,15 @@ rendered: - state suspend - shutdown +rendered_vlan_config: + commands: + - vlan configuration 101 + - member evpn-instance 101 vni 10101 + - vlan configuration 102 + - member evpn-instance 102 vni 10102 + - vlan configuration 901 + - member vni 50901 + rtt: commands: - vlan 10 diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 8f06c7771..95bdceea2 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -96,6 +96,26 @@ def test_ios_vlans_merged(self): commands = ["vlan 200", "name test_vlan_200", "state active", "remote-span", "no shutdown"] self.assertEqual(result["commands"], commands) + def test_ios_vlans_config_merged(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ) + ), + ], + state="merged", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = ["vlan configuration 101", "member evpn-instance 101 vni 10101"] + self.assertEqual(result["commands"], commands) + def test_ios_vlans_merged_idempotent(self): set_module_args( dict( @@ -157,6 +177,24 @@ def test_ios_vlans_merged_idempotent(self): ) self.execute_module(changed=False, commands=[], sort=True) + def test_ios_vlans_config_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ) + ), + ], + state="merged", + configuration=True, + ), + ) + self.execute_module(changed=False, commands=[], sort=True) + def test_ios_vlans_replaced(self): set_module_args( dict( @@ -311,6 +349,47 @@ def test_ios_vlans_overridden(self): self.assertEqual(result["commands"], commands) + def test_ios_vlans_config_overridden(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=102, + vni=10102, + ) + ), + dict( + vlan_id=102, + member=dict( + evi=101, + vni=10101, + ) + ), + ], + state="merged", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = [ + "vlan configuration 101", + "no member evpn-instance 101 vni 10101", + "vlan configuration 102", + "no member evpn-instance 102 vni 10102", + "vlan configuration 101", + "member evpn-instance 102 vni 10102", + "vlan configuration 102", + "member evpn-instance 101 vni 10101", + "no vlan configuration 201", + "no vlan configuration 202", + "no vlan configuration 901", + "no vlan configuration 902" + ] + + self.assertEqual(result["commands"], commands) + def test_ios_vlans_overridden_idempotent(self): set_module_args( dict( @@ -372,12 +451,43 @@ def test_ios_vlans_overridden_idempotent(self): ) self.execute_module(changed=False, commands=[], sort=True) - def test_ios_delete_vlans_config(self): + def test_ios_vlans_config_overridden(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=102, + vni=10102, + ) + ), + dict( + vlan_id=102, + member=dict( + evi=101, + vni=10101, + ) + ), + ], + state="merged", + configuration=True, + ), + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_delete_vlans(self): set_module_args(dict(config=[dict(vlan_id=150)], state="deleted")) result = self.execute_module(changed=True) commands = ["no vlan 150"] self.assertEqual(result["commands"], commands) + def test_ios_delete_vlans_config(self): + set_module_args(dict(config=[dict(vlan_id=101)], configuration=True, state="deleted")) + result = self.execute_module(changed=True) + commands = ["no vlan configuration 101"] + self.assertEqual(result["commands"], commands) + def test_vlans_rendered(self): set_module_args( dict( @@ -397,6 +507,24 @@ def test_vlans_rendered(self): result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), commands) + def test_vlans_config_rendered(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + ), + ], + state="rendered", + ), + ) + commands = [ + "vlan configuration 101", + "member evpn-instance 101 vni 10101" + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) + def test_vlan_parsed(self): set_module_args( dict( @@ -583,6 +711,50 @@ def test_vlan_parsed(self): self.maxDiff = None self.assertEqual(result["parsed"], parsed) + def test_vlan_config_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 901 + member vni 50901 + """, + ), + state="parsed", + configuration=True, + ), + ) + parsed = [ + { + "member": { + "evi": 101, + "vni": 10101 + }, + "vlan_id": 101 + }, + { + "member": { + "evi": 102, + "vni": 10102 + }, + "vlan_id": 102 + }, + { + "member": { + "vni": 50901 + }, + "vlan_id": 901 + } + ] + + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(result["parsed"], parsed) + def test_ios_vlans_gathered(self): set_module_args(dict(state="gathered")) gathered = [ @@ -648,3 +820,52 @@ def test_ios_vlans_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) + + def test_ios_vlans_config_gathered(self): + set_module_args(dict(configuration=True, state="gathered")) + gathered = [ + { + "member": { + "evi": 101, + "vni": 10101 + }, + "vlan_id": 101 + }, + { + "member": { + "evi": 102, + "vni": 10102 + }, + "vlan_id": 102 + }, + { + "member": { + "evi": 201, + "vni": 10201 + }, + "vlan_id": 201 + }, + { + "member": { + "evi": 202, + "vni": 10202 + }, + "vlan_id": 202 + }, + { + "member": { + "vni": 50901 + }, + "vlan_id": 901 + }, + { + "member": { + "vni": 50902 + }, + "vlan_id": 902 + } + ] + result = self.execute_module(changed=False) + + self.maxDiff = None + self.assertEqual(result["gathered"], gathered) From 90a8302b6f0a76dfbab51a80623c893cdad6b619 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:20:06 +0530 Subject: [PATCH 02/63] Update fix_ios_vlans.yaml --- changelogs/fragments/fix_ios_vlans.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/fix_ios_vlans.yaml b/changelogs/fragments/fix_ios_vlans.yaml index 0b3e759c6..8b78cf4ed 100644 --- a/changelogs/fragments/fix_ios_vlans.yaml +++ b/changelogs/fragments/fix_ios_vlans.yaml @@ -1,2 +1,3 @@ minor_changes: - - ios_vlans - added vlan config CLI feature \ No newline at end of file + - ios_vlans - added vlan config CLI feature + From 282c124e668997e26a8ef167fb2710929a280a08 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:50:52 +0000 Subject: [PATCH 03/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- changelogs/fragments/fix_ios_vlans.yaml | 1 - docs/cisco.ios.ios_vlans_module.rst | 260 +++++------------- .../network/ios/config/vlans/vlans.py | 77 +++--- .../network/ios/facts/vlans/vlans.py | 19 +- plugins/modules/ios_vlans.py | 16 +- .../targets/ios_vlans/tests/cli/merged.yaml | 14 +- .../ios_vlans/tests/cli/overridden.yaml | 1 - .../targets/ios_vlans/vars/main.yaml | 66 ++--- .../modules/network/ios/test_ios_vlans.py | 58 ++-- 9 files changed, 196 insertions(+), 316 deletions(-) diff --git a/changelogs/fragments/fix_ios_vlans.yaml b/changelogs/fragments/fix_ios_vlans.yaml index 8b78cf4ed..439fc9d0a 100644 --- a/changelogs/fragments/fix_ios_vlans.yaml +++ b/changelogs/fragments/fix_ios_vlans.yaml @@ -1,3 +1,2 @@ minor_changes: - ios_vlans - added vlan config CLI feature - diff --git a/docs/cisco.ios.ios_vlans_module.rst b/docs/cisco.ios.ios_vlans_module.rst index 6599431ae..948d61a6e 100644 --- a/docs/cisco.ios.ios_vlans_module.rst +++ b/docs/cisco.ios.ios_vlans_module.rst @@ -53,97 +53,92 @@ Parameters
- mtu + member
- integer + dictionary
-
VLAN Maximum Transmission Unit.
-
Refer to vendor documentation for valid values.
+
Members of VLAN
- + - + +
- name + evi
- string + integer
-
Ascii name of the VLAN.
-
NOTE, name should not be named/appended with default as it is reserved for device default vlans.
+
Ethernet Virtual Private Network (EVPN)
- + +
- private_vlan + vni
- dictionary + integer
-
Options for private vlan configuration.
+
VxLan vni
- - + + - +
- associated + mtu
- list - / elements=integer + integer
-
List of private VLANs associated with the primary . Only works with `type: primary`.
+
VLAN Maximum Transmission Unit.
+
Refer to vendor documentation for valid values.
- - +
- type + name
string
-
    Choices: -
  • primary
  • -
  • isolated
  • -
  • community
  • -
-
Private VLAN type
+
Ascii name of the VLAN.
+
NOTE, name should not be named/appended with default as it is reserved for device default vlans.
- +
- member + private_vlan
dictionary @@ -152,7 +147,7 @@ Parameters -
Members of VLAN.
+
Options for private vlan configuration.
@@ -160,16 +155,17 @@ Parameters
- vni + associated
- int + list + / elements=integer
-
VXLAN VNI.
+
List of private VLANs associated with the primary . Only works with `type: primary`.
@@ -177,19 +173,24 @@ Parameters
- evi + type
- int + string
+
    Choices: +
  • primary
  • +
  • isolated
  • +
  • community
  • +
-
Ethernet Virtual Private Network (EVPN)
+
Private VLAN type
- + @@ -271,33 +272,37 @@ Parameters
- running_config + configuration
- string + boolean
+
    Choices: +
  • no
  • +
  • yes
  • +
-
This option is used only with state parsed.
-
The value of this option should be the output received from the IOS device by executing the command show vlan.
-
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
+
When set to true, deals with vlan configuration CLIs
- configuration + running_config
- bool + string
-
When set to true, deals with vlan configuration CLIs
+
This option is used only with state parsed.
+
The value of this option should be the output received from the IOS device by executing the command show vlan.
+
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
@@ -418,10 +423,8 @@ Examples # ------------------------------------------------------------------------------ # 10 - - # Using merged (configuration: True) - + # Before state: # ------------- # @@ -430,21 +433,21 @@ Examples # member evpn-instance 101 vni 10101 # vlan configuration 201 # member evpn-instance 201 vni 10201 - - + + - name: Merge provided configuration with device configuration cisco.ios.ios_vlans: config: - vlan_id: 102 - member: + member: vni: 10102 evi: 102 - vlan_id: 901 - member: + member: vni: 50901 configuration: true state: merged - + # After state: # ------------ # @@ -520,8 +523,8 @@ Examples # 1004 fdnet 101004 1500 - - - ieee - 0 0 # 1005 trnet 101005 1500 - - - ibm - 0 0 - -# Using overridden (configuration: True) + + # Using overridden (configuration: True) # Before state: # ------------- @@ -540,11 +543,11 @@ Examples cisco.ios.ios_vlans: config: - vlan_id: 101 - member: + member: vni: 10102 evi: 102 - vlan_id: 102 - member: + member: vni: 10101 evi: 101 configuration: true @@ -720,7 +723,7 @@ Examples # 1005 trnet 101005 1500 - - - ibm - 0 0 # Using deleted (configuration: True) - + # Before state: # ------------- # @@ -843,135 +846,6 @@ Examples # no vlan configuration 901 # no vlan configuration 902 - # Using Gathered - - # Before state: - # ------------- - # - # vios_l2#show vlan - # VLAN Name Status Ports - # ---- -------------------------------- --------- ------------------------------- - # 1 default active Gi0/1, Gi0/2 - # 10 vlan_10 active - # 20 vlan_20 act/lshut - # 30 vlan_30 sus/lshut - # 1002 fddi-default act/unsup - # 1003 token-ring-default act/unsup - # 1004 fddinet-default act/unsup - # 1005 trnet-default act/unsup - # - # VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 - # ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ - # 1 enet 100001 1500 - - - - - 0 0 - # 10 enet 100010 1500 - - - - - 0 0 - # 20 enet 100020 610 - - - - - 0 0 - # 30 enet 100030 1500 - - - - - 0 0 - # 1002 fddi 101002 1500 - - - - - 0 0 - # 1003 tr 101003 1500 - - - - - 0 0 - # 1004 fdnet 101004 1500 - - - ieee - 0 0 - # 1005 trnet 101005 1500 - - - ibm - 0 0 - # - # Remote SPAN VLANs - # ------------------------------------------------------------------------------ - # 10 - - - name: Gather listed vlans with provided configurations - cisco.ios.ios_vlans: - config: - state: gathered - - # Module Execution Result: - # ------------------------ - # - # "gathered": [ - # { - # "mtu": 1500, - # "name": "default", - # "shutdown": "disabled", - # "state": "active", - # "vlan_id": 1 - # }, - # { - # "mtu": 1500, - # "name": "VLAN0010", - # "shutdown": "disabled", - # "state": "active", - # "vlan_id": 10 - # }, - # { - # "mtu": 1500, - # "name": "VLAN0020", - # "shutdown": "disabled", - # "state": "active", - # "vlan_id": 20 - # }, - # { - # "mtu": 1500, - # "name": "VLAN0030", - # "shutdown": "disabled", - # "state": "active", - # "vlan_id": 30 - # }, - # { - # "mtu": 1500, - # "name": "fddi-default", - # "shutdown": "enabled", - # "state": "active", - # "vlan_id": 1002 - # }, - # { - # "mtu": 1500, - # "name": "token-ring-default", - # "shutdown": "enabled", - # "state": "active", - # "vlan_id": 1003 - # }, - # { - # "mtu": 1500, - # "name": "fddinet-default", - # "shutdown": "enabled", - # "state": "active", - # "vlan_id": 1004 - # }, - # { - # "mtu": 1500, - # "name": "trnet-default", - # "shutdown": "enabled", - # "state": "active", - # "vlan_id": 1005 - # } - # ] - - # After state: - # ------------ - # - # vios_l2#show vlan - # VLAN Name Status Ports - # ---- -------------------------------- --------- ------------------------------- - # 1 default active Gi0/1, Gi0/2 - # 10 vlan_10 active - # 20 vlan_20 act/lshut - # 30 vlan_30 sus/lshut - # 1002 fddi-default act/unsup - # 1003 token-ring-default act/unsup - # 1004 fddinet-default act/unsup - # 1005 trnet-default act/unsup - # - # VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 - # ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ - # 1 enet 100001 1500 - - - - - 0 0 - # 10 enet 100010 1500 - - - - - 0 0 - # 20 enet 100020 610 - - - - - 0 0 - # 30 enet 100030 1500 - - - - - 0 0 - # 1002 fddi 101002 1500 - - - - - 0 0 - # 1003 tr 101003 1500 - - - - - 0 0 - # 1004 fdnet 101004 1500 - - - ieee - 0 0 - # 1005 trnet 101005 1500 - - - ibm - 0 0 - # - # Remote SPAN VLANs - # ------------------------------------------------------------------------------ - # 10 - # Using Gathered (configuration: True) # Before state: @@ -1088,11 +962,11 @@ Examples cisco.ios.ios_vlans: config: - vlan_id: 101 - member: + member: vni: 10101 evi: 101 - vlan_id: 102 - member: + member: vni: 10102 evi: 102 state: rendered @@ -1245,6 +1119,8 @@ Examples # } # ] + + Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 828151f38..cd0430927 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -267,14 +267,14 @@ def add_command_to_config_list(self, vlan_id, cmd, commands): commands.insert(0, vlan_id) if cmd not in commands: commands.append(cmd) - + def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] config_cmds = [] vlan = self.vlan_parent.format(want.get("vlan_id")) - + def negate_have_config(want_diff, have_diff, vlan, commands): name = dict(have_diff).get("name") if name and not dict(want_diff).get("name"): @@ -359,13 +359,15 @@ def negate_have_config(want_diff, have_diff, vlan, commands): member_evi = member_dict.get("evi") commands.extend( self._remove_vlan_vni_evi_mapping( - want - ) + want, + ), + ) + commands.extend( + [ + vlan, + self._get_member_cmds(member_dict), + ] ) - commands.extend([ - vlan, - self._get_member_cmds(member_dict), - ]) elif have_diff and (self.state == "replaced" or self.state == "overridden"): negate_have_config(diff, have_diff, vlan, commands) @@ -397,48 +399,51 @@ def _clear_config(self, want, have): return commands def _remove_vlan_vni_evi_mapping(self, want_dict): - commands = [] have_copy = self.have_now.copy() - vlan = want_dict['vlan_id'] + vlan = want_dict["vlan_id"] for vlan_dict in have_copy: - if vlan_dict['vlan_id'] == vlan: - if 'member' in vlan_dict: - commands.extend([ - self.vlan_parent.format(vlan), - self._get_member_cmds( - vlan_dict.get('member', {}), - prefix = 'no' - ) - ]) - vlan_dict.pop('member') - if vlan_dict['vlan_id'] != vlan: + if vlan_dict["vlan_id"] == vlan: + if "member" in vlan_dict: + commands.extend( + [ + self.vlan_parent.format(vlan), + self._get_member_cmds( + vlan_dict.get("member", {}), + prefix="no", + ), + ] + ) + vlan_dict.pop("member") + if vlan_dict["vlan_id"] != vlan: delete_member = False - if vlan_dict.get('member', {}).get('vni') == want_dict['member'].get('vni'): + if vlan_dict.get("member", {}).get("vni") == want_dict["member"].get("vni"): delete_member = True - if vlan_dict.get('member', {}).get('evi') == want_dict['member'].get('evi'): + if vlan_dict.get("member", {}).get("evi") == want_dict["member"].get("evi"): delete_member = True if delete_member: - commands.extend([ - self.vlan_parent.format(vlan_dict['vlan_id']), - self._get_member_cmds( - vlan_dict.get('member', {}), - prefix = 'no' - ) - ]) + commands.extend( + [ + self.vlan_parent.format(vlan_dict["vlan_id"]), + self._get_member_cmds( + vlan_dict.get("member", {}), + prefix="no", + ), + ] + ) self.have_now.remove(vlan_dict) return commands - def _get_member_cmds(self, member_dict, prefix=''): - cmd = '' + def _get_member_cmds(self, member_dict, prefix=""): + cmd = "" if prefix: - prefix = prefix + ' ' - member_vni = member_dict.get('vni') - member_evi = member_dict.get('evi') + prefix = prefix + " " + member_vni = member_dict.get("vni") + member_evi = member_dict.get("evi") if member_evi: cmd = prefix + "member evpn-instance {0} vni {1}".format(member_evi, member_vni) elif member_vni: cmd = prefix + "member vni {0}".format(member_vni) - + return cmd diff --git a/plugins/module_utils/network/ios/facts/vlans/vlans.py b/plugins/module_utils/network/ios/facts/vlans/vlans.py index 30b8c7e72..df5a2112a 100644 --- a/plugins/module_utils/network/ios/facts/vlans/vlans.py +++ b/plugins/module_utils/network/ios/facts/vlans/vlans.py @@ -16,9 +16,10 @@ __metaclass__ = type -from copy import deepcopy import re +from copy import deepcopy + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vlans.vlans import ( @@ -162,25 +163,25 @@ def render_config(self, spec, conf, vlan_info): def parse_vlan_config(self, vlan_conf): vlan_list = list() - re1 = re.compile(r'^vlan configuration +(?P\d+)$') - re2 = re.compile(r'^member +(evpn\-instance +(?P\d+) )?vni (?P[\d\-]+)$') + re1 = re.compile(r"^vlan configuration +(?P\d+)$") + re2 = re.compile(r"^member +(evpn\-instance +(?P\d+) )?vni (?P[\d\-]+)$") for line in vlan_conf.splitlines(): line = line.strip() m = re1.match(line) if m: - vlan = m.groupdict()['vlan'] - vlan_dict = {'vlan_id':vlan} + vlan = m.groupdict()["vlan"] + vlan_dict = {"vlan_id": vlan} continue m = re2.match(line) if m: group = m.groupdict() - vlan_dict.update({'member': {}}) - vlan_dict['member'].update({'vni': group['vni']}) - if group['evi']: - vlan_dict['member'].update({'evi': group['evi']}) + vlan_dict.update({"member": {}}) + vlan_dict["member"].update({"vni": group["vni"]}) + if group["evi"]: + vlan_dict["member"].update({"evi": group["evi"]}) vlan_list.append(vlan_dict) return vlan_list diff --git a/plugins/modules/ios_vlans.py b/plugins/modules/ios_vlans.py index 2884514c4..58031dcaf 100644 --- a/plugins/modules/ios_vlans.py +++ b/plugins/modules/ios_vlans.py @@ -97,7 +97,7 @@ elements: int member: description: - - Members of VLAN + - Members of VLAN type: dict suboptions: vni: @@ -239,11 +239,11 @@ cisco.ios.ios_vlans: config: - vlan_id: 102 - member: + member: vni: 10102 evi: 102 - vlan_id: 901 - member: + member: vni: 50901 configuration: true state: merged @@ -343,11 +343,11 @@ cisco.ios.ios_vlans: config: - vlan_id: 101 - member: + member: vni: 10102 evi: 102 - vlan_id: 102 - member: + member: vni: 10101 evi: 101 configuration: true @@ -523,7 +523,7 @@ # 1005 trnet 101005 1500 - - - ibm - 0 0 # Using deleted (configuration: True) - + # Before state: # ------------- # @@ -762,11 +762,11 @@ cisco.ios.ios_vlans: config: - vlan_id: 101 - member: + member: vni: 10101 evi: 101 - vlan_id: 102 - member: + member: vni: 10102 evi: 102 state: rendered diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index 74be50327..ba1f429d2 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -70,13 +70,13 @@ register: result cisco.ios.ios_vlans: &id001 config: - - vlan_id: 201 - member: - vni: 10201 - evi: 201 - - vlan_id: 902 - member: - vni: 50902 + - vlan_id: 201 + member: + vni: 10201 + evi: 201 + - vlan_id: 902 + member: + vni: 50902 configuration: True state: merged diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index 9fc5c3177..0016f175c 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -47,7 +47,6 @@ always: - ansible.builtin.include_tasks: _remove_config.yaml - - block: - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/vars/main.yaml b/tests/integration/targets/ios_vlans/vars/main.yaml index 01f4a3a68..9bbf653bb 100644 --- a/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/tests/integration/targets/ios_vlans/vars/main.yaml @@ -484,17 +484,17 @@ gathered: vlan_id: 1005 gathered_vlan_config: - - vlan_id: 101 - member: - evi: 101 - vni: 10101 - - vlan_id: 102 - member: - evi: 102 - vni: 10102 - - vlan_id: 901 - member: - vni: 50901 + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 parsed: config: @@ -540,28 +540,28 @@ parsed: vlan_id: 1005 parsed_vlan_config: - - vlan_id: 101 - member: - evi: 101 - vni: 10101 - - vlan_id: 102 - member: - evi: 102 - vni: 10102 - - vlan_id: 201 - member: - evi: 201 - vni: 10201 - - vlan_id: 202 - member: - evi: 202 - vni: 10202 - - vlan_id: 901 - member: - vni: 50901 - - vlan_id: 902 - member: - vni: 50902 + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 202 + member: + evi: 202 + vni: 10202 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 rendered: commands: diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 95bdceea2..1df54ff1f 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -105,7 +105,7 @@ def test_ios_vlans_config_merged(self): member=dict( evi=101, vni=10101, - ) + ), ), ], state="merged", @@ -186,7 +186,7 @@ def test_ios_vlans_config_merged_idempotent(self): member=dict( evi=101, vni=10101, - ) + ), ), ], state="merged", @@ -194,7 +194,7 @@ def test_ios_vlans_config_merged_idempotent(self): ), ) self.execute_module(changed=False, commands=[], sort=True) - + def test_ios_vlans_replaced(self): set_module_args( dict( @@ -358,14 +358,14 @@ def test_ios_vlans_config_overridden(self): member=dict( evi=102, vni=10102, - ) + ), ), dict( vlan_id=102, member=dict( evi=101, vni=10101, - ) + ), ), ], state="merged", @@ -385,7 +385,7 @@ def test_ios_vlans_config_overridden(self): "no vlan configuration 201", "no vlan configuration 202", "no vlan configuration 901", - "no vlan configuration 902" + "no vlan configuration 902", ] self.assertEqual(result["commands"], commands) @@ -460,14 +460,14 @@ def test_ios_vlans_config_overridden(self): member=dict( evi=102, vni=10102, - ) + ), ), dict( vlan_id=102, member=dict( evi=101, vni=10101, - ) + ), ), ], state="merged", @@ -520,7 +520,7 @@ def test_vlans_config_rendered(self): ) commands = [ "vlan configuration 101", - "member evpn-instance 101 vni 10101" + "member evpn-instance 101 vni 10101", ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), commands) @@ -732,23 +732,23 @@ def test_vlan_config_parsed(self): { "member": { "evi": 101, - "vni": 10101 + "vni": 10101, }, - "vlan_id": 101 + "vlan_id": 101, }, { "member": { "evi": 102, - "vni": 10102 + "vni": 10102, }, - "vlan_id": 102 + "vlan_id": 102, }, { "member": { - "vni": 50901 + "vni": 50901, }, - "vlan_id": 901 - } + "vlan_id": 901, + }, ] result = self.execute_module(changed=False) @@ -827,43 +827,43 @@ def test_ios_vlans_config_gathered(self): { "member": { "evi": 101, - "vni": 10101 + "vni": 10101, }, - "vlan_id": 101 + "vlan_id": 101, }, { "member": { "evi": 102, - "vni": 10102 + "vni": 10102, }, - "vlan_id": 102 + "vlan_id": 102, }, { "member": { "evi": 201, - "vni": 10201 + "vni": 10201, }, - "vlan_id": 201 + "vlan_id": 201, }, { "member": { "evi": 202, - "vni": 10202 + "vni": 10202, }, - "vlan_id": 202 + "vlan_id": 202, }, { "member": { - "vni": 50901 + "vni": 50901, }, - "vlan_id": 901 + "vlan_id": 901, }, { "member": { - "vni": 50902 + "vni": 50902, }, - "vlan_id": 902 - } + "vlan_id": 902, + }, ] result = self.execute_module(changed=False) From ac1f62147af88ef098b961c4a8c8a58307d4b087 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:24:01 +0530 Subject: [PATCH 04/63] Update vlans.py --- .../network/ios/config/vlans/vlans.py | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index cd0430927..ac6c1af2f 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -20,7 +20,7 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list, remove_empties from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.facts import Facts from ansible_collections.cisco.ios.plugins.module_utils.network.ios.utils.utils import dict_to_set @@ -116,7 +116,9 @@ def set_config(self, existing_vlans_facts): :returns: the commands necessary to migrate the current configuration to the desired configuration """ - want = self._module.params["config"] + want = [] + for cfg in self._module.params["config"]: + want.append(remove_empties(cfg)) have = existing_vlans_facts resp = self.set_state(want, have) return to_list(resp) @@ -267,14 +269,13 @@ def add_command_to_config_list(self, vlan_id, cmd, commands): commands.insert(0, vlan_id) if cmd not in commands: commands.append(cmd) - + def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] - config_cmds = [] vlan = self.vlan_parent.format(want.get("vlan_id")) - + def negate_have_config(want_diff, have_diff, vlan, commands): name = dict(have_diff).get("name") if name and not dict(want_diff).get("name"): @@ -303,6 +304,7 @@ def negate_have_config(want_diff, have_diff, vlan, commands): self.remove_command_from_config_list(vlan, "private-vlan association", commands) # Get the diff b/w want n have + want_dict = dict_to_set(want) have_dict = dict_to_set(have) diff = want_dict - have_dict @@ -359,15 +361,13 @@ def negate_have_config(want_diff, have_diff, vlan, commands): member_evi = member_dict.get("evi") commands.extend( self._remove_vlan_vni_evi_mapping( - want, - ), - ) - commands.extend( - [ - vlan, - self._get_member_cmds(member_dict), - ] + want + ) ) + commands.extend([ + vlan, + self._get_member_cmds(member_dict), + ]) elif have_diff and (self.state == "replaced" or self.state == "overridden"): negate_have_config(diff, have_diff, vlan, commands) @@ -399,51 +399,48 @@ def _clear_config(self, want, have): return commands def _remove_vlan_vni_evi_mapping(self, want_dict): + commands = [] have_copy = self.have_now.copy() - vlan = want_dict["vlan_id"] + vlan = want_dict['vlan_id'] for vlan_dict in have_copy: - if vlan_dict["vlan_id"] == vlan: - if "member" in vlan_dict: - commands.extend( - [ - self.vlan_parent.format(vlan), - self._get_member_cmds( - vlan_dict.get("member", {}), - prefix="no", - ), - ] - ) - vlan_dict.pop("member") - if vlan_dict["vlan_id"] != vlan: + if vlan_dict['vlan_id'] == vlan: + if 'member' in vlan_dict: + commands.extend([ + self.vlan_parent.format(vlan), + self._get_member_cmds( + vlan_dict.get('member', {}), + prefix = 'no' + ) + ]) + vlan_dict.pop('member') + if vlan_dict['vlan_id'] != vlan: delete_member = False - if vlan_dict.get("member", {}).get("vni") == want_dict["member"].get("vni"): + if vlan_dict.get('member', {}).get('vni') == want_dict['member'].get('vni'): delete_member = True - if vlan_dict.get("member", {}).get("evi") == want_dict["member"].get("evi"): + if vlan_dict.get('member', {}).get('evi') == want_dict['member'].get('evi'): delete_member = True if delete_member: - commands.extend( - [ - self.vlan_parent.format(vlan_dict["vlan_id"]), - self._get_member_cmds( - vlan_dict.get("member", {}), - prefix="no", - ), - ] - ) + commands.extend([ + self.vlan_parent.format(vlan_dict['vlan_id']), + self._get_member_cmds( + vlan_dict.get('member', {}), + prefix = 'no' + ) + ]) self.have_now.remove(vlan_dict) return commands - def _get_member_cmds(self, member_dict, prefix=""): - cmd = "" + def _get_member_cmds(self, member_dict, prefix=''): + cmd = '' if prefix: - prefix = prefix + " " - member_vni = member_dict.get("vni") - member_evi = member_dict.get("evi") + prefix = prefix + ' ' + member_vni = member_dict.get('vni') + member_evi = member_dict.get('evi') if member_evi: cmd = prefix + "member evpn-instance {0} vni {1}".format(member_evi, member_vni) elif member_vni: cmd = prefix + "member vni {0}".format(member_vni) - + return cmd From d842c5040bca719c37efa8a4823f0cb44370d17b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:56:42 +0000 Subject: [PATCH 05/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../network/ios/config/vlans/vlans.py | 82 ++++++++++--------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index ac6c1af2f..2c58a1f05 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -20,7 +20,10 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base import ( ConfigBase, ) -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list, remove_empties +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + remove_empties, + to_list, +) from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.facts import Facts from ansible_collections.cisco.ios.plugins.module_utils.network.ios.utils.utils import dict_to_set @@ -269,13 +272,13 @@ def add_command_to_config_list(self, vlan_id, cmd, commands): commands.insert(0, vlan_id) if cmd not in commands: commands.append(cmd) - + def _set_config(self, want, have): # Set the interface config based on the want and have config commands = [] vlan = self.vlan_parent.format(want.get("vlan_id")) - + def negate_have_config(want_diff, have_diff, vlan, commands): name = dict(have_diff).get("name") if name and not dict(want_diff).get("name"): @@ -361,13 +364,15 @@ def negate_have_config(want_diff, have_diff, vlan, commands): member_evi = member_dict.get("evi") commands.extend( self._remove_vlan_vni_evi_mapping( - want - ) + want, + ), + ) + commands.extend( + [ + vlan, + self._get_member_cmds(member_dict), + ] ) - commands.extend([ - vlan, - self._get_member_cmds(member_dict), - ]) elif have_diff and (self.state == "replaced" or self.state == "overridden"): negate_have_config(diff, have_diff, vlan, commands) @@ -399,48 +404,51 @@ def _clear_config(self, want, have): return commands def _remove_vlan_vni_evi_mapping(self, want_dict): - commands = [] have_copy = self.have_now.copy() - vlan = want_dict['vlan_id'] + vlan = want_dict["vlan_id"] for vlan_dict in have_copy: - if vlan_dict['vlan_id'] == vlan: - if 'member' in vlan_dict: - commands.extend([ - self.vlan_parent.format(vlan), - self._get_member_cmds( - vlan_dict.get('member', {}), - prefix = 'no' - ) - ]) - vlan_dict.pop('member') - if vlan_dict['vlan_id'] != vlan: + if vlan_dict["vlan_id"] == vlan: + if "member" in vlan_dict: + commands.extend( + [ + self.vlan_parent.format(vlan), + self._get_member_cmds( + vlan_dict.get("member", {}), + prefix="no", + ), + ] + ) + vlan_dict.pop("member") + if vlan_dict["vlan_id"] != vlan: delete_member = False - if vlan_dict.get('member', {}).get('vni') == want_dict['member'].get('vni'): + if vlan_dict.get("member", {}).get("vni") == want_dict["member"].get("vni"): delete_member = True - if vlan_dict.get('member', {}).get('evi') == want_dict['member'].get('evi'): + if vlan_dict.get("member", {}).get("evi") == want_dict["member"].get("evi"): delete_member = True if delete_member: - commands.extend([ - self.vlan_parent.format(vlan_dict['vlan_id']), - self._get_member_cmds( - vlan_dict.get('member', {}), - prefix = 'no' - ) - ]) + commands.extend( + [ + self.vlan_parent.format(vlan_dict["vlan_id"]), + self._get_member_cmds( + vlan_dict.get("member", {}), + prefix="no", + ), + ] + ) self.have_now.remove(vlan_dict) return commands - def _get_member_cmds(self, member_dict, prefix=''): - cmd = '' + def _get_member_cmds(self, member_dict, prefix=""): + cmd = "" if prefix: - prefix = prefix + ' ' - member_vni = member_dict.get('vni') - member_evi = member_dict.get('evi') + prefix = prefix + " " + member_vni = member_dict.get("vni") + member_evi = member_dict.get("evi") if member_evi: cmd = prefix + "member evpn-instance {0} vni {1}".format(member_evi, member_vni) elif member_vni: cmd = prefix + "member vni {0}".format(member_vni) - + return cmd From 0cf5be1b3dfcb4e222b60ed57965a5832f3e83c6 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:22:22 +0530 Subject: [PATCH 06/63] Update vlans.py - fix loop error --- plugins/module_utils/network/ios/config/vlans/vlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 2c58a1f05..dea79a403 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -391,7 +391,7 @@ def _clear_config(self, want, have): self.remove_command_from_config_list(vlan, "vlan", commands) if self.configuration and self.state == "overridden": self.have_now.remove(have) - if "default" not in have.get("name", ""): + elif "default" not in have.get("name", ""): if not self.configuration: if have.get("mtu") != want.get("mtu"): self.remove_command_from_config_list(vlan, "mtu", commands) From fa974edbe732af1025e3463cfafa46e9dbf84c45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:52:47 +0000 Subject: [PATCH 07/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/module_utils/network/ios/config/vlans/vlans.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index dea79a403..9c9d701d0 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -371,7 +371,7 @@ def negate_have_config(want_diff, have_diff, vlan, commands): [ vlan, self._get_member_cmds(member_dict), - ] + ], ) elif have_diff and (self.state == "replaced" or self.state == "overridden"): @@ -417,7 +417,7 @@ def _remove_vlan_vni_evi_mapping(self, want_dict): vlan_dict.get("member", {}), prefix="no", ), - ] + ], ) vlan_dict.pop("member") if vlan_dict["vlan_id"] != vlan: @@ -434,7 +434,7 @@ def _remove_vlan_vni_evi_mapping(self, want_dict): vlan_dict.get("member", {}), prefix="no", ), - ] + ], ) self.have_now.remove(vlan_dict) return commands From bd95ec6da4e61a0b72e949783746a355184bea5d Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:41:49 +0530 Subject: [PATCH 08/63] Update _populate_config_vlan_config.yaml --- .../ios_vlans/tests/cli/_populate_config_vlan_config.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index d66b7eeea..87e4de114 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,15 +1,14 @@ --- - name: Setup vars: - lines: - " + lines:""" vlan configuration 101 member evpn-instance 101 vni 10101 vlan configuration 102 member evpn-instance 102 vni 10102 vlan configuration 901 member vni 50901 - " + """ when: ansible_net_version != "15.6(2)T" ansible.netcommon.cli_config: config: "{{ lines }}" From 6a6a9b38e6e701a3c7ffb1fab6e855de274aa8a3 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:42:15 +0530 Subject: [PATCH 09/63] Update _remove_config_vlan_config.yaml --- .../ios_vlans/tests/cli/_remove_config_vlan_config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index ddf93d91c..adbb710a5 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -1,14 +1,14 @@ --- - name: Remove configuration vars: - lines: " + lines: """ no vlan configuration 101 no vlan configuration 102 no vlan configuration 901 no vlan configuration 201 no vlan configuration 202 no vlan configuration 902 - " + """ when: ansible_net_version != "15.6(2)T" ansible.netcommon.cli_config: config: "{{ lines }}" From fa5cd05c2c08c98f55ad4eb5dbaf1167c5163638 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:13:39 +0000 Subject: [PATCH 10/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../ios_vlans/tests/cli/_populate_config_vlan_config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index 87e4de114..dfa122734 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,7 +1,6 @@ --- - name: Setup - vars: - lines:""" + vars: lines:""" vlan configuration 101 member evpn-instance 101 vni 10101 vlan configuration 102 From 62cecececc5d3885121d1532d4acd2db674cb34d Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:51:19 +0530 Subject: [PATCH 11/63] Update _remove_config_vlan_config.yaml --- .../ios_vlans/tests/cli/_remove_config_vlan_config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index adbb710a5..862db89cc 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -1,7 +1,6 @@ --- - name: Remove configuration - vars: - lines: """ + vars: lines: """ no vlan configuration 101 no vlan configuration 102 no vlan configuration 901 From 47da75b4290af53b99fa05be30bdbecd2c1b3c8b Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:07:53 +0530 Subject: [PATCH 12/63] Update _populate_config_vlan_config.yaml --- .../tests/cli/_populate_config_vlan_config.yaml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index dfa122734..38be9c500 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,13 +1,14 @@ --- - name: Setup - vars: lines:""" - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 901 - member vni 50901 - """ + vars: + lines: | + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 901 + member vni 50901 + when: ansible_net_version != "15.6(2)T" ansible.netcommon.cli_config: config: "{{ lines }}" From 5cf83bb9a2ffc42a76e74223370ba13333f9263a Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:08:35 +0530 Subject: [PATCH 13/63] Update _remove_config_vlan_config.yaml --- .../tests/cli/_remove_config_vlan_config.yaml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index 862db89cc..10c8238ba 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -1,13 +1,14 @@ --- - name: Remove configuration - vars: lines: """ - no vlan configuration 101 - no vlan configuration 102 - no vlan configuration 901 - no vlan configuration 201 - no vlan configuration 202 - no vlan configuration 902 - """ + vars: + lines: | + no vlan configuration 101 + no vlan configuration 102 + no vlan configuration 901 + no vlan configuration 201 + no vlan configuration 202 + no vlan configuration 902 + when: ansible_net_version != "15.6(2)T" ansible.netcommon.cli_config: config: "{{ lines }}" From f9529c02198111c5de21b894a9cfb4414adefab2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:39:10 +0000 Subject: [PATCH 14/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../ios_vlans/tests/cli/_populate_config_vlan_config.yaml | 2 +- .../targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index 38be9c500..47d693d19 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,6 +1,6 @@ --- - name: Setup - vars: + vars: lines: | vlan configuration 101 member evpn-instance 101 vni 10101 diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index 10c8238ba..c31566bf1 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -1,6 +1,6 @@ --- - name: Remove configuration - vars: + vars: lines: | no vlan configuration 101 no vlan configuration 102 From 35c322ba3536f0ea15324e1ccdd7144ac818c145 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:46:19 +0530 Subject: [PATCH 15/63] Update overridden.yaml --- .../targets/ios_vlans/tests/cli/overridden.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index 0016f175c..a805f54ca 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -81,13 +81,5 @@ ansible.builtin.assert: that: - "{{ overridden_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" - - - name: Override device configuration of all interfaces with provided configuration (idempotent) - register: result - cisco.ios.ios_vlans: *id001 - - name: Assert that task was idempotent - ansible.builtin.assert: - that: - - result['changed'] == false always: - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml From c84267d8cd7ef1caa34f98e780c42e8f4b787ccf Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Wed, 30 Aug 2023 09:45:24 +0530 Subject: [PATCH 16/63] Update fix_ios_vlans.yaml --- changelogs/fragments/fix_ios_vlans.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/fix_ios_vlans.yaml b/changelogs/fragments/fix_ios_vlans.yaml index 439fc9d0a..e591322c3 100644 --- a/changelogs/fragments/fix_ios_vlans.yaml +++ b/changelogs/fragments/fix_ios_vlans.yaml @@ -1,2 +1,2 @@ minor_changes: - - ios_vlans - added vlan config CLI feature + - ios_vlans - added vlan config CLI feature. From 31d56c5f4ce944477c4fffeaaa12af8203551d76 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:17:03 +0530 Subject: [PATCH 17/63] Update test_ios_vlans.py --- .../modules/network/ios/test_ios_vlans.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 1df54ff1f..ab12e1d45 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -483,7 +483,31 @@ def test_ios_delete_vlans(self): self.assertEqual(result["commands"], commands) def test_ios_delete_vlans_config(self): - set_module_args(dict(config=[dict(vlan_id=101)], configuration=True, state="deleted")) + self.execute_show_command.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + {"vlan_id":101} + ], + configuration=True, + state="deleted" + ) + ) result = self.execute_module(changed=True) commands = ["no vlan configuration 101"] self.assertEqual(result["commands"], commands) @@ -869,3 +893,4 @@ def test_ios_vlans_config_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) + From 299ac132f5aeda8f85bd4650210dd35cdc06df63 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:18:21 +0530 Subject: [PATCH 18/63] Update vlans.py --- plugins/module_utils/network/ios/config/vlans/vlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 9c9d701d0..82ea4b1b9 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -67,9 +67,9 @@ def execute_module(self): result = {"changed": False} commands = list() warnings = list() + self.have_now = list() self.configuration = self._module.params["configuration"] if not self.configuration: - self.have_now = list() self.vlan_parent = "vlan {0}" else: self.vlan_parent = "vlan configuration {0}" From cf83c762f6088c6c03f69ffb34049dc9bffaea05 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Sep 2023 07:49:36 +0000 Subject: [PATCH 19/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index ab12e1d45..094be3014 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -502,11 +502,11 @@ def test_ios_delete_vlans_config(self): set_module_args( dict( config=[ - {"vlan_id":101} - ], - configuration=True, - state="deleted" - ) + {"vlan_id": 101}, + ], + configuration=True, + state="deleted", + ), ) result = self.execute_module(changed=True) commands = ["no vlan configuration 101"] @@ -893,4 +893,3 @@ def test_ios_vlans_config_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) - From 713f9e7b53f0dd769abe4e68ba8e439fbdda4440 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:20:35 +0530 Subject: [PATCH 20/63] Update test_ios_vlans.py --- .../unit/modules/network/ios/test_ios_vlans.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 094be3014..72131ff68 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -178,6 +178,22 @@ def test_ios_vlans_merged_idempotent(self): self.execute_module(changed=False, commands=[], sort=True) def test_ios_vlans_config_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) set_module_args( dict( config=[ @@ -893,3 +909,4 @@ def test_ios_vlans_config_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) + From 6186efa4a3497f67ccc39b503fd290fe5ef99323 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 15 Sep 2023 08:52:20 +0000 Subject: [PATCH 21/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 72131ff68..7c5ac9894 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -909,4 +909,3 @@ def test_ios_vlans_config_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) - From 4dab84c31e2c0f6d00cbbe6658c3aa16235aa8b9 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:36:44 +0530 Subject: [PATCH 22/63] Update test_ios_vlans.py --- .../modules/network/ios/test_ios_vlans.py | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 7c5ac9894..5a38032cf 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -366,6 +366,22 @@ def test_ios_vlans_overridden(self): self.assertEqual(result["commands"], commands) def test_ios_vlans_config_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) set_module_args( dict( config=[ @@ -384,7 +400,7 @@ def test_ios_vlans_config_overridden(self): ), ), ], - state="merged", + state="overridden", configuration=True, ), ) @@ -467,31 +483,6 @@ def test_ios_vlans_overridden_idempotent(self): ) self.execute_module(changed=False, commands=[], sort=True) - def test_ios_vlans_config_overridden(self): - set_module_args( - dict( - config=[ - dict( - vlan_id=101, - member=dict( - evi=102, - vni=10102, - ), - ), - dict( - vlan_id=102, - member=dict( - evi=101, - vni=10101, - ), - ), - ], - state="merged", - configuration=True, - ), - ) - self.execute_module(changed=False, commands=[], sort=True) - def test_ios_delete_vlans(self): set_module_args(dict(config=[dict(vlan_id=150)], state="deleted")) result = self.execute_module(changed=True) From 7abfbfbb8231b3e19f2a7f0d36b2324a038dbce3 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 25 Sep 2023 12:17:17 +0530 Subject: [PATCH 23/63] Update ios_vlans.py --- plugins/modules/ios_vlans.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/ios_vlans.py b/plugins/modules/ios_vlans.py index 58031dcaf..966b748b8 100644 --- a/plugins/modules/ios_vlans.py +++ b/plugins/modules/ios_vlans.py @@ -102,8 +102,9 @@ suboptions: vni: description: - - VxLan vni + - VXLAN vni type: int + required: true evi: description: - Ethernet Virtual Private Network (EVPN) From 3753b4f200b1bdbd6295c16ea9cd72210dcb284b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Sep 2023 06:47:45 +0000 Subject: [PATCH 24/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/cisco.ios.ios_vlans_module.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/cisco.ios.ios_vlans_module.rst b/docs/cisco.ios.ios_vlans_module.rst index 948d61a6e..40a0bc481 100644 --- a/docs/cisco.ios.ios_vlans_module.rst +++ b/docs/cisco.ios.ios_vlans_module.rst @@ -91,12 +91,13 @@ Parameters
integer + / required
-
VxLan vni
+
VXLAN vni
From fbd5d1e5206a9beeb679a1896c318b373065e8c9 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:26:03 +0530 Subject: [PATCH 25/63] Update merged.yaml --- tests/integration/targets/ios_vlans/tests/cli/merged.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index ba1f429d2..c04281329 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -61,9 +61,8 @@ always: - ansible.builtin.include_tasks: _remove_config.yaml -- block: - - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml - - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml +- ansible.builtin.include_tasks: _remove_config_vlan_config.yaml +- ansible.builtin.include_tasks: _populate_config_vlan_config.yaml - block: - name: Merge provided configuration with device configuration From 76d0b1d5d119811eefa730c61d8504e939e47cdd Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:28:43 +0530 Subject: [PATCH 26/63] Update vlans.py --- plugins/module_utils/network/ios/config/vlans/vlans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 82ea4b1b9..9668e9999 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -308,8 +308,8 @@ def negate_have_config(want_diff, have_diff, vlan, commands): # Get the diff b/w want n have - want_dict = dict_to_set(want) - have_dict = dict_to_set(have) + want_dict = dict_to_set(want, sort_dictionary=True) + have_dict = dict_to_set(have, sort_dictionary=True) diff = want_dict - have_dict have_diff = have_dict - want_dict From 3fc36ac74634ba3138fb28d65564195ef8bc7004 Mon Sep 17 00:00:00 2001 From: lguduru Date: Tue, 10 Oct 2023 04:01:38 -0400 Subject: [PATCH 27/63] ordered_dict --- .../network/ios/config/vlans/vlans.py | 4 ++-- plugins/module_utils/network/ios/utils/utils.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 82ea4b1b9..9668e9999 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -308,8 +308,8 @@ def negate_have_config(want_diff, have_diff, vlan, commands): # Get the diff b/w want n have - want_dict = dict_to_set(want) - have_dict = dict_to_set(have) + want_dict = dict_to_set(want, sort_dictionary=True) + have_dict = dict_to_set(have, sort_dictionary=True) diff = want_dict - have_dict have_diff = have_dict - want_dict diff --git a/plugins/module_utils/network/ios/utils/utils.py b/plugins/module_utils/network/ios/utils/utils.py index 90a30ba40..e404f2f6a 100644 --- a/plugins/module_utils/network/ios/utils/utils.py +++ b/plugins/module_utils/network/ios/utils/utils.py @@ -105,9 +105,11 @@ def expand_dict(dict_to_expand): expand_dict(new_dict) if tuple(iteritems(temp_dict)) not in test_set: test_set.add(tuple(iteritems(temp_dict))) + return test_dict - -def dict_to_set(sample_dict): +def dict_to_set(sample_dict, sort_dictionary=False): + if sort_dictionary: + sample_dict = sort_dict(sample_dict) # Generate a set with passed dictionary for comparison test_dict = dict() if isinstance(sample_dict, dict): @@ -421,3 +423,12 @@ def vlan_range_to_list(vlans): result.append(a) return numerical_sort(result) return result + +def sort_dict(dictionary): + sorted_dict = dict() + for key, value in sorted(dictionary.items()): + if isinstance(value, dict): + sorted_dict[key] = sort_dict(value) + else: + sorted_dict[key] = value + return sorted_dict From 416b4589bf8a7f9615b7bcef0f25b0997461fb1c Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:39:07 +0530 Subject: [PATCH 28/63] Update vlans.py --- plugins/module_utils/network/ios/config/vlans/vlans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 9668e9999..82ea4b1b9 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -308,8 +308,8 @@ def negate_have_config(want_diff, have_diff, vlan, commands): # Get the diff b/w want n have - want_dict = dict_to_set(want, sort_dictionary=True) - have_dict = dict_to_set(have, sort_dictionary=True) + want_dict = dict_to_set(want) + have_dict = dict_to_set(have) diff = want_dict - have_dict have_diff = have_dict - want_dict From 4db4e01d1001bdc7b706993c75960fa4b1b97723 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 08:11:07 +0000 Subject: [PATCH 29/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/module_utils/network/ios/utils/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/network/ios/utils/utils.py b/plugins/module_utils/network/ios/utils/utils.py index e404f2f6a..f3038f7f2 100644 --- a/plugins/module_utils/network/ios/utils/utils.py +++ b/plugins/module_utils/network/ios/utils/utils.py @@ -107,9 +107,10 @@ def expand_dict(dict_to_expand): test_set.add(tuple(iteritems(temp_dict))) return test_dict + def dict_to_set(sample_dict, sort_dictionary=False): if sort_dictionary: - sample_dict = sort_dict(sample_dict) + sample_dict = sort_dict(sample_dict) # Generate a set with passed dictionary for comparison test_dict = dict() if isinstance(sample_dict, dict): @@ -424,6 +425,7 @@ def vlan_range_to_list(vlans): return numerical_sort(result) return result + def sort_dict(dictionary): sorted_dict = dict() for key, value in sorted(dictionary.items()): From 6346764e128ff03f0f4811907d75269da62a1e3e Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:32:05 +0530 Subject: [PATCH 30/63] Update test_ios_vlans.py --- .../modules/network/ios/test_ios_vlans.py | 432 +++++++++--------- 1 file changed, 204 insertions(+), 228 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 5a38032cf..72689b0e8 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -60,6 +60,19 @@ def setUp(self): ) self._l2_device_command = self.mock_l2_device_command.start() + self.mock_get_resource_connection_facts_2 = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts_2 = self.mock_get_resource_connection_facts_2.start() + + self.mock_execute_show_command_2 = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." + "VlansFacts.get_vlans_data", + ) + self.execute_show_command_2 = self.mock_execute_show_command_2.start() + + def tearDown(self): super(TestIosVlansModule, self).tearDown() self.mock_get_resource_connection_config.stop() @@ -69,6 +82,8 @@ def tearDown(self): self.mock_load_config.stop() self.mock_execute_show_command.stop() self.mock_l2_device_command.stop() + self.mock_get_resource_connection_facts_2.stop() + self.mock_execute_show_command_2.stop() def load_fixtures(self, commands=None): def load_from_file(*args, **kwargs): @@ -96,26 +111,6 @@ def test_ios_vlans_merged(self): commands = ["vlan 200", "name test_vlan_200", "state active", "remote-span", "no shutdown"] self.assertEqual(result["commands"], commands) - def test_ios_vlans_config_merged(self): - set_module_args( - dict( - config=[ - dict( - vlan_id=101, - member=dict( - evi=101, - vni=10101, - ), - ), - ], - state="merged", - configuration=True, - ), - ) - result = self.execute_module(changed=True) - commands = ["vlan configuration 101", "member evpn-instance 101 vni 10101"] - self.assertEqual(result["commands"], commands) - def test_ios_vlans_merged_idempotent(self): set_module_args( dict( @@ -177,40 +172,6 @@ def test_ios_vlans_merged_idempotent(self): ) self.execute_module(changed=False, commands=[], sort=True) - def test_ios_vlans_config_merged_idempotent(self): - self.execute_show_command.return_value = dedent( - """\ - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 201 - member evpn-instance 201 vni 10201 - vlan configuration 202 - member evpn-instance 202 vni 10202 - vlan configuration 901 - member vni 50901 - vlan configuration 902 - member vni 50902 - """, - ) - set_module_args( - dict( - config=[ - dict( - vlan_id=101, - member=dict( - evi=101, - vni=10101, - ), - ), - ], - state="merged", - configuration=True, - ), - ) - self.execute_module(changed=False, commands=[], sort=True) - def test_ios_vlans_replaced(self): set_module_args( dict( @@ -365,63 +326,6 @@ def test_ios_vlans_overridden(self): self.assertEqual(result["commands"], commands) - def test_ios_vlans_config_overridden(self): - self.execute_show_command.return_value = dedent( - """\ - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 201 - member evpn-instance 201 vni 10201 - vlan configuration 202 - member evpn-instance 202 vni 10202 - vlan configuration 901 - member vni 50901 - vlan configuration 902 - member vni 50902 - """, - ) - set_module_args( - dict( - config=[ - dict( - vlan_id=101, - member=dict( - evi=102, - vni=10102, - ), - ), - dict( - vlan_id=102, - member=dict( - evi=101, - vni=10101, - ), - ), - ], - state="overridden", - configuration=True, - ), - ) - result = self.execute_module(changed=True) - commands = [ - "vlan configuration 101", - "no member evpn-instance 101 vni 10101", - "vlan configuration 102", - "no member evpn-instance 102 vni 10102", - "vlan configuration 101", - "member evpn-instance 102 vni 10102", - "vlan configuration 102", - "member evpn-instance 101 vni 10101", - "no vlan configuration 201", - "no vlan configuration 202", - "no vlan configuration 901", - "no vlan configuration 902", - ] - - self.assertEqual(result["commands"], commands) - def test_ios_vlans_overridden_idempotent(self): set_module_args( dict( @@ -489,36 +393,6 @@ def test_ios_delete_vlans(self): commands = ["no vlan 150"] self.assertEqual(result["commands"], commands) - def test_ios_delete_vlans_config(self): - self.execute_show_command.return_value = dedent( - """\ - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 201 - member evpn-instance 201 vni 10201 - vlan configuration 202 - member evpn-instance 202 vni 10202 - vlan configuration 901 - member vni 50901 - vlan configuration 902 - member vni 50902 - """, - ) - set_module_args( - dict( - config=[ - {"vlan_id": 101}, - ], - configuration=True, - state="deleted", - ), - ) - result = self.execute_module(changed=True) - commands = ["no vlan configuration 101"] - self.assertEqual(result["commands"], commands) - def test_vlans_rendered(self): set_module_args( dict( @@ -538,24 +412,6 @@ def test_vlans_rendered(self): result = self.execute_module(changed=False) self.assertEqual(sorted(result["rendered"]), commands) - def test_vlans_config_rendered(self): - set_module_args( - dict( - config=[ - dict( - vlan_id=101, - ), - ], - state="rendered", - ), - ) - commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101", - ] - result = self.execute_module(changed=False) - self.assertEqual(sorted(result["rendered"]), commands) - def test_vlan_parsed(self): set_module_args( dict( @@ -742,50 +598,6 @@ def test_vlan_parsed(self): self.maxDiff = None self.assertEqual(result["parsed"], parsed) - def test_vlan_config_parsed(self): - set_module_args( - dict( - running_config=dedent( - """\ - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 901 - member vni 50901 - """, - ), - state="parsed", - configuration=True, - ), - ) - parsed = [ - { - "member": { - "evi": 101, - "vni": 10101, - }, - "vlan_id": 101, - }, - { - "member": { - "evi": 102, - "vni": 10102, - }, - "vlan_id": 102, - }, - { - "member": { - "vni": 50901, - }, - "vlan_id": 901, - }, - ] - - result = self.execute_module(changed=False) - self.maxDiff = None - self.assertEqual(result["parsed"], parsed) - def test_ios_vlans_gathered(self): set_module_args(dict(state="gathered")) gathered = [ @@ -852,9 +664,193 @@ def test_ios_vlans_gathered(self): self.maxDiff = None self.assertEqual(result["gathered"], gathered) - def test_ios_vlans_config_gathered(self): - set_module_args(dict(configuration=True, state="gathered")) - gathered = [ + def test_ios_vlans_config_merged(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="merged", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = [ + "vlan configuration 101", + "member evpn-instance 101 vni 10101" + ] + self.assertEqual(result["commands"], commands) + + def test_ios_vlans_config_merged_idempotent(self): + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="merged", + configuration=True, + ), + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_vlans_config_overridden(self): + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=102, + vni=10102, + ), + ), + dict( + vlan_id=102, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="overridden", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = [ + "vlan configuration 101", + "no member evpn-instance 101 vni 10101", + "vlan configuration 102", + "no member evpn-instance 102 vni 10102", + "vlan configuration 101", + "member evpn-instance 102 vni 10102", + "vlan configuration 102", + "member evpn-instance 101 vni 10101", + "no vlan configuration 201", + "no vlan configuration 202", + "no vlan configuration 901", + "no vlan configuration 902", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_delete_vlans_config(self): + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + {"vlan_id": 101}, + ], + configuration=True, + state="deleted", + ), + ) + result = self.execute_module(changed=True) + commands = ["no vlan configuration 101"] + self.assertEqual(result["commands"], commands) + + def test_vlans_config_rendered(self): + self.execute_show_command_2.return_value = dedent( + """\ + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="rendered", + ), + ) + commands = [ + "vlan configuration 101", + "member evpn-instance 101 vni 10101", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) + + def test_vlans_config_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 901 + member vni 50901 + """, + ), + state="parsed", + configuration=True, + ), + ) + parsed = [ { "member": { "evi": 101, @@ -869,34 +865,14 @@ def test_ios_vlans_config_gathered(self): }, "vlan_id": 102, }, - { - "member": { - "evi": 201, - "vni": 10201, - }, - "vlan_id": 201, - }, - { - "member": { - "evi": 202, - "vni": 10202, - }, - "vlan_id": 202, - }, { "member": { "vni": 50901, }, "vlan_id": 901, }, - { - "member": { - "vni": 50902, - }, - "vlan_id": 902, - }, ] - result = self.execute_module(changed=False) + result = self.execute_module(changed=False) self.maxDiff = None - self.assertEqual(result["gathered"], gathered) + self.assertEqual(result["parsed"], parsed) From cc5459c7a78a72110d03053a61dda039ea226f5b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:02:33 +0000 Subject: [PATCH 31/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 72689b0e8..ff51360de 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -72,7 +72,6 @@ def setUp(self): ) self.execute_show_command_2 = self.mock_execute_show_command_2.start() - def tearDown(self): super(TestIosVlansModule, self).tearDown() self.mock_get_resource_connection_config.stop() @@ -682,8 +681,8 @@ def test_ios_vlans_config_merged(self): ) result = self.execute_module(changed=True) commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101" + "vlan configuration 101", + "member evpn-instance 101 vni 10101", ] self.assertEqual(result["commands"], commands) From 03a89830f78cbd454a3956977c1f30f4134779be Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:41:02 +0530 Subject: [PATCH 32/63] Update test_ios_vlans.py --- tests/unit/modules/network/ios/test_ios_vlans.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index ff51360de..7215fc800 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -72,6 +72,7 @@ def setUp(self): ) self.execute_show_command_2 = self.mock_execute_show_command_2.start() + def tearDown(self): super(TestIosVlansModule, self).tearDown() self.mock_get_resource_connection_config.stop() @@ -681,8 +682,8 @@ def test_ios_vlans_config_merged(self): ) result = self.execute_module(changed=True) commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101", + "vlan configuration 101", + "member evpn-instance 101 vni 10101" ] self.assertEqual(result["commands"], commands) @@ -822,6 +823,7 @@ def test_vlans_config_rendered(self): ), ), ], + configuration=True, state="rendered", ), ) From d0e954ffe9323da98e33010680efa22aad4fe612 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:11:29 +0000 Subject: [PATCH 33/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 7215fc800..eaf6c3201 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -72,7 +72,6 @@ def setUp(self): ) self.execute_show_command_2 = self.mock_execute_show_command_2.start() - def tearDown(self): super(TestIosVlansModule, self).tearDown() self.mock_get_resource_connection_config.stop() @@ -682,8 +681,8 @@ def test_ios_vlans_config_merged(self): ) result = self.execute_module(changed=True) commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101" + "vlan configuration 101", + "member evpn-instance 101 vni 10101", ] self.assertEqual(result["commands"], commands) From b55e51d6e271313e8102ba7ece08dc05aac7fe9e Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:58:21 +0530 Subject: [PATCH 34/63] Update test_ios_vlans.py --- .../modules/network/ios/test_ios_vlans.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index eaf6c3201..6575df2e9 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -50,16 +50,6 @@ def setUp(self): ) self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." - "VlansFacts.get_vlans_data", - ) - self.execute_show_command = self.mock_execute_show_command.start() - self.mock_l2_device_command = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_vlans._is_l2_device", - ) - self._l2_device_command = self.mock_l2_device_command.start() - self.mock_get_resource_connection_facts_2 = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", @@ -72,6 +62,16 @@ def setUp(self): ) self.execute_show_command_2 = self.mock_execute_show_command_2.start() + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." + "VlansFacts.get_vlans_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_l2_device_command = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vlans._is_l2_device", + ) + self._l2_device_command = self.mock_l2_device_command.start() + def tearDown(self): super(TestIosVlansModule, self).tearDown() self.mock_get_resource_connection_config.stop() @@ -681,8 +681,8 @@ def test_ios_vlans_config_merged(self): ) result = self.execute_module(changed=True) commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101", + "vlan configuration 101", + "member evpn-instance 101 vni 10101" ] self.assertEqual(result["commands"], commands) @@ -831,7 +831,7 @@ def test_vlans_config_rendered(self): "member evpn-instance 101 vni 10101", ] result = self.execute_module(changed=False) - self.assertEqual(sorted(result["rendered"]), commands) + self.assertEqual(result["rendered"], commands) def test_vlans_config_parsed(self): set_module_args( From 38dac86dd76ef2eb28a998bdd2413c6cf4a81ce0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:29:50 +0000 Subject: [PATCH 35/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 6575df2e9..312cdfbd6 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -681,8 +681,8 @@ def test_ios_vlans_config_merged(self): ) result = self.execute_module(changed=True) commands = [ - "vlan configuration 101", - "member evpn-instance 101 vni 10101" + "vlan configuration 101", + "member evpn-instance 101 vni 10101", ] self.assertEqual(result["commands"], commands) From 933beca48bf35441aef7a03affcd9134d017468a Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:19:08 +0530 Subject: [PATCH 36/63] Update merged.yaml --- tests/integration/targets/ios_vlans/tests/cli/merged.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index c04281329..ea50bd55f 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -67,7 +67,7 @@ - block: - name: Merge provided configuration with device configuration register: result - cisco.ios.ios_vlans: &id001 + cisco.ios.ios_vlans: &id002 config: - vlan_id: 201 member: @@ -96,7 +96,7 @@ - name: Merge provided configuration with device configuration (idempotent) register: result - cisco.ios.ios_vlans: *id001 + cisco.ios.ios_vlans: *id002 - name: Assert that the previous task was idempotent ansible.builtin.assert: that: From 79ebecc62e6d38917c62cc284147fb39462da7e7 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:23:21 +0530 Subject: [PATCH 37/63] Update test_ios_vlans.py --- tests/unit/modules/network/ios/test_ios_vlans.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 312cdfbd6..7fd8c622e 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -687,6 +687,7 @@ def test_ios_vlans_config_merged(self): self.assertEqual(result["commands"], commands) def test_ios_vlans_config_merged_idempotent(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() self.execute_show_command_2.return_value = dedent( """\ vlan configuration 101 From 3e17665accdb1ff1934fa26cf79d5b1beac6643e Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:55:40 +0530 Subject: [PATCH 38/63] Update test_ios_vlans.py --- tests/unit/modules/network/ios/test_ios_vlans.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 7fd8c622e..1417112a6 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -720,8 +720,10 @@ def test_ios_vlans_config_merged_idempotent(self): ), ) self.execute_module(changed=False, commands=[], sort=True) + self.mock_execute_show_command_2.stop() def test_ios_vlans_config_overridden(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() self.execute_show_command_2.return_value = dedent( """\ vlan configuration 101 @@ -776,8 +778,10 @@ def test_ios_vlans_config_overridden(self): "no vlan configuration 902", ] self.assertEqual(result["commands"], commands) + self.mock_execute_show_command_2.stop() def test_ios_delete_vlans_config(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() self.execute_show_command_2.return_value = dedent( """\ vlan configuration 101 @@ -806,7 +810,8 @@ def test_ios_delete_vlans_config(self): result = self.execute_module(changed=True) commands = ["no vlan configuration 101"] self.assertEqual(result["commands"], commands) - + self.mock_execute_show_command_2.stop() + def test_vlans_config_rendered(self): self.execute_show_command_2.return_value = dedent( """\ From a6af38c7ef4ce6a9b208b85dd786de53b95ec1f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 06:26:05 +0000 Subject: [PATCH 39/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/modules/network/ios/test_ios_vlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 1417112a6..9b1db40ae 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -811,7 +811,7 @@ def test_ios_delete_vlans_config(self): commands = ["no vlan configuration 101"] self.assertEqual(result["commands"], commands) self.mock_execute_show_command_2.stop() - + def test_vlans_config_rendered(self): self.execute_show_command_2.return_value = dedent( """\ From 287f39feb1cfa8bbca0ffd10d1cabd27d8c0ddce Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Wed, 11 Oct 2023 12:03:46 +0530 Subject: [PATCH 40/63] Update test_ios_vlans.py - fixed --- tests/unit/modules/network/ios/test_ios_vlans.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index 9b1db40ae..c19d58ffd 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -720,7 +720,6 @@ def test_ios_vlans_config_merged_idempotent(self): ), ) self.execute_module(changed=False, commands=[], sort=True) - self.mock_execute_show_command_2.stop() def test_ios_vlans_config_overridden(self): self.execute_show_command_2 = self.mock_execute_show_command_2.start() @@ -778,7 +777,6 @@ def test_ios_vlans_config_overridden(self): "no vlan configuration 902", ] self.assertEqual(result["commands"], commands) - self.mock_execute_show_command_2.stop() def test_ios_delete_vlans_config(self): self.execute_show_command_2 = self.mock_execute_show_command_2.start() @@ -810,7 +808,6 @@ def test_ios_delete_vlans_config(self): result = self.execute_module(changed=True) commands = ["no vlan configuration 101"] self.assertEqual(result["commands"], commands) - self.mock_execute_show_command_2.stop() def test_vlans_config_rendered(self): self.execute_show_command_2.return_value = dedent( From 0e0ee4075c3b5e7776b9df57130e43b73fbaa2cd Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:33:46 +0530 Subject: [PATCH 41/63] Update overridden.yaml --- .../targets/ios_vlans/tests/cli/overridden.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index a805f54ca..f0a082a9e 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -54,7 +54,7 @@ - block: - name: Override device configuration of all vlans with provided configuration register: result - cisco.ios.ios_vlans: &id001 + cisco.ios.ios_vlans: &id002 config: - vlan_id: 101 member: @@ -81,5 +81,13 @@ ansible.builtin.assert: that: - "{{ overridden_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id002 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false always: - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml From c076e0ecb43ad02335d864da928e96c8360746c0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:04:12 +0000 Subject: [PATCH 42/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/integration/targets/ios_vlans/tests/cli/overridden.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index f0a082a9e..99645b9f3 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -81,7 +81,7 @@ ansible.builtin.assert: that: - "{{ overridden_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" - + - name: Override device configuration of all interfaces with provided configuration (idempotent) register: result cisco.ios.ios_vlans: *id002 From 948cd3badf873473006089ff71c31d4ee2d4b326 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:40:20 +0530 Subject: [PATCH 43/63] Update _populate_config_vlan_config.yaml --- .../cli/_populate_config_vlan_config.yaml | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index 47d693d19..d04b4cd4f 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,14 +1,12 @@ ---- -- name: Setup - vars: - lines: | - vlan configuration 101 - member evpn-instance 101 vni 10101 - vlan configuration 102 - member evpn-instance 102 vni 10102 - vlan configuration 901 - member vni 50901 - - when: ansible_net_version != "15.6(2)T" - ansible.netcommon.cli_config: - config: "{{ lines }}" +- name: Populate configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 201 + member: + vni: 10201 + evi: 201 + - vlan_id: 902 + member: + vni: 50902 + configuration: True + state: merged From a5e2e880c7f7a7850970ce879426bcca23125132 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:42:09 +0530 Subject: [PATCH 44/63] Update _remove_config_vlan_config.yaml --- .../tests/cli/_remove_config_vlan_config.yaml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index c31566bf1..4591e7c2c 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -1,14 +1,6 @@ --- - name: Remove configuration - vars: - lines: | - no vlan configuration 101 - no vlan configuration 102 - no vlan configuration 901 - no vlan configuration 201 - no vlan configuration 202 - no vlan configuration 902 - - when: ansible_net_version != "15.6(2)T" - ansible.netcommon.cli_config: - config: "{{ lines }}" + cisco.ios.ios_vlans: + config: + configuration: true + state: deleted From 745328c6b1829a60459b05d0621694c536f3cea6 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:43:11 +0530 Subject: [PATCH 45/63] Update vlans.py --- plugins/module_utils/network/ios/facts/vlans/vlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/ios/facts/vlans/vlans.py b/plugins/module_utils/network/ios/facts/vlans/vlans.py index df5a2112a..9b506fa90 100644 --- a/plugins/module_utils/network/ios/facts/vlans/vlans.py +++ b/plugins/module_utils/network/ios/facts/vlans/vlans.py @@ -49,7 +49,7 @@ def get_vlans_data(self, connection, configuration): facts gracefully. Does not fail module. """ if configuration: - cmd = "show running-config nve | sec ^vlan configuration" + cmd = "show running-config | sec ^vlan configuration .+" else: cmd = "show vlan" check_os_type = connection.get_device_info() From 2a7028808e6336714998bcf2a80e24d8b7d3a277 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:50:18 +0530 Subject: [PATCH 46/63] Update parsed.yaml --- tests/integration/targets/ios_vlans/tests/cli/parsed.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml index 78e700190..1c7819ee5 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml @@ -28,4 +28,4 @@ - ansible.builtin.assert: that: - result.changed == false - - parsed_vlan_config['config']|symmetric_difference(result.parsed) == [] + - parsed_vlan_config|symmetric_difference(result.parsed) == [] From 6aca74e2cedd40aca48b0b33bc699607740835ca Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:52:32 +0530 Subject: [PATCH 47/63] Update overridden.yaml --- tests/integration/targets/ios_vlans/tests/cli/overridden.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index 99645b9f3..eaae58285 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -75,12 +75,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ overridden_vlan_config['before'] | symmetric_difference(result['before']) | length == 0 }}" + - overridden_vlan_config['before'] == result['before'] - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ overridden_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" + - overridden_vlan_config['after'] == result['after'] - name: Override device configuration of all interfaces with provided configuration (idempotent) register: result From 78b4dc581dcdfa1b1a295c3b45443b94ed70795c Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:54:00 +0530 Subject: [PATCH 48/63] Update _remove_config_vlan_config.yaml --- .../ios_vlans/tests/cli/_remove_config_vlan_config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index 4591e7c2c..f6de2bcee 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -2,5 +2,11 @@ - name: Remove configuration cisco.ios.ios_vlans: config: + - vlan_id: 101 + - vlan_id: 102 + - vlan_id: 201 + - vlan_id: 202 + - vlan_id: 901 + - vlan_id: 902 configuration: true state: deleted From 0ffa2739c5ce17a0b7e9f534b19eaab2a39c32fc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:25:21 +0000 Subject: [PATCH 49/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../tests/cli/_remove_config_vlan_config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml index f6de2bcee..f78bb0c56 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -2,11 +2,11 @@ - name: Remove configuration cisco.ios.ios_vlans: config: - - vlan_id: 101 - - vlan_id: 102 - - vlan_id: 201 - - vlan_id: 202 - - vlan_id: 901 - - vlan_id: 902 + - vlan_id: 101 + - vlan_id: 102 + - vlan_id: 201 + - vlan_id: 202 + - vlan_id: 901 + - vlan_id: 902 configuration: true state: deleted From 37b713e2e3b6ac26feef0caf0d5bb1dca3e748d6 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:58:56 +0530 Subject: [PATCH 50/63] Update _populate_config_vlan_config.yaml --- .../cli/_populate_config_vlan_config.yaml | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index d04b4cd4f..9e3a6daff 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,12 +1,27 @@ - name: Populate configuration cisco.ios.ios_vlans: config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 - vlan_id: 201 member: - vni: 10201 - evi: 201 + vni: 10201 + evi: 201 + - vlan_id: 202 + member: + vni: 10202 + evi: 202 + - vlan_id: 901 + member: + vni: 50901 - vlan_id: 902 member: - vni: 50902 + vni: 50902 configuration: True state: merged From 771834860a14d42b0d9767cbcfdbc79098727e79 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:26:09 +0530 Subject: [PATCH 51/63] Update _populate_config_vlan_config.yaml --- .../tests/cli/_populate_config_vlan_config.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index 9e3a6daff..0147f1ede 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -9,19 +9,8 @@ member: vni: 10102 evi: 102 - - vlan_id: 201 - member: - vni: 10201 - evi: 201 - - vlan_id: 202 - member: - vni: 10202 - evi: 202 - vlan_id: 901 member: vni: 50901 - - vlan_id: 902 - member: - vni: 50902 configuration: True state: merged From a5e0af1471f6d32e6a5611a1d26bdcd71b7847d0 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:27:02 +0530 Subject: [PATCH 52/63] Update main.yaml --- tests/integration/targets/ios_vlans/vars/main.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration/targets/ios_vlans/vars/main.yaml b/tests/integration/targets/ios_vlans/vars/main.yaml index 9bbf653bb..de98fb254 100644 --- a/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/tests/integration/targets/ios_vlans/vars/main.yaml @@ -318,9 +318,6 @@ overridden: overridden_vlan_config: before: - vlan_id: 101 - member: - evi: 101 - vni: 10101 - vlan_id: 102 member: evi: 102 From b13e51ca578b38f3ae5e4eba82be71937f1031cb Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:31:52 +0530 Subject: [PATCH 53/63] Update gathered.yaml --- tests/integration/targets/ios_vlans/tests/cli/gathered.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml index ddc6a44a6..011a304e8 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml @@ -30,12 +30,13 @@ register: result cisco.ios.ios_vlans: config: + configuration: true state: gathered - name: Assert ansible.builtin.assert: that: - - gathered_vlan_config['config'] | symmetric_difference(result.gathered) == [] + - gathered_vlan_config == result.gathered - result['changed'] == false always: - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml From a330d6e4b708d183e8973b0e3a9694c8afaadaa4 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:37:25 +0530 Subject: [PATCH 54/63] Update merged.yaml --- tests/integration/targets/ios_vlans/tests/cli/merged.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index ea50bd55f..9589a1d89 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -87,12 +87,12 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ merged_vlan_config['before'] | symmetric_difference(result['before']) | length == 0 }}" + - merged_vlan_config['before'] == result['before'] - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - "{{ merged_vlan_config['after'] | symmetric_difference(result['after']) | length == 0 }}" + - merged_vlan_config['after'] == result['after'] - name: Merge provided configuration with device configuration (idempotent) register: result From c58cd48e5756352756c0d0b9503db174393f90cb Mon Sep 17 00:00:00 2001 From: psivaraj Date: Thu, 2 Nov 2023 05:50:39 -0400 Subject: [PATCH 55/63] added sep test for vlan config --- .../targets/ios_vlans/tests/cli/merged.yaml | 43 ----------------- .../tests/cli/merged_vlan_config.yaml | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml index 9589a1d89..184a0317e 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -60,46 +60,3 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml - -- ansible.builtin.include_tasks: _remove_config_vlan_config.yaml -- ansible.builtin.include_tasks: _populate_config_vlan_config.yaml - -- block: - - name: Merge provided configuration with device configuration - register: result - cisco.ios.ios_vlans: &id002 - config: - - vlan_id: 201 - member: - vni: 10201 - evi: 201 - - vlan_id: 902 - member: - vni: 50902 - configuration: True - state: merged - - - name: Assert that correct set of commands were generated - ansible.builtin.assert: - that: - - "{{ merged_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" - - - name: Assert that before dicts are correctly generated - ansible.builtin.assert: - that: - - merged_vlan_config['before'] == result['before'] - - - name: Assert that after dict is correctly generated - ansible.builtin.assert: - that: - - merged_vlan_config['after'] == result['after'] - - - name: Merge provided configuration with device configuration (idempotent) - register: result - cisco.ios.ios_vlans: *id002 - - name: Assert that the previous task was idempotent - ansible.builtin.assert: - that: - - result['changed'] == false - always: - - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml new file mode 100644 index 000000000..edb5a6d22 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml @@ -0,0 +1,46 @@ +--- +- ansible.builtin.debug: + msg: START Merged ios_vlans state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config_vlan_config.yaml +- ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 201 + member: + vni: 10201 + evi: 201 + - vlan_id: 902 + member: + vni: 50902 + configuration: True + state: merged + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged_vlan_config['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - merged_vlan_config['after'] == result['after'] + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml From 683341b7c1dbc407a916891f0ab8e506bcdc5087 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:11:41 +0530 Subject: [PATCH 56/63] Update vlans.py --- plugins/module_utils/network/ios/config/vlans/vlans.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/ios/config/vlans/vlans.py b/plugins/module_utils/network/ios/config/vlans/vlans.py index 9668e9999..ee9be054a 100644 --- a/plugins/module_utils/network/ios/config/vlans/vlans.py +++ b/plugins/module_utils/network/ios/config/vlans/vlans.py @@ -120,8 +120,9 @@ def set_config(self, existing_vlans_facts): to the desired configuration """ want = [] - for cfg in self._module.params["config"]: - want.append(remove_empties(cfg)) + if self._module.params.get("config"): + for cfg in self._module.params["config"]: + want.append(remove_empties(cfg)) have = existing_vlans_facts resp = self.set_state(want, have) return to_list(resp) From 5d1d36721ffc7ceab8402e435954adc8fd2bbb89 Mon Sep 17 00:00:00 2001 From: psivaraj Date: Thu, 2 Nov 2023 06:59:41 -0400 Subject: [PATCH 57/63] separated test --- .../tests/cli/deleted_vlan_config.yaml | 40 +++++++++++ .../targets/ios_vlans/tests/cli/gathered.yaml | 19 ------ .../tests/cli/gathered_vlan_config.yaml | 23 +++++++ .../ios_vlans/tests/cli/overridden.yaml | 45 ------------ .../tests/cli/overridden_vlan_config.yaml | 48 +++++++++++++ .../targets/ios_vlans/tests/cli/parsed.yaml | 14 ---- .../tests/cli/parsed_vlan_config.yaml | 17 +++++ .../targets/ios_vlans/tests/cli/rendered.yaml | 25 ------- .../tests/cli/rendered_vlan_config.yaml | 28 ++++++++ .../targets/ios_vlans/vars/main.yaml | 68 ++++++++++--------- 10 files changed, 191 insertions(+), 136 deletions(-) create mode 100644 tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml create mode 100644 tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml new file mode 100644 index 000000000..3868e5551 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml @@ -0,0 +1,40 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for ios_vlans ansible_connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Delete vlans attributes for all configured vlans + register: result + cisco.ios.ios_vlans: &id001 + configuration: true + state: deleted + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - deleted['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - deleted['after'] == result['after'] + + - name: Delete vlans attributes for all configured vlans (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + diff --git a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml index 011a304e8..3c52d178a 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml @@ -21,22 +21,3 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml - -- block: - - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml - -- block: - - name: Gather the provided configuration with the existing running configuration - register: result - cisco.ios.ios_vlans: - config: - configuration: true - state: gathered - - - name: Assert - ansible.builtin.assert: - that: - - gathered_vlan_config == result.gathered - - result['changed'] == false - always: - - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml new file mode 100644 index 000000000..576adee2f --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: START ios_vlans gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.ios.ios_vlans: + config: + configuration: true + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - gathered_vlan_config.config == result.gathered + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml index eaae58285..4e5468f95 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -46,48 +46,3 @@ when: ansible_net_version == "15.6(2)T" always: - ansible.builtin.include_tasks: _remove_config.yaml - -- block: - - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml - - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml - -- block: - - name: Override device configuration of all vlans with provided configuration - register: result - cisco.ios.ios_vlans: &id002 - config: - - vlan_id: 101 - member: - vni: 10102 - evi: 102 - - vlan_id: 102 - member: - vni: 10101 - evi: 101 - configuration: True - state: overridden - - - name: Assert that correct set of commands were generated - ansible.builtin.assert: - that: - - "{{ overridden_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" - - - name: Assert that before dicts are correctly generated - ansible.builtin.assert: - that: - - overridden_vlan_config['before'] == result['before'] - - - name: Assert that after dict is correctly generated - ansible.builtin.assert: - that: - - overridden_vlan_config['after'] == result['after'] - - - name: Override device configuration of all interfaces with provided configuration (idempotent) - register: result - cisco.ios.ios_vlans: *id002 - - name: Assert that task was idempotent - ansible.builtin.assert: - that: - - result['changed'] == false - always: - - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml new file mode 100644 index 000000000..d41e1f598 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml @@ -0,0 +1,48 @@ +--- +- ansible.builtin.debug: + msg: START Overridden ios_vlans state for integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Override device configuration of all vlans with provided configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 101 + member: + vni: 10102 + evi: 102 + - vlan_id: 102 + member: + vni: 10101 + evi: 101 + configuration: True + state: overridden + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - overridden_vlan_config['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - overridden_vlan_config['after'] == result['after'] + + - name: Override device configuration of all interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml index 1c7819ee5..042fef68b 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml @@ -15,17 +15,3 @@ - result.changed == false - parsed['config']|symmetric_difference(result.parsed) == [] when: ansible_net_version != "15.6(2)T" - -- block: - - name: Parse the commands for provided configuration - become: true - register: result - cisco.ios.ios_vlans: - running_config: "{{ lookup('file', '_parsed_vlan_config.cfg') }}" - configuration: True - state: parsed - - - ansible.builtin.assert: - that: - - result.changed == false - - parsed_vlan_config|symmetric_difference(result.parsed) == [] diff --git a/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml new file mode 100644 index 000000000..f04b9e078 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml @@ -0,0 +1,17 @@ +--- +- ansible.builtin.debug: + msg: START ios_vlans parsed integration tests on connection={{ ansible_connection }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', '_parsed_vlan_config.cfg') }}" + configuration: True + state: parsed + + - ansible.builtin.assert: + that: + - result.changed == false + - parsed_vlan_config.config == result.parsed diff --git a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml index 25afe1305..38b0304c8 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml @@ -29,28 +29,3 @@ - result.changed == false - result.rendered|symmetric_difference(rendered.commands) == [] when: ansible_net_version != "15.6(2)T" - -- block: - - name: Render the commands for provided configuration - become: true - register: result - cisco.ios.ios_vlans: - config: - - vlan_id: 101 - member: - vni: 10101 - evi: 101 - - vlan_id: 102 - member: - vni: 10102 - evi: 102 - - vlan_id: 901 - member: - vni: 50901 - configuration: True - state: rendered - - - ansible.builtin.assert: - that: - - result.changed == false - - result.rendered|symmetric_difference(rendered_vlan_config.commands) == [] diff --git a/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml new file mode 100644 index 000000000..344f10e47 --- /dev/null +++ b/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml @@ -0,0 +1,28 @@ +--- +- ansible.builtin.debug: + msg: Start ios_vlans rendered integration tests ansible_connection={{ ansible_connection }} + +- block: + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: True + state: rendered + + - ansible.builtin.assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered_vlan_config.commands) == [] diff --git a/tests/integration/targets/ios_vlans/vars/main.yaml b/tests/integration/targets/ios_vlans/vars/main.yaml index de98fb254..6092684a9 100644 --- a/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/tests/integration/targets/ios_vlans/vars/main.yaml @@ -481,17 +481,18 @@ gathered: vlan_id: 1005 gathered_vlan_config: - - vlan_id: 101 - member: - evi: 101 - vni: 10101 - - vlan_id: 102 - member: - evi: 102 - vni: 10102 - - vlan_id: 901 - member: - vni: 50901 + config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 parsed: config: @@ -537,28 +538,29 @@ parsed: vlan_id: 1005 parsed_vlan_config: - - vlan_id: 101 - member: - evi: 101 - vni: 10101 - - vlan_id: 102 - member: - evi: 102 - vni: 10102 - - vlan_id: 201 - member: - evi: 201 - vni: 10201 - - vlan_id: 202 - member: - evi: 202 - vni: 10202 - - vlan_id: 901 - member: - vni: 50901 - - vlan_id: 902 - member: - vni: 50902 + config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 202 + member: + evi: 202 + vni: 10202 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 rendered: commands: From c7f12748961a1181dad7e41c53f1c2b55eeebca5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:03:15 +0000 Subject: [PATCH 58/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../targets/ios_vlans/tests/cli/deleted_vlan_config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml index 3868e5551..93e52b253 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml @@ -37,4 +37,3 @@ - result.changed == false always: - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml - From 36158b627f9aec25bded27fe278f54615d8d67a5 Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:52:38 +0530 Subject: [PATCH 59/63] Update deleted_vlan_config.yaml --- .../targets/ios_vlans/tests/cli/deleted_vlan_config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml index 93e52b253..21249d763 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml @@ -16,17 +16,17 @@ - name: Assert that correct set of commands were generated ansible.builtin.assert: that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + - "{{ deleted_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - deleted['before'] == result['before'] + - deleted_vlan_config['before'] == result['before'] - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - deleted['after'] == result['after'] + - deleted_vlan_config['after'] == result['after'] - name: Delete vlans attributes for all configured vlans (idempotent) register: result From f04d2c00a665e2a2fbc5da76b500e38c92aee8ab Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:42:50 +0530 Subject: [PATCH 60/63] Update overridden_vlan_config.yaml --- .../targets/ios_vlans/tests/cli/overridden_vlan_config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml index d41e1f598..52944e5ce 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml @@ -19,7 +19,7 @@ member: vni: 10101 evi: 101 - configuration: True + configuration: true state: overridden - name: Assert that correct set of commands were generated From 8eb402751dfb2ea9c5015428711d21647440fa6a Mon Sep 17 00:00:00 2001 From: PadminiSivaraj <108111540+PadminiSivaraj@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:45:17 +0530 Subject: [PATCH 61/63] Update _populate_config_vlan_config.yaml --- .../ios_vlans/tests/cli/_populate_config_vlan_config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index 0147f1ede..fe009eb86 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -1,3 +1,4 @@ +--- - name: Populate configuration cisco.ios.ios_vlans: config: From 47e84f93bb66ff4f1bd104e744f47e6ebda0f4a5 Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Mon, 20 Nov 2023 13:43:13 +0530 Subject: [PATCH 62/63] lint fixes --- plugins/modules/ios_vlans.py | 18 +++++++++++------- .../cli/_populate_config_vlan_config.yaml | 2 +- .../tests/cli/merged_vlan_config.yaml | 2 +- .../tests/cli/parsed_vlan_config.yaml | 2 +- .../tests/cli/rendered_vlan_config.yaml | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/modules/ios_vlans.py b/plugins/modules/ios_vlans.py index cd081abd5..82fcc6498 100644 --- a/plugins/modules/ios_vlans.py +++ b/plugins/modules/ios_vlans.py @@ -542,7 +542,7 @@ cisco.ios.ios_vlans: config: - vlan_id: 101 - configuration: True + configuration: true state: deleted # After state: @@ -614,7 +614,7 @@ # 1005 trnet 101005 1500 - - - ibm - 0 0 # Using Deleted without any config passed (configuration: True) -#"(NOTE: This will delete all of configured vlans attributes)" +# "(NOTE: This will delete all of configured vlans attributes)" # Before state: # ------------- @@ -633,7 +633,7 @@ - name: Delete attributes of ALL VLANs cisco.ios.ios_vlans: - configuration: True + configuration: true state: deleted # After state: @@ -667,7 +667,7 @@ - name: Gather listed vlans with provided configurations cisco.ios.ios_vlans: config: - configuration: True + configuration: true state: gathered # Module Execution Result: @@ -891,7 +891,7 @@ - name: Parse the commands for provided configuration cisco.ios.ios_vlans: running_config: "{{ lookup('file', './parsed.cfg') }}" - configuration: True + configuration: true state: parsed # Module Execution Result: @@ -947,8 +947,12 @@ from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vlans.vlans import ( VlansArgs, ) -from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vlans.vlans import Vlans -from ansible_collections.cisco.ios.plugins.module_utils.network.ios.ios import get_connection +from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vlans.vlans import ( + Vlans, +) +from ansible_collections.cisco.ios.plugins.module_utils.network.ios.ios import ( + get_connection, +) def _is_l2_device(module): diff --git a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml index fe009eb86..d1c517a03 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -13,5 +13,5 @@ - vlan_id: 901 member: vni: 50901 - configuration: True + configuration: true state: merged diff --git a/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml index edb5a6d22..6efce0fc0 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml @@ -17,7 +17,7 @@ - vlan_id: 902 member: vni: 50902 - configuration: True + configuration: true state: merged - name: Assert that correct set of commands were generated diff --git a/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml index f04b9e078..7d8311711 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml @@ -8,7 +8,7 @@ register: result cisco.ios.ios_vlans: running_config: "{{ lookup('file', '_parsed_vlan_config.cfg') }}" - configuration: True + configuration: true state: parsed - ansible.builtin.assert: diff --git a/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml b/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml index 344f10e47..63cc24a29 100644 --- a/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml +++ b/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml @@ -19,7 +19,7 @@ - vlan_id: 901 member: vni: 50901 - configuration: True + configuration: true state: rendered - ansible.builtin.assert: From 46076727c2efd0a03737f09c20af2d610a968fe8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Nov 2023 08:13:46 +0000 Subject: [PATCH 63/63] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/cisco.ios.ios_vlans_module.rst | 10 +++++----- plugins/modules/ios_vlans.py | 8 ++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/docs/cisco.ios.ios_vlans_module.rst b/docs/cisco.ios.ios_vlans_module.rst index db5a4a6f3..598486c57 100644 --- a/docs/cisco.ios.ios_vlans_module.rst +++ b/docs/cisco.ios.ios_vlans_module.rst @@ -742,7 +742,7 @@ Examples cisco.ios.ios_vlans: config: - vlan_id: 101 - configuration: True + configuration: true state: deleted # After state: @@ -814,7 +814,7 @@ Examples # 1005 trnet 101005 1500 - - - ibm - 0 0 # Using Deleted without any config passed (configuration: True) - #"(NOTE: This will delete all of configured vlans attributes)" + # "(NOTE: This will delete all of configured vlans attributes)" # Before state: # ------------- @@ -833,7 +833,7 @@ Examples - name: Delete attributes of ALL VLANs cisco.ios.ios_vlans: - configuration: True + configuration: true state: deleted # After state: @@ -867,7 +867,7 @@ Examples - name: Gather listed vlans with provided configurations cisco.ios.ios_vlans: config: - configuration: True + configuration: true state: gathered # Module Execution Result: @@ -1091,7 +1091,7 @@ Examples - name: Parse the commands for provided configuration cisco.ios.ios_vlans: running_config: "{{ lookup('file', './parsed.cfg') }}" - configuration: True + configuration: true state: parsed # Module Execution Result: diff --git a/plugins/modules/ios_vlans.py b/plugins/modules/ios_vlans.py index 82fcc6498..1dd3228ce 100644 --- a/plugins/modules/ios_vlans.py +++ b/plugins/modules/ios_vlans.py @@ -947,12 +947,8 @@ from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vlans.vlans import ( VlansArgs, ) -from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vlans.vlans import ( - Vlans, -) -from ansible_collections.cisco.ios.plugins.module_utils.network.ios.ios import ( - get_connection, -) +from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vlans.vlans import Vlans +from ansible_collections.cisco.ios.plugins.module_utils.network.ios.ios import get_connection def _is_l2_device(module):