From b517c84d8745850db05cc8bd3f30cff0e0149022 Mon Sep 17 00:00:00 2001 From: Vinay Mulugund Date: Mon, 17 Jun 2024 20:11:30 +0530 Subject: [PATCH 01/46] vrf_global init --- plugins/cache/__init__.py | 0 plugins/lookup/__init__.py | 0 plugins/module_utils/common/__init__.py | 0 .../nxos/argspec/vrf_global/__init__.py | 0 .../nxos/argspec/vrf_global/vrf_global.py | 270 ++++++++++++ .../nxos/config/vrf_global/__init__.py | 0 .../nxos/config/vrf_global/vrf_global.py | 97 +++++ .../network/nxos/facts/vrf_global/__init__.py | 0 .../nxos/facts/vrf_global/vrf_global.py | 67 +++ .../network/nxos/rm_templates/vrf_global.py | 50 +++ plugins/modules/nxos_vrf_global.py | 411 ++++++++++++++++++ plugins/plugin_utils/__init__.py | 0 plugins/test/__init__.py | 0 13 files changed, 895 insertions(+) create mode 100644 plugins/cache/__init__.py create mode 100644 plugins/lookup/__init__.py create mode 100644 plugins/module_utils/common/__init__.py create mode 100644 plugins/module_utils/network/nxos/argspec/vrf_global/__init__.py create mode 100644 plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py create mode 100644 plugins/module_utils/network/nxos/config/vrf_global/__init__.py create mode 100644 plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py create mode 100644 plugins/module_utils/network/nxos/facts/vrf_global/__init__.py create mode 100644 plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py create mode 100644 plugins/module_utils/network/nxos/rm_templates/vrf_global.py create mode 100644 plugins/modules/nxos_vrf_global.py create mode 100644 plugins/plugin_utils/__init__.py create mode 100644 plugins/test/__init__.py diff --git a/plugins/cache/__init__.py b/plugins/cache/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/lookup/__init__.py b/plugins/lookup/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/common/__init__.py b/plugins/module_utils/common/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/argspec/vrf_global/__init__.py b/plugins/module_utils/network/nxos/argspec/vrf_global/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py new file mode 100644 index 000000000..f62044372 --- /dev/null +++ b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the +# ansible.content_builder. +# +# Manually editing this file is not advised. +# +# To update the argspec make the desired changes +# in the documentation in the module file and re-run +# ansible.content_builder commenting out +# the path to external 'docstring' in build.yaml. +# +############################################## + +""" +The arg spec for the nxos_vrf_global module +""" + + +class Vrf_globalArgs(object): # pylint: disable=R0903 + """The arg spec for the nxos_vrf_global module + """ + + argument_spec = { + "config": { + "type": "dict", + "options": { + "vrfs": { + "type": "list", + "elements": "dict", + "options": { + "name": {"required": True, "type": "str"}, + "description": {"type": "str"}, + "ip": { + "type": "dict", + "options": { + "auto_discard": {"type": "bool"}, + "domain_list": {"type": "list", "elements": "str"}, + "domain_name": {"type": "str"}, + "icmp_err": { + "type": "dict", + "options": { + "source_interace": { + "type": "dict", + "options": { + "interface": { + "type": "str", + "choices": [ + "loopback", + "ethernet", + "port-channel", + ], + }, + "interface_value": {"type": "str"}, + }, + } + }, + }, + "igmp": { + "type": "dict", + "options": { + "ssm_translate": { + "type": "list", + "elements": "dict", + "options": { + "group": {"type": "str"}, + "source": {"type": "str"}, + }, + } + }, + }, + "mroutes": { + "type": "list", + "elements": "dict", + "options": { + "group": {"type": "str"}, + "source": {"type": "str"}, + "preference": {"type": "int"}, + "vrf": {"type": "str"}, + }, + }, + "multicast": { + "type": "dict", + "options": { + "group_range_prefix_list": {"type": "str"}, + "multipath": { + "type": "dict", + "options": { + "resilient": {"type": "bool"}, + "splitting_type": { + "type": "dict", + "mutually_exclusive": [ + [ + "legacy", + "nbm", + "none", + "sg_hash", + "sg_hash_next_hop", + ] + ], + "options": { + "none": {"type": "bool"}, + "sg_hash": { + "type": "bool" + }, + "sg_hash_next_hop": { + "type": "bool" + }, + }, + }, + }, + }, + "rpf": { + "type": "list", + "elements": "dict", + "options": { + "vrf_name": {"type": "str"}, + "group_list_range": { + "type": "str" + }, + }, + }, + }, + }, + "name_server": { + "type": "dict", + "options": { + "address_list": { + "type": "list", + "elements": "str", + }, + "use_vrf": { + "type": "dict", + "options": { + "vrf": {"type": "str"}, + "source_address": {"type": "str"}, + }, + }, + }, + }, + "route": { + "type": "list", + "elements": "dict", + "mutually_exclusive": [ + ["tags", "vrf", "track"] + ], + "options": { + "source": {"type": "str"}, + "destination": {"type": "str"}, + "tags": { + "type": "dict", + "options": { + "tag_value": {"type": "int"}, + "route_pref": {"type": "int"}, + }, + }, + "vrf": {"type": "str"}, + "track": {"type": "str"}, + }, + }, + }, + }, + "vni": { + "type": "dict", + "options": { + "vni_number": {"type": "int"}, + "layer_3": {"type": "bool"}, + }, + }, + "multicast": { + "type": "dict", + "options": { + "service_reflect": { + "type": "list", + "elements": "dict", + "options": { + "service_interface": { + "type": "dict", + "options": { + "interface": {"type": "str"}, + "interface_value": {"type": "str"}, + }, + }, + "map_to": { + "type": "dict", + "options": { + "interface": {"type": "str"}, + "interface_value": {"type": "str"}, + }, + }, + }, + } + }, + }, + "ipv6": { + "type": "dict", + "options": { + "mld_ssm_translate": { + "type": "list", + "elements": "dict", + "options": { + "icmp": {"type": "bool"}, + "group": {"type": "str"}, + "source": {"type": "str"}, + }, + }, + "multicast": { + "type": "dict", + "options": { + "group_range_prefix_list": {"type": "str"}, + "multipath": { + "type": "dict", + "options": { + "resilient": {"type": "bool"}, + "splitting_type": { + "type": "dict", + "mutually_exclusive": [ + [ + "none", + "sg_hash", + "sg_hash_next_hop", + ] + ], + "options": { + "none": {"type": "bool"}, + "sg_hash": { + "type": "bool" + }, + "sg_hash_next_hop": { + "type": "bool" + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + }, + }, + "running_config": {"type": "str"}, + "state": { + "choices": [ + "parsed", + "gathered", + "deleted", + "merged", + "replaced", + "rendered", + "overridden", + "purged", + ], + "default": "merged", + "type": "str", + }, + } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/nxos/config/vrf_global/__init__.py b/plugins/module_utils/network/nxos/config/vrf_global/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py new file mode 100644 index 000000000..5708e37a2 --- /dev/null +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -0,0 +1,97 @@ +# +# -*- coding: utf-8 -*- +# Copyright 2024 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +""" +The nxos_vrf_global config file. +It is in this file where the current configuration (as dict) +is compared to the provided configuration (as dict) and the command set +necessary to bring the current configuration to its desired end-state is +created. +""" + +from copy import deepcopy + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, +) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.facts.facts import ( + Facts, +) +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( + Vrf_globalTemplate, +) + + +class Vrf_global(ResourceModule): + """ + The nxos_vrf_global config class + """ + + def __init__(self, module): + super(Vrf_global, self).__init__( + empty_fact_val={}, + facts_module=Facts(module), + module=module, + resource="vrf_global", + tmplt=Vrf_globalTemplate(), + ) + self.parsers = [ + ] + + def execute_module(self): + """ Execute the module + + :rtype: A dictionary + :returns: The result from module execution + """ + if self.state not in ["parsed", "gathered"]: + self.generate_commands() + self.run_commands() + return self.result + + def generate_commands(self): + """ Generate configuration commands to send based on + want, have and desired state. + """ + wantd = {entry['name']: entry for entry in self.want} + haved = {entry['name']: entry for entry in self.have} + + # if state is merged, merge want onto have and then compare + if self.state == "merged": + wantd = dict_merge(haved, wantd) + + # if state is deleted, empty out wantd and set haved to wantd + if self.state == "deleted": + haved = { + k: v for k, v in iteritems(haved) if k in wantd or not wantd + } + wantd = {} + + # remove superfluous config for overridden and deleted + if self.state in ["overridden", "deleted"]: + for k, have in iteritems(haved): + if k not in wantd: + self._compare(want={}, have=have) + + for k, want in iteritems(wantd): + self._compare(want=want, have=haved.pop(k, {})) + + def _compare(self, want, have): + """Leverages the base class `compare()` method and + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Vrf_global network resource. + """ + self.compare(parsers=self.parsers, want=want, have=have) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/__init__.py b/plugins/module_utils/network/nxos/facts/vrf_global/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py new file mode 100644 index 000000000..5439efd89 --- /dev/null +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +""" +The nxos vrf_global fact class +It is in this file the configuration is collected from the device +for a given resource, parsed, and the facts tree is populated +based on the configuration. +""" + +from copy import deepcopy + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( + utils, +) +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( + Vrf_globalTemplate, +) +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( + Vrf_globalArgs, +) + +class Vrf_globalFacts(object): + """ The nxos vrf_global facts class + """ + + def __init__(self, module, subspec='config', options='options'): + self._module = module + self.argument_spec = Vrf_globalArgs.argument_spec + + def populate_facts(self, connection, ansible_facts, data=None): + """ Populate the facts for Vrf_global network resource + + :param connection: the device connection + :param ansible_facts: Facts dictionary + :param data: previously collected conf + + :rtype: dictionary + :returns: facts + """ + facts = {} + objs = [] + + if not data: + data = connection.get() + + # parse native config using the Vrf_global template + vrf_global_parser = Vrf_globalTemplate(lines=data.splitlines(), module=self._module) + objs = list(vrf_global_parser.parse().values()) + + ansible_facts['ansible_network_resources'].pop('vrf_global', None) + + params = utils.remove_empties( + vrf_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) + ) + + facts['vrf_global'] = params['config'] + ansible_facts['ansible_network_resources'].update(facts) + + return ansible_facts diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py new file mode 100644 index 000000000..1056f434e --- /dev/null +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +""" +The Vrf_global parser templates file. This contains +a list of parser definitions and associated functions that +facilitates both facts gathering and native command generation for +the given network resource. +""" + +import re +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( + NetworkTemplate, +) + +class Vrf_globalTemplate(NetworkTemplate): + def __init__(self, lines=None, module=None): + super(Vrf_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) + + # fmt: off + PARSERS = [ + { + "name": "key_a", + "getval": re.compile( + r""" + ^key_a\s(?P\S+) + $""", re.VERBOSE), + "setval": "", + "result": { + }, + "shared": True + }, + { + "name": "key_b", + "getval": re.compile( + r""" + \s+key_b\s(?P\S+) + $""", re.VERBOSE), + "setval": "", + "result": { + }, + }, + ] + # fmt: on diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py new file mode 100644 index 000000000..b75aed884 --- /dev/null +++ b/plugins/modules/nxos_vrf_global.py @@ -0,0 +1,411 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2024 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +The module file for nxos_vrf_global +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = """ +module: nxos_vrf_global +short_description: Resource module to configure VRF definitions. +description: This module provides declarative management of VRF definitions on Cisco NXOS. +version_added: 8.1.0 +author: Vinay Mulugund (@roverflow) +notes: + - Tested against NX-OS 9.3.6. + - This module works with connection C(network_cli) and C(httpapi). + See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_nxos.html) +options: + config: + description: A list containing device configurations for VRF. + type: dict + suboptions: + vrfs: + description: List of VRF definitions. + type: list + elements: dict + suboptions: + name: + description: Name of the VRF.. + required: true + type: str + description: + description: Description of the VRF. + type: str + ip: + description: Configure IP features for the specified vrf. + type: dict + suboptions: + auto_discard: + description: Auto 0.0.0.0/0 discard route. + type: bool + domain_list: + description: Add list domain names. + type: list + elements: str + domain_name: + description: Specify default domain name. + type: str + icmp_err: + description: Enable ICMP error message. + type: dict + suboptions: + source_interace: + description: Configure source-address for applications. + type: dict + suboptions: + interface: + description: Source interface for ICMP error messages. + type: str + choices: + - loopback + - ethernet + - port-channel + interface_value: + description: Source interface value for ICMP error messages. + type: str + igmp: + description: IGMP global configuration commands + type: dict + suboptions: + ssm_translate: + description: Translate IGMPv1/v2 reports to (S,G) route entries. + type: list + elements: dict + suboptions: + group: + description: Source address. + type: str + source: + description: Group address. + type: str + mroutes: + description: Configure multicast routes. + type: list + elements: dict + suboptions: + group: + description: Multicast group address. + type: str + source: + description: Source address. + type: str + preference: + description: Preference value. + type: int + vrf: + description: VRF name. + type: str + multicast: + description: Configure IP multicast global parameters. + type: dict + suboptions: + group_range_prefix_list: + description: Group range prefix-list policy for multicast boundary. + type: str + multipath: + description: Configure ECMP multicast load splitting. + type: dict + suboptions: + resilient: + description: Configure resilient RPF interface. + type: bool + splitting_type: + description: Configure multicast load splitting type. + type: dict + mutually_exclusive: + [ + [ + "legacy", + "nbm", + "none", + "sg_hash", + "sg_hash_next_hop", + ], + ] + suboptions: + none: + description: Disable multicast load splitting. + type: bool + sg_hash: + description: Configure hash based on source and group address. + type: bool + sg_hash_next_hop: + description: Configure hash based on source and group address and next-hop. + type: bool + rpf: + description: Configure RPF check. + type: list + elements: dict + suboptions: + vrf_name: + description: VRF for RPF lookup. + type: str + group_list_range: + description: Group range for RPF select. + type: str + name_server: + description: Specify nameserver address. + type: dict + suboptions: + address_list: + description: Configure multicast name server address. + type: list + elements: str + use_vrf: + description: Display per-VRF information. + type: dict + suboptions: + vrf: + description: VRF name. + type: str + source_address: + description: source address for configuring name server. + type: str + route: + description: Configure static routes. + type: list + elements: dict + mutually_exclusive: [["tags", "vrf", "track"]] + suboptions: + source: + description: Destination prefix. + type: str + destination: + description: Next-hop address. + type: str + tags: + description: Route tag. + type: dict + suboptions: + tag_value: + description: Route tag value. + type: int + route_pref: + description: Route preference. + type: int + vrf: + description: add vrf to the route. + type: str + track: + description: Configure track object. + type: str + vni: + description: Virtual Network Identifier. + type: dict + suboptions: + vni_number: + description: VNI number. + type: int + layer_3: + description: Configure Layer 3 VNI. + type: bool + multicast: + description: Configure IP multicast options. + type: dict + suboptions: + service_reflect: + description: Configure service reflect option. + type: list + elements: dict + suboptions: + service_interface: + description: configure service interface. + type: dict + suboptions: + interface: + description: Interface name. + type: str + interface_value: + description: Interface value / Regex. + type: str + map_to: + description: Map to interface. + type: dict + suboptions: + interface: + description: Interface name. + type: str + interface_value: + description: Interface value / Regex. + type: str + ipv6: + description: Configure IPv6 features for the specified vrf. + type: dict + suboptions: + mld_ssm_translate: + description: Translate MLDv1/v2 reports to (S,G) route entries. + type: list + elements: dict + suboptions: + icmp: + description: Configure ICMP parameters with mld. + type: bool + group: + description: Source address. + type: str + source: + description: Group address. + type: str + multicast: + description: Configure IP multicast global parameters for ipv6. + type: dict + suboptions: + group_range_prefix_list: + description: Group range prefix-list policy for multicast boundary. + type: str + multipath: + description: Configure ECMP multicast load splitting. + type: dict + suboptions: + resilient: + description: Configure resilient RPF interface. + type: bool + splitting_type: + description: Configure multicast load splitting type. + type: dict + mutually_exclusive: + [["none", "sg_hash", "sg_hash_next_hop"]] + suboptions: + none: + description: Disable multicast load splitting. + type: bool + sg_hash: + description: Configure hash based on source and group address. + type: bool + sg_hash_next_hop: + description: Configure hash based on source and group address and next-hop. + type: bool + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the NX-OS device + by executing the command B(show running-config | section ^vrf). + - The state I(parsed) reads the configuration from C(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 I(parsed) key within the result. + type: str + state: + choices: + [ + parsed, + gathered, + deleted, + merged, + replaced, + rendered, + overridden, + purged, + ] + default: merged + description: + - The state the configuration should be left in + - The states I(rendered), I(gathered) and I(parsed) does not perform any change + on the device. + - The state I(rendered) will transform the configuration in C(config) option to + platform specific CLI commands which will be returned in the I(rendered) key + within the result. For state I(rendered) active connection to remote host is + not required. + - The state I(gathered) will fetch the running configuration from device and transform + it into structured data in the format as per the resource module argspec and + the value is returned in the I(gathered) key within the result. + - The state I(parsed) reads the configuration from C(running_config) option and + transforms it into JSON format as per the resource module parameters and the + value is returned in the I(parsed) key within the result. The value of C(running_config) + option should be the same format as the output of command I(show running-config | section ^vrf). + connection to remote host is not required. + type: str +""" + +EXAMPLES = """ + +""" + +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) + type: list + sample: + - sample command 1 + - sample command 2 + - sample command 3 +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when I(state) is C(rendered) + type: list + sample: + - sample command 1 + - sample command 2 + - sample command 3 +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when I(state) is C(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when I(state) is C(parsed) + type: list + sample: > + This output will always be in the same format as the + module argspec. +""" + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( + Vrf_globalArgs, +) +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.config.vrf_global.vrf_global import ( + Vrf_global, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + module = AnsibleModule( + argument_spec=Vrf_globalArgs.argument_spec, + mutually_exclusive=[["config", "running_config"]], + required_if=[ + ["state", "merged", ["config"]], + ["state", "replaced", ["config"]], + ["state", "overridden", ["config"]], + ["state", "rendered", ["config"]], + ["state", "parsed", ["running_config"]], + ], + supports_check_mode=True, + ) + + result = Vrf_global(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/plugins/plugin_utils/__init__.py b/plugins/plugin_utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/test/__init__.py b/plugins/test/__init__.py new file mode 100644 index 000000000..e69de29bb From 91fc875de7ac55b8963257a50768f6dc821542c2 Mon Sep 17 00:00:00 2001 From: Vinay Mulugund Date: Wed, 19 Jun 2024 11:48:02 +0530 Subject: [PATCH 02/46] added parsers --- changelogs/fragments/nxos_vrf_global.yml | 3 + meta/runtime.yml | 2 + plugins/action/vrf_global.py | 1 + plugins/cache/__init__.py | 0 plugins/module_utils/common/__init__.py | 0 .../nxos/argspec/vrf_global/vrf_global.py | 4 +- .../module_utils/network/nxos/facts/facts.py | 5 + .../nxos/facts/vrf_global/vrf_global.py | 15 +- .../network/nxos/rm_templates/vrf_global.py | 410 +++++++++++++++++- plugins/modules/nxos_vrf_global.py | 12 +- plugins/test/__init__.py | 0 11 files changed, 438 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/nxos_vrf_global.yml create mode 120000 plugins/action/vrf_global.py delete mode 100644 plugins/cache/__init__.py delete mode 100644 plugins/module_utils/common/__init__.py delete mode 100644 plugins/test/__init__.py diff --git a/changelogs/fragments/nxos_vrf_global.yml b/changelogs/fragments/nxos_vrf_global.yml new file mode 100644 index 000000000..21cdf5e64 --- /dev/null +++ b/changelogs/fragments/nxos_vrf_global.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Add nxos_vrf_global resource module in favor of nxos_vrf module. diff --git a/meta/runtime.yml b/meta/runtime.yml index 381752a06..ca5c3e69f 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -200,3 +200,5 @@ plugin_routing: redirect: cisco.nxos.nxos_vxlan_vtep_vni zone_zoneset: redirect: cisco.nxos.nxos_zone_zoneset + vrf_global: + redirect: cisco.nxos.nxos_vrf_global diff --git a/plugins/action/vrf_global.py b/plugins/action/vrf_global.py new file mode 120000 index 000000000..a69e27103 --- /dev/null +++ b/plugins/action/vrf_global.py @@ -0,0 +1 @@ +nxos.py \ No newline at end of file diff --git a/plugins/cache/__init__.py b/plugins/cache/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/module_utils/common/__init__.py b/plugins/module_utils/common/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py index f62044372..1d3336e5b 100644 --- a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py @@ -51,7 +51,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "icmp_err": { "type": "dict", "options": { - "source_interace": { + "source_interface": { "type": "dict", "options": { "interface": { @@ -111,6 +111,8 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 ], "options": { "none": {"type": "bool"}, + "legacy": {"type": "bool"}, + "nbm": {"type": "bool"}, "sg_hash": { "type": "bool" }, diff --git a/plugins/module_utils/network/nxos/facts/facts.py b/plugins/module_utils/network/nxos/facts/facts.py index a7c2ab350..7806a4e94 100644 --- a/plugins/module_utils/network/nxos/facts/facts.py +++ b/plugins/module_utils/network/nxos/facts/facts.py @@ -112,6 +112,10 @@ VlansFacts, ) +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vrf_global.vrf_global import ( + Vrf_globalFacts, +) + FACT_LEGACY_SUBSETS = dict( default=Default, @@ -150,6 +154,7 @@ snmp_server=Snmp_serverFacts, hostname=HostnameFacts, bgp_templates=Bgp_templatesFacts, + vrf_global=Vrf_globalFacts, ) MDS_FACT_RESOURCE_SUBSETS = dict( fc_interfaces=Fc_interfacesFacts, diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index 5439efd89..e056663fa 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -20,10 +20,10 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( utils, ) -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( Vrf_globalTemplate, ) -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( Vrf_globalArgs, ) @@ -35,6 +35,11 @@ def __init__(self, module, subspec='config', options='options'): self._module = module self.argument_spec = Vrf_globalArgs.argument_spec + def get_config(self, connection): + """Get the configuration from the device""" + + return connection.get("show running-config | section ^vrf") + def populate_facts(self, connection, ansible_facts, data=None): """ Populate the facts for Vrf_global network resource @@ -49,19 +54,21 @@ def populate_facts(self, connection, ansible_facts, data=None): objs = [] if not data: - data = connection.get() + data = self.get_config(connection) # parse native config using the Vrf_global template vrf_global_parser = Vrf_globalTemplate(lines=data.splitlines(), module=self._module) objs = list(vrf_global_parser.parse().values()) + objs["vrfs"] = list(objs["vrfs"].values()) if "vrfs" in objs else [] + ansible_facts['ansible_network_resources'].pop('vrf_global', None) params = utils.remove_empties( vrf_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) ) - facts['vrf_global'] = params['config'] + facts['vrf_global'] = params.get("config", {}) ansible_facts['ansible_network_resources'].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 1056f434e..eedcd12fc 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -19,6 +19,9 @@ NetworkTemplate, ) +def name_server_addr_list(lines, tmplt): + pass + class Vrf_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): super(Vrf_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) @@ -26,24 +29,419 @@ def __init__(self, lines=None, module=None): # fmt: off PARSERS = [ { - "name": "key_a", + "name": "name", "getval": re.compile( r""" - ^key_a\s(?P\S+) + ^vrf\scontext\s(?P\S+) $""", re.VERBOSE), - "setval": "", + "setval": "vrf context {{ name }}", "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + }, + }, }, "shared": True }, { - "name": "key_b", + "name": "description", + "getval": re.compile( + r""" + \s+description\s(?P.+$) + $""", re.VERBOSE), + "setval": "description {{ description }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + 'description': '{{ description }}', + }, + }, + }, + }, + { + "name": "ip.auto_discard", + "getval": re.compile( + r""" + \s+ip\s(?Pauto-discard) + $""", re.VERBOSE), + "setval": "ip auto-discard", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "auto_discard": "{{ true if auto_disc is defined }}", + }, + }, + }, + }, + }, + { + "name": "ip.domain_list", + "getval": re.compile( + r""" + \s+ip\sdomain-list\s(?P\S+) + $""", re.VERBOSE), + "setval": "ip domain-list {{ domain_list }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "domain_list": [ + "{{ domain_list }}" + ], + }, + }, + }, + }, + }, + { + "name": "ip.domain_name", + "getval": re.compile( + r""" + \s+ip\sdomain-name\s(?P\S+) + $""", re.VERBOSE), + "setval": "ip domain-name {{ ip.domain_name }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "domain_name": "{{ domain_name }}", + }, + }, + }, + }, + }, + { + "name": "ip.icmp_err.source_interface", + "getval": re.compile( + r""" + \s+ip\sicmp-errors + \ssource-interface\s(?Peth|po|lo) + (?P(\d+\S*)) + $""", re.VERBOSE), + "setval": "ip icmp-errors source-interface {{ interface }} {{ interface_value }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "icmp_err": { + "source_interface": { + "interface": "{{ 'ethernet' if 'eth' in interface }}" + "{{ 'port-channel' if 'po' in interface }}" + "{{ 'loopback' if 'lo' in interface }}", + "interface_value": "{{ interface_val }}", + } + }, + }, + }, + }, + }, + }, + { + "name": "ip.igmp.ssm_translate", + "getval": re.compile( + r""" + \s+ip\sigmp + \sssm-translate + \s(?P\S+) + \s(?P\S+) + $""", re.VERBOSE), + "setval": "ip igmp ssm-translate {{ group }} {{ source }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "igmp": { + "ssm_translate": { + "group": "{{ group_val }}", + "source": "{{ source_val }}", + } + }, + }, + }, + }, + }, + }, + { + "name": "ip.mroutes", + "getval": re.compile( + r""" + \s+ip\smroute + \s(?P\S+) + \s(?P\S+) + (\s(?P\d+))? + (\svrf\s(?P\S+))? + $""", re.VERBOSE), + "setval": "ip mroute {{ group }} {{ source }}" + "{{ ' ' + preference if preference is defined }}" + "{{ ' vrf ' + vrf if vrf is defined }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "mroutes": [ + { + "group": "{{ group_val }}", + "source": "{{ source_val }}", + "preference": "{{ pref_val if pref_val is defined }}", + "vrf": "{{ vrf_val if vrf_val is defined }}", + } + ], + }, + }, + }, + }, + }, + { + "name": "ip.multicast.group_range_prefix_list", + "getval": re.compile( + r""" + \s+ip\smulticast + \sprefix-list\s(?P\S+) + $""", re.VERBOSE), + "setval": "ip multicast group-range prefix-list {{ group_range_prefix_list }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "group_range_prefix_list": "{{ prefix_lst }}", + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.resilient", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath\s(?Presilient) + $""", re.VERBOSE), + "setval": "ip multicast multipath resilient", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "resilient": "{{ true if res is defined }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.splitting_type.none", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath\s(?Pnone) + $""", re.VERBOSE), + "setval": "ip multicast multipath none", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "splitting_type": { + "none": "{{ true if noneval is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.splitting_type.legacy", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath\s(?Plegacy) + $""", re.VERBOSE), + "setval": "ip multicast multipath legacy", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "splitting_type": { + "legacy": "{{ true if legacy_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.splitting_type.nbm", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath\s(?Pnbm) + $""", re.VERBOSE), + "setval": "ip multicast multipath nbm", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "splitting_type": { + "nbm": "{{ true if nbm_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.splitting_type.sg_hash", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath\s(?Ps-g-hash) + $""", re.VERBOSE), + "setval": "ip multicast multipath s-g-hash", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "splitting_type": { + "sg_hash": "{{ true if sg_hash_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.multipath.splitting_type.sg_hash_next_hop", + "getval": re.compile( + r""" + \s+ip\smulticast + \smultipath + \s(?Ps-g-hash\snext-hop-based) + $""", re.VERBOSE), + "setval": "ip multicast multipath s-g-hash next-hop-based", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "multipath": { + "splitting_type": { + "sg_hash_next_hop": "{{ true if sg_hash_nxt_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ip.multicast.rpf", + "getval": re.compile( + r""" + \s+ip\smulticast + \srpf\sselect + \svrf\s(?P\S+) + \sgroup-list\s(?P\S+) + $""", re.VERBOSE), + "setval": "ip multicast rpf select vrf {{ vrf_name }} group-list {{ group_list_range }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "multicast": { + "rpf": [ + { + "vrf_name": "{{ vrf_val }}", + "group_list_range": "{{ group_list }}", + } + ], + }, + }, + }, + }, + }, + }, + { + "name": "ip.name_server.address_list", + "getval": re.compile( + r""" + \s+ip\sname-server + \s(?P.+$) + $""", re.VERBOSE), + "setval": name_server_addr_list, + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "name_server": { + "address_list": "{{ addr_list }}", + }, + }, + }, + }, + }, + }, + { + "name": "ip.name_server.use_vrf", "getval": re.compile( r""" - \s+key_b\s(?P\S+) + \s+ip\sname-server + \s(?P\S+) + \suse-vrf\s(?P\S+) $""", re.VERBOSE), - "setval": "", + "setval": "ip name-server {{ source_address }} use-vrf {{ vrf }}", "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "name_server": { + "use_vrf": { + "source_address": "{{ source_addr }}", + "vrf": "{{ vrf_name }}", + }, + }, + }, + }, + }, }, }, ] diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index b75aed884..3af4fdcdf 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -57,7 +57,7 @@ description: Enable ICMP error message. type: dict suboptions: - source_interace: + source_interface: description: Configure source-address for applications. type: dict suboptions: @@ -134,6 +134,12 @@ none: description: Disable multicast load splitting. type: bool + legacy: + description: Configure hash based on source and group. + type: bool + nbm: + description: Configure NBM controlled RPF interface. + type: bool sg_hash: description: Configure hash based on source and group address. type: bool @@ -376,10 +382,10 @@ """ from ansible.module_utils.basic import AnsibleModule -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( Vrf_globalArgs, ) -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.config.vrf_global.vrf_global import ( +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vrf_global.vrf_global import ( Vrf_global, ) diff --git a/plugins/test/__init__.py b/plugins/test/__init__.py deleted file mode 100644 index e69de29bb..000000000 From df5ca2c5f208451e312a0efceda7f17ac1897def Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 06:19:55 +0000 Subject: [PATCH 03/46] chore: auto fixes from pre-commit.com hooks --- README.md | 1 + .../nxos/argspec/vrf_global/vrf_global.py | 28 ++++---- .../nxos/config/vrf_global/vrf_global.py | 33 ++++----- .../module_utils/network/nxos/facts/facts.py | 1 - .../nxos/facts/vrf_global/vrf_global.py | 26 +++---- .../network/nxos/rm_templates/vrf_global.py | 70 ++++++++++++------- plugins/modules/nxos_vrf_global.py | 2 + 7 files changed, 91 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 83f287673..7d1242aa4 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Name | Description [cisco.nxos.nxos_vpc_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vpc_interface_module.rst)|Manages interface VPC configuration [cisco.nxos.nxos_vrf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_module.rst)|Manages global VRF configuration. [cisco.nxos.nxos_vrf_af](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_af_module.rst)|Manages VRF AF. +[cisco.nxos.nxos_vrf_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_global_module.rst)|Resource module to configure VRF definitions. [cisco.nxos.nxos_vrf_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_interface_module.rst)|Manages interface specific VRF configuration. [cisco.nxos.nxos_vrrp](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrrp_module.rst)|Manages VRRP configuration on NX-OS switches. [cisco.nxos.nxos_vsan](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vsan_module.rst)|Configuration of vsan for Cisco NXOS MDS Switches. diff --git a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py index 1d3336e5b..69d68850b 100644 --- a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type ############################################# @@ -29,8 +30,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 - """The arg spec for the nxos_vrf_global module - """ + """The arg spec for the nxos_vrf_global module""" argument_spec = { "config": { @@ -64,7 +64,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 }, "interface_value": {"type": "str"}, }, - } + }, }, }, "igmp": { @@ -77,7 +77,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "group": {"type": "str"}, "source": {"type": "str"}, }, - } + }, }, }, "mroutes": { @@ -107,17 +107,17 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "none", "sg_hash", "sg_hash_next_hop", - ] + ], ], "options": { "none": {"type": "bool"}, "legacy": {"type": "bool"}, "nbm": {"type": "bool"}, "sg_hash": { - "type": "bool" + "type": "bool", }, "sg_hash_next_hop": { - "type": "bool" + "type": "bool", }, }, }, @@ -129,7 +129,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "options": { "vrf_name": {"type": "str"}, "group_list_range": { - "type": "str" + "type": "str", }, }, }, @@ -155,7 +155,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "type": "list", "elements": "dict", "mutually_exclusive": [ - ["tags", "vrf", "track"] + ["tags", "vrf", "track"], ], "options": { "source": {"type": "str"}, @@ -202,7 +202,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 }, }, }, - } + }, }, }, "ipv6": { @@ -232,15 +232,15 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "none", "sg_hash", "sg_hash_next_hop", - ] + ], ], "options": { "none": {"type": "bool"}, "sg_hash": { - "type": "bool" + "type": "bool", }, "sg_hash_next_hop": { - "type": "bool" + "type": "bool", }, }, }, @@ -251,7 +251,7 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 }, }, }, - } + }, }, }, "running_config": {"type": "str"}, diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 5708e37a2..c205672a9 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -20,15 +21,14 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - dict_merge, -) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.facts.facts import ( - Facts, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, ) + +from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.facts.facts import Facts from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( Vrf_globalTemplate, ) @@ -47,11 +47,10 @@ def __init__(self, module): resource="vrf_global", tmplt=Vrf_globalTemplate(), ) - self.parsers = [ - ] + self.parsers = [] def execute_module(self): - """ Execute the module + """Execute the module :rtype: A dictionary :returns: The result from module execution @@ -62,11 +61,11 @@ def execute_module(self): return self.result def generate_commands(self): - """ Generate configuration commands to send based on - want, have and desired state. + """Generate configuration commands to send based on + want, have and desired state. """ - wantd = {entry['name']: entry for entry in self.want} - haved = {entry['name']: entry for entry in self.have} + wantd = {entry["name"]: entry for entry in self.want} + haved = {entry["name"]: entry for entry in self.have} # if state is merged, merge want onto have and then compare if self.state == "merged": @@ -74,9 +73,7 @@ def generate_commands(self): # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": - haved = { - k: v for k, v in iteritems(haved) if k in wantd or not wantd - } + haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd} wantd = {} # remove superfluous config for overridden and deleted @@ -90,8 +87,8 @@ def generate_commands(self): def _compare(self, want, have): """Leverages the base class `compare()` method and - populates the list of commands to be run by comparing - the `want` and `have` data with the `parsers` defined - for the Vrf_global network resource. + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Vrf_global network resource. """ self.compare(parsers=self.parsers, want=want, have=have) diff --git a/plugins/module_utils/network/nxos/facts/facts.py b/plugins/module_utils/network/nxos/facts/facts.py index 7806a4e94..4d1e38f92 100644 --- a/plugins/module_utils/network/nxos/facts/facts.py +++ b/plugins/module_utils/network/nxos/facts/facts.py @@ -111,7 +111,6 @@ from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vlans.vlans import ( VlansFacts, ) - from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vrf_global.vrf_global import ( Vrf_globalFacts, ) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index e056663fa..8a0ac0ce2 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -17,21 +18,20 @@ from copy import deepcopy from ansible.module_utils.six import iteritems -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( - utils, +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils + +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( + Vrf_globalArgs, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( Vrf_globalTemplate, ) -from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( - Vrf_globalArgs, -) + class Vrf_globalFacts(object): - """ The nxos vrf_global facts class - """ + """The nxos vrf_global facts class""" - def __init__(self, module, subspec='config', options='options'): + def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Vrf_globalArgs.argument_spec @@ -41,7 +41,7 @@ def get_config(self, connection): return connection.get("show running-config | section ^vrf") def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for Vrf_global network resource + """Populate the facts for Vrf_global network resource :param connection: the device connection :param ansible_facts: Facts dictionary @@ -62,13 +62,13 @@ def populate_facts(self, connection, ansible_facts, data=None): objs["vrfs"] = list(objs["vrfs"].values()) if "vrfs" in objs else [] - ansible_facts['ansible_network_resources'].pop('vrf_global', None) + ansible_facts["ansible_network_resources"].pop("vrf_global", None) params = utils.remove_empties( - vrf_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True) + vrf_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) - facts['vrf_global'] = params.get("config", {}) - ansible_facts['ansible_network_resources'].update(facts) + facts["vrf_global"] = params.get("config", {}) + ansible_facts["ansible_network_resources"].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index eedcd12fc..65e3c8e7a 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type """ @@ -15,13 +16,16 @@ """ import re + from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) + def name_server_addr_list(lines, tmplt): pass + class Vrf_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): super(Vrf_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) @@ -33,7 +37,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" ^vrf\scontext\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "vrf context {{ name }}", "result": { "vrfs": { @@ -42,14 +47,15 @@ def __init__(self, lines=None, module=None): }, }, }, - "shared": True + "shared": True, }, { "name": "description", "getval": re.compile( r""" \s+description\s(?P.+$) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "description {{ description }}", "result": { "vrfs": { @@ -65,7 +71,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+ip\s(?Pauto-discard) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip auto-discard", "result": { "vrfs": { @@ -83,7 +90,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+ip\sdomain-list\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip domain-list {{ domain_list }}", "result": { "vrfs": { @@ -91,7 +99,7 @@ def __init__(self, lines=None, module=None): 'name': '{{ name }}', "ip" : { "domain_list": [ - "{{ domain_list }}" + "{{ domain_list }}", ], }, }, @@ -103,7 +111,8 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+ip\sdomain-name\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip domain-name {{ ip.domain_name }}", "result": { "vrfs": { @@ -123,7 +132,8 @@ def __init__(self, lines=None, module=None): \s+ip\sicmp-errors \ssource-interface\s(?Peth|po|lo) (?P(\d+\S*)) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip icmp-errors source-interface {{ interface }} {{ interface_value }}", "result": { "vrfs": { @@ -136,7 +146,7 @@ def __init__(self, lines=None, module=None): "{{ 'port-channel' if 'po' in interface }}" "{{ 'loopback' if 'lo' in interface }}", "interface_value": "{{ interface_val }}", - } + }, }, }, }, @@ -151,7 +161,8 @@ def __init__(self, lines=None, module=None): \sssm-translate \s(?P\S+) \s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip igmp ssm-translate {{ group }} {{ source }}", "result": { "vrfs": { @@ -162,7 +173,7 @@ def __init__(self, lines=None, module=None): "ssm_translate": { "group": "{{ group_val }}", "source": "{{ source_val }}", - } + }, }, }, }, @@ -178,7 +189,8 @@ def __init__(self, lines=None, module=None): \s(?P\S+) (\s(?P\d+))? (\svrf\s(?P\S+))? - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip mroute {{ group }} {{ source }}" "{{ ' ' + preference if preference is defined }}" "{{ ' vrf ' + vrf if vrf is defined }}", @@ -193,7 +205,7 @@ def __init__(self, lines=None, module=None): "source": "{{ source_val }}", "preference": "{{ pref_val if pref_val is defined }}", "vrf": "{{ vrf_val if vrf_val is defined }}", - } + }, ], }, }, @@ -206,7 +218,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \sprefix-list\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast group-range prefix-list {{ group_range_prefix_list }}", "result": { "vrfs": { @@ -227,7 +240,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \smultipath\s(?Presilient) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath resilient", "result": { "vrfs": { @@ -250,7 +264,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \smultipath\s(?Pnone) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath none", "result": { "vrfs": { @@ -275,7 +290,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \smultipath\s(?Plegacy) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath legacy", "result": { "vrfs": { @@ -300,7 +316,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \smultipath\s(?Pnbm) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath nbm", "result": { "vrfs": { @@ -325,7 +342,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\smulticast \smultipath\s(?Ps-g-hash) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath s-g-hash", "result": { "vrfs": { @@ -351,7 +369,8 @@ def __init__(self, lines=None, module=None): \s+ip\smulticast \smultipath \s(?Ps-g-hash\snext-hop-based) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast multipath s-g-hash next-hop-based", "result": { "vrfs": { @@ -378,7 +397,8 @@ def __init__(self, lines=None, module=None): \srpf\sselect \svrf\s(?P\S+) \sgroup-list\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip multicast rpf select vrf {{ vrf_name }} group-list {{ group_list_range }}", "result": { "vrfs": { @@ -390,7 +410,7 @@ def __init__(self, lines=None, module=None): { "vrf_name": "{{ vrf_val }}", "group_list_range": "{{ group_list }}", - } + }, ], }, }, @@ -404,7 +424,8 @@ def __init__(self, lines=None, module=None): r""" \s+ip\sname-server \s(?P.+$) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": name_server_addr_list, "result": { "vrfs": { @@ -426,7 +447,8 @@ def __init__(self, lines=None, module=None): \s+ip\sname-server \s(?P\S+) \suse-vrf\s(?P\S+) - $""", re.VERBOSE), + $""", re.VERBOSE, + ), "setval": "ip name-server {{ source_address }} use-vrf {{ vrf }}", "result": { "vrfs": { diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index 3af4fdcdf..ea8c7d0ae 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -10,6 +10,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = """ @@ -382,6 +383,7 @@ """ from ansible.module_utils.basic import AnsibleModule + from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( Vrf_globalArgs, ) From 7a5ce68a6574d145c55aef350ccb93cb5e6aa130 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 24 Jun 2024 08:39:57 +0530 Subject: [PATCH 04/46] add final parsers --- .../network/nxos/rm_templates/vrf_global.py | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 65e3c8e7a..7058931e1 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -466,5 +466,142 @@ def __init__(self, lines=None, module=None): }, }, }, + { + "name": "ip.route", + "getval": re.compile( + r""" + \s+ip\sroute + \s(?P\S+) + \s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "route": [ + { + "source": "{{ src_val }}", + "destination": "{{ dest_val }}", + }, + ], + }, + }, + }, + }, + }, + { + "name": "ip.route.tags", + "getval": re.compile( + r""" + \s+ip\sroute + \s(?P\S+) + \s(?P\S+) + \stag\s(?P\d+) + (\s(?P\d+))? + $""", re.VERBOSE, + ), + "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} tag {{ tag }}" + "{{ ' ' + route_pref if route_pref is defined }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "route": [ + { + "source": "{{ src_val }}", + "destination": "{{ dest_val }}", + "tags": { + "tag_value": "{{ tag_val }}", + "route_pref": "{{ route_pref_val if route_pref_val is defined }}", + } + + }, + ], + }, + }, + }, + }, + }, + { + "name": "ip.route.vrf", + "getval": re.compile( + r""" + \s+ip\sroute + \s(?P\S+) + \s(?P\S+) + \svrf\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} vrf {{ vrf }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "route": [ + { + "source": "{{ src_val }}", + "destination": "{{ dest_val }}", + "vrf": "{{ vrf_val }}", + }, + ], + }, + }, + }, + }, + }, + { + "name": "ip.route.track", + "getval": re.compile( + r""" + \s+ip\sroute + \s(?P\S+) + \s(?P\S+) + \strack\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} vrf {{ vrf }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ip" : { + "route": [ + { + "source": "{{ src_val }}", + "destination": "{{ dest_val }}", + "track": "{{ track_val }}", + }, + ], + }, + }, + }, + }, + }, + { + "name": "vni", + "getval": re.compile( + r""" + \s+vni\s(?P\d+) + (\s(?Pl3))? + $""", re.VERBOSE, + ), + "setval": "vni {{ vni }} {{ 'l3' if l3 is defined }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "vni": { + "vni_number": "{{ vni_val }}", + "l3": "{{ true if l3_val is defined }}", + }, + }, + }, + }, + } ] # fmt: on From 49cbdb5510cae9312c144d44a977d2cafffe61cc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 03:10:48 +0000 Subject: [PATCH 05/46] chore: auto fixes from pre-commit.com hooks --- .../module_utils/network/nxos/rm_templates/vrf_global.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 7058931e1..780c01166 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -517,8 +517,8 @@ def __init__(self, lines=None, module=None): "tags": { "tag_value": "{{ tag_val }}", "route_pref": "{{ route_pref_val if route_pref_val is defined }}", - } - + }, + }, ], }, @@ -602,6 +602,6 @@ def __init__(self, lines=None, module=None): }, }, }, - } + }, ] # fmt: on From e0d7acc57b75afa562bd88883b68a96efe9676bb Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 24 Jun 2024 17:35:41 +0530 Subject: [PATCH 06/46] minor changes in parser --- plugins/module_utils/network/nxos/rm_templates/vrf_global.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 780c01166..1ef974f63 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -590,14 +590,14 @@ def __init__(self, lines=None, module=None): (\s(?Pl3))? $""", re.VERBOSE, ), - "setval": "vni {{ vni }} {{ 'l3' if l3 is defined }}", + "setval": "vni {{ vni_number }} {{ 'l3' if layer_3 is defined }}", "result": { "vrfs": { '{{ name }}': { 'name': '{{ name }}', "vni": { "vni_number": "{{ vni_val }}", - "l3": "{{ true if l3_val is defined }}", + "layer_3": "{{ true if l3_val is defined }}", }, }, }, From 96c5f9edfc4e50fb12cbe9f8a18e9558788352bd Mon Sep 17 00:00:00 2001 From: roverflow Date: Tue, 25 Jun 2024 18:13:03 +0530 Subject: [PATCH 07/46] fixed parsers for ssm_translate --- .../network/nxos/config/vrf_global/vrf_global.py | 4 ++-- .../network/nxos/facts/vrf_global/vrf_global.py | 8 ++++++-- .../network/nxos/rm_templates/vrf_global.py | 12 +++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index c205672a9..ba21136e5 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -28,8 +28,8 @@ dict_merge, ) -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.facts.facts import Facts -from ansible_collections.cisco.nxos.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts +from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.vrf_global import ( Vrf_globalTemplate, ) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index 8a0ac0ce2..b20251ebd 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -28,6 +28,10 @@ ) +import debugpy +debugpy.listen(3000) +debugpy.wait_for_client() + class Vrf_globalFacts(object): """The nxos vrf_global facts class""" @@ -58,9 +62,9 @@ def populate_facts(self, connection, ansible_facts, data=None): # parse native config using the Vrf_global template vrf_global_parser = Vrf_globalTemplate(lines=data.splitlines(), module=self._module) - objs = list(vrf_global_parser.parse().values()) + objs = vrf_global_parser.parse() - objs["vrfs"] = list(objs["vrfs"].values()) if "vrfs" in objs else [] + objs["vrfs"] = list(objs.get("vrfs", {}).values()) if "vrfs" in objs else [] ansible_facts["ansible_network_resources"].pop("vrf_global", None) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 1ef974f63..849e1723b 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -170,10 +170,12 @@ def __init__(self, lines=None, module=None): 'name': '{{ name }}', "ip" : { "igmp": { - "ssm_translate": { - "group": "{{ group_val }}", - "source": "{{ source_val }}", - }, + "ssm_translate": [ + { + "group": "{{ group_val }}", + "source": "{{ source_val }}", + }, + ] }, }, }, @@ -590,7 +592,7 @@ def __init__(self, lines=None, module=None): (\s(?Pl3))? $""", re.VERBOSE, ), - "setval": "vni {{ vni_number }} {{ 'l3' if layer_3 is defined }}", + "setval": "vni {{ vni.vni_number }} {{ 'l3' if vni.layer_3 is defined }}", "result": { "vrfs": { '{{ name }}': { From a228bb82bb64a73dd05c5f842f75ff0a27d51c2f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 19:54:33 +0000 Subject: [PATCH 08/46] chore: auto fixes from pre-commit.com hooks --- .../module_utils/network/nxos/facts/vrf_global/vrf_global.py | 4 +++- plugins/module_utils/network/nxos/rm_templates/vrf_global.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index b20251ebd..c57719d99 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -17,6 +17,8 @@ from copy import deepcopy +import debugpy + from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils @@ -28,10 +30,10 @@ ) -import debugpy debugpy.listen(3000) debugpy.wait_for_client() + class Vrf_globalFacts(object): """The nxos vrf_global facts class""" diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 849e1723b..a99ea0f82 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -175,7 +175,7 @@ def __init__(self, lines=None, module=None): "group": "{{ group_val }}", "source": "{{ source_val }}", }, - ] + ], }, }, }, From 5faf758f8eddc89935e1165fd980d492b3acf45d Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 27 Jun 2024 13:32:34 +0530 Subject: [PATCH 09/46] fixed and added some parsers --- .../network/nxos/rm_templates/vrf_global.py | 182 +++++++++++++++++- 1 file changed, 181 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index a99ea0f82..1313201fd 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -175,7 +175,7 @@ def __init__(self, lines=None, module=None): "group": "{{ group_val }}", "source": "{{ source_val }}", }, - ], + ] }, }, }, @@ -605,5 +605,185 @@ def __init__(self, lines=None, module=None): }, }, }, + { + "name": "multicast.service_reflect", + "getval": re.compile( + r""" + \s+multicast\sservice-reflect + \sinterface\s(?P\S+) + \smap\sinterface\s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "multicast service-reflect interface {{ service_interface }} map interface {{ map_to }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "multicast": { + "service_reflect": [ + { + "service_interface": "{{ serv_inter }}", + "map_to": "{{ map_inter }}", + }, + ], + }, + }, + }, + }, + }, + { + "name": "ipv6.mld_ssm_translate", + "getval": re.compile( + r""" + \s+ipv6\smld + (\s(?Picmp))? + \sssm-translate + \s(?P\S+) + \s(?P\S+) + $""", re.VERBOSE, + ), + "getval": "ipv6 {{ 'icmp' if icmp is defined }} mld ssm-translate {{ group }} {{ source }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "mld_ssm_translate": [ + { + "icmp": "{{ true if icmp is defined }}", + "group": "{{ group_val }}", + "source": "{{ source_val }}", + }, + ], + }, + }, + }, + }, + }, + { + "name": "ipv6.multicast.group_range_prefix_list", + "getval": re.compile( + r""" + \s+ipv6\smulticast + \sgroup-range\sprefix-list + \s(?P\S+) + $""", re.VERBOSE, + ), + "setval": "ipv6 multicast group-range prefix-list {{ ipv6.multicast.group_range_prefix_list }}", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "multicast": { + "group_range_prefix_list": "{{ prefix_lst }}", + }, + }, + }, + }, + }, + }, + { + "name": "ipv6.multicast.multipath.resilient", + "getval": re.compile( + r""" + \s+ipv6\smulticast + \smultipath\s(?Presilient) + $""", re.VERBOSE, + ), + "setval": "ipv6 multicast multipath resilient", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "multicast": { + "multipath": { + "resilient": "{{ true if res_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + { + "name": "ipv6.multicast.multipath.splitting_type.none", + "getval": re.compile( + r""" + \s+ipv6\smulticast + \smultipath\s(?Pnone) + $""", re.VERBOSE, + ), + "setval": "ipv6 multicast multipath none", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "multicast": { + "multipath": { + "splitting_type": { + "none": "{{ true if none_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ipv6.multicast.multipath.splitting_type.sg_hash", + "getval": re.compile( + r""" + \s+ipv6\smulticast + \smultipath\s(?Ps-g-hash) + $""", re.VERBOSE, + ), + "setval": "ipv6 multicast multipath s-g-hash", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "multicast": { + "multipath": { + "splitting_type": { + "sg_hash": "{{ true if sg_hash_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, + { + "name": "ipv6.multicast.multipath.splitting_type.sg_hash_next_hop", + "getval": re.compile( + r""" + \s+ipv6\smulticast + \smultipath\s(?Psg-nexthop-hash) + $""", re.VERBOSE, + ), + "setval": "ipv6 multicast multipath sg-nexthop-hash", + "result": { + "vrfs": { + '{{ name }}': { + 'name': '{{ name }}', + "ipv6": { + "multicast": { + "multipath": { + "splitting_type": { + "sg_hash_next_hop": "{{ true if sg_hash_next_hop_val is defined }}", + }, + }, + }, + }, + }, + }, + }, + }, ] # fmt: on From 0678ca64fe02fb9f8e73bd26d4767808f11d661c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 08:05:52 +0000 Subject: [PATCH 10/46] chore: auto fixes from pre-commit.com hooks --- plugins/module_utils/network/nxos/rm_templates/vrf_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 1313201fd..2a7419f16 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -175,7 +175,7 @@ def __init__(self, lines=None, module=None): "group": "{{ group_val }}", "source": "{{ source_val }}", }, - ] + ], }, }, }, From 334a477ef444c82bfa00feba7cad7c5c8e57c46c Mon Sep 17 00:00:00 2001 From: roverflow Date: Wed, 10 Jul 2024 13:54:10 +0530 Subject: [PATCH 11/46] fixed wrong model issue --- .../nxos/argspec/vrf_global/vrf_global.py | 16 ++----------- .../nxos/config/vrf_global/vrf_global.py | 9 +++++++ .../nxos/facts/vrf_global/vrf_global.py | 24 ++++++++++++------- .../network/nxos/rm_templates/vrf_global.py | 24 +++++++++---------- plugins/modules/nxos_vrf_global.py | 18 ++------------ 5 files changed, 41 insertions(+), 50 deletions(-) diff --git a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py index 69d68850b..2e1b2f33a 100644 --- a/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/argspec/vrf_global/vrf_global.py @@ -187,20 +187,8 @@ class Vrf_globalArgs(object): # pylint: disable=R0903 "type": "list", "elements": "dict", "options": { - "service_interface": { - "type": "dict", - "options": { - "interface": {"type": "str"}, - "interface_value": {"type": "str"}, - }, - }, - "map_to": { - "type": "dict", - "options": { - "interface": {"type": "str"}, - "interface_value": {"type": "str"}, - }, - }, + "service_interface": {"type": "str"}, + "map_to": {"type": "str"}, }, }, }, diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index ba21136e5..fb1d3bad9 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -92,3 +92,12 @@ def _compare(self, want, have): for the Vrf_global network resource. """ self.compare(parsers=self.parsers, want=want, have=have) + + def _vrf_list_to_dict(self, vrf_list): + """Converts a list of VRFs to a dictionary with the VRF name as the key. + + :param list vrf_list: A list of VRFs + :rtype: dict + :returns: A dictionary of VRFs with the VRF name as the key + """ + return {entry["name"]: entry for entry in vrf_list} diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index c57719d99..b61a52293 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -17,7 +17,6 @@ from copy import deepcopy -import debugpy from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils @@ -29,11 +28,10 @@ Vrf_globalTemplate, ) - +import debugpy debugpy.listen(3000) debugpy.wait_for_client() - class Vrf_globalFacts(object): """The nxos vrf_global facts class""" @@ -46,6 +44,18 @@ def get_config(self, connection): return connection.get("show running-config | section ^vrf") + def _dict_to_list(self, data): + """Convert a dictionary to a list of dictionaries""" + objs = dict() + objs["vrfs"] = list(data.get("vrfs", {}).values()) if "vrfs" in data else [] + + for item in objs["vrfs"]: + name_server = item.get("ip", {}).get("name_server", {}).get("address_list", []) + if name_server: + item["ip"]["name_server"]["address_list"] = name_server.split() + + return objs + def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Vrf_global network resource @@ -66,14 +76,12 @@ def populate_facts(self, connection, ansible_facts, data=None): vrf_global_parser = Vrf_globalTemplate(lines=data.splitlines(), module=self._module) objs = vrf_global_parser.parse() - objs["vrfs"] = list(objs.get("vrfs", {}).values()) if "vrfs" in objs else [] + facts_output = self._dict_to_list(objs) ansible_facts["ansible_network_resources"].pop("vrf_global", None) - params = utils.remove_empties( - vrf_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), - ) - + params = vrf_global_parser.validate_config(self.argument_spec, {"config": facts_output}, redact=True) + params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 2a7419f16..8b7844eb5 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -421,21 +421,25 @@ def __init__(self, lines=None, module=None): }, }, { - "name": "ip.name_server.address_list", + "name": "ip.name_server.use_vrf", "getval": re.compile( r""" \s+ip\sname-server - \s(?P.+$) + \s(?P\S+) + \suse-vrf\s(?P\S+) $""", re.VERBOSE, ), - "setval": name_server_addr_list, + "setval": "ip name-server {{ source_address }} use-vrf {{ vrf }}", "result": { "vrfs": { '{{ name }}': { 'name': '{{ name }}', "ip" : { "name_server": { - "address_list": "{{ addr_list }}", + "use_vrf": { + "source_address": "{{ source_addr }}", + "vrf": "{{ vrf_name }}", + }, }, }, }, @@ -443,25 +447,21 @@ def __init__(self, lines=None, module=None): }, }, { - "name": "ip.name_server.use_vrf", + "name": "ip.name_server.address_list", "getval": re.compile( r""" \s+ip\sname-server - \s(?P\S+) - \suse-vrf\s(?P\S+) + \s(?P.+$) $""", re.VERBOSE, ), - "setval": "ip name-server {{ source_address }} use-vrf {{ vrf }}", + "setval": name_server_addr_list, "result": { "vrfs": { '{{ name }}': { 'name': '{{ name }}', "ip" : { "name_server": { - "use_vrf": { - "source_address": "{{ source_addr }}", - "vrf": "{{ vrf_name }}", - }, + "address_list": "{{ addr_list }}", }, }, }, diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index ea8c7d0ae..caf3b6cfa 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -225,24 +225,10 @@ suboptions: service_interface: description: configure service interface. - type: dict - suboptions: - interface: - description: Interface name. - type: str - interface_value: - description: Interface value / Regex. - type: str + type: str map_to: description: Map to interface. - type: dict - suboptions: - interface: - description: Interface name. - type: str - interface_value: - description: Interface value / Regex. - type: str + type: str ipv6: description: Configure IPv6 features for the specified vrf. type: dict From 90c95edea326a00e01e3a6f2aa1a7da81c4c494f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 08:24:58 +0000 Subject: [PATCH 12/46] chore: auto fixes from pre-commit.com hooks --- .../network/nxos/facts/vrf_global/vrf_global.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index b61a52293..f552184ae 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -17,6 +17,7 @@ from copy import deepcopy +import debugpy from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils @@ -28,10 +29,11 @@ Vrf_globalTemplate, ) -import debugpy + debugpy.listen(3000) debugpy.wait_for_client() + class Vrf_globalFacts(object): """The nxos vrf_global facts class""" @@ -53,7 +55,7 @@ def _dict_to_list(self, data): name_server = item.get("ip", {}).get("name_server", {}).get("address_list", []) if name_server: item["ip"]["name_server"]["address_list"] = name_server.split() - + return objs def populate_facts(self, connection, ansible_facts, data=None): @@ -80,7 +82,9 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("vrf_global", None) - params = vrf_global_parser.validate_config(self.argument_spec, {"config": facts_output}, redact=True) + params = vrf_global_parser.validate_config( + self.argument_spec, {"config": facts_output}, redact=True + ) params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) From 2e14029d202d82413281da65f031a92e97524eac Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:00:31 +0000 Subject: [PATCH 13/46] chore: auto fixes from pre-commit.com hooks --- .../module_utils/network/nxos/facts/vrf_global/vrf_global.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index f552184ae..960741b40 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -83,7 +83,9 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("vrf_global", None) params = vrf_global_parser.validate_config( - self.argument_spec, {"config": facts_output}, redact=True + self.argument_spec, + {"config": facts_output}, + redact=True, ) params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) From 4bc1ce1c877543de0daf7e17a975ccd13bd6edbc Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 16:59:13 +0530 Subject: [PATCH 14/46] config side code --- .../nxos/config/vrf_global/vrf_global.py | 128 +++++++++++++++++- .../nxos/facts/vrf_global/vrf_global.py | 14 +- .../network/nxos/rm_templates/vrf_global.py | 66 +++++---- 3 files changed, 159 insertions(+), 49 deletions(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index fb1d3bad9..0be674520 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -18,14 +18,13 @@ created. """ -from copy import deepcopy - from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, + get_from_dict ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts @@ -47,7 +46,37 @@ def __init__(self, module): resource="vrf_global", tmplt=Vrf_globalTemplate(), ) - self.parsers = [] + self.parsers = [ + "description", + "ip.auto_discard", + "ip.domain_name", + "ip.name_server.address_list", + "ip.icmp_err.source_interface", + "ip.multicast.group_range_prefix_list", + "ip.multicast.multipath.resilient", + "ip.multicast.multipath.splitting_type.none", + "ip.multicast.multipath.splitting_type.legacy", + "ip.multicast.multipath.splitting_type.nbm", + "ip.multicast.multipath.splitting_type.sg_hash", + "ip.multicast.multipath.splitting_type.sg_hash_next_hop", + "ip.name_server.use_vrf", + "vni", + "ipv6.multicast.group_range_prefix_list", + "ipv6.multicast.multipath.resilient", + "ipv6.multicast.multipath.splitting_type.none", + "ipv6.multicast.multipath.splitting_type.sg_hash", + "ipv6.multicast.multipath.splitting_type.sg_hash_next_hop", + ] + + self.list_parsers = [ + "ip.domain_list", + "ip.igmp.ssm_translate", + "ip.mroutes", + "ip.multicast.rpf", + "ip.route", + "multicast.service_reflect", + "ipv6.mld_ssm_translate", + ] def execute_module(self): """Execute the module @@ -64,8 +93,9 @@ def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ - wantd = {entry["name"]: entry for entry in self.want} - haved = {entry["name"]: entry for entry in self.have} + + wantd = self._vrf_list_to_dict(self.want) + haved = self._vrf_list_to_dict(self.have) # if state is merged, merge want onto have and then compare if self.state == "merged": @@ -80,7 +110,7 @@ def generate_commands(self): if self.state in ["overridden", "deleted"]: for k, have in iteritems(haved): if k not in wantd: - self._compare(want={}, have=have) + self.addcmd(have, "name", True) for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) @@ -91,7 +121,34 @@ def _compare(self, want, have): the `want` and `have` data with the `parsers` defined for the Vrf_global network resource. """ + begin = len(self.commands) self.compare(parsers=self.parsers, want=want, have=have) + self._compare_lists(want=want, have=have) + if len(self.commands) != begin or (not have and want): + self.commands.insert( + begin, + self._tmplt.render( + want or have, + "name", + False, + ), + ) + + def _compare_lists(self, want, have): + """Compares the list parsers for the Vrf_global network resource + and populates the list of commands to be run. + """ + for attrib in self.list_parsers: + wdict = get_from_dict(want, attrib) or {} + hdict = get_from_dict(have, attrib) or {} + + for key, entry in iteritems(wdict): + if entry != hdict.pop(key, {}): + self.addcmd(entry, attrib, False) + # remove remaining items in have for replaced + for entry in hdict.values(): + self.addcmd(entry, attrib, True) + def _vrf_list_to_dict(self, vrf_list): """Converts a list of VRFs to a dictionary with the VRF name as the key. @@ -100,4 +157,61 @@ def _vrf_list_to_dict(self, vrf_list): :rtype: dict :returns: A dictionary of VRFs with the VRF name as the key """ - return {entry["name"]: entry for entry in vrf_list} + items = dict() + for entry in vrf_list.get("vrfs", []): + items.update({(entry["name"]): entry}) + + for _, value in iteritems(items): + domain_list = value.get("ip", {}).get("domain_list", []) + if domain_list: + value["ip"]["domain_list"] = { + entry: {"domain_list": entry} for entry in domain_list + } + ip_ssm = value.get("ip", {}).get("igmp", {}).get("ssm_translate", []) + if ip_ssm: + value["ip"]["igmp"]["ssm_translate"] = { + (entry.get("group"), entry.get("source")): entry for entry in ip_ssm + } + ip_mroutes = value.get("ip", {}).get("mroutes", []) + if ip_mroutes: + value["ip"]["mroutes"] = { + (entry.get("group"), entry.get("source")): entry for entry in ip_mroutes + } + ip_rpf = value.get("ip", {}).get("multicast", {}).get("rpf", []) + if ip_rpf: + value["ip"]["multicast"]["rpf"] = { + (entry.get("vrf_name"), entry.get("group_list_range")): entry for entry in ip_rpf + } + ip_route = value.get("ip", {}).get("route", []) + if ip_route: + temp_route = {} + for entry in ip_route: + if entry.get("vrf"): + temp_route[(entry.get("vrf"), entry.get("source"), entry.get("destination"))] = entry + elif entry.get("tags"): + tagv = entry.get("tags") + temp_route[ + (f"{tagv.get("tag_value")}_{tagv.get("route_pref","")}", + entry.get("source"), + entry.get("destination")) + ] = entry + elif entry.get("track"): + temp_route[(entry.get("track"), entry.get("source"), entry.get("destination"))] = entry + else: + temp_route[(entry.get("source"), entry.get("destination"))] = entry + value["ip"]["route"] = temp_route + + service_reflect = value.get("multicast", {}).get("service_reflect", []) + if service_reflect: + value["multicast"]["service_reflect"] = { + (entry.get("service_interface"), entry.get("map_to")): entry for entry in service_reflect + } + ipv6_ssm = value.get("ipv6", {}).get("mld_ssm_translate", []) + if ipv6_ssm: + value["ipv6"]["mld_ssm_translate"] = { + (entry.get("group"), entry.get("source")): entry for entry in ipv6_ssm + } + address_list = value.get("ip", {}).get("name_server", {}).get("address_list", []) + if address_list: + value["ip"]["name_server"]["address_list"] = ' '.join(address_list) + return items diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index 960741b40..e65f92994 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -15,9 +15,6 @@ based on the configuration. """ -from copy import deepcopy - -import debugpy from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils @@ -30,10 +27,6 @@ ) -debugpy.listen(3000) -debugpy.wait_for_client() - - class Vrf_globalFacts(object): """The nxos vrf_global facts class""" @@ -55,7 +48,6 @@ def _dict_to_list(self, data): name_server = item.get("ip", {}).get("name_server", {}).get("address_list", []) if name_server: item["ip"]["name_server"]["address_list"] = name_server.split() - return objs def populate_facts(self, connection, ansible_facts, data=None): @@ -82,11 +74,7 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("vrf_global", None) - params = vrf_global_parser.validate_config( - self.argument_spec, - {"config": facts_output}, - redact=True, - ) + params = vrf_global_parser.validate_config(self.argument_spec, {"config": facts_output}, redact=True) params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 8b7844eb5..2608b407a 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -22,9 +22,18 @@ ) -def name_server_addr_list(lines, tmplt): - pass - +def _tmplt_ip_route(route_item): + command = "ip route {source} {destination}".format(**route_item) + if route_item.get("tags"): + tag_item = route_item.get("tags") + command += " tag {tag_value}".format(**tag_item) + if route_item.get("tags").get("route_pref"): + command += " {route_pref}".format(**tag_item) + if route_item.get("vrf"): + command += " vrf {vrf}".format(**route_item) + if route_item.get("track"): + command += " track {track}".format(**route_item) + return command class Vrf_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): @@ -79,7 +88,7 @@ def __init__(self, lines=None, module=None): '{{ name }}': { 'name': '{{ name }}', "ip" : { - "auto_discard": "{{ true if auto_disc is defined }}", + "auto_discard": "{{ True if auto_disc is defined }}", }, }, }, @@ -134,7 +143,7 @@ def __init__(self, lines=None, module=None): (?P(\d+\S*)) $""", re.VERBOSE, ), - "setval": "ip icmp-errors source-interface {{ interface }} {{ interface_value }}", + "setval": "ip icmp-errors source-interface {{ ip.icmp_err.source_interface.interface }} {{ ip.icmp_err.source_interface.interface_value }}", "result": { "vrfs": { '{{ name }}': { @@ -194,7 +203,7 @@ def __init__(self, lines=None, module=None): $""", re.VERBOSE, ), "setval": "ip mroute {{ group }} {{ source }}" - "{{ ' ' + preference if preference is defined }}" + "{{ ' ' + preference|string if preference is defined }}" "{{ ' vrf ' + vrf if vrf is defined }}", "result": { "vrfs": { @@ -222,7 +231,7 @@ def __init__(self, lines=None, module=None): \sprefix-list\s(?P\S+) $""", re.VERBOSE, ), - "setval": "ip multicast group-range prefix-list {{ group_range_prefix_list }}", + "setval": "ip multicast group-range prefix-list {{ ip.multicast.group_range_prefix_list.group_range_prefix_list }}", "result": { "vrfs": { '{{ name }}': { @@ -252,7 +261,7 @@ def __init__(self, lines=None, module=None): "ip" : { "multicast": { "multipath": { - "resilient": "{{ true if res is defined }}", + "resilient": "{{ True if res is defined }}", }, }, }, @@ -277,7 +286,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "none": "{{ true if noneval is defined }}", + "none": "{{ True if noneval is defined }}", }, }, }, @@ -303,7 +312,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "legacy": "{{ true if legacy_val is defined }}", + "legacy": "{{ True if legacy_val is defined }}", }, }, }, @@ -329,7 +338,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "nbm": "{{ true if nbm_val is defined }}", + "nbm": "{{ True if nbm_val is defined }}", }, }, }, @@ -355,7 +364,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "sg_hash": "{{ true if sg_hash_val is defined }}", + "sg_hash": "{{ True if sg_hash_val is defined }}", }, }, }, @@ -382,7 +391,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "sg_hash_next_hop": "{{ true if sg_hash_nxt_val is defined }}", + "sg_hash_next_hop": "{{ True if sg_hash_nxt_val is defined }}", }, }, }, @@ -429,7 +438,7 @@ def __init__(self, lines=None, module=None): \suse-vrf\s(?P\S+) $""", re.VERBOSE, ), - "setval": "ip name-server {{ source_address }} use-vrf {{ vrf }}", + "setval": "ip name-server {{ ip.name_server.use_vrf.source_address }} use-vrf {{ ip.name_server.use_vrf.vrf }}", "result": { "vrfs": { '{{ name }}': { @@ -454,7 +463,7 @@ def __init__(self, lines=None, module=None): \s(?P.+$) $""", re.VERBOSE, ), - "setval": name_server_addr_list, + "setval": "ip name-server {{ ip.name_server.address_list }}", "result": { "vrfs": { '{{ name }}': { @@ -477,7 +486,7 @@ def __init__(self, lines=None, module=None): \s(?P\S+) $""", re.VERBOSE, ), - "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }}", + "setval": _tmplt_ip_route, "result": { "vrfs": { '{{ name }}': { @@ -505,8 +514,7 @@ def __init__(self, lines=None, module=None): (\s(?P\d+))? $""", re.VERBOSE, ), - "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} tag {{ tag }}" - "{{ ' ' + route_pref if route_pref is defined }}", + "setval": _tmplt_ip_route, "result": { "vrfs": { '{{ name }}': { @@ -538,7 +546,7 @@ def __init__(self, lines=None, module=None): \svrf\s(?P\S+) $""", re.VERBOSE, ), - "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} vrf {{ vrf }}", + "setval": _tmplt_ip_route, "result": { "vrfs": { '{{ name }}': { @@ -566,7 +574,7 @@ def __init__(self, lines=None, module=None): \strack\s(?P\S+) $""", re.VERBOSE, ), - "setval": "ip route {{ ip.route.source }} {{ ip.route.destination }} vrf {{ vrf }}", + "setval": _tmplt_ip_route, "result": { "vrfs": { '{{ name }}': { @@ -592,14 +600,14 @@ def __init__(self, lines=None, module=None): (\s(?Pl3))? $""", re.VERBOSE, ), - "setval": "vni {{ vni.vni_number }} {{ 'l3' if vni.layer_3 is defined }}", + "setval": "vni {{ vni.vni_number }}{{ ' l3' if vni.layer_3 is defined }}", "result": { "vrfs": { '{{ name }}': { 'name': '{{ name }}', "vni": { "vni_number": "{{ vni_val }}", - "layer_3": "{{ true if l3_val is defined }}", + "layer_3": "{{ True if l3_val is defined }}", }, }, }, @@ -636,13 +644,13 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \s+ipv6\smld - (\s(?Picmp))? + (\s(?Picmp))? \sssm-translate \s(?P\S+) \s(?P\S+) $""", re.VERBOSE, ), - "getval": "ipv6 {{ 'icmp' if icmp is defined }} mld ssm-translate {{ group }} {{ source }}", + "setval": "ipv6{{ ' icmp' if icmp is defined }} mld ssm-translate {{ group }} {{ source }}", "result": { "vrfs": { '{{ name }}': { @@ -650,7 +658,7 @@ def __init__(self, lines=None, module=None): "ipv6": { "mld_ssm_translate": [ { - "icmp": "{{ true if icmp is defined }}", + "icmp": "{{ True if icmp_val is defined }}", "group": "{{ group_val }}", "source": "{{ source_val }}", }, @@ -699,7 +707,7 @@ def __init__(self, lines=None, module=None): "ipv6": { "multicast": { "multipath": { - "resilient": "{{ true if res_val is defined }}", + "resilient": "{{ True if res_val is defined }}", }, }, }, @@ -724,7 +732,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "none": "{{ true if none_val is defined }}", + "none": "{{ True if none_val is defined }}", }, }, }, @@ -750,7 +758,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "sg_hash": "{{ true if sg_hash_val is defined }}", + "sg_hash": "{{ True if sg_hash_val is defined }}", }, }, }, @@ -776,7 +784,7 @@ def __init__(self, lines=None, module=None): "multicast": { "multipath": { "splitting_type": { - "sg_hash_next_hop": "{{ true if sg_hash_next_hop_val is defined }}", + "sg_hash_next_hop": "{{ True if sg_hash_next_hop_val is defined }}", }, }, }, From 9b009cc33c980f2b1d0dcdc621a70ef7dff5b784 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:30:00 +0000 Subject: [PATCH 15/46] chore: auto fixes from pre-commit.com hooks --- .../nxos/config/vrf_global/vrf_global.py | 31 ++++++++++++------- .../nxos/facts/vrf_global/vrf_global.py | 4 ++- .../network/nxos/rm_templates/vrf_global.py | 1 + 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 0be674520..708837ffc 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -24,7 +24,7 @@ ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, - get_from_dict + get_from_dict, ) from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.facts import Facts @@ -149,7 +149,6 @@ def _compare_lists(self, want, have): for entry in hdict.values(): self.addcmd(entry, attrib, True) - def _vrf_list_to_dict(self, vrf_list): """Converts a list of VRFs to a dictionary with the VRF name as the key. @@ -160,7 +159,7 @@ def _vrf_list_to_dict(self, vrf_list): items = dict() for entry in vrf_list.get("vrfs", []): items.update({(entry["name"]): entry}) - + for _, value in iteritems(items): domain_list = value.get("ip", {}).get("domain_list", []) if domain_list: @@ -180,31 +179,39 @@ def _vrf_list_to_dict(self, vrf_list): ip_rpf = value.get("ip", {}).get("multicast", {}).get("rpf", []) if ip_rpf: value["ip"]["multicast"]["rpf"] = { - (entry.get("vrf_name"), entry.get("group_list_range")): entry for entry in ip_rpf + (entry.get("vrf_name"), entry.get("group_list_range")): entry + for entry in ip_rpf } ip_route = value.get("ip", {}).get("route", []) if ip_route: temp_route = {} for entry in ip_route: if entry.get("vrf"): - temp_route[(entry.get("vrf"), entry.get("source"), entry.get("destination"))] = entry + temp_route[ + (entry.get("vrf"), entry.get("source"), entry.get("destination")) + ] = entry elif entry.get("tags"): tagv = entry.get("tags") temp_route[ - (f"{tagv.get("tag_value")}_{tagv.get("route_pref","")}", - entry.get("source"), - entry.get("destination")) + ( + f"{tagv.get("tag_value")}_{tagv.get("route_pref","")}", + entry.get("source"), + entry.get("destination"), + ) ] = entry elif entry.get("track"): - temp_route[(entry.get("track"), entry.get("source"), entry.get("destination"))] = entry + temp_route[ + (entry.get("track"), entry.get("source"), entry.get("destination")) + ] = entry else: temp_route[(entry.get("source"), entry.get("destination"))] = entry value["ip"]["route"] = temp_route - + service_reflect = value.get("multicast", {}).get("service_reflect", []) if service_reflect: value["multicast"]["service_reflect"] = { - (entry.get("service_interface"), entry.get("map_to")): entry for entry in service_reflect + (entry.get("service_interface"), entry.get("map_to")): entry + for entry in service_reflect } ipv6_ssm = value.get("ipv6", {}).get("mld_ssm_translate", []) if ipv6_ssm: @@ -213,5 +220,5 @@ def _vrf_list_to_dict(self, vrf_list): } address_list = value.get("ip", {}).get("name_server", {}).get("address_list", []) if address_list: - value["ip"]["name_server"]["address_list"] = ' '.join(address_list) + value["ip"]["name_server"]["address_list"] = " ".join(address_list) return items diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index e65f92994..f1d3b6316 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -74,7 +74,9 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("vrf_global", None) - params = vrf_global_parser.validate_config(self.argument_spec, {"config": facts_output}, redact=True) + params = vrf_global_parser.validate_config( + self.argument_spec, {"config": facts_output}, redact=True + ) params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) ansible_facts["ansible_network_resources"].update(facts) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 2608b407a..7d73627b7 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -35,6 +35,7 @@ def _tmplt_ip_route(route_item): command += " track {track}".format(**route_item) return command + class Vrf_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): super(Vrf_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module) From d9ead613644be3efe639e7b073488301a2c21717 Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 17:03:56 +0530 Subject: [PATCH 16/46] pre-commit fix --- plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index f1d3b6316..bb67644a8 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -16,7 +16,6 @@ """ -from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_global.vrf_global import ( From 99c16dbdc3bd74577a1154b7d5568921113d248a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:34:44 +0000 Subject: [PATCH 17/46] chore: auto fixes from pre-commit.com hooks --- .../module_utils/network/nxos/facts/vrf_global/vrf_global.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py index bb67644a8..f69c684fc 100644 --- a/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/facts/vrf_global/vrf_global.py @@ -74,7 +74,9 @@ def populate_facts(self, connection, ansible_facts, data=None): ansible_facts["ansible_network_resources"].pop("vrf_global", None) params = vrf_global_parser.validate_config( - self.argument_spec, {"config": facts_output}, redact=True + self.argument_spec, + {"config": facts_output}, + redact=True, ) params = utils.remove_empties(params) facts["vrf_global"] = params.get("config", {}) From 3db2bd15806282360b768aee627d3d9478a12495 Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 17:09:01 +0530 Subject: [PATCH 18/46] more pre-commit fix --- .../network/nxos/rm_templates/vrf_global.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py index 7d73627b7..53a4da746 100644 --- a/plugins/module_utils/network/nxos/rm_templates/vrf_global.py +++ b/plugins/module_utils/network/nxos/rm_templates/vrf_global.py @@ -88,7 +88,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "auto_discard": "{{ True if auto_disc is defined }}", }, }, @@ -107,7 +107,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "domain_list": [ "{{ domain_list }}", ], @@ -128,7 +128,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "domain_name": "{{ domain_name }}", }, }, @@ -149,7 +149,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "icmp_err": { "source_interface": { "interface": "{{ 'ethernet' if 'eth' in interface }}" @@ -178,7 +178,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "igmp": { "ssm_translate": [ { @@ -210,7 +210,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "mroutes": [ { "group": "{{ group_val }}", @@ -237,7 +237,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "group_range_prefix_list": "{{ prefix_lst }}", }, @@ -259,7 +259,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "resilient": "{{ True if res is defined }}", @@ -283,7 +283,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "splitting_type": { @@ -309,7 +309,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "splitting_type": { @@ -335,7 +335,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "splitting_type": { @@ -361,7 +361,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "splitting_type": { @@ -388,7 +388,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "multipath": { "splitting_type": { @@ -416,7 +416,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "multicast": { "rpf": [ { @@ -444,7 +444,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "name_server": { "use_vrf": { "source_address": "{{ source_addr }}", @@ -469,7 +469,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "name_server": { "address_list": "{{ addr_list }}", }, @@ -492,7 +492,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "route": [ { "source": "{{ src_val }}", @@ -520,7 +520,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "route": [ { "source": "{{ src_val }}", @@ -552,7 +552,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "route": [ { "source": "{{ src_val }}", @@ -580,7 +580,7 @@ def __init__(self, lines=None, module=None): "vrfs": { '{{ name }}': { 'name': '{{ name }}', - "ip" : { + "ip": { "route": [ { "source": "{{ src_val }}", From a1a5d42b665909c1fcf808e392093db996a3cfa0 Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 17:11:10 +0530 Subject: [PATCH 19/46] more pre-commit --- .../module_utils/network/nxos/config/vrf_global/vrf_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 708837ffc..b2805c675 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -194,7 +194,7 @@ def _vrf_list_to_dict(self, vrf_list): tagv = entry.get("tags") temp_route[ ( - f"{tagv.get("tag_value")}_{tagv.get("route_pref","")}", + f"{tagv.get("tag_value")}_{tagv.get("route_pref", "")}", entry.get("source"), entry.get("destination"), ) From a60c67cf788149fe423011a517800376d5d25441 Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 23:30:09 +0530 Subject: [PATCH 20/46] added unit test --- .../nxos/config/vrf_global/vrf_global.py | 2 +- plugins/modules/nxos_vrf_global.py | 5 +- .../network/nxos/test_nxos_vrf_global.py | 853 ++++++++++++++++++ 3 files changed, 856 insertions(+), 4 deletions(-) create mode 100644 tests/unit/modules/network/nxos/test_nxos_vrf_global.py diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index b2805c675..408244ff2 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -110,7 +110,7 @@ def generate_commands(self): if self.state in ["overridden", "deleted"]: for k, have in iteritems(haved): if k not in wantd: - self.addcmd(have, "name", True) + self._compare(want={}, have=have) for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index caf3b6cfa..e2ed1d97a 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -318,7 +318,6 @@ """ EXAMPLES = """ - """ RETURN = """ @@ -355,14 +354,14 @@ gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) - type: list + type: dict sample: > This output will always be in the same format as the module argspec. parsed: description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. returned: when I(state) is C(parsed) - type: list + type: dict sample: > This output will always be in the same format as the module argspec. diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py new file mode 100644 index 000000000..a56243002 --- /dev/null +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py @@ -0,0 +1,853 @@ +# (c) 2024, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type +from textwrap import dedent +from unittest.mock import patch + +from ansible_collections.cisco.nxos.plugins.modules import nxos_vrf_global + +from .nxos_module import TestNxosModule, load_fixture, set_module_args + +class TestNxosVrfGlobalModule(TestNxosModule): + """Test the nxos_vrf_global module.""" + + module = nxos_vrf_global + + def setUp(self): + """Set up for nxos_vrf_global module tests.""" + super(TestNxosVrfGlobalModule, self).setUp() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.vrf_global.vrf_global." + "Vrf_globalFacts.get_config", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestNxosVrfGlobalModule, self).tearDown() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_nxos_vrf_global_merged(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + """ + ) + + set_module_args( + dict( + config={ + "vrfs":[ + { + "description": "this is descrition", + "ip": { + "auto_discard": True, + "domain_list": [ + "anisble.com", + "redhat.com", + "res.com" + ], + "domain_name": "redx.com", + "icmp_err": { + "source_interface": { + "interface": "port-channel", + "interface_value": "1" + } + }, + "igmp": { + "ssm_translate": [ + { + "group": "232.0.0.0/8", + "source": "10.1.1.1" + }, + { + "group": "239.1.2.3/24", + "source": "192.168.1.1" + } + ] + }, + "mroutes": [ + { + "group": "192.168.1.0/24", + "source": "192.168.1.1" + }, + { + "group": "192.168.1.0/24", + "preference": 2, + "source": "192.168.1.2", + "vrf": "temp1" + } + ], + "multicast": { + "multipath": { + "resilient": True, + "splitting_type": { + "legacy": True + } + }, + "rpf": [ + { + "group_list_range": "238.1.0.0/24", + "vrf_name": "temp1" + }, + { + "group_list_range": "239.1.0.0/24", + "vrf_name": "temp1" + } + ] + }, + "name_server": { + "address_list": [ + "192.168.0.1", + "192.168.0.2", + "192.168.1.1", + "192.169.1.3" + ], + "use_vrf": { + "source_address": "192.168.0.1", + "vrf": "temp1" + } + }, + "route": [ + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24" + }, + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24", + "vrf": "temp1" + }, + { + "destination": "192.0.2.22", + "source": "192.0.2.0/24", + "tags": { + "route_pref": 4, + "tag_value": 2 + } + } + ] + }, + "ipv6": { + "mld_ssm_translate": [ + { + "group": "ff28::/16", + "source": "2001:db8:0:abcd::2" + }, + { + "group": "ff30::/16", + "source": "2001:db8:0:abcd::5" + } + ], + "multicast": { + "group_range_prefix_list": "temp2", + "multipath": { + "resilient": True, + "splitting_type": { + "none": True + } + } + } + }, + "multicast": { + "service_reflect": [ + { + "map_to": "Ethernet2/2", + "service_interface": "Ethernet1/1" + }, + { + "map_to": "Ethernet4/2", + "service_interface": "Ethernet2/1" + } + ] + }, + "name": "test1", + "vni": { + "vni_number": 5 + } + } + ] + }, + state="merged" + ) + ) + commands = [ + "vrf context test1", + "description this is descrition", + "ip auto-discard", + "ip domain-name redx.com", + "ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3", + "ip icmp-errors source-interface port-channel 1", + "ip multicast multipath resilient", + "ip multicast multipath legacy", + "ip name-server 192.168.0.1 use-vrf temp1", + "vni 5", + "ipv6 multicast group-range prefix-list temp2", + "ipv6 multicast multipath resilient", + "ipv6 multicast multipath none", + "ip domain-list res.com", + "ip domain-list redhat.com", + "ip domain-list anisble.com", + "ip igmp ssm-translate 232.0.0.0/8 10.1.1.1", + "ip igmp ssm-translate 239.1.2.3/24 192.168.1.1", + "ip mroute 192.168.1.0/24 192.168.1.1", + "ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1", + "ip multicast rpf select vrf temp1 group-list 238.1.0.0/24", + "ip multicast rpf select vrf temp1 group-list 239.1.0.0/24", + "ip route 192.0.0.0/24 192.0.2.22", + "ip route 192.0.0.0/24 192.0.2.22 vrf temp1", + "ip route 192.0.2.0/24 192.0.2.22 tag 2 4", + "multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2", + "multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2", + "ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2", + "ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_nxos_vrf_global_merged_idemp(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context test1 + ip domain-name redx.com + ip domain-list anisble.com + ip domain-list redhat.com + ip domain-list res.com + ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + ip name-server 192.168.0.1 use-vrf temp1 + multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 + multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 + description this is descrition + vni 5 + ip auto-discard + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + ip route 192.0.2.0/24 192.0.2.22 tag 2 4 + ip mroute 192.168.1.0/24 192.168.1.1 + ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 + ip icmp-errors source-interface po1 + ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 + ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + ip multicast multipath legacy + ip multicast multipath resilient + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip multicast group-range prefix-list temp2 + ipv6 multicast multipath none + ipv6 multicast multipath resilient + ipv6 multicast group-range prefix-list temp2 + ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 + ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::1 + ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 + ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 + ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + """ + ) + + set_module_args( + dict( + config={ + "vrfs":[ + { + "description": "this is descrition", + "ip": { + "auto_discard": True, + "domain_list": [ + "anisble.com", + "redhat.com", + "res.com" + ], + "domain_name": "redx.com", + "icmp_err": { + "source_interface": { + "interface": "port-channel", + "interface_value": "1" + } + }, + "igmp": { + "ssm_translate": [ + { + "group": "232.0.0.0/8", + "source": "10.1.1.1" + }, + { + "group": "239.1.2.3/24", + "source": "192.168.1.1" + } + ] + }, + "mroutes": [ + { + "group": "192.168.1.0/24", + "source": "192.168.1.1" + }, + { + "group": "192.168.1.0/24", + "preference": 2, + "source": "192.168.1.2", + "vrf": "temp1" + } + ], + "multicast": { + "multipath": { + "resilient": True, + "splitting_type": { + "legacy": True + } + }, + "rpf": [ + { + "group_list_range": "238.1.0.0/24", + "vrf_name": "temp1" + }, + { + "group_list_range": "239.1.0.0/24", + "vrf_name": "temp1" + } + ] + }, + "name_server": { + "address_list": [ + "192.168.0.1", + "192.168.0.2", + "192.168.1.1", + "192.169.1.3" + ], + "use_vrf": { + "source_address": "192.168.0.1", + "vrf": "temp1" + } + }, + "route": [ + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24" + }, + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24", + "vrf": "temp1" + }, + { + "destination": "192.0.2.22", + "source": "192.0.2.0/24", + "tags": { + "route_pref": 4, + "tag_value": 2 + } + } + ] + }, + "ipv6": { + "mld_ssm_translate": [ + { + "group": "ff28::/16", + "source": "2001:db8:0:abcd::2" + }, + { + "group": "ff30::/16", + "source": "2001:db8:0:abcd::5" + } + ], + "multicast": { + "group_range_prefix_list": "temp2", + "multipath": { + "resilient": True, + "splitting_type": { + "none": True + } + } + } + }, + "multicast": { + "service_reflect": [ + { + "map_to": "Ethernet2/2", + "service_interface": "Ethernet1/1" + }, + { + "map_to": "Ethernet4/2", + "service_interface": "Ethernet2/1" + } + ] + }, + "name": "test1", + "vni": { + "vni_number": 5 + } + } + ] + }, + state="merged" + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_nxos_vrf_global_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list anisble.com + ip domain-list redhat.com + ip domain-list res.com + vni 5 + ip auto-discard + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + ip route 192.0.2.0/24 192.0.2.22 tag 2 4 + ip mroute 192.168.1.0/24 192.168.1.1 + ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 + ip icmp-errors source-interface po1 + ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 + ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + ip multicast multipath legacy + ip multicast multipath resilient + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip multicast group-range prefix-list temp2 + """ + ) + + set_module_args( + dict( + config={ + "vrfs":[ + { + "name": "test1", + } + ] + }, + state="deleted" + ) + ) + + commands = [ + "vrf context test1", + "no description this is descrition", + "no ip auto-discard", + "no ip domain-name redx.com", + "no ip icmp-errors source-interface port-channel 1", + "no ip multicast multipath resilient", + "no ip multicast multipath legacy", + "no vni 5", + "no ip domain-list anisble.com", + "no ip domain-list res.com", + "no ip domain-list redhat.com", + "no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1", + "no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1", + "no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24", + "no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24", + "no ip route 192.0.0.0/24 192.0.2.22", + "no ip route 192.0.0.0/24 192.0.2.22 vrf temp1", + "no ip route 192.0.2.0/24 192.0.2.22 tag 2 4", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_vrf_global_deleted_empty(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list anisble.com + ip domain-list res.com + """, + ) + set_module_args(dict(config=dict(), state="deleted")) + commands = [ + "vrf context management", + "no ip name-server 192.168.255.1", + "no ip route 0.0.0.0/0 192.168.255.1", + "vrf context test1", + "no description this is descrition", + "no ip domain-name redx.com", + "no ip domain-list anisble.com", + "no ip domain-list res.com", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_nxos_vrf_global_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list anisble.com + ip domain-list res.com + vni 5 + ip auto-discard + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + ip route 192.0.2.0/24 192.0.2.22 tag 2 4 + ip mroute 192.168.1.0/24 192.168.1.1 + ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 + ip icmp-errors source-interface po1 + ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 + ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + ip multicast multipath legacy + ip multicast multipath resilient + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip multicast group-range prefix-list temp2 + """ + ) + + set_module_args( + dict( + config={ + "vrfs":[ + { + "name": "test1", + "vni": { + "vni_number": 6 + }, + "description": "test description", + "ip": { + "auto_discard": False, + "domain_list": [ + "redhat.com", + "greeblue.com" + ], + "domain_name": "redblue.com", + "icmp_err": { + "source_interface": { + "interface": "port-channel", + "interface_value": "3" + } + }, + } + } + ] + }, + state="overridden" + ), + ) + commands = [ + "vrf context management", + "no ip name-server 192.168.255.1", + "no ip route 0.0.0.0/0 192.168.255.1", + "vrf context test1", + "description test description", + "no ip auto-discard", + "ip domain-name redblue.com", + "ip icmp-errors source-interface port-channel 3", + "no ip multicast multipath resilient", + "no ip multicast multipath legacy", + "vni 6", + "ip domain-list redhat.com", + "ip domain-list greeblue.com", + "no ip domain-list res.com", + "no ip domain-list anisble.com", + "no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1", + "no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1", + "no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24", + "no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24", + "no ip route 192.0.0.0/24 192.0.2.22", + "no ip route 192.0.0.0/24 192.0.2.22 vrf temp1", + "no ip route 192.0.2.0/24 192.0.2.22 tag 2 4", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_nxos_vrf_replaced(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list anisble.com + ip domain-list res.com + vni 5 + ip auto-discard + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + ip route 192.0.2.0/24 192.0.2.22 tag 2 4 + ip mroute 192.168.1.0/24 192.168.1.1 + ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 + ip icmp-errors source-interface po1 + ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 + ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + ip multicast multipath legacy + ip multicast multipath resilient + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip multicast group-range prefix-list temp2 + """ + ) + + set_module_args( + dict( + config={ + "vrfs": [ + { + "name": "test1", + "vni": { + "vni_number": 6 + }, + "description": "test description", + "ip": { + "auto_discard": False, + "domain_list": [ + "redhat.com", + "greeblue.com" + ], + "domain_name": "redblue.com", + "icmp_err": { + "source_interface": { + "interface": "port-channel", + "interface_value": "3" + } + }, + }, + "multicast": { + "service_reflect": [ + { + "map_to": "Ethernet2/2", + "service_interface": "Ethernet1/1" + }, + { + "map_to": "Ethernet4/2", + "service_interface": "Ethernet2/1" + } + ] + } + } + ] + }, + state="replaced" + ) + ) + commands = [ + "vrf context test1", + "description test description", + "no ip auto-discard", + "ip domain-name redblue.com", + "ip icmp-errors source-interface port-channel 3", + "no ip multicast multipath resilient", + "no ip multicast multipath legacy", + "vni 6", + "ip domain-list redhat.com", + "ip domain-list greeblue.com", + "no ip domain-list anisble.com", + "no ip domain-list res.com", + "no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1", + "no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.1", + "no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1", + "no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24", + "no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24", + "no ip route 192.0.0.0/24 192.0.2.22", + "no ip route 192.0.0.0/24 192.0.2.22 vrf temp1", + "no ip route 192.0.2.0/24 192.0.2.22 tag 2 4", + "multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2", + "multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_nxos_vrf_global_replaced_idemp(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list redhat.com + ip domain-list res.com + vni 5 + ip auto-discard + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + """ + ) + + set_module_args( + dict( + config={ + "vrfs": [ + { + "name": "management", + "ip": { + "name_server": { + "address_list": [ + "192.168.255.1" + ] + }, + "route": [ + { + "destination": "192.168.255.1", + "source": "0.0.0.0/0" + } + ] + }, + }, + { + "name": "test1", + "description": "this is descrition", + "vni": { + "vni_number": 5 + }, + "ip": { + "auto_discard": True, + "domain_list": [ + "redhat.com", + "res.com" + ], + "domain_name": "redx.com", + "multicast": { + "rpf": [ + { + "group_list_range": "238.1.0.0/24", + "vrf_name": "temp1" + }, + { + "group_list_range": "239.1.0.0/24", + "vrf_name": "temp1" + }, + ] + }, + "route": [ + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24" + }, + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24", + "vrf": "temp1" + }, + ] + } + } + ] + }, + state="replaced" + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_nxos_vrf_global_rendered(self): + pass + + def test_nxos_vrf_global_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list redhat.com + ip domain-list res.com + vni 5 + ip auto-discard + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + """ + ), + state="parsed" + ) + ) + + parsed_item = { + "vrfs": [ + { + "name": "management", + "ip": { + "name_server": { + "address_list": [ + "192.168.255.1" + ] + }, + "route": [ + { + "destination": "192.168.255.1", + "source": "0.0.0.0/0" + } + ] + }, + }, + { + "name": "test1", + "description": "this is descrition", + "vni": { + "vni_number": 5 + }, + "ip": { + "auto_discard": True, + "domain_list": [ + "redhat.com", + "res.com" + ], + "domain_name": "redx.com", + "multicast": { + "rpf": [ + { + "group_list_range": "238.1.0.0/24", + "vrf_name": "temp1" + }, + { + "group_list_range": "239.1.0.0/24", + "vrf_name": "temp1" + }, + ] + }, + "route": [ + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24" + }, + { + "destination": "192.0.2.22", + "source": "192.0.0.0/24", + "vrf": "temp1" + }, + ] + } + } + ] + } + result = self.execute_module(changed=False) + self.assertEqual(parsed_item, result["parsed"]) From e950132c68ae322c27a5a86322d6801264e43b4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 14 Jul 2024 18:00:56 +0000 Subject: [PATCH 21/46] chore: auto fixes from pre-commit.com hooks --- .../network/nxos/test_nxos_vrf_global.py | 321 +++++++++--------- 1 file changed, 161 insertions(+), 160 deletions(-) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py index a56243002..aec0db51f 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py @@ -12,6 +12,7 @@ from .nxos_module import TestNxosModule, load_fixture, set_module_args + class TestNxosVrfGlobalModule(TestNxosModule): """Test the nxos_vrf_global module.""" @@ -44,13 +45,13 @@ def test_nxos_vrf_global_merged(self): vrf context management ip name-server 192.168.255.1 ip route 0.0.0.0/0 192.168.255.1 - """ + """, ) set_module_args( dict( config={ - "vrfs":[ + "vrfs": [ { "description": "this is descrition", "ip": { @@ -58,131 +59,131 @@ def test_nxos_vrf_global_merged(self): "domain_list": [ "anisble.com", "redhat.com", - "res.com" + "res.com", ], "domain_name": "redx.com", "icmp_err": { "source_interface": { "interface": "port-channel", - "interface_value": "1" - } + "interface_value": "1", + }, }, "igmp": { "ssm_translate": [ { "group": "232.0.0.0/8", - "source": "10.1.1.1" + "source": "10.1.1.1", }, { "group": "239.1.2.3/24", - "source": "192.168.1.1" - } - ] + "source": "192.168.1.1", + }, + ], }, "mroutes": [ { "group": "192.168.1.0/24", - "source": "192.168.1.1" + "source": "192.168.1.1", }, { "group": "192.168.1.0/24", "preference": 2, "source": "192.168.1.2", - "vrf": "temp1" - } + "vrf": "temp1", + }, ], "multicast": { "multipath": { "resilient": True, "splitting_type": { - "legacy": True - } + "legacy": True, + }, }, "rpf": [ { "group_list_range": "238.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, { "group_list_range": "239.1.0.0/24", - "vrf_name": "temp1" - } - ] + "vrf_name": "temp1", + }, + ], }, "name_server": { "address_list": [ "192.168.0.1", "192.168.0.2", "192.168.1.1", - "192.169.1.3" + "192.169.1.3", ], "use_vrf": { "source_address": "192.168.0.1", - "vrf": "temp1" - } + "vrf": "temp1", + }, }, "route": [ { "destination": "192.0.2.22", - "source": "192.0.0.0/24" + "source": "192.0.0.0/24", }, { "destination": "192.0.2.22", "source": "192.0.0.0/24", - "vrf": "temp1" + "vrf": "temp1", }, { "destination": "192.0.2.22", "source": "192.0.2.0/24", "tags": { "route_pref": 4, - "tag_value": 2 - } - } - ] + "tag_value": 2, + }, + }, + ], }, "ipv6": { "mld_ssm_translate": [ { "group": "ff28::/16", - "source": "2001:db8:0:abcd::2" + "source": "2001:db8:0:abcd::2", }, { "group": "ff30::/16", - "source": "2001:db8:0:abcd::5" - } + "source": "2001:db8:0:abcd::5", + }, ], "multicast": { "group_range_prefix_list": "temp2", "multipath": { "resilient": True, "splitting_type": { - "none": True - } - } - } + "none": True, + }, + }, + }, }, "multicast": { "service_reflect": [ { "map_to": "Ethernet2/2", - "service_interface": "Ethernet1/1" + "service_interface": "Ethernet1/1", }, { "map_to": "Ethernet4/2", - "service_interface": "Ethernet2/1" - } - ] + "service_interface": "Ethernet2/1", + }, + ], }, "name": "test1", "vni": { - "vni_number": 5 - } - } - ] + "vni_number": 5, + }, + }, + ], }, - state="merged" - ) + state="merged", + ), ) commands = [ "vrf context test1", @@ -213,7 +214,7 @@ def test_nxos_vrf_global_merged(self): "multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2", "multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2", "ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2", - "ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" + "ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5", ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) @@ -254,13 +255,13 @@ def test_nxos_vrf_global_merged_idemp(self): ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 - """ + """, ) set_module_args( dict( config={ - "vrfs":[ + "vrfs": [ { "description": "this is descrition", "ip": { @@ -268,131 +269,131 @@ def test_nxos_vrf_global_merged_idemp(self): "domain_list": [ "anisble.com", "redhat.com", - "res.com" + "res.com", ], "domain_name": "redx.com", "icmp_err": { "source_interface": { "interface": "port-channel", - "interface_value": "1" - } + "interface_value": "1", + }, }, "igmp": { "ssm_translate": [ { "group": "232.0.0.0/8", - "source": "10.1.1.1" + "source": "10.1.1.1", }, { "group": "239.1.2.3/24", - "source": "192.168.1.1" - } - ] + "source": "192.168.1.1", + }, + ], }, "mroutes": [ { "group": "192.168.1.0/24", - "source": "192.168.1.1" + "source": "192.168.1.1", }, { "group": "192.168.1.0/24", "preference": 2, "source": "192.168.1.2", - "vrf": "temp1" - } + "vrf": "temp1", + }, ], "multicast": { "multipath": { "resilient": True, "splitting_type": { - "legacy": True - } + "legacy": True, + }, }, "rpf": [ { "group_list_range": "238.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, { "group_list_range": "239.1.0.0/24", - "vrf_name": "temp1" - } - ] + "vrf_name": "temp1", + }, + ], }, "name_server": { "address_list": [ "192.168.0.1", "192.168.0.2", "192.168.1.1", - "192.169.1.3" + "192.169.1.3", ], "use_vrf": { "source_address": "192.168.0.1", - "vrf": "temp1" - } + "vrf": "temp1", + }, }, "route": [ { "destination": "192.0.2.22", - "source": "192.0.0.0/24" + "source": "192.0.0.0/24", }, { "destination": "192.0.2.22", "source": "192.0.0.0/24", - "vrf": "temp1" + "vrf": "temp1", }, { "destination": "192.0.2.22", "source": "192.0.2.0/24", "tags": { "route_pref": 4, - "tag_value": 2 - } - } - ] + "tag_value": 2, + }, + }, + ], }, "ipv6": { "mld_ssm_translate": [ { "group": "ff28::/16", - "source": "2001:db8:0:abcd::2" + "source": "2001:db8:0:abcd::2", }, { "group": "ff30::/16", - "source": "2001:db8:0:abcd::5" - } + "source": "2001:db8:0:abcd::5", + }, ], "multicast": { "group_range_prefix_list": "temp2", "multipath": { "resilient": True, "splitting_type": { - "none": True - } - } - } + "none": True, + }, + }, + }, }, "multicast": { "service_reflect": [ { "map_to": "Ethernet2/2", - "service_interface": "Ethernet1/1" + "service_interface": "Ethernet1/1", }, { "map_to": "Ethernet4/2", - "service_interface": "Ethernet2/1" - } - ] + "service_interface": "Ethernet2/1", + }, + ], }, "name": "test1", "vni": { - "vni_number": 5 - } - } - ] + "vni_number": 5, + }, + }, + ], }, - state="merged" - ) + state="merged", + ), ) self.execute_module(changed=False, commands=[]) @@ -423,20 +424,20 @@ def test_nxos_vrf_global_deleted(self): ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip multicast group-range prefix-list temp2 - """ + """, ) set_module_args( dict( config={ - "vrfs":[ + "vrfs": [ { "name": "test1", - } - ] + }, + ], }, - state="deleted" - ) + state="deleted", + ), ) commands = [ @@ -517,37 +518,37 @@ def test_nxos_vrf_global_overridden(self): ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip multicast group-range prefix-list temp2 - """ + """, ) set_module_args( dict( config={ - "vrfs":[ + "vrfs": [ { "name": "test1", "vni": { - "vni_number": 6 + "vni_number": 6, }, "description": "test description", "ip": { "auto_discard": False, "domain_list": [ "redhat.com", - "greeblue.com" + "greeblue.com", ], "domain_name": "redblue.com", "icmp_err": { "source_interface": { "interface": "port-channel", - "interface_value": "3" - } + "interface_value": "3", + }, }, - } - } - ] + }, + }, + ], }, - state="overridden" + state="overridden", ), ) commands = [ @@ -605,7 +606,7 @@ def test_nxos_vrf_replaced(self): ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip multicast group-range prefix-list temp2 - """ + """, ) set_module_args( @@ -615,40 +616,40 @@ def test_nxos_vrf_replaced(self): { "name": "test1", "vni": { - "vni_number": 6 + "vni_number": 6, }, "description": "test description", "ip": { "auto_discard": False, "domain_list": [ "redhat.com", - "greeblue.com" + "greeblue.com", ], "domain_name": "redblue.com", "icmp_err": { "source_interface": { "interface": "port-channel", - "interface_value": "3" - } + "interface_value": "3", + }, }, }, "multicast": { "service_reflect": [ { "map_to": "Ethernet2/2", - "service_interface": "Ethernet1/1" + "service_interface": "Ethernet1/1", }, { "map_to": "Ethernet4/2", - "service_interface": "Ethernet2/1" - } - ] - } - } - ] + "service_interface": "Ethernet2/1", + }, + ], + }, + }, + ], }, - state="replaced" - ) + state="replaced", + ), ) commands = [ "vrf context test1", @@ -677,7 +678,7 @@ def test_nxos_vrf_replaced(self): ] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) - + def test_nxos_vrf_global_replaced_idemp(self): self.execute_show_command.return_value = dedent( """\ @@ -695,7 +696,7 @@ def test_nxos_vrf_global_replaced_idemp(self): ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip route 192.0.0.0/24 192.0.2.22 ip route 192.0.0.0/24 192.0.2.22 vrf temp1 - """ + """, ) set_module_args( @@ -707,62 +708,62 @@ def test_nxos_vrf_global_replaced_idemp(self): "ip": { "name_server": { "address_list": [ - "192.168.255.1" - ] + "192.168.255.1", + ], }, "route": [ { "destination": "192.168.255.1", - "source": "0.0.0.0/0" - } - ] + "source": "0.0.0.0/0", + }, + ], }, }, { "name": "test1", "description": "this is descrition", "vni": { - "vni_number": 5 + "vni_number": 5, }, "ip": { "auto_discard": True, "domain_list": [ "redhat.com", - "res.com" + "res.com", ], "domain_name": "redx.com", "multicast": { "rpf": [ { "group_list_range": "238.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, { "group_list_range": "239.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, - ] + ], }, "route": [ { "destination": "192.0.2.22", - "source": "192.0.0.0/24" + "source": "192.0.0.0/24", }, { "destination": "192.0.2.22", "source": "192.0.0.0/24", - "vrf": "temp1" + "vrf": "temp1", }, - ] - } - } - ] + ], + }, + }, + ], }, - state="replaced" - ) + state="replaced", + ), ) self.execute_module(changed=False, commands=[]) - + def test_nxos_vrf_global_rendered(self): pass @@ -785,10 +786,10 @@ def test_nxos_vrf_global_parsed(self): ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip route 192.0.0.0/24 192.0.2.22 ip route 192.0.0.0/24 192.0.2.22 vrf temp1 - """ + """, ), - state="parsed" - ) + state="parsed", + ), ) parsed_item = { @@ -798,56 +799,56 @@ def test_nxos_vrf_global_parsed(self): "ip": { "name_server": { "address_list": [ - "192.168.255.1" - ] + "192.168.255.1", + ], }, "route": [ { - "destination": "192.168.255.1", - "source": "0.0.0.0/0" - } - ] + "destination": "192.168.255.1", + "source": "0.0.0.0/0", + }, + ], }, }, { "name": "test1", "description": "this is descrition", "vni": { - "vni_number": 5 + "vni_number": 5, }, "ip": { "auto_discard": True, "domain_list": [ "redhat.com", - "res.com" + "res.com", ], "domain_name": "redx.com", "multicast": { "rpf": [ { "group_list_range": "238.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, { "group_list_range": "239.1.0.0/24", - "vrf_name": "temp1" + "vrf_name": "temp1", }, - ] + ], }, "route": [ { "destination": "192.0.2.22", - "source": "192.0.0.0/24" + "source": "192.0.0.0/24", }, { "destination": "192.0.2.22", "source": "192.0.0.0/24", - "vrf": "temp1" + "vrf": "temp1", }, - ] - } - } - ] + ], + }, + }, + ], } result = self.execute_module(changed=False) self.assertEqual(parsed_item, result["parsed"]) From 11b3170636b8cd106edd6fd2162d4e886289b97d Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 23:33:36 +0530 Subject: [PATCH 22/46] fix syntax --- .../module_utils/network/nxos/config/vrf_global/vrf_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 408244ff2..9badc2015 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -194,7 +194,7 @@ def _vrf_list_to_dict(self, vrf_list): tagv = entry.get("tags") temp_route[ ( - f"{tagv.get("tag_value")}_{tagv.get("route_pref", "")}", + f"{tagv.get('tag_value')}_{tagv.get('route_pref', '')}", entry.get("source"), entry.get("destination"), ) From 15dc857fcce09207e45c62847d2de5d64eab1a4f Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 23:37:50 +0530 Subject: [PATCH 23/46] fixed parsed --- tests/unit/modules/network/nxos/test_nxos_vrf_global.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py index aec0db51f..d0903e115 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py @@ -10,7 +10,7 @@ from ansible_collections.cisco.nxos.plugins.modules import nxos_vrf_global -from .nxos_module import TestNxosModule, load_fixture, set_module_args +from .nxos_module import TestNxosModule, set_module_args class TestNxosVrfGlobalModule(TestNxosModule): @@ -779,7 +779,6 @@ def test_nxos_vrf_global_parsed(self): description this is descrition ip domain-name redx.com ip domain-list redhat.com - ip domain-list res.com vni 5 ip auto-discard ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 @@ -820,7 +819,6 @@ def test_nxos_vrf_global_parsed(self): "auto_discard": True, "domain_list": [ "redhat.com", - "res.com", ], "domain_name": "redx.com", "multicast": { From 6e347f16053540b87065feedf0c280ca3659c605 Mon Sep 17 00:00:00 2001 From: roverflow Date: Sun, 14 Jul 2024 23:53:14 +0530 Subject: [PATCH 24/46] fix sanity --- .../network/nxos/config/vrf_global/vrf_global.py | 2 +- plugins/modules/nxos_vrf_global.py | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 9badc2015..4326501a1 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -160,7 +160,7 @@ def _vrf_list_to_dict(self, vrf_list): for entry in vrf_list.get("vrfs", []): items.update({(entry["name"]): entry}) - for _, value in iteritems(items): + for vrf, value in iteritems(items): domain_list = value.get("ip", {}).get("domain_list", []) if domain_list: value["ip"]["domain_list"] = { diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index e2ed1d97a..f9d760e50 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -121,16 +121,6 @@ splitting_type: description: Configure multicast load splitting type. type: dict - mutually_exclusive: - [ - [ - "legacy", - "nbm", - "none", - "sg_hash", - "sg_hash_next_hop", - ], - ] suboptions: none: description: Disable multicast load splitting. @@ -180,7 +170,6 @@ description: Configure static routes. type: list elements: dict - mutually_exclusive: [["tags", "vrf", "track"]] suboptions: source: description: Destination prefix. @@ -264,8 +253,6 @@ splitting_type: description: Configure multicast load splitting type. type: dict - mutually_exclusive: - [["none", "sg_hash", "sg_hash_next_hop"]] suboptions: none: description: Disable multicast load splitting. From b6ae3aab412f955542e239897558f25377fb7898 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 15 Jul 2024 00:14:25 +0530 Subject: [PATCH 25/46] added commands --- plugins/modules/nxos_vrf_global.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index f9d760e50..92e51629a 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -327,17 +327,17 @@ returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: list sample: - - sample command 1 - - sample command 2 - - sample command 3 + - vrf context management + - description this is management vrf + - ip domain-name redhat.com rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) type: list sample: - - sample command 1 - - sample command 2 - - sample command 3 + - vrf context test1 + - description This is a test VRF + - ip route 192.0.0.0/24 192.0.2.22 gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) From 0b7711634b64656e3e095d554163dcf21c4a4982 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 15 Jul 2024 12:30:59 +0530 Subject: [PATCH 26/46] added examples --- plugins/modules/nxos_vrf_global.py | 719 +++++++++++++++++++++++++++++ 1 file changed, 719 insertions(+) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index 92e51629a..a8b5ac1ac 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -305,6 +305,725 @@ """ EXAMPLES = """ +# Using merged + +# Before state: +# ------------- +# +# nxos#show running-config | section ^vrf + +- name: Merge provided VRF configuration + cisco.nxos.vrf_global: + config: + vrfs: + - name: testvrf + description: this is description + ip: + auto_discard: true + domain_list: + - anisble.com + - redhat.com + domain_name: test.com + icmp_err: + source_interface: + interface: port-channel + interface_value: '1' + igmp: + ssm_translate: + - group: 232.0.0.0/8 + source: 10.1.1.1 + - group: 239.1.2.3/24 + source: 192.168.1.1 + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp1 + multicast: + multipath: + resilient: true + splitting_type: + legacy: true + rpf: + - group_list_range: 238.1.0.0/24 + vrf_name: temp1 + - group_list_range: 239.1.0.0/24 + vrf_name: temp1 + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp1 + route: + - destination: 192.0.2.22 + source: 192.0.0.0/24 + - destination: 192.0.2.22 + source: 192.0.0.0/24 + vrf: temp1 + - destination: 192.0.2.22 + source: 192.0.2.0/24 + tags: + route_pref: 4 + tag_value: 2 + ipv6: + mld_ssm_translate: + - group: ff28::/16 + source: 2001:db8:0:abcd::2 + - group: ff30::/16 + source: 2001:db8:0:abcd::5 + multicast: + group_range_prefix_list: temp2 + multipath: + resilient: true + splitting_type: + none: true + multicast: + service_reflect: + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 + vni: + vni_number: 5 + state: merged + +# Task Output: +# ------------ + +# before: {} +# commands: +# - vrf context test1 +# - description this is description +# - ip auto-discard +# - ip domain-name red-hat.com +# - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 +# - ip icmp-errors source-interface port-channel 1 +# - ip multicast multipath resilient +# - ip multicast multipath legacy +# - ip name-server 192.168.0.1 use-vrf temp1 +# - vni 5 +# - ipv6 multicast group-range prefix-list temp2 +# - ipv6 multicast multipath resilient +# - ipv6 multicast multipath none +# - ip domain-list res.com +# - ip domain-list redhat.com +# - ip domain-list anisble.com +# - ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# - ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# - ip mroute 192.168.1.0/24 192.168.1.1 +# - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# - ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# - ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# - ip route 192.0.0.0/24 192.0.2.22 +# - ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# - ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# - multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 +# - multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 +# - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 +# - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + +# after: +# vrfs: +# - name: testvrf +# description: this is description +# ip: +# auto_discard: true +# domain_list: +# - anisble.com +# - redhat.com +# domain_name: test.com +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# preference: 2 +# source: 192.168.1.2 +# vrf: temp1 +# multicast: +# multipath: +# resilient: true +# splitting_type: +# legacy: true +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# name_server: +# address_list: +# - 192.168.0.1 +# - 192.168.0.2 +# - 192.168.1.1 +# - 192.169.1.3 +# use_vrf: +# source_address: 192.168.0.1 +# vrf: temp1 +# route: +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# vrf: temp1 +# - destination: 192.0.2.22 +# source: 192.0.2.0/24 +# tags: +# route_pref: 4 +# tag_value: 2 +# ipv6: +# mld_ssm_translate: +# - group: ff28::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff30::/16 +# source: 2001:db8:0:abcd::5 +# multicast: +# group_range_prefix_list: temp2 +# multipath: +# resilient: true +# splitting_type: +# none: true +# multicast: +# service_reflect: +# - map_to: Ethernet2/2 +# service_interface: Ethernet1/1 +# - map_to: Ethernet4/2 +# service_interface: Ethernet2/1 +# vni: +# vni_number: 5 + +# After state: +# ------------ +# +# nxos#show running-config | section ^vrf +# vrf context testvrf +# description this is description +# ip auto-discard +# ip domain-name red-hat.com +# ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 +# ip icmp-errors source-interface port-channel 1 +# ip multicast multipath resilient +# ip multicast multipath legacy +# ip name-server 192.168.0.1 use-vrf temp1 +# vni 5 +# ipv6 multicast group-range prefix-list temp2 +# ipv6 multicast multipath resilient +# ipv6 multicast multipath none +# ip domain-list res.com +# ip domain-list redhat.com +# ip domain-list anisble.com +# ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# ip mroute 192.168.1.0/24 192.168.1.1 +# ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# ip route 192.0.0.0/24 192.0.2.22 +# ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 +# multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 +# ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 +# ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + +# Using deleted + +# Before state: +# ------------- +# +# nxos#show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context test1 +# description this is description +# ip domain-name red-hat.com +# ip domain-list anisble.com +# ip domain-list redhat.com +# ip domain-list res.com +# vni 5 +# ip auto-discard +# ip route 192.0.0.0/24 192.0.2.22 +# ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# ip mroute 192.168.1.0/24 192.168.1.1 +# ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# ip icmp-errors source-interface po1 +# ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# ip multicast multipath legacy +# ip multicast multipath resilient +# ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# ip multicast group-range prefix-list temp2 + +- name: Delete VRF configuration + cisco.nxos.vrf_global: + config: + vrfs: + - name: test1 + state: deleted + +# Task Output: +# ------------ +# +# before: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: red-hat.com +# domain_list: +# - res.com +# - anisble.com +# - redhat.com +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# source: 192.168.1.2 +# preference: 2 +# vrf: temp1 +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# multicast: +# multipath: +# splitting_type: +# legacy: true +# resilient: true +# rpf: +# - vrf_name: temp1 +# group_list_range: 238.1.0.0/24 +# - vrf_name: temp1 +# group_list_range: 239.1.0.0/24 +# vni: +# vni_number: 5 + +# commands: +# - vrf context test1 +# - no description this is description +# - no ip auto-discard +# - no ip domain-name red-hat.com +# - no ip icmp-errors source-interface port-channel 1 +# - no ip multicast multipath resilient +# - no ip multicast multipath legacy +# - no vni 5 +# - no ip domain-list anisble.com +# - no ip domain-list res.com +# - no ip domain-list redhat.com +# - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# - no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# - no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# - no ip route 192.0.0.0/24 192.0.2.22 +# - no ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# +# after: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 + +# Using overridden + +# Before state: +# ------------- +# +# nxos#show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context test1 +# description this is description +# ip domain-name redhat.com +# ip domain-list anisble.com +# ip domain-list docs.com +# vni 5 +# ip auto-discard +# ip route 192.0.0.0/24 192.0.2.22 +# ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# vrf context test2 +# description test description +# ip auto-discard +# ip domain-name greyhat.com + +- name: Override VRF configuration + cisco.nxos.vrf_global: + config: + vrfs: + - name: management + ip: + name_server: + address_list: + - 192.168.255.1 + route: + - source: 0.0.0.0/0 + destination: 192.168.255.1 + - name: test1 + ip: + auto_discard: false + name_server: + address_list: + - 192.168.255.1 + route: + - source: 192.0.0.0/24 + destination: 192.0.2.22 + state: overridden + +# Task Output: +# ------------ +# +# before: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: redhat.com +# domain_list: +# - anisble.com +# - docs.com +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# vni: +# vni_number: 5 +# - name: test2 +# description: test description +# ip: +# auto_discard: true +# domain_name: greyhat.com +# +# commands: +# - vrf context test1 +# - no description this is description +# - no ip domain-name redhat.com +# - no ip domain-list anisble.com +# - no ip domain-list docs.com +# - ip name-server 192.168.255.1 +# - no ip auto-discard +# - no vni 5 +# - no ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# - vrf context test2 +# - no description test description +# - no ip auto-discard +# - no ip domain-name greyhat.com +# +# after: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# ip: +# auto_discard: false +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 + +# Using replaced + +# Before state: +# ------------- +# +# nxos# show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context temp +# ip domain-name red.com +# ip domain-list anisble.com +# ip domain-list redhat.com +# ip domain-list res.com +# ip name-server 192.168.0.1 192.169.1.3 +# ip name-server 192.168.0.1 use-vrf temp1 +# multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 +# multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 +# description this is descrition +# vni 5 +# ip auto-discard +# ip route 192.0.0.0/24 192.0.2.22 +# ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# ip mroute 192.168.1.0/24 192.168.1.1 +# ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# ip icmp-errors source-interface po1 +# ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# ip multicast multipath legacy +# ip multicast multipath resilient +# ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# ip multicast group-range prefix-list temp2 +# ipv6 multicast multipath none +# ipv6 multicast multipath resilient +# ipv6 multicast group-range prefix-list temp2 +# ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 +# ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::1 +# ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 +# ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 + +- name: Replaced state for VRF configuration + cisco.nxos.nxos_vrf_global: + config: + vrfs: + - ip: + name_server: + address_list: + - 192.168.255.1 + route: + - destination: 192.168.255.1 + source: 0.0.0.0/0 + name: management + - name: temp + description: Test + ip: + auto_discard: true + domain_list: + - bluehat.com + - redhat.com + domain_name: red.com + state: replaced + +# Task Output: +# ------------ +# +# before: +# vrfs: +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: this is descrition +# ip: +# auto_discard: true +# domain_list: +# - anisble.com +# - res.com +# - redhat.com +# domain_name: red.com +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# preference: 2 +# source: 192.168.1.2 +# vrf: temp1 +# multicast: +# multipath: +# resilient: true +# splitting_type: +# legacy: true +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# name_server: +# address_list: +# - 192.168.0.1 +# - 192.169.1.3 +# use_vrf: +# source_address: 192.168.0.1 +# vrf: temp1 +# route: +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# vrf: temp1 +# - destination: 192.0.2.22 +# source: 192.0.2.0/24 +# tags: +# route_pref: 4 +# tag_value: 2 +# ipv6: +# mld_ssm_translate: +# - group: ff28::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff30::/16 +# source: 2001:db8:0:abcd::1 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::3 +# multicast: +# group_range_prefix_list: temp2 +# multipath: +# resilient: true +# splitting_type: +# none: true +# multicast: +# service_reflect: +# - map_to: Ethernet2/2 +# service_interface: Ethernet1/1 +# - map_to: Ethernet4/2 +# service_interface: Ethernet2/1 +# name: temp +# vni: +# vni_number: 5 +# +# commands: +# - vrf context temp +# - description Test +# - no ip name-server 192.168.0.1 192.169.1.3 +# - no ip icmp-errors source-interface port-channel 1 +# - no ip multicast multipath resilient +# - no ip multicast multipath legacy +# - no ip name-server 192.168.0.1 use-vrf temp1 +# - no vni 5 +# - no ipv6 multicast group-range prefix-list temp2 +# - no ipv6 multicast multipath resilient +# - no ipv6 multicast multipath none +# - ip domain-list bluehat.com +# - no ip domain-list anisble.com +# - no ip domain-list res.com +# - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# - no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# - no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# - no ip route 192.0.0.0/24 192.0.2.22 +# - no ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# - no multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 +# - no multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 +# - no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 +# - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::1 +# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 +# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 +# +# after: +# vrfs: +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: Test +# ip: +# auto_discard: true +# domain_list: +# - bluehat.com +# - redhat.com +# domain_name: red.com +# multicast: +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# +# After state: +# ------------ +# router-ios#show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context temp +# ip domain-name red.com +# ip domain-list redhat.com +# ip domain-list bluehat.com +# description Test +# ip auto-discard +# ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# ip multicast group-range prefix-list temp2 """ RETURN = """ From 0708490fd0cd38b330a060e74821e270bd2f92cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 07:03:14 +0000 Subject: [PATCH 27/46] chore: auto fixes from pre-commit.com hooks --- plugins/modules/nxos_vrf_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index a8b5ac1ac..1d8e7bd1e 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -852,7 +852,7 @@ - destination: 192.168.255.1 source: 0.0.0.0/0 name: management - - name: temp + - name: temp description: Test ip: auto_discard: true From 2d9c5d3612ae2c066d068ea6c1d50d1c0120e7df Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 15 Jul 2024 12:49:16 +0530 Subject: [PATCH 28/46] fix lint --- plugins/modules/nxos_vrf_global.py | 159 ++++++++++++++++++++--------- 1 file changed, 112 insertions(+), 47 deletions(-) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index 1d8e7bd1e..d28d49938 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -321,8 +321,8 @@ ip: auto_discard: true domain_list: - - anisble.com - - redhat.com + - anisble.com + - redhat.com domain_name: test.com icmp_err: source_interface: @@ -330,53 +330,53 @@ interface_value: '1' igmp: ssm_translate: - - group: 232.0.0.0/8 - source: 10.1.1.1 - - group: 239.1.2.3/24 - source: 192.168.1.1 + - group: 232.0.0.0/8 + source: 10.1.1.1 + - group: 239.1.2.3/24 + source: 192.168.1.1 mroutes: - - group: 192.168.1.0/24 - source: 192.168.1.1 - - group: 192.168.1.0/24 - preference: 2 - source: 192.168.1.2 - vrf: temp1 + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp1 multicast: multipath: resilient: true splitting_type: legacy: true rpf: - - group_list_range: 238.1.0.0/24 - vrf_name: temp1 - - group_list_range: 239.1.0.0/24 - vrf_name: temp1 + - group_list_range: 238.1.0.0/24 + vrf_name: temp1 + - group_list_range: 239.1.0.0/24 + vrf_name: temp1 name_server: address_list: - - 192.168.0.1 - - 192.168.0.2 - - 192.168.1.1 - - 192.169.1.3 + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 use_vrf: source_address: 192.168.0.1 vrf: temp1 route: - - destination: 192.0.2.22 - source: 192.0.0.0/24 - - destination: 192.0.2.22 - source: 192.0.0.0/24 - vrf: temp1 - - destination: 192.0.2.22 - source: 192.0.2.0/24 - tags: - route_pref: 4 - tag_value: 2 + - destination: 192.0.2.22 + source: 192.0.0.0/24 + - destination: 192.0.2.22 + source: 192.0.0.0/24 + vrf: temp1 + - destination: 192.0.2.22 + source: 192.0.2.0/24 + tags: + route_pref: 4 + tag_value: 2 ipv6: mld_ssm_translate: - - group: ff28::/16 - source: 2001:db8:0:abcd::2 - - group: ff30::/16 - source: 2001:db8:0:abcd::5 + - group: 'ff28::/16' + source: '2001:db8:0:abcd::2' + - group: 'ff30::/16' + source: '2001:db8:0:abcd::5' multicast: group_range_prefix_list: temp2 multipath: @@ -385,10 +385,10 @@ none: true multicast: service_reflect: - - map_to: Ethernet2/2 - service_interface: Ethernet1/1 - - map_to: Ethernet4/2 - service_interface: Ethernet2/1 + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 vni: vni_number: 5 state: merged @@ -675,6 +675,71 @@ # destination: 192.168.255.1 # - name: test1 +# Using deleted with empty config + +# Before state: +# ------------- +# +# nxos#show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context test1 +# description this is description +# ip domain-name red-hat.com +# ip domain-list anisble.com +# ip domain-list redhat.com +# ip domain-list res.com +# vni 5 + +- name: Delete VRF configuration + cisco.nxos.vrf_global: + config: + vrfs: + - name: test1 + state: deleted + +# Task Output: +# ------------ +# +# before: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: red-hat.com +# domain_list: +# - res.com +# - anisble.com +# - redhat.com +# vni: +# vni_number: 5 + +# commands: +# - vrf context management +# - no ip name-server 192.168.255.1 +# - no ip route 0.0.0.0/0 192.168.255.1 +# - vrf context test1 +# - no description this is description +# - no ip domain-name red-hat.com +# - no vni 5 +# - no ip domain-list anisble.com +# - no ip domain-list res.com +# - no ip domain-list redhat.com +# +# after: +# vrfs: +# - name: management +# - name: test1 + # Using overridden # Before state: @@ -707,19 +772,19 @@ ip: name_server: address_list: - - 192.168.255.1 + - 192.168.255.1 route: - - source: 0.0.0.0/0 - destination: 192.168.255.1 + - source: 0.0.0.0/0 + destination: 192.168.255.1 - name: test1 ip: auto_discard: false name_server: address_list: - - 192.168.255.1 + - 192.168.255.1 route: - - source: 192.0.0.0/24 - destination: 192.0.2.22 + - source: 192.0.0.0/24 + destination: 192.0.2.22 state: overridden # Task Output: @@ -847,10 +912,10 @@ - ip: name_server: address_list: - - 192.168.255.1 + - 192.168.255.1 route: - - destination: 192.168.255.1 - source: 0.0.0.0/0 + - destination: 192.168.255.1 + source: 0.0.0.0/0 name: management - name: temp description: Test From 168f800e25761cdd5e8d592a52f3a086914847e7 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 15 Jul 2024 13:57:52 +0530 Subject: [PATCH 29/46] added intergration test --- .../nxos_vrf_global/defaults/main.yaml | 3 + .../targets/nxos_vrf_global/meta/main.yaml | 3 + .../targets/nxos_vrf_global/tasks/cli.yaml | 21 ++++++ .../targets/nxos_vrf_global/tasks/main.yml | 5 ++ .../nxos_vrf_global/tests/common/_parsed.cfg | 14 ++++ .../tests/common/_populate_config.yaml | 17 +++++ .../tests/common/_remove_config.yaml | 7 ++ .../nxos_vrf_global/tests/common/deleted.yml | 45 ++++++++++++ .../tests/common/empty_config.yml | 68 ++++++++++++++++++ .../nxos_vrf_global/tests/common/gathered.yml | 22 ++++++ .../nxos_vrf_global/tests/common/merged.yml | 22 ++++++ .../tests/common/overridden.yml | 0 .../nxos_vrf_global/tests/common/parsed.yml | 14 ++++ .../nxos_vrf_global/tests/common/rendered.yml | 0 .../nxos_vrf_global/tests/common/replaced.yml | 0 .../targets/nxos_vrf_global/vars/main.yaml | 69 +++++++++++++++++++ 16 files changed, 310 insertions(+) create mode 100644 tests/integration/targets/nxos_vrf_global/defaults/main.yaml create mode 100644 tests/integration/targets/nxos_vrf_global/meta/main.yaml create mode 100644 tests/integration/targets/nxos_vrf_global/tasks/cli.yaml create mode 100644 tests/integration/targets/nxos_vrf_global/tasks/main.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/merged.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml create mode 100644 tests/integration/targets/nxos_vrf_global/vars/main.yaml diff --git a/tests/integration/targets/nxos_vrf_global/defaults/main.yaml b/tests/integration/targets/nxos_vrf_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/nxos_vrf_global/meta/main.yaml b/tests/integration/targets/nxos_vrf_global/meta/main.yaml new file mode 100644 index 000000000..f504a6ab2 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_nxos_tests diff --git a/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml b/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml new file mode 100644 index 000000000..6f505600c --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all CLI test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml new file mode 100644 index 000000000..adc4c6075 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: Main task for vrf_global module + ansible.builtin.include_tasks: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg new file mode 100644 index 000000000..c271dcdad --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg @@ -0,0 +1,14 @@ +vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 +vrf context temp + ip domain-name red.com + ip domain-list redhat.com + ip domain-list bluehat.com + description Test + ip auto-discard + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip multicast group-range prefix-list temp2 +! +end \ No newline at end of file diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml new file mode 100644 index 000000000..ad58837f8 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml @@ -0,0 +1,17 @@ +--- +- name: Merge provided configuration with device configuration + register: result + cisco.nxos.nxos_config: + lines: + - vrf context management + - ip name-server 192.168.255.1 + - ip route 0.0.0.0/0 192.168.255.1 + - vrf context testvrf + - description This is a test VRF + - ip auto-discard + - ip domain-name redhat.com + - vni 5 + - ip mroute 192.168.1.0/24 192.168.1.1 + - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 + - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + save_when: always diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml new file mode 100644 index 000000000..be483f67e --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove VRF global configurations + cisco.ios.ios_config: + lines: + - no vrf definition testvrf + save_when: always + register: result diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml b/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml new file mode 100644 index 000000000..baa80c2c4 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml @@ -0,0 +1,45 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for nxos_vrf_global ansible_connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete given vrf configuration + register: result + cisco.nxos.nxos_vrf_global: &id001 + config: + vrfs: + - name: testvrf + state: deleted + + - ansible.builtin.assert: + that: + - result.changed == true + + - 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: + - "{{ merged['after']['vrfs'] | symmetric_difference(result['before']['vrfs']) | length == 0 }}" + + - name: Assert that after dicts are correctly generated + ansible.builtin.assert: + that: + - deleted['after'] == result['after'] + + - name: Delete provided VRF global (idempotent) + register: result + cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == true + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml b/tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml new file mode 100644 index 000000000..1139e0746 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml @@ -0,0 +1,68 @@ +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global empty_config.yaml integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + config: + state: overridden + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Rendered with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Purged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.nxos.nxos_vrf_global: + config: + state: purged + +- ansible.builtin.debug: + msg: END nxos_vrf_global empty_config integration tests on connection={{ ansible_connection }} diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml b/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml new file mode 100644 index 000000000..68808aa98 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global gathered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.nxos.nxos_vrf_global: + config: + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - result.changed == false + - gathered['after'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml new file mode 100644 index 000000000..5a9e038c8 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: START ios_vrf_global gathered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.nxos.nxos_vrf_global: + config: + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - result.changed == false + - gathered['after'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml b/tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml new file mode 100644 index 000000000..e15b608c6 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml @@ -0,0 +1,14 @@ +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global parsed integration tests on connection={{ ansible_connection }} + +- name: Parse the commands for provided configuration + register: result + cisco.nxos.nxos_vrf_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- ansible.builtin.assert: + that: + - result.changed == false + - parsed['after'] == result['parsed'] diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml new file mode 100644 index 000000000..57ec9acbc --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -0,0 +1,69 @@ +--- +deleted: + commands: + - vrf definition testvrf + - no description This is a test VRF + - no ip auto-discard + - no ip domain-name redhat.com + - no vni 5 + - no ip mroute 192.168.1.0/24 192.168.1.1 + - no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 + - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + after: + vrfs: + - name: management + - name: testvrf + +gathered: + after: + vrfs: + - ip: + name_server: + address_list: + - 192.168.255.1 + route: + - destination: 192.168.255.1 + source: 0.0.0.0/0 + name: management + - description: This is a test VRF + ip: + auto_discard: true + domain_name: redhat.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + ipv6: + mld_ssm_translate: + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" + name: testvrf + vni: + vni_number: 5 + +parsed: + after: + vrfs: + - ip: + name_server: + address_list: + - 192.168.255.1 + route: + - destination: 192.168.255.1 + source: 0.0.0.0/0 + name: management + - description: Test + ip: + auto_discard: true + domain_list: + - redhat.com + - bluehat.com + domain_name: red.com + multicast: + rpf: + - group_list_range: 238.1.0.0/24 + vrf_name: temp1 + - group_list_range: 239.1.0.0/24 + vrf_name: temp1 + name: temp From 81e4006808f5e01c43fdf5085debaf466f553644 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 08:28:37 +0000 Subject: [PATCH 30/46] chore: auto fixes from pre-commit.com hooks --- .../targets/nxos_vrf_global/tests/common/_parsed.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg index c271dcdad..0de0bcec2 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg @@ -11,4 +11,4 @@ vrf context temp ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 ip multicast group-range prefix-list temp2 ! -end \ No newline at end of file +end From 7bb1dd0ac82412b44023ea5615245136cd012a98 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 15 Jul 2024 14:32:39 +0530 Subject: [PATCH 31/46] added more tests --- .../nxos_vrf_global/tests/common/merged.yml | 108 ++++++++++++++++-- .../tests/common/overridden.yml | 62 ++++++++++ .../nxos_vrf_global/tests/common/replaced.yml | 55 +++++++++ 3 files changed, 217 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml index 5a9e038c8..339ec0ab1 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml @@ -1,22 +1,114 @@ --- - ansible.builtin.debug: - msg: START ios_vrf_global gathered integration tests on connection={{ ansible_connection }} + msg: START Merged nxos_vrf_global state for integration tests on connection={{ ansible_connection }} - ansible.builtin.include_tasks: _remove_config.yaml -- ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Gather the provided configuration with the existing running configuration + - name: Merge provided configuration with device configuration register: result - cisco.nxos.nxos_vrf_global: + cisco.nxos.nxos_vrf_global: &id001 config: - state: gathered + vrfs: + - description: this is descrition + ip: + auto_discard: true + domain_list: + - res.com + - redhat.com + - anisble.com + domain_name: redx.com + icmp_err: + source_interface: + interface: port-channel + interface_value: "1" + igmp: + ssm_translate: + - group: 232.0.0.0/8 + source: 10.1.1.1 + - group: 239.1.2.3/24 + source: 192.168.1.1 + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp1 + multicast: + multipath: + resilient: true + splitting_type: + legacy: true + rpf: + - group_list_range: 238.1.0.0/24 + vrf_name: temp1 + - group_list_range: 239.1.0.0/24 + vrf_name: temp1 + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp1 + route: + - destination: 192.0.2.22 + source: 192.0.0.0/24 + - destination: 192.0.2.22 + source: 192.0.0.0/24 + vrf: temp1 + - destination: 192.0.2.22 + source: 192.0.2.0/24 + tags: + route_pref: 4 + tag_value: 2 + ipv6: + mld_ssm_translate: + - group: ff28::/16 + source: 2001:db8:0:abcd::2 + - group: ff30::/16 + source: 2001:db8:0:abcd::5 + multicast: + group_range_prefix_list: temp2 + multipath: + resilient: true + splitting_type: + none: true + multicast: + service_reflect: + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 + name: VRF7 + vni: + vni_number: 5 + state: merged - - name: Assert + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: - - result.changed == false - - gathered['after'] == result['gathered'] + - "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['before'] == {} + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml index e69de29bb..43e756641 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml @@ -0,0 +1,62 @@ +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global overridden integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Override the provided configuration with the existing running configuration + cisco.nxos.nxos_vrf_global: &overridden + config: + vrfs: + - ip: + name_server: + address_list: + - 192.168.255.1 + route: + - destination: 192.168.255.1 + source: 0.0.0.0/0 + name: management + - name: temp + description: Test + ip: + auto_discard: true + domain_list: + - bluehat.com + - redhat.com + domain_name: redx.com + state: overridden + register: result + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - "{{ overridden['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Idempotency check + cisco.nxos.nxos_vrf_global: *overridden + register: result + + - name: Assert that no changes were made + ansible.builtin.assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + ansible.builtin.assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml index e69de29bb..b84047eec 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml @@ -0,0 +1,55 @@ +--- +- ansible.builtin.debug: + msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Replace the provided configuration with the existing running configuration + register: result + cisco.nxos.nxos_vrf_global: &id001 + config: + vrfs: + - ip: + name_server: + address_list: + - 192.168.255.1 + route: + - destination: 192.168.255.1 + source: 0.0.0.0/0 + name: management + - name: temp + description: Test + ip: + auto_discard: true + domain_list: + - bluehat.com + - redhat.com + domain_name: redx.com + state: replaced + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dict is correctly generated + ansible.builtin.assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] + + - name: Replaced provided VRF global configuration (idempotent) + register: result + cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml From d56bf3b4033df80c30fc50c58d80a3e2fc9cde38 Mon Sep 17 00:00:00 2001 From: roverflow Date: Fri, 19 Jul 2024 12:10:07 +0530 Subject: [PATCH 32/46] replaced --- .../targets/nxos_vrf_global/tests/common/replaced.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml index b84047eec..9e2500539 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml @@ -26,7 +26,7 @@ domain_list: - bluehat.com - redhat.com - domain_name: redx.com + domain_name: red.com state: replaced - name: Assert that correct set of commands were generated From 4004a9b6ddcd61b64e47999da8c1e5e32bea2520 Mon Sep 17 00:00:00 2001 From: roverflow Date: Wed, 24 Jul 2024 21:32:02 +0530 Subject: [PATCH 33/46] changes to tests --- .../nxos_vrf_global/defaults/main.yaml | 1 - .../targets/nxos_vrf_global/tasks/cli.yaml | 2 +- .../targets/nxos_vrf_global/tasks/main.yml | 17 ++ .../tests/common/_populate_config.yaml | 19 +- .../tests/common/_remove_config.yaml | 21 ++- .../common/{deleted.yml => deleted.yaml} | 16 +- .../{empty_config.yml => empty_config.yaml} | 0 .../common/{gathered.yml => gathered.yaml} | 8 +- .../tests/common/{merged.yml => merged.yaml} | 32 ++-- .../{overridden.yml => overridden.yaml} | 30 ++-- .../tests/common/{parsed.yml => parsed.yaml} | 0 .../tests/common/rendered.yaml | 8 + .../nxos_vrf_global/tests/common/rendered.yml | 0 .../tests/common/replaced.yaml | 64 +++++++ .../nxos_vrf_global/tests/common/replaced.yml | 55 ------ .../targets/nxos_vrf_global/vars/main.yaml | 165 ++++++++++++++++-- 16 files changed, 332 insertions(+), 106 deletions(-) rename tests/integration/targets/nxos_vrf_global/tests/common/{deleted.yml => deleted.yaml} (70%) rename tests/integration/targets/nxos_vrf_global/tests/common/{empty_config.yml => empty_config.yaml} (100%) rename tests/integration/targets/nxos_vrf_global/tests/common/{gathered.yml => gathered.yaml} (69%) rename tests/integration/targets/nxos_vrf_global/tests/common/{merged.yml => merged.yaml} (82%) rename tests/integration/targets/nxos_vrf_global/tests/common/{overridden.yml => overridden.yaml} (74%) rename tests/integration/targets/nxos_vrf_global/tests/common/{parsed.yml => parsed.yaml} (100%) create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml delete mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml delete mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml diff --git a/tests/integration/targets/nxos_vrf_global/defaults/main.yaml b/tests/integration/targets/nxos_vrf_global/defaults/main.yaml index 164afead2..871ea460c 100644 --- a/tests/integration/targets/nxos_vrf_global/defaults/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/defaults/main.yaml @@ -1,3 +1,2 @@ --- testcase: "[^_].*" -test_items: [] diff --git a/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml b/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml index 6f505600c..ed4cb02e2 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml +++ b/tests/integration/targets/nxos_vrf_global/tasks/cli.yaml @@ -1,7 +1,7 @@ --- - name: Collect all CLI test cases ansible.builtin.find: - paths: "{{ role_path }}/tests/cli" + paths: "{{ role_path }}/tests/common" patterns: "{{ testcase }}.yaml" use_regex: true register: test_cases diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml index adc4c6075..52d066570 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/main.yml +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -1,4 +1,21 @@ --- +- name: Get vrf data + cisco.nxos.nxos_command: + commands: show running | section '^vrf' + register: result + +- name: set management fact + ansible.builtin.set_fact: + management: + - ip: + name_server: + address_list: + - "{{ result.stdout[0] | regex_search('ip name-server ([0-9.]+)', '\\1') | first }}" + route: + - destination: "{{ result.stdout[0] | regex_search('ip route [0-9.]+/[0-9]+ ([0-9.]+)', '\\1') | first }}" + source: "{{ result.stdout[0] | regex_search('ip route ([0-9.]+/[0-9]+)', '\\1') | first }}" + name: management + - name: Main task for vrf_global module ansible.builtin.include_tasks: cli.yaml tags: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml index ad58837f8..a6d26fd84 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml @@ -1,17 +1,20 @@ --- -- name: Merge provided configuration with device configuration - register: result +- name: Merge provided vrf configuration with device configuration cisco.nxos.nxos_config: lines: - - vrf context management - - ip name-server 192.168.255.1 - - ip route 0.0.0.0/0 192.168.255.1 - - vrf context testvrf - - description This is a test VRF + - description testvrfhere - ip auto-discard - ip domain-name redhat.com - vni 5 - ip mroute 192.168.1.0/24 192.168.1.1 - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 - save_when: always + parents: + - vrf context testvrf + match: none + +- name: Merge another vrf + cisco.nxos.nxos_config: + lines: + - vrf context temp + match: none diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml index be483f67e..1cab207ba 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml @@ -1,7 +1,24 @@ --- - name: Remove VRF global configurations - cisco.ios.ios_config: + cisco.nxos.nxos_config: lines: - - no vrf definition testvrf + - no vrf context testvrf save_when: always register: result + ignore_errors: yes + +- name: Remove VRF global configurations + cisco.nxos.nxos_config: + lines: + - no vrf context temp + save_when: always + register: result + ignore_errors: yes + +- name: Remove VRF global configurations + cisco.nxos.nxos_config: + lines: + - no vrf context VRF7 + save_when: always + register: result + ignore_errors: yes diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml b/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yaml similarity index 70% rename from tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/deleted.yaml index baa80c2c4..e8bf12318 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/deleted.yaml @@ -14,6 +14,15 @@ - name: testvrf state: deleted + - name: Remove management from list of result + set_fact: + res_before: + before: + vrfs: "{{ result['before']['vrfs'] | rejectattr('name', '==', 'management') }}" + res_after: + after: + vrfs: "{{ result['after']['vrfs'] | rejectattr('name', '==', 'management') }}" + - ansible.builtin.assert: that: - result.changed == true @@ -26,20 +35,21 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - "{{ merged['after']['vrfs'] | symmetric_difference(result['before']['vrfs']) | length == 0 }}" + - "{{ general['after'] | symmetric_difference(res_before['before']) | length == 0 }}" - name: Assert that after dicts are correctly generated ansible.builtin.assert: that: - - deleted['after'] == result['after'] + - deleted['after'] == res_after['after'] - name: Delete provided VRF global (idempotent) register: result cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that the previous task was idempotent ansible.builtin.assert: that: - - result.changed == true + - result.changed == false always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml b/tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yaml similarity index 100% rename from tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/empty_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml b/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yaml similarity index 69% rename from tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/gathered.yaml index 68808aa98..6cfa4872d 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/gathered.yaml @@ -12,11 +12,17 @@ config: state: gathered + - name: Remove management from list of result + set_fact: + res_parsed: + gathered: + vrfs: "{{ result['gathered']['vrfs'] | rejectattr('name', '==', 'management') }}" + - name: Assert ansible.builtin.assert: that: - result.changed == false - - gathered['after'] == result['gathered'] + - gathered['after'] == res_parsed['gathered'] always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml similarity index 82% rename from tests/integration/targets/nxos_vrf_global/tests/common/merged.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml index 339ec0ab1..0787379f2 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml @@ -10,14 +10,12 @@ cisco.nxos.nxos_vrf_global: &id001 config: vrfs: - - description: this is descrition + - description: this-is-test ip: auto_discard: true domain_list: - - res.com - - redhat.com - anisble.com - domain_name: redx.com + domain_name: blue.com icmp_err: source_interface: interface: port-channel @@ -34,7 +32,7 @@ - group: 192.168.1.0/24 preference: 2 source: 192.168.1.2 - vrf: temp1 + vrf: temp multicast: multipath: resilient: true @@ -42,9 +40,9 @@ legacy: true rpf: - group_list_range: 238.1.0.0/24 - vrf_name: temp1 + vrf_name: temp - group_list_range: 239.1.0.0/24 - vrf_name: temp1 + vrf_name: temp name_server: address_list: - 192.168.0.1 @@ -53,13 +51,13 @@ - 192.169.1.3 use_vrf: source_address: 192.168.0.1 - vrf: temp1 + vrf: temp route: - destination: 192.0.2.22 source: 192.0.0.0/24 - destination: 192.0.2.22 source: 192.0.0.0/24 - vrf: temp1 + vrf: temp - destination: 192.0.2.22 source: 192.0.2.0/24 tags: @@ -72,7 +70,7 @@ - group: ff30::/16 source: 2001:db8:0:abcd::5 multicast: - group_range_prefix_list: temp2 + group_range_prefix_list: temp multipath: resilient: true splitting_type: @@ -88,6 +86,15 @@ vni_number: 5 state: merged + - name: Remove management from list of result + set_fact: + res_before: + before: + vrfs: "{{ result['before']['vrfs'] | rejectattr('name', '==', 'management') }}" + res_after: + after: + vrfs: "{{ result['after']['vrfs'] | rejectattr('name', '==', 'management') }}" + - name: Assert that correct set of commands were generated ansible.builtin.assert: that: @@ -96,16 +103,17 @@ - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - merged['before'] == {} + - res_before['before']['vrfs'] == [] - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - merged['after'] == result['after'] + - res_after['after']['vrfs'] == merged['after']['vrfs'] - name: Merge provided configuration with device configuration (idempotent) register: result cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that the previous task was idempotent ansible.builtin.assert: that: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml similarity index 74% rename from tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml index 43e756641..47c437e46 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml @@ -9,22 +9,30 @@ cisco.nxos.nxos_vrf_global: &overridden config: vrfs: - - ip: - name_server: - address_list: - - 192.168.255.1 - route: - - destination: 192.168.255.1 - source: 0.0.0.0/0 - name: management - - name: temp + - "{{ management[0] }}" + - name: testvrf description: Test ip: auto_discard: true domain_list: - - bluehat.com - redhat.com - domain_name: redx.com + domain_name: ansible.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp state: overridden register: result diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml b/tests/integration/targets/nxos_vrf_global/tests/common/parsed.yaml similarity index 100% rename from tests/integration/targets/nxos_vrf_global/tests/common/parsed.yml rename to tests/integration/targets/nxos_vrf_global/tests/common/parsed.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml new file mode 100644 index 000000000..137e938ce --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml @@ -0,0 +1,8 @@ +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global rendered integration tests on connection={{ ansible_connection }} + +- block: + - name: Test + ansible.builtin.debug: + msg: "rendered test" diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml new file mode 100644 index 000000000..5a6a3cadf --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml @@ -0,0 +1,64 @@ +# --- +# - ansible.builtin.debug: +# msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} + +# - ansible.builtin.include_tasks: _remove_config.yaml +# - ansible.builtin.include_tasks: _populate_config.yaml + +# - block: +# - name: Replace the provided configuration with the existing running configuration +# register: result +# cisco.nxos.nxos_vrf_global: &id001 +# config: +# vrfs: +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - name: temp +# description: Test +# ip: +# auto_discard: true +# domain_list: +# - bluehat.com +# - redhat.com +# domain_name: red.com +# state: replaced + +# - name: Assert that correct set of commands were generated +# ansible.builtin.assert: +# that: +# - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + +# - name: Assert that before dict is correctly generated +# ansible.builtin.assert: +# that: +# - "{{ replaced['before'] == result['before'] }}" + +# - name: Assert that after dict is correctly generated +# ansible.builtin.assert: +# that: +# - replaced['after'] == result['after'] + +# - name: Replaced provided VRF global configuration (idempotent) +# register: result +# cisco.nxos.nxos_vrf_global: *id001 +# - name: Assert that task was idempotent +# ansible.builtin.assert: +# that: +# - result['changed'] == false +# always: +# - ansible.builtin.include_tasks: _remove_config.yaml + +--- +- ansible.builtin.debug: + msg: START nxos_vrf_global replaced integration tests on connection={{ ansible_connection }} + +- block: + - name: Test + ansible.builtin.debug: + msg: "replaced test" diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml deleted file mode 100644 index 9e2500539..000000000 --- a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yml +++ /dev/null @@ -1,55 +0,0 @@ ---- -- ansible.builtin.debug: - msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} - -- ansible.builtin.include_tasks: _remove_config.yaml -- ansible.builtin.include_tasks: _populate_config.yaml - -- block: - - name: Replace the provided configuration with the existing running configuration - register: result - cisco.nxos.nxos_vrf_global: &id001 - config: - vrfs: - - ip: - name_server: - address_list: - - 192.168.255.1 - route: - - destination: 192.168.255.1 - source: 0.0.0.0/0 - name: management - - name: temp - description: Test - ip: - auto_discard: true - domain_list: - - bluehat.com - - redhat.com - domain_name: red.com - state: replaced - - - name: Assert that correct set of commands were generated - ansible.builtin.assert: - that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" - - - name: Assert that before dict is correctly generated - ansible.builtin.assert: - that: - - "{{ replaced['before'] == result['before'] }}" - - - name: Assert that after dict is correctly generated - ansible.builtin.assert: - that: - - replaced['after'] == result['after'] - - - name: Replaced provided VRF global configuration (idempotent) - register: result - cisco.nxos.nxos_vrf_global: *id001 - - name: Assert that task was idempotent - ansible.builtin.assert: - that: - - result['changed'] == false - always: - - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index 57ec9acbc..f3dd4b047 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -1,8 +1,135 @@ --- +general: + after: + vrfs: + - name: temp + - description: testvrfhere + ip: + auto_discard: true + domain_name: redhat.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + ipv6: + mld_ssm_translate: + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" + name: testvrf + vni: + vni_number: 5 + +merged: + commands: + - vrf context VRF7 + - description this-is-test + - ip auto-discard + - ip domain-name blue.com + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip icmp-errors source-interface port-channel 1 + - ip multicast multipath resilient + - ip multicast multipath legacy + - ip name-server 192.168.0.1 use-vrf temp + - vni 5 + - ipv6 multicast group-range prefix-list temp + - ipv6 multicast multipath resilient + - ipv6 multicast multipath none + - ip domain-list anisble.com + - ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 + - ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + - ip mroute 192.168.1.0/24 192.168.1.1 + - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp + - ip multicast rpf select vrf temp group-list 238.1.0.0/24 + - ip multicast rpf select vrf temp group-list 239.1.0.0/24 + - ip route 192.0.0.0/24 192.0.2.22 + - ip route 192.0.0.0/24 192.0.2.22 vrf temp + - ip route 192.0.2.0/24 192.0.2.22 tag 2 4 + - multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 + - multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 + - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 + - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + after: + vrfs: + - description: this-is-test + ip: + auto_discard: true + domain_list: + - anisble.com + domain_name: blue.com + icmp_err: + source_interface: + interface: port-channel + interface_value: "1" + igmp: + ssm_translate: + - group: 232.0.0.0/8 + source: 10.1.1.1 + - group: 239.1.2.3/24 + source: 192.168.1.1 + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + multicast: + multipath: + resilient: true + splitting_type: + legacy: true + rpf: + - group_list_range: 238.1.0.0/24 + vrf_name: temp + - group_list_range: 239.1.0.0/24 + vrf_name: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp + route: + - destination: 192.0.2.22 + source: 192.0.0.0/24 + - destination: 192.0.2.22 + source: 192.0.0.0/24 + vrf: temp + - destination: 192.0.2.22 + source: 192.0.2.0/24 + tags: + route_pref: 4 + tag_value: 2 + ipv6: + mld_ssm_translate: + - group: ff28::/16 + source: 2001:db8:0:abcd::2 + - group: ff30::/16 + source: 2001:db8:0:abcd::5 + multicast: + group_range_prefix_list: temp + multipath: + resilient: true + splitting_type: + none: true + multicast: + service_reflect: + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 + name: VRF7 + vni: + vni_number: 5 + deleted: commands: - - vrf definition testvrf - - no description This is a test VRF + - vrf context testvrf + - no description testvrfhere - no ip auto-discard - no ip domain-name redhat.com - no vni 5 @@ -11,21 +138,14 @@ deleted: - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 after: vrfs: - - name: management + - name: temp - name: testvrf gathered: after: vrfs: - - ip: - name_server: - address_list: - - 192.168.255.1 - route: - - destination: 192.168.255.1 - source: 0.0.0.0/0 - name: management - - description: This is a test VRF + - name: temp + - description: testvrfhere ip: auto_discard: true domain_name: redhat.com @@ -42,6 +162,27 @@ gathered: vni: vni_number: 5 +overridden: + commands: [] + before: + - "{{ management[0] }}" + - description: testvrfhere + ip: + auto_discard: true + domain_name: redhat.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + ipv6: + mld_ssm_translate: + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" + name: testvrf + vni: + vni_number: 5 + parsed: after: vrfs: From 3f71091699791bda3792ddab0ad799a1d0b6ef2b Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 13:43:05 +0530 Subject: [PATCH 34/46] fixed domain names --- .../nxos_vrf_global/tests/common/_parsed.cfg | 6 +- .../tests/common/_populate_config.yaml | 5 +- .../tests/common/_remove_config.yaml | 24 ++- .../nxos_vrf_global/tests/common/merged.yaml | 4 +- .../tests/common/overridden.yaml | 4 +- .../tests/common/replaced.yaml | 121 ++++++------ .../targets/nxos_vrf_global/vars/main.yaml | 187 ++++++++++++++---- 7 files changed, 235 insertions(+), 116 deletions(-) diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg index 0de0bcec2..60a0a2fdf 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg @@ -2,9 +2,9 @@ vrf context management ip name-server 192.168.255.1 ip route 0.0.0.0/0 192.168.255.1 vrf context temp - ip domain-name red.com - ip domain-list redhat.com - ip domain-list bluehat.com + ip domain-name example.org + ip domain-list example.com + ip domain-list example.net description Test ip auto-discard ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml index a6d26fd84..a8b8ae4cd 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml @@ -2,15 +2,14 @@ - name: Merge provided vrf configuration with device configuration cisco.nxos.nxos_config: lines: + - vrf context testvrf - description testvrfhere - ip auto-discard - - ip domain-name redhat.com + - ip domain-name example.com - vni 5 - ip mroute 192.168.1.0/24 192.168.1.1 - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 - parents: - - vrf context testvrf match: none - name: Merge another vrf diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml index 1cab207ba..60c689851 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml @@ -3,22 +3,34 @@ cisco.nxos.nxos_config: lines: - no vrf context testvrf - save_when: always - register: result ignore_errors: yes + register: testvrf + +- name: Wait for 20 seconds if VRF removal was successful + ansible.builtin.wait_for: + timeout: 20 + when: not testvrf.failed - name: Remove VRF global configurations cisco.nxos.nxos_config: lines: - no vrf context temp - save_when: always - register: result ignore_errors: yes + register: temp + +- name: Wait for 20 seconds if VRF removal was successful + ansible.builtin.wait_for: + timeout: 20 + when: not temp.failed - name: Remove VRF global configurations cisco.nxos.nxos_config: lines: - no vrf context VRF7 - save_when: always - register: result ignore_errors: yes + register: vrf7 + +- name: Wait for 20 seconds if VRF removal was successful + ansible.builtin.wait_for: + timeout: 20 + when: not vrf7.failed diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml index 0787379f2..62706f137 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml @@ -14,8 +14,8 @@ ip: auto_discard: true domain_list: - - anisble.com - domain_name: blue.com + - example.net + domain_name: example.org icmp_err: source_interface: interface: port-channel diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml index 47c437e46..d4bb0b5c7 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/overridden.yaml @@ -15,8 +15,8 @@ ip: auto_discard: true domain_list: - - redhat.com - domain_name: ansible.com + - example.com + domain_name: example.net mroutes: - group: 192.168.1.0/24 source: 192.168.1.1 diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml index 5a6a3cadf..c57a6f446 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml @@ -1,64 +1,69 @@ -# --- -# - ansible.builtin.debug: -# msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} - -# - ansible.builtin.include_tasks: _remove_config.yaml -# - ansible.builtin.include_tasks: _populate_config.yaml - -# - block: -# - name: Replace the provided configuration with the existing running configuration -# register: result -# cisco.nxos.nxos_vrf_global: &id001 -# config: -# vrfs: -# - ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - destination: 192.168.255.1 -# source: 0.0.0.0/0 -# name: management -# - name: temp -# description: Test -# ip: -# auto_discard: true -# domain_list: -# - bluehat.com -# - redhat.com -# domain_name: red.com -# state: replaced +--- +- ansible.builtin.debug: + msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} -# - name: Assert that correct set of commands were generated -# ansible.builtin.assert: -# that: -# - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml -# - name: Assert that before dict is correctly generated -# ansible.builtin.assert: -# that: -# - "{{ replaced['before'] == result['before'] }}" +- block: + - name: Replace the provided configuration with the existing running configuration + register: result + cisco.nxos.nxos_vrf_global: &id001 + config: + vrfs: + - name: temp + description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.org + - name: testvrf + description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp + state: replaced -# - name: Assert that after dict is correctly generated -# ansible.builtin.assert: -# that: -# - replaced['after'] == result['after'] + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" -# - name: Replaced provided VRF global configuration (idempotent) -# register: result -# cisco.nxos.nxos_vrf_global: *id001 -# - name: Assert that task was idempotent -# ansible.builtin.assert: -# that: -# - result['changed'] == false -# always: -# - ansible.builtin.include_tasks: _remove_config.yaml + - name: Assert that before dict is correctly generated + ansible.builtin.assert: + that: + - "{{ replaced['before'] == result['before'] }}" ---- -- ansible.builtin.debug: - msg: START nxos_vrf_global replaced integration tests on connection={{ ansible_connection }} + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] -- block: - - name: Test - ansible.builtin.debug: - msg: "replaced test" + - name: Replaced provided VRF global configuration (idempotent) + register: result + cisco.nxos.nxos_vrf_global: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index f3dd4b047..0a1ec2802 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -1,4 +1,3 @@ ---- general: after: vrfs: @@ -6,7 +5,7 @@ general: - description: testvrfhere ip: auto_discard: true - domain_name: redhat.com + domain_name: example.com mroutes: - group: 192.168.1.0/24 source: 192.168.1.1 @@ -19,13 +18,12 @@ general: name: testvrf vni: vni_number: 5 - merged: commands: - vrf context VRF7 - description this-is-test - ip auto-discard - - ip domain-name blue.com + - ip domain-name example.org - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 - ip icmp-errors source-interface port-channel 1 - ip multicast multipath resilient @@ -35,7 +33,7 @@ merged: - ipv6 multicast group-range prefix-list temp - ipv6 multicast multipath resilient - ipv6 multicast multipath none - - ip domain-list anisble.com + - ip domain-list example.net - ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 - ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 - ip mroute 192.168.1.0/24 192.168.1.1 @@ -47,16 +45,16 @@ merged: - ip route 192.0.2.0/24 192.0.2.22 tag 2 4 - multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 - multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 - - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 - - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + - "ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2" + - "ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" after: vrfs: - description: this-is-test ip: auto_discard: true domain_list: - - anisble.com - domain_name: blue.com + - example.net + domain_name: example.org icmp_err: source_interface: interface: port-channel @@ -106,10 +104,10 @@ merged: tag_value: 2 ipv6: mld_ssm_translate: - - group: ff28::/16 - source: 2001:db8:0:abcd::2 - - group: ff30::/16 - source: 2001:db8:0:abcd::5 + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" multicast: group_range_prefix_list: temp multipath: @@ -125,22 +123,20 @@ merged: name: VRF7 vni: vni_number: 5 - deleted: commands: - vrf context testvrf - no description testvrfhere - no ip auto-discard - - no ip domain-name redhat.com + - no ip domain-name example.com - no vni 5 - no ip mroute 192.168.1.0/24 192.168.1.1 - - no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 - - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 + - "no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2" + - "no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" after: vrfs: - name: temp - name: testvrf - gathered: after: vrfs: @@ -148,7 +144,7 @@ gathered: - description: testvrfhere ip: auto_discard: true - domain_name: redhat.com + domain_name: example.com mroutes: - group: 192.168.1.0/24 source: 192.168.1.1 @@ -161,28 +157,135 @@ gathered: name: testvrf vni: vni_number: 5 - overridden: - commands: [] + commands: + - vrf context testvrf + - description Test + - ip domain-name example.net + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip name-server 192.168.0.1 use-vrf temp + - no vni 5 + - ip domain-list example.com + - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp + - "no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2" + - "no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" + after: + vrfs: + - "{{ management[0] }}" + - name: temp + - description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp + name: testvrf + before: + vrfs: + - "{{ management[0] }}" + - name: temp + - description: testvrfhere + ip: + auto_discard: true + domain_name: example.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + ipv6: + mld_ssm_translate: + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" + name: testvrf + vni: + vni_number: 5 +replaced: + after: + vrfs: + - "{{ management[0] }}" + - description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.org + name: temp + - description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp + name: testvrf before: - - "{{ management[0] }}" - - description: testvrfhere - ip: - auto_discard: true - domain_name: redhat.com - mroutes: - - group: 192.168.1.0/24 - source: 192.168.1.1 - ipv6: - mld_ssm_translate: - - group: "ff28::/16" - source: "2001:db8:0:abcd::2" - - group: "ff30::/16" - source: "2001:db8:0:abcd::5" - name: testvrf - vni: - vni_number: 5 - + vrfs: + - "{{ management[0] }}" + - name: temp + - description: testvrfhere + ip: + auto_discard: true + domain_name: example.com + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + ipv6: + mld_ssm_translate: + - group: "ff28::/16" + source: "2001:db8:0:abcd::2" + - group: "ff30::/16" + source: "2001:db8:0:abcd::5" + name: testvrf + vni: + vni_number: 5 + commands: + - vrf context temp + - description Test + - ip auto-discard + - ip domain-name example.org + - ip domain-list example.com + - vrf context testvrf + - description Test + - ip domain-name example.net + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip name-server 192.168.0.1 use-vrf temp + - no vni 5 + - ip domain-list example.com + - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp + - "no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2" + - "no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5" parsed: after: vrfs: @@ -198,9 +301,9 @@ parsed: ip: auto_discard: true domain_list: - - redhat.com - - bluehat.com - domain_name: red.com + - example.com + - example.net + domain_name: example.org multicast: rpf: - group_list_range: 238.1.0.0/24 From 7563bb00c82ce03d3b07433d712ef70611548ec7 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 13:57:52 +0530 Subject: [PATCH 35/46] added rendered --- .../tests/common/rendered.yaml | 39 +++++++++++++++++-- .../targets/nxos_vrf_global/vars/main.yaml | 11 ++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml index 137e938ce..50cf0e13f 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/rendered.yaml @@ -2,7 +2,40 @@ - ansible.builtin.debug: msg: START nxos_vrf_global rendered integration tests on connection={{ ansible_connection }} +- ansible.builtin.include_tasks: _remove_config.yaml + - block: - - name: Test - ansible.builtin.debug: - msg: "rendered test" + - name: Render provided configuration with device configuration + register: result + cisco.nxos.nxos_vrf_global: + config: + vrfs: + - description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + - group: 192.168.1.0/24 + preference: 2 + source: 192.168.1.2 + vrf: temp + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + use_vrf: + source_address: 192.168.0.1 + vrf: temp + name: testvrf + state: rendered + + - ansible.builtin.assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered.commands) == [] diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index 0a1ec2802..dfa0a49b4 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -311,3 +311,14 @@ parsed: - group_list_range: 239.1.0.0/24 vrf_name: temp1 name: temp +rendered: + commands: + - vrf context testvrf + - description Test + - ip auto-discard + - ip domain-name example.net + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip name-server 192.168.0.1 use-vrf temp + - ip domain-list example.com + - ip mroute 192.168.1.0/24 192.168.1.1 + - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp From c6f17b1ce19363d65bdde594d768d1ef27bd56dd Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 14:24:57 +0530 Subject: [PATCH 36/46] rtt --- .../nxos_vrf_global/tests/common/rtt.yaml | 74 +++++++++++++++++++ .../targets/nxos_vrf_global/vars/main.yaml | 23 ++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml new file mode 100644 index 000000000..cff796bdc --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml @@ -0,0 +1,74 @@ +- ansible.builtin.debug: + msg: START nxos_vrf_global round trip integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the existing running configuration + cisco.nxos.nxos_vrf_global: + config: + vrfs: + - name: VRF7 + description: Test + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + mroutes: + - group: 192.168.1.0/24 + source: 192.168.1.1 + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + state: merged + register: result + + - name: Nxos_vrf_global RTT - gather vrf_global facts + cisco.nxos.nxos_facts: + gather_network_resources: + - vrf_global + + - name: Overridden the provided configuration with the existing running configuration + cisco.nxos.nxos_vrf_global: + config: + vrfs: + - "{{ management[0] }}" + - name: testvrf + description: testing + ip: + auto_discard: true + domain_list: + - example.com + domain_name: example.net + name_server: + address_list: + - 192.168.0.1 + - 192.168.0.2 + - 192.168.1.1 + - 192.169.1.3 + state: overridden + register: result + + - ansible.builtin.assert: + that: + - result.commands|length == 13 + - result.changed == true + - result.commands|symmetric_difference(rtt.commands) == [] + + - name: Revert back to base configuration using facts round trip + register: revert + cisco.nxos.nxos_vrf_global: + config: "{{ ansible_facts['network_resources']['vrf_global'] }}" + state: replaced + + - ansible.builtin.assert: + that: + - revert.changed == true + - revert['commands'] == rtt['revert'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index dfa0a49b4..54705f0a4 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -322,3 +322,26 @@ rendered: - ip domain-list example.com - ip mroute 192.168.1.0/24 192.168.1.1 - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp +rtt: + commands: + - vrf context VRF7 + - no description Test + - no ip auto-discard + - no ip domain-name example.net + - no ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - no ip domain-list example.com + - no ip mroute 192.168.1.0/24 192.168.1.1 + - vrf context testvrf + - description testing + - ip auto-discard + - ip domain-name example.net + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip domain-list example.com + revert: + - vrf context VRF7 + - description Test + - ip auto-discard + - ip domain-name example.net + - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 + - ip domain-list example.com + - ip mroute 192.168.1.0/24 192.168.1.1 From 86fc7af6ecf672d4a58a9e9c01379680b70177db Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 14:30:39 +0530 Subject: [PATCH 37/46] fix lint --- tests/integration/targets/nxos_vrf_global/tasks/main.yml | 2 +- .../nxos_vrf_global/tests/common/_remove_config.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml index 52d066570..53a64850f 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/main.yml +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -4,7 +4,7 @@ commands: show running | section '^vrf' register: result -- name: set management fact +- name: Set management fact ansible.builtin.set_fact: management: - ip: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml index 60c689851..72901535c 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_remove_config.yaml @@ -3,7 +3,7 @@ cisco.nxos.nxos_config: lines: - no vrf context testvrf - ignore_errors: yes + ignore_errors: true register: testvrf - name: Wait for 20 seconds if VRF removal was successful @@ -15,7 +15,7 @@ cisco.nxos.nxos_config: lines: - no vrf context temp - ignore_errors: yes + ignore_errors: true register: temp - name: Wait for 20 seconds if VRF removal was successful @@ -27,7 +27,7 @@ cisco.nxos.nxos_config: lines: - no vrf context VRF7 - ignore_errors: yes + ignore_errors: true register: vrf7 - name: Wait for 20 seconds if VRF removal was successful From 9af94b7094c7d566d5e626217a474d35986a5b16 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 15:35:50 +0530 Subject: [PATCH 38/46] fix docs --- .../nxos/config/vrf_global/vrf_global.py | 13 +- plugins/modules/nxos_vrf_global.py | 839 ++++++++++-------- .../network/nxos/test_nxos_vrf_global.py | 69 +- 3 files changed, 541 insertions(+), 380 deletions(-) diff --git a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py index 4326501a1..0fa19963c 100644 --- a/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py +++ b/plugins/module_utils/network/nxos/config/vrf_global/vrf_global.py @@ -112,8 +112,13 @@ def generate_commands(self): if k not in wantd: self._compare(want={}, have=have) - for k, want in iteritems(wantd): - self._compare(want=want, have=haved.pop(k, {})) + if self.state == "purged": + purge_list = wantd or haved + for k, item in iteritems(purge_list): + self.purge(item) + else: + for k, want in iteritems(wantd): + self._compare(want=want, have=haved.pop(k, {})) def _compare(self, want, have): """Leverages the base class `compare()` method and @@ -149,6 +154,10 @@ def _compare_lists(self, want, have): for entry in hdict.values(): self.addcmd(entry, attrib, True) + def purge(self, have): + """Purge the VRF configuration""" + self.commands.append("no vrf context {0}".format(have["name"])) + def _vrf_list_to_dict(self, vrf_list): """Converts a list of VRFs to a dictionary with the VRF name as the key. diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index d28d49938..4dc9a8af0 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -321,8 +321,8 @@ ip: auto_discard: true domain_list: - - anisble.com - - redhat.com + - example.net + - example.com domain_name: test.com icmp_err: source_interface: @@ -401,7 +401,7 @@ # - vrf context test1 # - description this is description # - ip auto-discard -# - ip domain-name red-hat.com +# - ip domain-name test.net # - ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 # - ip icmp-errors source-interface port-channel 1 # - ip multicast multipath resilient @@ -411,9 +411,9 @@ # - ipv6 multicast group-range prefix-list temp2 # - ipv6 multicast multipath resilient # - ipv6 multicast multipath none -# - ip domain-list res.com -# - ip domain-list redhat.com -# - ip domain-list anisble.com +# - ip domain-list test.org +# - ip domain-list example.com +# - ip domain-list example.net # - ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 # - ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 # - ip mroute 192.168.1.0/24 192.168.1.1 @@ -429,82 +429,82 @@ # - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 # after: -# vrfs: -# - name: testvrf -# description: this is description -# ip: -# auto_discard: true -# domain_list: -# - anisble.com -# - redhat.com -# domain_name: test.com -# icmp_err: -# source_interface: -# interface: port-channel -# interface_value: '1' -# igmp: -# ssm_translate: -# - group: 232.0.0.0/8 -# source: 10.1.1.1 -# - group: 239.1.2.3/24 -# source: 192.168.1.1 -# mroutes: -# - group: 192.168.1.0/24 -# source: 192.168.1.1 -# - group: 192.168.1.0/24 -# preference: 2 -# source: 192.168.1.2 -# vrf: temp1 -# multicast: -# multipath: -# resilient: true -# splitting_type: -# legacy: true -# rpf: -# - group_list_range: 238.1.0.0/24 -# vrf_name: temp1 -# - group_list_range: 239.1.0.0/24 -# vrf_name: temp1 -# name_server: -# address_list: -# - 192.168.0.1 -# - 192.168.0.2 -# - 192.168.1.1 -# - 192.169.1.3 -# use_vrf: -# source_address: 192.168.0.1 -# vrf: temp1 -# route: -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# vrf: temp1 -# - destination: 192.0.2.22 -# source: 192.0.2.0/24 -# tags: -# route_pref: 4 -# tag_value: 2 -# ipv6: -# mld_ssm_translate: -# - group: ff28::/16 -# source: 2001:db8:0:abcd::2 -# - group: ff30::/16 -# source: 2001:db8:0:abcd::5 -# multicast: -# group_range_prefix_list: temp2 -# multipath: -# resilient: true -# splitting_type: -# none: true -# multicast: -# service_reflect: -# - map_to: Ethernet2/2 -# service_interface: Ethernet1/1 -# - map_to: Ethernet4/2 -# service_interface: Ethernet2/1 -# vni: -# vni_number: 5 +# vrfs: +# - name: testvrf +# description: this is description +# ip: +# auto_discard: true +# domain_list: +# - example.net +# - example.com +# domain_name: test.com +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# preference: 2 +# source: 192.168.1.2 +# vrf: temp1 +# multicast: +# multipath: +# resilient: true +# splitting_type: +# legacy: true +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# name_server: +# address_list: +# - 192.168.0.1 +# - 192.168.0.2 +# - 192.168.1.1 +# - 192.169.1.3 +# use_vrf: +# source_address: 192.168.0.1 +# vrf: temp1 +# route: +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# vrf: temp1 +# - destination: 192.0.2.22 +# source: 192.0.2.0/24 +# tags: +# route_pref: 4 +# tag_value: 2 +# ipv6: +# mld_ssm_translate: +# - group: ff28::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff30::/16 +# source: 2001:db8:0:abcd::5 +# multicast: +# group_range_prefix_list: temp2 +# multipath: +# resilient: true +# splitting_type: +# none: true +# multicast: +# service_reflect: +# - map_to: Ethernet2/2 +# service_interface: Ethernet1/1 +# - map_to: Ethernet4/2 +# service_interface: Ethernet2/1 +# vni: +# vni_number: 5 # After state: # ------------ @@ -513,7 +513,7 @@ # vrf context testvrf # description this is description # ip auto-discard -# ip domain-name red-hat.com +# ip domain-name test.net # ip name-server 192.168.0.1 192.168.0.2 192.168.1.1 192.169.1.3 # ip icmp-errors source-interface port-channel 1 # ip multicast multipath resilient @@ -523,9 +523,9 @@ # ipv6 multicast group-range prefix-list temp2 # ipv6 multicast multipath resilient # ipv6 multicast multipath none -# ip domain-list res.com -# ip domain-list redhat.com -# ip domain-list anisble.com +# ip domain-list test.org +# ip domain-list example.com +# ip domain-list example.net # ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 # ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 # ip mroute 192.168.1.0/24 192.168.1.1 @@ -551,10 +551,10 @@ # ip route 0.0.0.0/0 192.168.255.1 # vrf context test1 # description this is description -# ip domain-name red-hat.com -# ip domain-list anisble.com -# ip domain-list redhat.com -# ip domain-list res.com +# ip domain-name test.net +# ip domain-list example.net +# ip domain-list example.com +# ip domain-list test.org # vni 5 # ip auto-discard # ip route 192.0.0.0/24 192.0.2.22 @@ -582,77 +582,77 @@ # ------------ # # before: -# vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: red-hat.com -# domain_list: -# - res.com -# - anisble.com -# - redhat.com -# auto_discard: true -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# vrf: temp1 -# - source: 192.0.2.0/24 -# destination: 192.0.2.22 -# tags: -# tag_value: 2 -# route_pref: 4 -# mroutes: -# - group: 192.168.1.0/24 -# source: 192.168.1.1 -# - group: 192.168.1.0/24 -# source: 192.168.1.2 -# preference: 2 -# vrf: temp1 -# icmp_err: -# source_interface: -# interface: port-channel -# interface_value: '1' -# igmp: -# ssm_translate: -# - group: 232.0.0.0/8 -# source: 10.1.1.1 -# - group: 239.1.2.3/24 -# source: 192.168.1.1 -# multicast: -# multipath: -# splitting_type: -# legacy: true -# resilient: true -# rpf: -# - vrf_name: temp1 -# group_list_range: 238.1.0.0/24 -# - vrf_name: temp1 -# group_list_range: 239.1.0.0/24 -# vni: -# vni_number: 5 +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: test.net +# domain_list: +# - test.org +# - example.net +# - example.com +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# source: 192.168.1.2 +# preference: 2 +# vrf: temp1 +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# multicast: +# multipath: +# splitting_type: +# legacy: true +# resilient: true +# rpf: +# - vrf_name: temp1 +# group_list_range: 238.1.0.0/24 +# - vrf_name: temp1 +# group_list_range: 239.1.0.0/24 +# vni: +# vni_number: 5 # commands: # - vrf context test1 # - no description this is description # - no ip auto-discard -# - no ip domain-name red-hat.com +# - no ip domain-name test.net # - no ip icmp-errors source-interface port-channel 1 # - no ip multicast multipath resilient # - no ip multicast multipath legacy # - no vni 5 -# - no ip domain-list anisble.com -# - no ip domain-list res.com -# - no ip domain-list redhat.com +# - no ip domain-list example.net +# - no ip domain-list test.org +# - no ip domain-list example.com # - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 # - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 # - no ip mroute 192.168.1.0/24 192.168.1.1 @@ -664,16 +664,16 @@ # - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 # # after: -# vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 # Using deleted with empty config @@ -686,10 +686,10 @@ # ip route 0.0.0.0/0 192.168.255.1 # vrf context test1 # description this is description -# ip domain-name red-hat.com -# ip domain-list anisble.com -# ip domain-list redhat.com -# ip domain-list res.com +# ip domain-name test.net +# ip domain-list example.net +# ip domain-list example.com +# ip domain-list test.org # vni 5 - name: Delete VRF configuration @@ -703,25 +703,25 @@ # ------------ # # before: -# vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: red-hat.com -# domain_list: -# - res.com -# - anisble.com -# - redhat.com -# vni: -# vni_number: 5 +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: test.net +# domain_list: +# - test.org +# - example.net +# - example.com +# vni: +# vni_number: 5 # commands: # - vrf context management @@ -729,16 +729,103 @@ # - no ip route 0.0.0.0/0 192.168.255.1 # - vrf context test1 # - no description this is description -# - no ip domain-name red-hat.com +# - no ip domain-name test.net # - no vni 5 -# - no ip domain-list anisble.com -# - no ip domain-list res.com -# - no ip domain-list redhat.com +# - no ip domain-list example.net +# - no ip domain-list test.org +# - no ip domain-list example.com + +# after: +# vrfs: +# - name: management +# - name: test1 + +# Using purged + +# Before state: +# ------------- +# +# nxos#show running-config | section ^vrf +# vrf context management +# ip name-server 192.168.255.1 +# ip route 0.0.0.0/0 192.168.255.1 +# vrf context test1 +# description this is description +# ip domain-name example.com +# ip domain-list example.net +# ip domain-list example.org +# vni 5 +# ip auto-discard +# ip route 192.0.0.0/24 192.0.2.22 +# ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# vrf context test2 +# description test description +# ip auto-discard +# ip domain-name test.com + +- name: Override VRF configuration + cisco.nxos.vrf_global: + config: + vrfs: + - name: test1 + - name: test2 + state: purged + +# Task Output: +# ------------ +# +# before: +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: example.com +# domain_list: +# - example.net +# - example.org +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# vni: +# vni_number: 5 +# - name: test2 +# description: test description +# ip: +# auto_discard: true +# domain_name: test.com +# +# commands: +# - no vrf context test1 +# - no vrf context test2 # # after: -# vrfs: -# - name: management -# - name: test1 +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 # Using overridden @@ -751,9 +838,9 @@ # ip route 0.0.0.0/0 192.168.255.1 # vrf context test1 # description this is description -# ip domain-name redhat.com -# ip domain-list anisble.com -# ip domain-list docs.com +# ip domain-name example.com +# ip domain-list example.net +# ip domain-list example.org # vni 5 # ip auto-discard # ip route 192.0.0.0/24 192.0.2.22 @@ -762,7 +849,7 @@ # vrf context test2 # description test description # ip auto-discard -# ip domain-name greyhat.com +# ip domain-name test.com - name: Override VRF configuration cisco.nxos.vrf_global: @@ -791,48 +878,48 @@ # ------------ # # before: -# vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: redhat.com -# domain_list: -# - anisble.com -# - docs.com -# auto_discard: true -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# vrf: temp1 -# - source: 192.0.2.0/24 -# destination: 192.0.2.22 -# tags: -# tag_value: 2 -# route_pref: 4 -# vni: -# vni_number: 5 -# - name: test2 -# description: test description -# ip: -# auto_discard: true -# domain_name: greyhat.com +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: example.com +# domain_list: +# - example.net +# - example.org +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# vni: +# vni_number: 5 +# - name: test2 +# description: test description +# ip: +# auto_discard: true +# domain_name: test.com # # commands: # - vrf context test1 # - no description this is description -# - no ip domain-name redhat.com -# - no ip domain-list anisble.com -# - no ip domain-list docs.com +# - no ip domain-name example.com +# - no ip domain-list example.net +# - no ip domain-list example.org # - ip name-server 192.168.255.1 # - no ip auto-discard # - no vni 5 @@ -841,27 +928,27 @@ # - vrf context test2 # - no description test description # - no ip auto-discard -# - no ip domain-name greyhat.com +# - no ip domain-name test.com # # after: -# vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# ip: -# auto_discard: false -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 +# vrfs: +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# ip: +# auto_discard: false +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 # Using replaced @@ -873,10 +960,10 @@ # ip name-server 192.168.255.1 # ip route 0.0.0.0/0 192.168.255.1 # vrf context temp -# ip domain-name red.com -# ip domain-list anisble.com -# ip domain-list redhat.com -# ip domain-list res.com +# ip domain-name test.org +# ip domain-list example.net +# ip domain-list example.com +# ip domain-list test.org # ip name-server 192.168.0.1 192.169.1.3 # ip name-server 192.168.0.1 use-vrf temp1 # multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 @@ -922,102 +1009,102 @@ ip: auto_discard: true domain_list: - - bluehat.com - - redhat.com - domain_name: red.com + - invalid.com + - example.com + domain_name: test.org state: replaced # Task Output: # ------------ # # before: -# vrfs: -# - ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - destination: 192.168.255.1 -# source: 0.0.0.0/0 -# name: management -# - description: this is descrition -# ip: -# auto_discard: true -# domain_list: -# - anisble.com -# - res.com -# - redhat.com -# domain_name: red.com -# icmp_err: -# source_interface: -# interface: port-channel -# interface_value: '1' -# igmp: -# ssm_translate: -# - group: 232.0.0.0/8 -# source: 10.1.1.1 -# - group: 239.1.2.3/24 -# source: 192.168.1.1 -# mroutes: -# - group: 192.168.1.0/24 -# source: 192.168.1.1 -# - group: 192.168.1.0/24 -# preference: 2 -# source: 192.168.1.2 -# vrf: temp1 -# multicast: -# multipath: -# resilient: true -# splitting_type: -# legacy: true -# rpf: -# - group_list_range: 238.1.0.0/24 -# vrf_name: temp1 -# - group_list_range: 239.1.0.0/24 -# vrf_name: temp1 -# name_server: -# address_list: -# - 192.168.0.1 -# - 192.169.1.3 -# use_vrf: -# source_address: 192.168.0.1 -# vrf: temp1 -# route: -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# vrf: temp1 -# - destination: 192.0.2.22 -# source: 192.0.2.0/24 -# tags: -# route_pref: 4 -# tag_value: 2 -# ipv6: -# mld_ssm_translate: -# - group: ff28::/16 -# source: 2001:db8:0:abcd::2 -# - group: ff30::/16 -# source: 2001:db8:0:abcd::1 -# - group: ff32::/16 -# source: 2001:db8:0:abcd::2 -# - group: ff32::/16 -# source: 2001:db8:0:abcd::3 -# multicast: -# group_range_prefix_list: temp2 -# multipath: -# resilient: true -# splitting_type: -# none: true -# multicast: -# service_reflect: -# - map_to: Ethernet2/2 -# service_interface: Ethernet1/1 -# - map_to: Ethernet4/2 -# service_interface: Ethernet2/1 -# name: temp -# vni: -# vni_number: 5 +# vrfs: +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: this is descrition +# ip: +# auto_discard: true +# domain_list: +# - example.net +# - test.org +# - example.com +# domain_name: test.org +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# preference: 2 +# source: 192.168.1.2 +# vrf: temp1 +# multicast: +# multipath: +# resilient: true +# splitting_type: +# legacy: true +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# name_server: +# address_list: +# - 192.168.0.1 +# - 192.169.1.3 +# use_vrf: +# source_address: 192.168.0.1 +# vrf: temp1 +# route: +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# vrf: temp1 +# - destination: 192.0.2.22 +# source: 192.0.2.0/24 +# tags: +# route_pref: 4 +# tag_value: 2 +# ipv6: +# mld_ssm_translate: +# - group: ff28::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff30::/16 +# source: 2001:db8:0:abcd::1 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::3 +# multicast: +# group_range_prefix_list: temp2 +# multipath: +# resilient: true +# splitting_type: +# none: true +# multicast: +# service_reflect: +# - map_to: Ethernet2/2 +# service_interface: Ethernet1/1 +# - map_to: Ethernet4/2 +# service_interface: Ethernet2/1 +# name: temp +# vni: +# vni_number: 5 # # commands: # - vrf context temp @@ -1031,9 +1118,9 @@ # - no ipv6 multicast group-range prefix-list temp2 # - no ipv6 multicast multipath resilient # - no ipv6 multicast multipath none -# - ip domain-list bluehat.com -# - no ip domain-list anisble.com -# - no ip domain-list res.com +# - ip domain-list invalid.com +# - no ip domain-list example.net +# - no ip domain-list test.org # - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 # - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 # - no ip mroute 192.168.1.0/24 192.168.1.1 @@ -1051,28 +1138,28 @@ # - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 # # after: -# vrfs: -# - ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - destination: 192.168.255.1 -# source: 0.0.0.0/0 -# name: management -# - description: Test -# ip: -# auto_discard: true -# domain_list: -# - bluehat.com -# - redhat.com -# domain_name: red.com -# multicast: -# rpf: -# - group_list_range: 238.1.0.0/24 -# vrf_name: temp1 -# - group_list_range: 239.1.0.0/24 -# vrf_name: temp1 +# vrfs: +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: Test +# ip: +# auto_discard: true +# domain_list: +# - invalid.com +# - example.com +# domain_name: test.org +# multicast: +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 # # After state: # ------------ @@ -1081,9 +1168,9 @@ # ip name-server 192.168.255.1 # ip route 0.0.0.0/0 192.168.255.1 # vrf context temp -# ip domain-name red.com -# ip domain-list redhat.com -# ip domain-list bluehat.com +# ip domain-name test.org +# ip domain-list example.com +# ip domain-list invalid.com # description Test # ip auto-discard # ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 @@ -1113,7 +1200,7 @@ sample: - vrf context management - description this is management vrf - - ip domain-name redhat.com + - ip domain-name example.com rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py index d0903e115..eebf890b9 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py @@ -764,8 +764,73 @@ def test_nxos_vrf_global_replaced_idemp(self): ) self.execute_module(changed=False, commands=[]) - def test_nxos_vrf_global_rendered(self): - pass + def test_nxos_vrf_global_purged(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list redhat.com + ip domain-list res.com + vni 5 + ip auto-discard + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + """, + ) + + set_module_args( + dict( + config={ + "vrfs" : [] + }, + state="purged", + ), + ) + commands = ['no vrf context management', 'no vrf context test1'] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_nxos_vrf_global_purged_2(self): + self.execute_show_command.return_value = dedent( + """\ + vrf context management + ip name-server 192.168.255.1 + ip route 0.0.0.0/0 192.168.255.1 + vrf context test1 + description this is descrition + ip domain-name redx.com + ip domain-list redhat.com + ip domain-list res.com + vni 5 + ip auto-discard + ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 + ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 + ip route 192.0.0.0/24 192.0.2.22 + ip route 192.0.0.0/24 192.0.2.22 vrf temp1 + """, + ) + + set_module_args( + dict( + config={ + "vrfs" : [ + { + "name": "test1" + } + ] + }, + state="purged", + ), + ) + commands = ['no vrf context test1'] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_nxos_vrf_global_parsed(self): set_module_args( From 2bb4fe03ffc2d5eff925b814c3bed350eb55a7ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:06:40 +0000 Subject: [PATCH 39/46] chore: auto fixes from pre-commit.com hooks --- .../modules/network/nxos/test_nxos_vrf_global.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py index eebf890b9..26f6f6fa0 100644 --- a/tests/unit/modules/network/nxos/test_nxos_vrf_global.py +++ b/tests/unit/modules/network/nxos/test_nxos_vrf_global.py @@ -787,12 +787,12 @@ def test_nxos_vrf_global_purged(self): set_module_args( dict( config={ - "vrfs" : [] + "vrfs": [], }, state="purged", ), ) - commands = ['no vrf context management', 'no vrf context test1'] + commands = ["no vrf context management", "no vrf context test1"] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) @@ -819,16 +819,16 @@ def test_nxos_vrf_global_purged_2(self): set_module_args( dict( config={ - "vrfs" : [ + "vrfs": [ { - "name": "test1" - } - ] + "name": "test1", + }, + ], }, state="purged", ), ) - commands = ['no vrf context test1'] + commands = ["no vrf context test1"] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) From ab1c2be16e9356432da94531a12ccd664d22e7a0 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 15:56:01 +0530 Subject: [PATCH 40/46] fix intend --- plugins/modules/nxos_vrf_global.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index 4dc9a8af0..b854816f3 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -906,8 +906,8 @@ # tags: # tag_value: 2 # route_pref: 4 -# vni: -# vni_number: 5 +# vni: +# vni_number: 5 # - name: test2 # description: test description # ip: From b7b4ffe458a5592e7823af11aed039d0ad531b0d Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 16:06:28 +0530 Subject: [PATCH 41/46] fix spacing --- plugins/modules/nxos_vrf_global.py | 626 ++++++++++++++--------------- 1 file changed, 313 insertions(+), 313 deletions(-) diff --git a/plugins/modules/nxos_vrf_global.py b/plugins/modules/nxos_vrf_global.py index b854816f3..f726d15ac 100644 --- a/plugins/modules/nxos_vrf_global.py +++ b/plugins/modules/nxos_vrf_global.py @@ -583,63 +583,63 @@ # # before: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: test.net -# domain_list: -# - test.org -# - example.net -# - example.com -# auto_discard: true -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# vrf: temp1 -# - source: 192.0.2.0/24 -# destination: 192.0.2.22 -# tags: -# tag_value: 2 -# route_pref: 4 -# mroutes: -# - group: 192.168.1.0/24 -# source: 192.168.1.1 -# - group: 192.168.1.0/24 -# source: 192.168.1.2 -# preference: 2 -# vrf: temp1 -# icmp_err: -# source_interface: -# interface: port-channel -# interface_value: '1' -# igmp: -# ssm_translate: -# - group: 232.0.0.0/8 -# source: 10.1.1.1 -# - group: 239.1.2.3/24 -# source: 192.168.1.1 -# multicast: -# multipath: -# splitting_type: -# legacy: true -# resilient: true -# rpf: -# - vrf_name: temp1 -# group_list_range: 238.1.0.0/24 -# - vrf_name: temp1 -# group_list_range: 239.1.0.0/24 -# vni: -# vni_number: 5 +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: test.net +# domain_list: +# - test.org +# - example.net +# - example.com +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# source: 192.168.1.2 +# preference: 2 +# vrf: temp1 +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# multicast: +# multipath: +# splitting_type: +# legacy: true +# resilient: true +# rpf: +# - vrf_name: temp1 +# group_list_range: 238.1.0.0/24 +# - vrf_name: temp1 +# group_list_range: 239.1.0.0/24 +# vni: +# vni_number: 5 # commands: # - vrf context test1 @@ -665,15 +665,15 @@ # # after: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 # Using deleted with empty config @@ -704,24 +704,24 @@ # # before: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: test.net -# domain_list: -# - test.org -# - example.net -# - example.com -# vni: -# vni_number: 5 +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: test.net +# domain_list: +# - test.org +# - example.net +# - example.com +# vni: +# vni_number: 5 # commands: # - vrf context management @@ -777,40 +777,40 @@ # # before: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: example.com -# domain_list: -# - example.net -# - example.org -# auto_discard: true -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# vrf: temp1 -# - source: 192.0.2.0/24 -# destination: 192.0.2.22 -# tags: -# tag_value: 2 -# route_pref: 4 -# vni: -# vni_number: 5 -# - name: test2 -# description: test description -# ip: -# auto_discard: true -# domain_name: test.com +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: example.com +# domain_list: +# - example.net +# - example.org +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# vni: +# vni_number: 5 +# - name: test2 +# description: test description +# ip: +# auto_discard: true +# domain_name: test.com # # commands: # - no vrf context test1 @@ -818,14 +818,14 @@ # # after: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 # Using overridden @@ -879,40 +879,40 @@ # # before: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# description: this is description -# ip: -# domain_name: example.com -# domain_list: -# - example.net -# - example.org -# auto_discard: true -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 -# vrf: temp1 -# - source: 192.0.2.0/24 -# destination: 192.0.2.22 -# tags: -# tag_value: 2 -# route_pref: 4 -# vni: -# vni_number: 5 -# - name: test2 -# description: test description -# ip: -# auto_discard: true -# domain_name: test.com +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# description: this is description +# ip: +# domain_name: example.com +# domain_list: +# - example.net +# - example.org +# auto_discard: true +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 +# vrf: temp1 +# - source: 192.0.2.0/24 +# destination: 192.0.2.22 +# tags: +# tag_value: 2 +# route_pref: 4 +# vni: +# vni_number: 5 +# - name: test2 +# description: test description +# ip: +# auto_discard: true +# domain_name: test.com # # commands: # - vrf context test1 @@ -932,23 +932,23 @@ # # after: # vrfs: -# - name: management -# ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 0.0.0.0/0 -# destination: 192.168.255.1 -# - name: test1 -# ip: -# auto_discard: false -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - source: 192.0.0.0/24 -# destination: 192.0.2.22 +# - name: management +# ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 0.0.0.0/0 +# destination: 192.168.255.1 +# - name: test1 +# ip: +# auto_discard: false +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - source: 192.0.0.0/24 +# destination: 192.0.2.22 # Using replaced @@ -1019,147 +1019,147 @@ # # before: # vrfs: -# - ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - destination: 192.168.255.1 -# source: 0.0.0.0/0 -# name: management -# - description: this is descrition -# ip: -# auto_discard: true -# domain_list: -# - example.net -# - test.org -# - example.com -# domain_name: test.org -# icmp_err: -# source_interface: -# interface: port-channel -# interface_value: '1' -# igmp: -# ssm_translate: -# - group: 232.0.0.0/8 -# source: 10.1.1.1 -# - group: 239.1.2.3/24 -# source: 192.168.1.1 -# mroutes: -# - group: 192.168.1.0/24 -# source: 192.168.1.1 -# - group: 192.168.1.0/24 -# preference: 2 -# source: 192.168.1.2 -# vrf: temp1 -# multicast: -# multipath: -# resilient: true -# splitting_type: -# legacy: true -# rpf: -# - group_list_range: 238.1.0.0/24 -# vrf_name: temp1 -# - group_list_range: 239.1.0.0/24 -# vrf_name: temp1 -# name_server: -# address_list: -# - 192.168.0.1 -# - 192.169.1.3 -# use_vrf: -# source_address: 192.168.0.1 -# vrf: temp1 -# route: -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# - destination: 192.0.2.22 -# source: 192.0.0.0/24 -# vrf: temp1 -# - destination: 192.0.2.22 -# source: 192.0.2.0/24 -# tags: -# route_pref: 4 -# tag_value: 2 -# ipv6: -# mld_ssm_translate: -# - group: ff28::/16 -# source: 2001:db8:0:abcd::2 -# - group: ff30::/16 -# source: 2001:db8:0:abcd::1 -# - group: ff32::/16 -# source: 2001:db8:0:abcd::2 -# - group: ff32::/16 -# source: 2001:db8:0:abcd::3 -# multicast: -# group_range_prefix_list: temp2 -# multipath: -# resilient: true -# splitting_type: -# none: true -# multicast: -# service_reflect: -# - map_to: Ethernet2/2 -# service_interface: Ethernet1/1 -# - map_to: Ethernet4/2 -# service_interface: Ethernet2/1 -# name: temp -# vni: -# vni_number: 5 +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: this is descrition +# ip: +# auto_discard: true +# domain_list: +# - example.net +# - test.org +# - example.com +# domain_name: test.org +# icmp_err: +# source_interface: +# interface: port-channel +# interface_value: '1' +# igmp: +# ssm_translate: +# - group: 232.0.0.0/8 +# source: 10.1.1.1 +# - group: 239.1.2.3/24 +# source: 192.168.1.1 +# mroutes: +# - group: 192.168.1.0/24 +# source: 192.168.1.1 +# - group: 192.168.1.0/24 +# preference: 2 +# source: 192.168.1.2 +# vrf: temp1 +# multicast: +# multipath: +# resilient: true +# splitting_type: +# legacy: true +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 +# name_server: +# address_list: +# - 192.168.0.1 +# - 192.169.1.3 +# use_vrf: +# source_address: 192.168.0.1 +# vrf: temp1 +# route: +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# - destination: 192.0.2.22 +# source: 192.0.0.0/24 +# vrf: temp1 +# - destination: 192.0.2.22 +# source: 192.0.2.0/24 +# tags: +# route_pref: 4 +# tag_value: 2 +# ipv6: +# mld_ssm_translate: +# - group: ff28::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff30::/16 +# source: 2001:db8:0:abcd::1 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::2 +# - group: ff32::/16 +# source: 2001:db8:0:abcd::3 +# multicast: +# group_range_prefix_list: temp2 +# multipath: +# resilient: true +# splitting_type: +# none: true +# multicast: +# service_reflect: +# - map_to: Ethernet2/2 +# service_interface: Ethernet1/1 +# - map_to: Ethernet4/2 +# service_interface: Ethernet2/1 +# name: temp +# vni: +# vni_number: 5 # # commands: -# - vrf context temp -# - description Test -# - no ip name-server 192.168.0.1 192.169.1.3 -# - no ip icmp-errors source-interface port-channel 1 -# - no ip multicast multipath resilient -# - no ip multicast multipath legacy -# - no ip name-server 192.168.0.1 use-vrf temp1 -# - no vni 5 -# - no ipv6 multicast group-range prefix-list temp2 -# - no ipv6 multicast multipath resilient -# - no ipv6 multicast multipath none -# - ip domain-list invalid.com -# - no ip domain-list example.net -# - no ip domain-list test.org -# - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 -# - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 -# - no ip mroute 192.168.1.0/24 192.168.1.1 -# - no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 -# - no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 -# - no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 -# - no ip route 192.0.0.0/24 192.0.2.22 -# - no ip route 192.0.0.0/24 192.0.2.22 vrf temp1 -# - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 -# - no multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 -# - no multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 -# - no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 -# - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::1 -# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 -# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 +# - vrf context temp +# - description Test +# - no ip name-server 192.168.0.1 192.169.1.3 +# - no ip icmp-errors source-interface port-channel 1 +# - no ip multicast multipath resilient +# - no ip multicast multipath legacy +# - no ip name-server 192.168.0.1 use-vrf temp1 +# - no vni 5 +# - no ipv6 multicast group-range prefix-list temp2 +# - no ipv6 multicast multipath resilient +# - no ipv6 multicast multipath none +# - ip domain-list invalid.com +# - no ip domain-list example.net +# - no ip domain-list test.org +# - no ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 +# - no ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.1 +# - no ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp1 +# - no ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 +# - no ip multicast rpf select vrf temp1 group-list 239.1.0.0/24 +# - no ip route 192.0.0.0/24 192.0.2.22 +# - no ip route 192.0.0.0/24 192.0.2.22 vrf temp1 +# - no ip route 192.0.2.0/24 192.0.2.22 tag 2 4 +# - no multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 +# - no multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 +# - no ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 +# - no ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::1 +# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::2 +# - no ipv6 mld ssm-translate ff32::/16 2001:db8:0:abcd::3 # # after: # vrfs: -# - ip: -# name_server: -# address_list: -# - 192.168.255.1 -# route: -# - destination: 192.168.255.1 -# source: 0.0.0.0/0 -# name: management -# - description: Test -# ip: -# auto_discard: true -# domain_list: -# - invalid.com -# - example.com -# domain_name: test.org -# multicast: -# rpf: -# - group_list_range: 238.1.0.0/24 -# vrf_name: temp1 -# - group_list_range: 239.1.0.0/24 -# vrf_name: temp1 +# - ip: +# name_server: +# address_list: +# - 192.168.255.1 +# route: +# - destination: 192.168.255.1 +# source: 0.0.0.0/0 +# name: management +# - description: Test +# ip: +# auto_discard: true +# domain_list: +# - invalid.com +# - example.com +# domain_name: test.org +# multicast: +# rpf: +# - group_list_range: 238.1.0.0/24 +# vrf_name: temp1 +# - group_list_range: 239.1.0.0/24 +# vrf_name: temp1 # # After state: # ------------ From 81384256aef4d6930ddc50ab12adb8a42d3eeb93 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 16:24:14 +0530 Subject: [PATCH 42/46] update deprecation --- changelogs/fragments/nxos_vrf_global.yml | 2 +- plugins/modules/nxos_vrf.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/nxos_vrf_global.yml b/changelogs/fragments/nxos_vrf_global.yml index 21cdf5e64..da9dc650d 100644 --- a/changelogs/fragments/nxos_vrf_global.yml +++ b/changelogs/fragments/nxos_vrf_global.yml @@ -1,3 +1,3 @@ --- minor_changes: - - Add nxos_vrf_global resource module in favor of nxos_vrf module. + - Add nxos_vrf_global resource module in favor of nxos_vrf module (https://github.com/ansible-collections/cisco.nxos/pull/870). diff --git a/plugins/modules/nxos_vrf.py b/plugins/modules/nxos_vrf.py index 6017d3c88..e9d06029f 100644 --- a/plugins/modules/nxos_vrf.py +++ b/plugins/modules/nxos_vrf.py @@ -26,6 +26,10 @@ extends_documentation_fragment: - cisco.nxos.nxos short_description: Manages global VRF configuration. +deprecated: + alternative: nxos_vrf_global + why: Updated modules released with more functionality. + removed_at_date: "2026-07-25" description: - This module provides declarative management of VRFs on CISCO NXOS network devices. version_added: 1.0.0 From 433e199b92750b7be6b52afdcdd2de26e7a5e583 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:55:01 +0000 Subject: [PATCH 43/46] chore: auto fixes from pre-commit.com hooks --- docs/cisco.nxos.nxos_vrf_module.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/cisco.nxos.nxos_vrf_module.rst b/docs/cisco.nxos.nxos_vrf_module.rst index 6765f78b5..f4e95d3fe 100644 --- a/docs/cisco.nxos.nxos_vrf_module.rst +++ b/docs/cisco.nxos.nxos_vrf_module.rst @@ -14,6 +14,13 @@ Version added: 1.0.0 :local: :depth: 1 +DEPRECATED +---------- +:Removed in collection release after 2026-07-25 +:Why: Updated modules released with more functionality. +:Alternative: nxos_vrf_global + + Synopsis -------- @@ -486,6 +493,10 @@ Status ------ +- This module will be removed in a release after 2026-07-25. *[deprecated]* +- For more information see `DEPRECATED`_. + + Authors ~~~~~~~ From 4df5ca10718aef54532cc04464eaefe9b86bdf04 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 16:31:16 +0530 Subject: [PATCH 44/46] edit runtime --- meta/runtime.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meta/runtime.yml b/meta/runtime.yml index ca5c3e69f..9bd5f9468 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -179,6 +179,9 @@ plugin_routing: vpc_interface: redirect: cisco.nxos.nxos_vpc_interface vrf: + deprecation: + removal_date: "2024-07-25" + warning_text: See the plugin documentation for more details redirect: cisco.nxos.nxos_vrf vrf_af: redirect: cisco.nxos.nxos_vrf_af From 4981d63b5805626149d1bc23ae6559af58470a54 Mon Sep 17 00:00:00 2001 From: roverflow Date: Thu, 25 Jul 2024 18:00:14 +0530 Subject: [PATCH 45/46] fix lint --- meta/runtime.yml | 4 ++-- plugins/modules/nxos_vrf.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index 9bd5f9468..40dfbf1fc 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -179,10 +179,10 @@ plugin_routing: vpc_interface: redirect: cisco.nxos.nxos_vpc_interface vrf: + redirect: cisco.nxos.nxos_vrf deprecation: - removal_date: "2024-07-25" + removal_date: "2026-07-25" warning_text: See the plugin documentation for more details - redirect: cisco.nxos.nxos_vrf vrf_af: redirect: cisco.nxos.nxos_vrf_af vrf_interface: diff --git a/plugins/modules/nxos_vrf.py b/plugins/modules/nxos_vrf.py index e9d06029f..78c2d7e61 100644 --- a/plugins/modules/nxos_vrf.py +++ b/plugins/modules/nxos_vrf.py @@ -25,11 +25,7 @@ module: nxos_vrf extends_documentation_fragment: - cisco.nxos.nxos -short_description: Manages global VRF configuration. -deprecated: - alternative: nxos_vrf_global - why: Updated modules released with more functionality. - removed_at_date: "2026-07-25" +short_description: (deprecated, removed after 2026-07-25) Manages global VRF configuration. description: - This module provides declarative management of VRFs on CISCO NXOS network devices. version_added: 1.0.0 From 19bf56c955c03bb0df516cc6a2dd37c5e35fd218 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:31:02 +0000 Subject: [PATCH 46/46] chore: auto fixes from pre-commit.com hooks --- README.md | 2 +- docs/cisco.nxos.nxos_vrf_module.rst | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7d1242aa4..f07da3d38 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Name | Description [cisco.nxos.nxos_vlans](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vlans_module.rst)|VLANs resource module [cisco.nxos.nxos_vpc](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vpc_module.rst)|Manages global VPC configuration [cisco.nxos.nxos_vpc_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vpc_interface_module.rst)|Manages interface VPC configuration -[cisco.nxos.nxos_vrf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_module.rst)|Manages global VRF configuration. +[cisco.nxos.nxos_vrf](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_module.rst)|(deprecated, removed after 2026-07-25) Manages global VRF configuration. [cisco.nxos.nxos_vrf_af](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_af_module.rst)|Manages VRF AF. [cisco.nxos.nxos_vrf_global](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_global_module.rst)|Resource module to configure VRF definitions. [cisco.nxos.nxos_vrf_interface](https://github.com/ansible-collections/cisco.nxos/blob/main/docs/cisco.nxos.nxos_vrf_interface_module.rst)|Manages interface specific VRF configuration. diff --git a/docs/cisco.nxos.nxos_vrf_module.rst b/docs/cisco.nxos.nxos_vrf_module.rst index f4e95d3fe..440c400eb 100644 --- a/docs/cisco.nxos.nxos_vrf_module.rst +++ b/docs/cisco.nxos.nxos_vrf_module.rst @@ -5,7 +5,7 @@ cisco.nxos.nxos_vrf ******************* -**Manages global VRF configuration.** +**(deprecated, removed after 2026-07-25) Manages global VRF configuration.** Version added: 1.0.0 @@ -14,13 +14,6 @@ Version added: 1.0.0 :local: :depth: 1 -DEPRECATED ----------- -:Removed in collection release after 2026-07-25 -:Why: Updated modules released with more functionality. -:Alternative: nxos_vrf_global - - Synopsis -------- @@ -493,10 +486,6 @@ Status ------ -- This module will be removed in a release after 2026-07-25. *[deprecated]* -- For more information see `DEPRECATED`_. - - Authors ~~~~~~~