From b987bebe4f181ec708efd7caba879b6f3af8eb16 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Fri, 9 Apr 2021 16:42:33 +0530 Subject: [PATCH 01/23] Intial commit --- .../vyos/argspec/route_map/__init__.py | 0 .../vyos/argspec/route_map/route_map.py | 125 +++++++ .../network/vyos/config/route_map/__init__.py | 0 .../vyos/config/route_map/route_map.py | 97 ++++++ .../network/vyos/facts/route_map/__init__.py | 0 .../network/vyos/facts/route_map/route_map.py | 77 +++++ .../network/vyos/rm_templates/route_map.py | 50 +++ plugins/modules/vyos_route_map.py | 327 ++++++++++++++++++ 8 files changed, 676 insertions(+) create mode 100644 plugins/module_utils/network/vyos/argspec/route_map/__init__.py create mode 100644 plugins/module_utils/network/vyos/argspec/route_map/route_map.py create mode 100644 plugins/module_utils/network/vyos/config/route_map/__init__.py create mode 100644 plugins/module_utils/network/vyos/config/route_map/route_map.py create mode 100644 plugins/module_utils/network/vyos/facts/route_map/__init__.py create mode 100644 plugins/module_utils/network/vyos/facts/route_map/route_map.py create mode 100644 plugins/module_utils/network/vyos/rm_templates/route_map.py create mode 100644 plugins/modules/vyos_route_map.py diff --git a/plugins/module_utils/network/vyos/argspec/route_map/__init__.py b/plugins/module_utils/network/vyos/argspec/route_map/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/module_utils/network/vyos/argspec/route_map/route_map.py b/plugins/module_utils/network/vyos/argspec/route_map/route_map.py new file mode 100644 index 00000000..6ea189c5 --- /dev/null +++ b/plugins/module_utils/network/vyos/argspec/route_map/route_map.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 +# cli_rm_builder. +# +# Manually editing this file is not advised. +# +# To update the argspec make the desired changes +# in the module docstring and re-run +# cli_rm_builder. +# +############################################# + +""" +The arg spec for the vyos_route_map module +""" + + +class Route_mapArgs(object): # pylint: disable=R0903 + """The arg spec for the vyos_route_map module + """ + + def __init__(self, **kwargs): + pass + + argument_spec = { + "config": { + "type": "list", + "elements": "dict", + "options": { + "route_map_name": {"type": "str"}, + "description": {"type": "str"}, + "rules": { + "type": "list", + "elements": "dict", + "options": { + "rule_number": {"type": "int"}, + "call": {"type": "str"}, + "description": {"type": "str"}, + "action": {"type": "str", "choices": ["deny", "permit"]}, + "continue": {"type": "int"}, + "set": { + "type": "dict", + "options": { + "aggregator": { + "type": "dict", + "options": { + "ip": {"type": "str"}, + "as": {"type": "str"}, + }, + }, + "as_path_exclude": {"type": "str"}, + "as_path_prepend": {"type": "str"}, + "atomic_aggregate": {"type": "bool"}, + "bgp_extcommunity_rt": {"type": "str"}, + "comm_list": { + "type": "dict", + "options": { + "comm_list": {"type": "str"}, + "delete": {"type": "bool"}, + }, + }, + "community": { + "type": "dict", + "options": { + "value": {"type": "str"}, + "local_AS": {"type": "bool"}, + "no_advertise": {"type": "bool"}, + "no_expert": {"type": "bool"}, + "internet": {"type": "bool"}, + "additive": {"type": "bool"}, + "none": {"type": "bool"}, + }, + }, + "extcommunity_rt": {"type": "str"}, + "extcommunity_soo": {"type": "str"}, + "ip_next_hop": {"type": "str"}, + "ipv6_next_hop": {"type": "str"}, + "large_community": {"type": "str"}, + "local_preference": {"type": "str"}, + "metric": {"type": "str"}, + "metric_type": { + "type": "str", + "choices": ["type-1", "type-2"], + }, + "origin": { + "type": "str", + "choices": ["ebgp", "ibgp", "incomplete"], + }, + "originator_id": {"type": "str"}, + "src": {"type": "str"}, + "tag": {"type": "str"}, + "weight": {"type": "str"}, + }, + }, + }, + }, + }, + }, + "running_config": {"type": "str"}, + "state": { + "type": "str", + "choices": [ + "deleted", + "merged", + "overridden", + "replaced", + "gathered", + "rendered", + "parsed", + ], + "default": "merged", + }, + } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/vyos/config/route_map/__init__.py b/plugins/module_utils/network/vyos/config/route_map/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/module_utils/network/vyos/config/route_map/route_map.py b/plugins/module_utils/network/vyos/config/route_map/route_map.py new file mode 100644 index 00000000..78c114fc --- /dev/null +++ b/plugins/module_utils/network/vyos/config/route_map/route_map.py @@ -0,0 +1,97 @@ +# +# -*- coding: utf-8 -*- +# Copyright 2021 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 vyos_route_map 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.resource_module import ( + ResourceModule, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( + Facts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_map import ( + Route_mapTemplate, +) + + +class Route_map(ResourceModule): + """ + The vyos_route_map config class + """ + + def __init__(self, module): + super(Route_map, self).__init__( + empty_fact_val={}, + facts_module=Facts(module), + module=module, + resource="route_map", + tmplt=Route_mapTemplate(), + ) + 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 Route_map network resource. + """ + self.compare(parsers=self.parsers, want=want, have=have) diff --git a/plugins/module_utils/network/vyos/facts/route_map/__init__.py b/plugins/module_utils/network/vyos/facts/route_map/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plugins/module_utils/network/vyos/facts/route_map/route_map.py b/plugins/module_utils/network/vyos/facts/route_map/route_map.py new file mode 100644 index 00000000..e5a33105 --- /dev/null +++ b/plugins/module_utils/network/vyos/facts/route_map/route_map.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 vyos route_map 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.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_map import ( + Route_mapTemplate, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_map.route_map import ( + Route_mapArgs, +) + +class Route_mapFacts(object): + """ The vyos route_map facts class + """ + + def __init__(self, module, subspec='config', options='options'): + self._module = module + self.argument_spec = Route_mapArgs.argument_spec + spec = deepcopy(self.argument_spec) + if subspec: + if options: + facts_argument_spec = spec[subspec][options] + else: + facts_argument_spec = spec[subspec] + else: + facts_argument_spec = spec + + self.generated_spec = utils.generate_dict(facts_argument_spec) + + def populate_facts(self, connection, ansible_facts, data=None): + """ Populate the facts for Route_map 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 Route_map template + route_map_parser = Route_mapTemplate(lines=data.splitlines()) + objs = list(route_map_parser.parse().values()) + + ansible_facts['ansible_network_resources'].pop('route_map', None) + + params = utils.remove_empties( + utils.validate_config(self.argument_spec, {"config": objs}) + ) + + facts['route_map'] = params['config'] + ansible_facts['ansible_network_resources'].update(facts) + + return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/route_map.py b/plugins/module_utils/network/vyos/rm_templates/route_map.py new file mode 100644 index 00000000..30290f77 --- /dev/null +++ b/plugins/module_utils/network/vyos/rm_templates/route_map.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 Route_map 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.network_template import ( + NetworkTemplate, +) + +class Route_mapTemplate(NetworkTemplate): + def __init__(self, lines=None): + super(Route_mapTemplate, self).__init__(lines=lines, tmplt=self) + + # 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/vyos_route_map.py b/plugins/modules/vyos_route_map.py new file mode 100644 index 00000000..4d4d3d46 --- /dev/null +++ b/plugins/modules/vyos_route_map.py @@ -0,0 +1,327 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2021 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +The module file for vyos_route_map +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = """ +module: vyos_route_map +version_added: 2.0.2 +short_description: Route Map Resource Module. +description: +- This module manages route map configurations on devices running VYOS. +author: Ashwini Mhatre (@amhatre) +notes: +- Tested against vyos 1.2. +- This module works with connection C(network_cli). +options: + config: + description: A list of route-map options + type: list + elements: dict + suboptions: + route_map_name: + description: Route map name. + type: str + description: + description: Description for the route map. + type: str + rules: + description: Route Map rules. + type: list + elements: dict + suboptions: + rule_number: + type: int + description: Route-map rule number + call: + description: Route map name + type: str + description: + description: Description for the rule. + type: str + action: + description: Action for matching routes + type: str + choices: ["deny", "permit"] + continue: + description: Route map rule number <1-65535>. + type: int + set: + description: Route parameters. + type: dict + suboptions: + aggregator: + type: dict + description: Border Gateway Protocol (BGP) aggregator attribute. + suboptions: + ip: + type: str + description: IP address. + as: + type: str + description: AS number of an aggregation. + as_path_exclude: + type: str + description: BGP AS path exclude string ex "456 64500 45001" + as_path_prepend: + type: str + description: Prepend string for a Border Gateway Protocol (BGP) AS-path attribute. + atomic_aggregate: + type: bool + description: Border Gateway Protocol (BGP) atomic aggregate attribute. + bgp_extcommunity_rt: + type: str + description: ExtCommunity in format AS:value + comm_list: + type: dict + description: Border Gateway Protocol (BGP) communities matching a community-list. + suboptions: + comm_list: + type: str + description: BGP communities with a community-list. + delete: + type: bool + description: Delete BGP communities matching the community-list. + community: + type: dict + description: Border Gateway Protocl (BGP) community attribute. + suboptions: + value: + type: str + description: Community in 4 octet AS:value format. + local_AS: + type: bool + description: Advertise communities in local AS only (NO_EXPORT_SUBCONFED). + no_advertise: + type: bool + description: Don't advertise this route to any peer (NO_ADVERTISE) + no_expert: + type: bool + description: Don't advertise outside of this AS of confederation boundry (NO_EXPORT) + internet: + type: bool + description: Symbolic Internet community 0. + additive: + type: bool + description: Add the community instead of replacing existing communities. + none: + type: bool + description: none + extcommunity_rt: + type: str + description: Set route target value. + extcommunity_soo: + type: str + description: Set Site of Origin value. + ip_next_hop: + type: str + description: IP address. + ipv6_next_hop: + type: str + description: Nexthop IPv6 address. + large_community: + type: str + description: Set BGP large community value. + local_preference: + type: str + description: Border Gateway Protocol (BGP) local preference attribute. + metric: + type: str + description: Destination routing protocol metric. + metric_type: + type: str + choices: ['type-1', 'type-2'] + description: Open Shortest Path First (OSPF) external metric-type. + origin: + description: Set bgp origin. + type: str + choices: [ "ebgp", "ibgp", "incomplete" ] + originator_id: + type: str + description: Border Gateway Protocol (BGP) originator ID attribute. + src: + type: str + description: Source address for route. + tag: + type: str + description: Tag value for routing protocol + weight: + type: str + description: Border Gateway Protocol (BGP) weight attribute. + match: + description: Route parameters to match. + type: dict + suboptions: + as_path: + description: Set as-path. + type: str + community: + description: BGP community attribute. + type: dict + suboptions: + community_list: + description: BGP community-list to match + type: str + exact_match: + description: BGP community-list to match + type: bool + extcommunity: + description: Extended community name. + type: str + interface: + description: First hop interface of a route to match. + type: str + ip: + description: IP prefix parameters to match. + type: dict + suboptions: + address: + description: IP address of route to match. + type: dict + suboptions: + access_list: &access_list + description: IP access-list to match. + type: int + prefix_list: &prefix_list + description: IP prefix-list to match + type: str + next_hop: + description: next hop prefix list. + type: dict + suboptions: + access_list: *access_list + prefix_list: *prefix_list + route_source: + description: IP route-source to match + type: dict + suboptions: + access_list: *access_list + prefix_list: *prefix_list + ipv6: + description: IPv6 prefix parameters to match. + type: dict + suboptions: + address: + description: IPv6 address of route to match. + type: dict + suboptions: + access_list: + description: IPv6 access-list to match. + type: str + prefix_list: + description: IPv6 prefix-list to match + type: str + next_hop: + description: next-hop ipv6 address IPv6 . + type: str + large_community_large_community_list: + type: str + description: BGP large-community-list to match. + metric: + description: Route metric <1-65535>. + type: int + origin: + description: bgp origin. + type: str + choices: [ "ebgp", "ibgp", "incomplete" ] + peer: + type: str + description: Peer IP address . + rpki: + type: dict + description: Match RPKI validation result. + suboptions: + rpki_validation: + type: str + description: Match RPKI validation result. + valid: + type: bool + description: valid rpki. + invalid: + type: bool + description: invalid rpki. + notfound: + type: bool + description: notfound rpki. + tag: + type: int + description: Route tag <1-65535> + on_match: + type: dict + description: Exit policy on matches. + suboptions: + next: + type: bool + description: Next sequence number to goto on match. + goto: + type: int + description: Rule number to goto on match <1-65535>. + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the VYOS device by + executing the command B(show configuration commands | grep route-map). + - The state I(parsed) reads the configuration from C(show configuration commands | grep route-map) 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: + description: + - The state the configuration should be left in. + type: str + choices: + - deleted + - merged + - overridden + - replaced + - gathered + - rendered + - parsed + default: merged +""" +EXAMPLES = """ +""" + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_map.route_map import ( + Route_mapArgs, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.route_map.route_map import ( + Route_map, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + module = AnsibleModule( + argument_spec=Route_mapArgs.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 = Route_map(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() From 2afd971622cde196396d161e54bc69f70f9c00b4 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Fri, 9 Apr 2021 17:04:20 +0530 Subject: [PATCH 02/23] intial commit --- .../{route_map => route_maps}/__init__.py | 0 .../route_map.py => route_maps/route_maps.py} | 6 ++-- .../{route_map => route_maps}/__init__.py | 0 .../route_map.py => route_maps/route_maps.py} | 18 ++++++------ .../module_utils/network/vyos/facts/facts.py | 4 +++ .../{route_map => route_maps}/__init__.py | 0 .../route_map.py => route_maps/route_maps.py} | 28 +++++++++---------- .../{route_map.py => route_maps.py} | 6 ++-- .../{vyos_route_map.py => vyos_route_maps.py} | 16 +++++------ 9 files changed, 41 insertions(+), 37 deletions(-) rename plugins/module_utils/network/vyos/argspec/{route_map => route_maps}/__init__.py (100%) rename plugins/module_utils/network/vyos/argspec/{route_map/route_map.py => route_maps/route_maps.py} (96%) rename plugins/module_utils/network/vyos/config/{route_map => route_maps}/__init__.py (100%) rename plugins/module_utils/network/vyos/config/{route_map/route_map.py => route_maps/route_maps.py} (89%) rename plugins/module_utils/network/vyos/facts/{route_map => route_maps}/__init__.py (100%) rename plugins/module_utils/network/vyos/facts/{route_map/route_map.py => route_maps/route_maps.py} (75%) rename plugins/module_utils/network/vyos/rm_templates/{route_map.py => route_maps.py} (87%) rename plugins/modules/{vyos_route_map.py => vyos_route_maps.py} (97%) diff --git a/plugins/module_utils/network/vyos/argspec/route_map/__init__.py b/plugins/module_utils/network/vyos/argspec/route_maps/__init__.py similarity index 100% rename from plugins/module_utils/network/vyos/argspec/route_map/__init__.py rename to plugins/module_utils/network/vyos/argspec/route_maps/__init__.py diff --git a/plugins/module_utils/network/vyos/argspec/route_map/route_map.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py similarity index 96% rename from plugins/module_utils/network/vyos/argspec/route_map/route_map.py rename to plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 6ea189c5..b6fdb9eb 100644 --- a/plugins/module_utils/network/vyos/argspec/route_map/route_map.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -23,12 +23,12 @@ ############################################# """ -The arg spec for the vyos_route_map module +The arg spec for the vyos_route_maps module """ -class Route_mapArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_route_map module +class Route_mapsArgs(object): # pylint: disable=R0903 + """The arg spec for the vyos_route_maps module """ def __init__(self, **kwargs): diff --git a/plugins/module_utils/network/vyos/config/route_map/__init__.py b/plugins/module_utils/network/vyos/config/route_maps/__init__.py similarity index 100% rename from plugins/module_utils/network/vyos/config/route_map/__init__.py rename to plugins/module_utils/network/vyos/config/route_maps/__init__.py diff --git a/plugins/module_utils/network/vyos/config/route_map/route_map.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py similarity index 89% rename from plugins/module_utils/network/vyos/config/route_map/route_map.py rename to plugins/module_utils/network/vyos/config/route_maps/route_maps.py index 78c114fc..e6321e6e 100644 --- a/plugins/module_utils/network/vyos/config/route_map/route_map.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -10,7 +10,7 @@ __metaclass__ = type """ -The vyos_route_map config file. +The vyos_route_maps 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 @@ -29,23 +29,23 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( Facts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_map import ( - Route_mapTemplate, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import ( + Route_mapsTemplate, ) -class Route_map(ResourceModule): +class Route_maps(ResourceModule): """ - The vyos_route_map config class + The vyos_route_maps config class """ def __init__(self, module): - super(Route_map, self).__init__( + super(Route_maps, self).__init__( empty_fact_val={}, facts_module=Facts(module), module=module, - resource="route_map", - tmplt=Route_mapTemplate(), + resource="route_maps", + tmplt=Route_mapsTemplate(), ) self.parsers = [ ] @@ -92,6 +92,6 @@ 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 Route_map network resource. + for the Route_maps network resource. """ self.compare(parsers=self.parsers, want=want, have=have) diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index 1a2d7861..18c38bfd 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -55,6 +55,9 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import ( Bgp_address_familyFacts, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_map.route_map import ( + Route_mapFacts, +) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import ( Default, Neighbors, @@ -78,6 +81,7 @@ ospf_interfaces=Ospf_interfacesFacts, bgp_global=Bgp_globalFacts, bgp_address_family=Bgp_address_familyFacts, + route_map=Route_mapFacts, ) diff --git a/plugins/module_utils/network/vyos/facts/route_map/__init__.py b/plugins/module_utils/network/vyos/facts/route_maps/__init__.py similarity index 100% rename from plugins/module_utils/network/vyos/facts/route_map/__init__.py rename to plugins/module_utils/network/vyos/facts/route_maps/__init__.py diff --git a/plugins/module_utils/network/vyos/facts/route_map/route_map.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py similarity index 75% rename from plugins/module_utils/network/vyos/facts/route_map/route_map.py rename to plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index e5a33105..daf28b32 100644 --- a/plugins/module_utils/network/vyos/facts/route_map/route_map.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -8,7 +8,7 @@ __metaclass__ = type """ -The vyos route_map fact class +The vyos route_maps 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. @@ -20,20 +20,20 @@ from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( utils, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_map import ( - Route_mapTemplate, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import ( + Route_mapsTemplate, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_map.route_map import ( - Route_mapArgs, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import ( + Route_mapsArgs, ) -class Route_mapFacts(object): - """ The vyos route_map facts class +class Route_mapsFacts(object): + """ The vyos route_maps facts class """ def __init__(self, module, subspec='config', options='options'): self._module = module - self.argument_spec = Route_mapArgs.argument_spec + self.argument_spec = Route_mapsArgs.argument_spec spec = deepcopy(self.argument_spec) if subspec: if options: @@ -46,7 +46,7 @@ def __init__(self, module, subspec='config', options='options'): self.generated_spec = utils.generate_dict(facts_argument_spec) def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for Route_map network resource + """ Populate the facts for Route_maps network resource :param connection: the device connection :param ansible_facts: Facts dictionary @@ -61,17 +61,17 @@ def populate_facts(self, connection, ansible_facts, data=None): if not data: data = connection.get() - # parse native config using the Route_map template - route_map_parser = Route_mapTemplate(lines=data.splitlines()) - objs = list(route_map_parser.parse().values()) + # parse native config using the Route_maps template + route_maps_parser = Route_mapsTemplate(lines=data.splitlines()) + objs = list(route_maps_parser.parse().values()) - ansible_facts['ansible_network_resources'].pop('route_map', None) + ansible_facts['ansible_network_resources'].pop('route_maps', None) params = utils.remove_empties( utils.validate_config(self.argument_spec, {"config": objs}) ) - facts['route_map'] = params['config'] + facts['route_maps'] = params['config'] ansible_facts['ansible_network_resources'].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/route_map.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py similarity index 87% rename from plugins/module_utils/network/vyos/rm_templates/route_map.py rename to plugins/module_utils/network/vyos/rm_templates/route_maps.py index 30290f77..5f689dc1 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_map.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -8,7 +8,7 @@ __metaclass__ = type """ -The Route_map parser templates file. This contains +The Route_maps 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. @@ -19,9 +19,9 @@ NetworkTemplate, ) -class Route_mapTemplate(NetworkTemplate): +class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None): - super(Route_mapTemplate, self).__init__(lines=lines, tmplt=self) + super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self) # fmt: off PARSERS = [ diff --git a/plugins/modules/vyos_route_map.py b/plugins/modules/vyos_route_maps.py similarity index 97% rename from plugins/modules/vyos_route_map.py rename to plugins/modules/vyos_route_maps.py index 4d4d3d46..8e336add 100644 --- a/plugins/modules/vyos_route_map.py +++ b/plugins/modules/vyos_route_maps.py @@ -5,7 +5,7 @@ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ -The module file for vyos_route_map +The module file for vyos_route_maps """ from __future__ import absolute_import, division, print_function @@ -13,7 +13,7 @@ __metaclass__ = type DOCUMENTATION = """ -module: vyos_route_map +module: vyos_route_maps version_added: 2.0.2 short_description: Route Map Resource Module. description: @@ -292,11 +292,11 @@ """ from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_map.route_map import ( - Route_mapArgs, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.route_maps.route_maps import ( + Route_mapsArgs, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.route_map.route_map import ( - Route_map, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.route_maps.route_maps import ( + Route_maps, ) @@ -307,7 +307,7 @@ def main(): :returns: the result form module invocation """ module = AnsibleModule( - argument_spec=Route_mapArgs.argument_spec, + argument_spec=Route_mapsArgs.argument_spec, mutually_exclusive=[["config", "running_config"]], required_if=[ ["state", "merged", ["config"]], @@ -319,7 +319,7 @@ def main(): supports_check_mode=True, ) - result = Route_map(module).execute_module() + result = Route_maps(module).execute_module() module.exit_json(**result) From b54d98425cec7f15c7755974e3bd4cf7b28468bf Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 12 Apr 2021 12:27:08 +0530 Subject: [PATCH 03/23] Intial commit --- .../vyos/argspec/route_maps/route_maps.py | 86 +++++++++++++++- .../module_utils/network/vyos/facts/facts.py | 6 +- .../vyos/facts/route_maps/route_maps.py | 7 +- .../network/vyos/rm_templates/route_maps.py | 97 +++++++++++++++++-- plugins/modules/vyos_route_maps.py | 32 +++--- 5 files changed, 195 insertions(+), 33 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index b6fdb9eb..04ff7a01 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -39,9 +39,9 @@ def __init__(self, **kwargs): "type": "list", "elements": "dict", "options": { - "route_map_name": {"type": "str"}, - "description": {"type": "str"}, - "rules": { + "route_map": {"type": "str"}, + "entries": { + "aliases": "rules", "type": "list", "elements": "dict", "options": { @@ -104,6 +104,86 @@ def __init__(self, **kwargs): "weight": {"type": "str"}, }, }, + "match": { + "type": "dict", + "options": { + "as_path": {"type": "str"}, + "community": { + "type": "dict", + "options": { + "community_list": {"type": "str"}, + "exact_match": {"type": "bool"}, + }, + }, + "extcommunity": {"type": "str"}, + "interface": {"type": "str"}, + "ip": { + "type": "dict", + "options": { + "address": { + "type": "dict", + "options": { + "access_list": {"type": "int"}, + "prefix_list": {"type": "str"}, + }, + }, + "next_hop": { + "type": "dict", + "options": { + "access_list": {"type": "int"}, + "prefix_list": {"type": "str"}, + }, + }, + "route_source": { + "type": "dict", + "options": { + "access_list": {"type": "int"}, + "prefix_list": {"type": "str"}, + }, + }, + }, + }, + "ipv6": { + "type": "dict", + "options": { + "address": { + "type": "dict", + "options": { + "access_list": {"type": "str"}, + "prefix_list": {"type": "str"}, + }, + }, + "next_hop": {"type": "str"}, + }, + }, + "large_community_large_community_list": { + "type": "str" + }, + "metric": {"type": "int"}, + "origin": { + "type": "str", + "choices": ["ebgp", "ibgp", "incomplete"], + }, + "peer": {"type": "str"}, + "rpki": { + "type": "dict", + "options": { + "rpki_validation": {"type": "str"}, + "valid": {"type": "bool"}, + "invalid": {"type": "bool"}, + "notfound": {"type": "bool"}, + "tag": {"type": "int"}, + }, + }, + }, + }, + "on_match": { + "type": "dict", + "options": { + "next": {"type": "bool"}, + "goto": {"type": "int"}, + }, + }, }, }, }, diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index 18c38bfd..81518f8f 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -55,8 +55,8 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import ( Bgp_address_familyFacts, ) -from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_map.route_map import ( - Route_mapFacts, +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps import ( + Route_mapsFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import ( Default, @@ -81,7 +81,7 @@ ospf_interfaces=Ospf_interfacesFacts, bgp_global=Bgp_globalFacts, bgp_address_family=Bgp_address_familyFacts, - route_map=Route_mapFacts, + route_maps=Route_mapsFacts, ) diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index daf28b32..934d52e0 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -45,6 +45,11 @@ def __init__(self, module, subspec='config', options='options'): self.generated_spec = utils.generate_dict(facts_argument_spec) + def get_config(self, connection): + return connection.get( + 'show configuration commands | grep route-map' + ) + def populate_facts(self, connection, ansible_facts, data=None): """ Populate the facts for Route_maps network resource @@ -59,7 +64,7 @@ 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 Route_maps template route_maps_parser = Route_mapsTemplate(lines=data.splitlines()) diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 5f689dc1..76f355b8 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -21,29 +21,108 @@ class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None): - super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self) + prefix = {"set": "set", "remove": "delete"} + super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix) # fmt: off PARSERS = [ { - "name": "key_a", + "name": "route_map", "getval": re.compile( r""" - ^key_a\s(?P\S+) - $""", re.VERBOSE), - "setval": "", + ^set + \s+policy + \s+route-map + \s+(?P\S+) + *$""", + re.VERBOSE, + ), + "setval": "policy route-map {{route_map_name}}", + "compval": "route_map_name", "result": { + "route_maps": { + "{{ route_map }}": { + "route_map_name": "{{route_map}}" + }, + }, }, "shared": True }, { - "name": "key_b", + "name": "route_map_description", "getval": re.compile( r""" - \s+key_b\s(?P\S+) - $""", re.VERBOSE), - "setval": "", + ^set + \s+policy + \s+route-map + \s+(?P\S+) + \s+description + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "setval": "policy route-map {{route_map_name}} description {{description}}", + "compval": "description", "result": { + "route_maps": { + "{{ route_map}}": { + "description": "{{description}}" + }, + }, + }, + }, + { + "name": "rule_number", + "getval": re.compile( + r""" + ^set + \s+policy + \s+route-map + \s+(?P\S+) + \s+rule + \s+(?P\d+) + *$""", + re.VERBOSE, + ), + "setval": "policy route-map {{route_map_name}} rule {{rule_number}}", + "result": { + "route_maps": { + "{{ route_map}}": { + "rules": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}" + } + + } + }, + }, + }, + }, + { + "name": "rule_number", + "getval": re.compile( + r""" + ^set + \s+policy + \s+route-map + \s+(?P\S+) + \s+rule + \s+(?P\d+) + *$""", + re.VERBOSE, + ), + "setval": "policy route-map {{route_map_name}} rule {{rule_number}}", + "result": { + "route_maps": { + "{{ route_map}}": { + "rules": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}" + } + + } + }, + }, }, }, ] diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index 8e336add..061eb53b 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -24,18 +24,16 @@ - This module works with connection C(network_cli). options: config: - description: A list of route-map options + description: A list of route-map configuration. type: list elements: dict suboptions: - route_map_name: + route_map: description: Route map name. type: str - description: - description: Description for the route map. - type: str - rules: + entries: description: Route Map rules. + aliases: rules type: list elements: dict suboptions: @@ -157,7 +155,7 @@ weight: type: str description: Border Gateway Protocol (BGP) weight attribute. - match: + match: description: Route parameters to match. type: dict suboptions: @@ -255,16 +253,16 @@ tag: type: int description: Route tag <1-65535> - on_match: - type: dict - description: Exit policy on matches. - suboptions: - next: - type: bool - description: Next sequence number to goto on match. - goto: - type: int - description: Rule number to goto on match <1-65535>. + on_match: + type: dict + description: Exit policy on matches. + suboptions: + next: + type: bool + description: Next sequence number to goto on match. + goto: + type: int + description: Rule number to goto on match <1-65535>. running_config: description: - This option is used only with state I(parsed). From c76f95606872204aefc9692a43b6d178fb59d2df Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Wed, 14 Apr 2021 12:36:12 +0530 Subject: [PATCH 04/23] Add parsers for vyos --- .../vyos/argspec/route_maps/route_maps.py | 2 +- .../vyos/facts/route_maps/route_maps.py | 4 +- .../network/vyos/rm_templates/route_maps.py | 1116 ++++++++++++++++- plugins/modules/vyos_route_maps.py | 3 +- 4 files changed, 1064 insertions(+), 61 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 04ff7a01..d43e9e07 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -41,7 +41,7 @@ def __init__(self, **kwargs): "options": { "route_map": {"type": "str"}, "entries": { - "aliases": "rules", + "aliases": ["rules"], "type": "list", "elements": "dict", "options": { diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index 934d52e0..a8ab8217 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -47,7 +47,7 @@ def __init__(self, module, subspec='config', options='options'): def get_config(self, connection): return connection.get( - 'show configuration commands | grep route-map' + 'show configuration commands | grep route-map' ) def populate_facts(self, connection, ansible_facts, data=None): @@ -68,7 +68,9 @@ def populate_facts(self, connection, ansible_facts, data=None): # parse native config using the Route_maps template route_maps_parser = Route_mapsTemplate(lines=data.splitlines()) + objs = list(route_maps_parser.parse().values()) + #import epdb;epdb.serve() ansible_facts['ansible_network_resources'].pop('route_maps', None) diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 76f355b8..2318fb84 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -30,100 +30,1100 @@ def __init__(self, lines=None): "name": "route_map", "getval": re.compile( r""" - ^set - \s+policy - \s+route-map - \s+(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map_name}}", - "compval": "route_map_name", + "compval": "route_map", + "setval": "policy route-map {{route_map}}", + "remval": "policy route-map {{route_map}}", "result": { "route_maps": { "{{ route_map }}": { - "route_map_name": "{{route_map}}" - }, - }, + "route_map": '{{ route_map }}', + } + } }, - "shared": True }, { - "name": "route_map_description", + "name": "rule_number", "getval": re.compile( r""" - ^set - \s+policy - \s+route-map - \s+(?P\S+) - \s+description - \s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map_name}} description {{description}}", - "compval": "description", + "compval": "rule_number", + "setval": "policy route-map {{route_map}} rule {{rule_number}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}}", "result": { "route_maps": { - "{{ route_map}}": { - "description": "{{description}}" - }, - }, - }, + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}" + } + } + } + } + } }, { - "name": "rule_number", + "name": "call", "getval": re.compile( r""" - ^set - \s+policy - \s+route-map - \s+(?P\S+) - \s+rule - \s+(?P\d+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scall\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map_name}} rule {{rule_number}}", + "compval": "rule_number", + "setval": "policy route-map {{route_map}} rule {{rule_number}} call {{call}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} call {{call}}", "result": { "route_maps": { - "{{ route_map}}": { - "rules": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}" - } - + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "call": "{{call}}" + } } - }, - }, - }, + } + } + } }, { - "name": "rule_number", + "name": "description", "getval": re.compile( r""" - ^set - \s+policy - \s+route-map - \s+(?P\S+) - \s+rule - \s+(?P\d+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sdescription\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map_name}} rule {{rule_number}}", + "compval": "rule_number", + "setval": "policy route-map {{route_map}} rule {{rule_number}} description {{description}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} description {{description}}", "result": { "route_maps": { - "{{ route_map}}": { - "rules": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}" - } - + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "description": "{{description}}" + } } - }, - }, - }, + } + } + } + }, + { + "name": "action", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\saction\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "rule_number", + "setval": "policy route-map {{route_map}} rule {{rule_number}} action {{action}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} action {{action}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "action": "{{action}}" + } + } + } + } + } + }, + { + "name": "continue", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scontinue\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "rule_number", + "setval": "policy route-map {{route_map}} rule {{rule_number}} continue {{continue}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} continue {{continue}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "continue": "{{continue}}" + } + } + } + } + } + }, + { + "name": "on_match_next", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\snext(?P) + *$""", + re.VERBOSE, + ), + "compval": "on_match.next", + "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match next", + "remval": "policy route-map {{route_map}} rule {{rule_number}} on-match next", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "on_match": { + "next": "{{True if next is defined}}" + } + } + } + } + } + } + }, + { + "name": "on_match_goto", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\sgoto\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "on_match.next", + "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match goto {{on_match.goto}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} on-match next {{on_match.goto}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "on_match": { + "goto": "{{goto}}" + } + } + } + } + } + } + }, + { + "name": "set_aggregator_ip", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sip\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.aggregator", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{aggregator.ip}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{aggregator.ip}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "aggregator": { + "ip": "{{ip}}" + } + } + } + } + } + } + } + }, + { + "name": "set_aggregator_as", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sas\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.aggregator", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{aggregator.as}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{aggregator.as}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "aggregator": { + "as": "{{as}}" + } + } + } + } + } + } + } + }, + { + "name": "set_as_path_exclude", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-exclude\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.as_path_exclude", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{as_path_exclude}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{as_path_exclude}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "as_path_exclude": "{{as}}" + } + } + } + } + } + } + }, + { + "name": "set_as_path_prepend", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-prepend\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.as_path_prepend", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{as_path_prepend}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{as_path_exclude}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "as_path_prepend": "{{as}}" + } + } + } + } + } + } + }, + { + "name": "set_atomic_aggregate", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\satomic-aggregate(?P) + *$""", + re.VERBOSE, + ), + "compval": "set.atomic-aggregate", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set atomic-aggregate", + "remval": "policy route-map {{route_map}} rule {{rule_number}} set atomic-aggregate", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "atomic_aggregate": "{{True if as is defined}}" + } + } + } + } + } + } + }, + { + "name": "set_bgp_extcommunity_rt", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sbgp-extcommunity-rt\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.bgp_extcommunity_rt", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set bgp-extcommunity-rt {{bgp_extcommunity_rt}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set bgp-extcommunity-rt {{bgp_extcommunity_rt}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "bgp_extcommunity_rt": "{{bgp}}" + } + } + } + } + } + } }, + { + "name": "set_comm_list", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\scomm-list\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.comm_list.comm_list", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set comm-list comm-list {{comm_list}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set comm-list comm-list {{comm_list}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "comm_list": {"comm_list": "{{comm_list}}"} + } + } + } + } + } + } + }, + { + "name": "set_comm_list_delete", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\sdelete(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.comm_list.comm_list", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set comm-list delete", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set comm-list delete", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "comm_list": {"delete": "{{True if delete is defined}}"} + } + } + } + } + } + } + }, + { + "name": "set_extcommunity_rt", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-rt\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.extcommunity_rt", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set extcommunity-rt {{extcommunity_rt}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set extcommunity-rt {{extcommunity_rt}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "extcommunity_rt": "{{extcommunity_rt}}" + } + } + } + } + } + } + }, + { + "name": "set_extcommunity_soo", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-soo\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.extcommunity_soo", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set extcommunity-soo {{extcommunity_soo}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set extcommunity-soo {{extcommunity_soo}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "extcommunity_soo": "{{extcommunity_soo}}" + } + } + } + } + } + } + }, + { + "name": "set_ip_next_hop", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sip-next-hop\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.ip_next_hop", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set ip-next-hop {{ip_next_hop}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set ip-next-hop {{ip_next_hop}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "ip_next_hop": "{{ip_next_hop}}" + } + } + } + } + } + } + }, + { + "name": "set_ipv6_next_hop", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sipv6-next-hop\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.ipv6_next_hop", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set ipv6-next-hop {{ipv6_next_hop}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set ipv6-next-hop {{ipv6_next_hop}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "ipv6_next_hop": "{{ipv6_next_hop}}" + } + } + } + } + } + } + }, + { + "name": "set_large_community", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slarge-community\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.large_community", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set large-community {{large_community}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set large-community {{large_community}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "large_community": "{{large_community}}" + } + } + } + } + } + } + }, + { + "name": "set_local_preference", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slocal-preference\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.local_preference", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set local-preference {{local_preference}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set local_preference {{local_preference}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "local_preference": "{{local_preference}}" + } + } + } + } + } + } + }, + { + "name": "set_metric", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.metric", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set metric {{metric}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set metric {{metric}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "metric": "{{metric}}" + } + } + } + } + } + } + }, + { + "name": "set_metric_type", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric_type\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.metric_type", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set metric-type {{metric_type}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set metric-type {{metric_type}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "metric_type": "{{metric_type}}" + } + } + } + } + } + } + }, + { + "name": "set_origin", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sorigin\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.origin", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set origin {{origin}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set origin {{origin}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "origin": "{{origin}}" + } + } + } + } + } + } + }, + { + "name": "set_originator_id", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\soriginator-id\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.originator_id", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set originator-id {{originator_id}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set originator-id {{originator_id}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "originator_id": "{{originator_id}}" + } + } + } + } + } + } + }, + { + "name": "set_src", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\ssrc\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.src", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set src {{src}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set src {{src}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "src": "{{src}}" + } + } + } + } + } + } + }, + { + "name": "set_tag", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\stag\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.tag", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set tag {{tag}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set tag {{tag}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "tag": "{{tag}}" + } + } + } + } + } + } + }, + { + "name": "set_weight", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sweight\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.weight", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set weight {{weight}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "set weight {{weight}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "weight": "{{weight}}" + } + } + } + } + } + } + }, + { + "name": "match_as_path", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sas-path\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.as_path", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match as-path {{as_path}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match as-path {{as_path}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "as_path": "{{as_path}}" + } + } + } + } + } + } + }, + { + "name": "match_community_community_list", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\scommunity-list\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.community.community_list", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match community community-list {{community_list}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match community community-list {{community_list}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "community": {"community_list": "{{community_list}}"} + } + } + } + } + } + } + }, + { + "name": "match_community_exact_match", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\sexact_match(?P) + *$""", + re.VERBOSE, + ), + "compval": "match.community.exact_match", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match community exact-match", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match community exact-match", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "community": {"exact_match": "{{True if exact_match is defined}}"} + } + } + } + } + } + } + }, + { + "name": "match_extcommunity", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sextcommunity\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.extcommunity", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match extcommunity {{extcommunity}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match extcommunity {{extcommunity}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "extcommunity": "{{extcommunity}}" + } + } + } + } + } + } + }, + { + "name": "match_interface", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sinterface\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.interface", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match interface {{interface}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match interface {{interface}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "interface": "{{interface}}" + } + } + } + } + } + } + }, + { + "name": "match_large_community_large_community_list", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\slarge-community\slarge-community-list\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.large_community_large_community_list", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match large-community large-community-list {{lc}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match large-community large-community-list {{lc}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "large_community_large_community_list": "{{large_community_large_community_list}}" + } + } + } + } + } + } + }, + { + "name": "match_metric", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\smetric\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.metric", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match metric {{metric}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match metric {{metric}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "metric": "{{metric}}" + } + } + } + } + } + } + }, + { + "name": "match_origin", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sorigin\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.origin", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match origin {{origin}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match origin {{origin}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "origin": "{{origin}}" + } + } + } + } + } + } + }, + { + "name": "match_peer", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\speer\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.peer", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match peer {{peer}}", + "remval": "policy route-map {{route_map}} rule {{rule_number}} " + "match peer {{peer}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "match": { + "peer": "{{peer}}" + } + } + } + } + } + } + }, + ] # fmt: on diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index 061eb53b..c702ccdb 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -33,7 +33,8 @@ type: str entries: description: Route Map rules. - aliases: rules + aliases: + - rules type: list elements: dict suboptions: From f5ceb0d40aa786b0fb19cd3f43ca494bc624e1de Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Wed, 5 May 2021 16:33:12 +0530 Subject: [PATCH 05/23] Add vyos_route_maps module --- .../vyos/argspec/route_maps/route_maps.py | 73 ++-- .../vyos/config/route_maps/route_maps.py | 85 +++- .../vyos/facts/route_maps/route_maps.py | 13 +- .../network/vyos/rm_templates/route_maps.py | 370 +++++++++++++----- plugins/modules/vyos_route_maps.py | 99 ++--- .../vyos_route_maps/defaults/main.yaml | 0 .../targets/vyos_route_maps/meta/main.yaml | 0 .../targets/vyos_route_maps/tasks/cli.yaml | 0 .../targets/vyos_route_maps/tasks/main.yaml | 0 .../vyos_route_maps/tests/cli/_parsed.cfg | 0 .../vyos_route_maps/tests/cli/_populate.yaml | 0 .../tests/cli/_remove_config.yaml | 0 .../tests/cli/empty_config.yaml | 0 .../vyos_route_maps/tests/cli/merged.yaml | 0 .../targets/vyos_route_maps/vars/main.yaml | 0 .../vyos/fixtures/vyos_route_maps_config.cfg | 0 .../network/vyos/test_vyos_route_maps.py | 0 17 files changed, 434 insertions(+), 206 deletions(-) create mode 100644 tests/integration/targets/vyos_route_maps/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_route_maps/meta/main.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tasks/cli.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml create mode 100644 tests/integration/targets/vyos_route_maps/vars/main.yaml create mode 100644 tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg create mode 100644 tests/unit/modules/network/vyos/test_vyos_route_maps.py diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index d43e9e07..ae7bba9e 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -73,20 +73,21 @@ def __init__(self, **kwargs): }, "community": { "type": "dict", - "options": { - "value": {"type": "str"}, - "local_AS": {"type": "bool"}, - "no_advertise": {"type": "bool"}, - "no_expert": {"type": "bool"}, - "internet": {"type": "bool"}, - "additive": {"type": "bool"}, - "none": {"type": "bool"}, - }, + "options": {"value": {"type": "str"}}, }, "extcommunity_rt": {"type": "str"}, "extcommunity_soo": {"type": "str"}, "ip_next_hop": {"type": "str"}, - "ipv6_next_hop": {"type": "str"}, + "ipv6_next_hop": { + "type": "dict", + "options": { + "ip_type": { + "type": "str", + "choices": ["global", "local"], + }, + "value": {"type": "str"}, + }, + }, "large_community": {"type": "str"}, "local_preference": {"type": "str"}, "metric": {"type": "str"}, @@ -96,7 +97,7 @@ def __init__(self, **kwargs): }, "origin": { "type": "str", - "choices": ["ebgp", "ibgp", "incomplete"], + "choices": ["egp", "igp", "incomplete"], }, "originator_id": {"type": "str"}, "src": {"type": "str"}, @@ -123,22 +124,40 @@ def __init__(self, **kwargs): "address": { "type": "dict", "options": { - "access_list": {"type": "int"}, - "prefix_list": {"type": "str"}, + "list_type": { + "type": "str", + "choices": [ + "access-list", + "prefix-list", + ], + }, + "value": {"type": "str"}, }, }, "next_hop": { "type": "dict", "options": { - "access_list": {"type": "int"}, - "prefix_list": {"type": "str"}, + "list_type": { + "type": "str", + "choices": [ + "access-list", + "prefix-list", + ], + }, + "value": {"type": "str"}, }, }, "route_source": { "type": "dict", "options": { - "access_list": {"type": "int"}, - "prefix_list": {"type": "str"}, + "list_type": { + "type": "str", + "choices": [ + "access-list", + "prefix-list", + ], + }, + "value": {"type": "str"}, }, }, }, @@ -149,8 +168,14 @@ def __init__(self, **kwargs): "address": { "type": "dict", "options": { - "access_list": {"type": "str"}, - "prefix_list": {"type": "str"}, + "list_type": { + "type": "str", + "choices": [ + "access-list", + "prefix-list", + ], + }, + "value": {"type": "str"}, }, }, "next_hop": {"type": "str"}, @@ -166,14 +191,8 @@ def __init__(self, **kwargs): }, "peer": {"type": "str"}, "rpki": { - "type": "dict", - "options": { - "rpki_validation": {"type": "str"}, - "valid": {"type": "bool"}, - "invalid": {"type": "bool"}, - "notfound": {"type": "bool"}, - "tag": {"type": "int"}, - }, + "type": "str", + "choices": ["notfound", "invalid", "valid"], }, }, }, diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index e6321e6e..feec4fe1 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -17,7 +17,6 @@ created. """ -from copy import deepcopy from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( @@ -48,6 +47,49 @@ def __init__(self, module): tmplt=Route_mapsTemplate(), ) self.parsers = [ + "call", + "description", + "action", + "continue", + "set_aggregator_ip", + "set_aggregator_as", + "set_as_path_exclude", + "set_as_path_prepend", + "set_atomic_aggregate", + "set_bgp_extcommunity_rt", + "set_extcommunity_rt", + "set_extcommunity_soo", + "set_ip_next_hop", + "set_ipv6_next_hop", + "set_large_community", + "set_local_preference", + "set_metric", + "set_metric_type", + "set_origin", + "set_originator_id", + "set_src", + "set_tag", + "set_weight", + "set_comm_list", + "set_comm_list_delete", + "set_community", + "match_as_path", + "match_community_community_list", + "match_community_exact_match", + "match_extcommunity", + "match_interface", + "match_large_community_large_community_list", + "match_metric", + "match_origin", + "match_peer", + "match_ip_address", + "match_ip_next_hop", + "match_ip_route_source", + "on_match_goto", + "on_match_next", + "match_ipv6_address", + "match_ipv6_nexthop", + "match_rpki" ] def execute_module(self): @@ -65,8 +107,8 @@ 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._route_maps_list_to_dict(self.want) + haved = self._route_maps_list_to_dict(self.have) # if state is merged, merge want onto have and then compare if self.state == "merged": @@ -81,12 +123,15 @@ def generate_commands(self): # remove superfluous config for overridden and deleted if self.state in ["overridden", "deleted"]: + #import epdb;epdb.serve() for k, have in iteritems(haved): if k not in wantd: - self._compare(want={}, have=have) + self.commands.append( + self._tmplt.render({"route_map": k}, "route_map", True) + ) - for k, want in iteritems(wantd): - self._compare(want=want, have=haved.pop(k, {})) + for wk, want in iteritems(wantd): + self._compare(want=want, have=haved.pop(wk, {})) def _compare(self, want, have): """Leverages the base class `compare()` method and @@ -94,4 +139,30 @@ def _compare(self, want, have): the `want` and `have` data with the `parsers` defined for the Route_maps network resource. """ - self.compare(parsers=self.parsers, want=want, have=have) + w_entries = want.get("entries", {}) + h_entries = have.get("entries", {}) + self._compare_entries(want=w_entries, have=h_entries) + + def _compare_entries(self, want, have): + for wk, wentry in iteritems(want): + hentry = have.pop(wk, {}) + self.compare(parsers=self.parsers, want=wentry, have=hentry) + + # remove superfluos entries from have + #for _hk, hentry in iteritems(have): + # self.commands.append(self._tmplt.render(hentry, "route_map", True)) + + + def _route_maps_list_to_dict(self, entry): + entry = {x["route_map"]: x for x in entry} + for rmap, data in iteritems(entry): + if "entries" in data: + for x in data["entries"]: + x.update({"route_map": rmap}) + data["entries"] = { + (rmap, entry.get("rule_number")): entry + for entry in data["entries"] + } + #import epdb;epdb.serve() + return entry + diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index a8ab8217..1582ff1b 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -62,23 +62,26 @@ def populate_facts(self, connection, ansible_facts, data=None): """ facts = {} objs = [] - if not data: data = self.get_config(connection) # parse native config using the Route_maps template route_maps_parser = Route_mapsTemplate(lines=data.splitlines()) - - objs = list(route_maps_parser.parse().values()) - #import epdb;epdb.serve() + if route_maps_parser.parse().get('route_maps'): + objs = list(route_maps_parser.parse().get('route_maps').values()) + for item in objs: + if item.get("entries"): + item["entries"] = list(item["entries"].values()) ansible_facts['ansible_network_resources'].pop('route_maps', None) + #import epdb;epdb.serve() params = utils.remove_empties( utils.validate_config(self.argument_spec, {"config": objs}) ) - facts['route_maps'] = params['config'] + if params.get("config"): + facts['route_maps'] = params['config'] ansible_facts['ansible_network_resources'].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 2318fb84..17366fc4 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -19,6 +19,8 @@ NetworkTemplate, ) + + class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None): prefix = {"set": "set", "remove": "delete"} @@ -55,7 +57,6 @@ def __init__(self, lines=None): ), "compval": "rule_number", "setval": "policy route-map {{route_map}} rule {{rule_number}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}}", "result": { "route_maps": { "{{ route_map }}": { @@ -78,9 +79,7 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "rule_number", "setval": "policy route-map {{route_map}} rule {{rule_number}} call {{call}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} call {{call}}", "result": { "route_maps": { "{{ route_map }}": { @@ -104,9 +103,7 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "rule_number", "setval": "policy route-map {{route_map}} rule {{rule_number}} description {{description}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} description {{description}}", "result": { "route_maps": { "{{ route_map }}": { @@ -130,9 +127,7 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "rule_number", "setval": "policy route-map {{route_map}} rule {{rule_number}} action {{action}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} action {{action}}", "result": { "route_maps": { "{{ route_map }}": { @@ -156,9 +151,7 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "rule_number", "setval": "policy route-map {{route_map}} rule {{rule_number}} continue {{continue}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} continue {{continue}}", "result": { "route_maps": { "{{ route_map }}": { @@ -184,7 +177,6 @@ def __init__(self, lines=None): ), "compval": "on_match.next", "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match next", - "remval": "policy route-map {{route_map}} rule {{rule_number}} on-match next", "result": { "route_maps": { "{{ route_map }}": { @@ -210,9 +202,8 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "on_match.next", + "compval": "on_match.goto", "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match goto {{on_match.goto}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} on-match next {{on_match.goto}}", "result": { "route_maps": { "{{ route_map }}": { @@ -238,9 +229,8 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "set.aggregator", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{aggregator.ip}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{aggregator.ip}}", + "compval": "set.aggregator.ip", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{set.aggregator.ip}}", "result": { "route_maps": { "{{ route_map }}": { @@ -268,9 +258,8 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "set.aggregator", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{aggregator.as}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{aggregator.as}}", + "compval": "set.aggregator.as", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{set.aggregator.as}}", "result": { "route_maps": { "{{ route_map }}": { @@ -299,8 +288,7 @@ def __init__(self, lines=None): re.VERBOSE, ), "compval": "set.as_path_exclude", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{as_path_exclude}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{as_path_exclude}}", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{set.as_path_exclude}}", "result": { "route_maps": { "{{ route_map }}": { @@ -327,8 +315,7 @@ def __init__(self, lines=None): re.VERBOSE, ), "compval": "set.as_path_prepend", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{as_path_prepend}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{as_path_exclude}}", + "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{set.as_path_prepend}}", "result": { "route_maps": { "{{ route_map }}": { @@ -354,9 +341,7 @@ def __init__(self, lines=None): *$""", re.VERBOSE, ), - "compval": "set.atomic-aggregate", "setval": "policy route-map {{route_map}} rule {{rule_number}} set atomic-aggregate", - "remval": "policy route-map {{route_map}} rule {{rule_number}} set atomic-aggregate", "result": { "route_maps": { "{{ route_map }}": { @@ -384,9 +369,7 @@ def __init__(self, lines=None): ), "compval": "set.bgp_extcommunity_rt", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set bgp-extcommunity-rt {{bgp_extcommunity_rt}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set bgp-extcommunity-rt {{bgp_extcommunity_rt}}", + "set bgp-extcommunity-rt {{set.bgp_extcommunity_rt}}", "result": { "route_maps": { "{{ route_map }}": { @@ -414,9 +397,7 @@ def __init__(self, lines=None): ), "compval": "set.comm_list.comm_list", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set comm-list comm-list {{comm_list}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set comm-list comm-list {{comm_list}}", + "set comm-list comm-list {{set.comm_list.comm_list}}", "result": { "route_maps": { "{{ route_map }}": { @@ -445,8 +426,6 @@ def __init__(self, lines=None): "compval": "set.comm_list.comm_list", "setval": "policy route-map {{route_map}} rule {{rule_number}} " "set comm-list delete", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set comm-list delete", "result": { "route_maps": { "{{ route_map }}": { @@ -474,9 +453,7 @@ def __init__(self, lines=None): ), "compval": "set.extcommunity_rt", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set extcommunity-rt {{extcommunity_rt}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set extcommunity-rt {{extcommunity_rt}}", + "set extcommunity-rt {{set.extcommunity_rt}}", "result": { "route_maps": { "{{ route_map }}": { @@ -504,9 +481,7 @@ def __init__(self, lines=None): ), "compval": "set.extcommunity_soo", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set extcommunity-soo {{extcommunity_soo}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set extcommunity-soo {{extcommunity_soo}}", + "set extcommunity-soo {{set.extcommunity_soo}}", "result": { "route_maps": { "{{ route_map }}": { @@ -516,7 +491,7 @@ def __init__(self, lines=None): { "rule_number": "{{rule_number}}", "set": { - "extcommunity_soo": "{{extcommunity_soo}}" + "extcommunity_soo": "{{set.extcommunity_soo}}" } } } @@ -534,9 +509,7 @@ def __init__(self, lines=None): ), "compval": "set.ip_next_hop", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set ip-next-hop {{ip_next_hop}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set ip-next-hop {{ip_next_hop}}", + "set ip-next-hop {{set.ip_next_hop}}", "result": { "route_maps": { "{{ route_map }}": { @@ -558,15 +531,15 @@ def __init__(self, lines=None): "name": "set_ipv6_next_hop", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sipv6-next-hop\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sipv6-next-hop + \s(?Pglobal|local) + \s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.ipv6_next_hop", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set ipv6-next-hop {{ipv6_next_hop}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set ipv6-next-hop {{ipv6_next_hop}}", + "set ipv6-next-hop {{set.ipv6_next_hop.ip_type}} {{set.ipv6_next_hop.value}}", "result": { "route_maps": { "{{ route_map }}": { @@ -576,7 +549,10 @@ def __init__(self, lines=None): { "rule_number": "{{rule_number}}", "set": { - "ipv6_next_hop": "{{ipv6_next_hop}}" + "ipv6_next_hop": { + "ip_type": "{{type}}", + "value": "{{value}}" + } } } } @@ -594,9 +570,7 @@ def __init__(self, lines=None): ), "compval": "set.large_community", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set large-community {{large_community}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set large-community {{large_community}}", + "set large-community {{set.large_community}}", "result": { "route_maps": { "{{ route_map }}": { @@ -624,9 +598,7 @@ def __init__(self, lines=None): ), "compval": "set.local_preference", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set local-preference {{local_preference}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set local_preference {{local_preference}}", + "set local-preference {{set.local_preference}}", "result": { "route_maps": { "{{ route_map }}": { @@ -654,9 +626,7 @@ def __init__(self, lines=None): ), "compval": "set.metric", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set metric {{metric}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set metric {{metric}}", + "set metric {{set.metric}}", "result": { "route_maps": { "{{ route_map }}": { @@ -678,15 +648,13 @@ def __init__(self, lines=None): "name": "set_metric_type", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric_type\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric-type\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.metric_type", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set metric-type {{metric_type}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set metric-type {{metric_type}}", + "set metric-type {{set.metric_type}}", "result": { "route_maps": { "{{ route_map }}": { @@ -714,9 +682,7 @@ def __init__(self, lines=None): ), "compval": "set.origin", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set origin {{origin}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set origin {{origin}}", + "set origin {{set.origin}}", "result": { "route_maps": { "{{ route_map }}": { @@ -744,9 +710,7 @@ def __init__(self, lines=None): ), "compval": "set.originator_id", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set originator-id {{originator_id}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set originator-id {{originator_id}}", + "set originator-id {{set.originator_id}}", "result": { "route_maps": { "{{ route_map }}": { @@ -774,9 +738,7 @@ def __init__(self, lines=None): ), "compval": "set.src", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set src {{src}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set src {{src}}", + "set src {{set.src}}", "result": { "route_maps": { "{{ route_map }}": { @@ -804,9 +766,7 @@ def __init__(self, lines=None): ), "compval": "set.tag", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set tag {{tag}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set tag {{tag}}", + "set tag {{set.tag}}", "result": { "route_maps": { "{{ route_map }}": { @@ -834,9 +794,7 @@ def __init__(self, lines=None): ), "compval": "set.weight", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "set weight {{weight}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "set weight {{weight}}", + "set weight {{set.weight}}", "result": { "route_maps": { "{{ route_map }}": { @@ -854,6 +812,36 @@ def __init__(self, lines=None): } } }, + { + "name": "set_community", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scommunity\s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "set.community.value", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "set community {{set.community.value}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": + { + "rule_number": "{{rule_number}}", + "set": { + "community": { + "value": "{{value}}", + } + } + } + } + } + } + } + }, { "name": "match_as_path", "getval": re.compile( @@ -864,9 +852,7 @@ def __init__(self, lines=None): ), "compval": "match.as_path", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match as-path {{as_path}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match as-path {{as_path}}", + "match as-path {{match.as_path}}", "result": { "route_maps": { "{{ route_map }}": { @@ -894,9 +880,7 @@ def __init__(self, lines=None): ), "compval": "match.community.community_list", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match community community-list {{community_list}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match community community-list {{community_list}}", + "match community community-list {{match.community.community_list}}", "result": { "route_maps": { "{{ route_map }}": { @@ -918,15 +902,13 @@ def __init__(self, lines=None): "name": "match_community_exact_match", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\sexact_match(?P) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\sexact-match(?P) *$""", re.VERBOSE, ), "compval": "match.community.exact_match", "setval": "policy route-map {{route_map}} rule {{rule_number}} " "match community exact-match", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match community exact-match", "result": { "route_maps": { "{{ route_map }}": { @@ -954,9 +936,7 @@ def __init__(self, lines=None): ), "compval": "match.extcommunity", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match extcommunity {{extcommunity}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match extcommunity {{extcommunity}}", + "match extcommunity {{match.extcommunity}}", "result": { "route_maps": { "{{ route_map }}": { @@ -984,9 +964,7 @@ def __init__(self, lines=None): ), "compval": "match.interface", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match interface {{interface}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match interface {{interface}}", + "match interface {{match.interface}}", "result": { "route_maps": { "{{ route_map }}": { @@ -1014,9 +992,7 @@ def __init__(self, lines=None): ), "compval": "match.large_community_large_community_list", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match large-community large-community-list {{lc}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match large-community large-community-list {{lc}}", + "match large-community large-community-list {{match.large_community_large_community_list}}", "result": { "route_maps": { "{{ route_map }}": { @@ -1026,7 +1002,7 @@ def __init__(self, lines=None): { "rule_number": "{{rule_number}}", "match": { - "large_community_large_community_list": "{{large_community_large_community_list}}" + "large_community_large_community_list": "{{lc}}" } } } @@ -1044,9 +1020,7 @@ def __init__(self, lines=None): ), "compval": "match.metric", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match metric {{metric}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match metric {{metric}}", + "match metric {{match.metric}}", "result": { "route_maps": { "{{ route_map }}": { @@ -1074,9 +1048,7 @@ def __init__(self, lines=None): ), "compval": "match.origin", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match origin {{origin}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match origin {{origin}}", + "match origin {{match.origin}}", "result": { "route_maps": { "{{ route_map }}": { @@ -1104,9 +1076,7 @@ def __init__(self, lines=None): ), "compval": "match.peer", "setval": "policy route-map {{route_map}} rule {{rule_number}} " - "match peer {{peer}}", - "remval": "policy route-map {{route_map}} rule {{rule_number}} " - "match peer {{peer}}", + "match peer {{match.peer}}", "result": { "route_maps": { "{{ route_map }}": { @@ -1124,6 +1094,200 @@ def __init__(self, lines=None): } } }, + { + "name": "match_ip_address", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\saddress + \s(?Paccess-list|prefix-list) + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.ip.address", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match ip address {{match.ip.address.list_type}} {{match.ip.address.value}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "ip": { + "address": { + "list_type": "{{list_type}}", + "value": "{{value}}" + } + } + } + } + } + } + } + } + }, + { + "name": "match_ip_next_hop", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\snexthop + \s(?Paccess-list|prefix-list) + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.ip.next_hop", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match ip nexthop {{match.ip.next_hop.list_type}} {{match.ip.next_hop.value}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "ip": { + "next_hop": { + "list_type": "{{list_type}}", + "value": "{{value}}" + } + } + } + } + } + } + } + } + }, + { + "name": "match_ip_route_source", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\sroute-source + \s(?Paccess-list|prefix-list) + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.ip.route_source", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match ip route-source {{match.ip.route_source.list_type}} {{match.ip.route_source.value}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "ip": { + "route_source": { + "list_type": "{{list_type}}", + "value": "{{value}}" + } + } + } + } + } + } + } + } + }, + { + "name": "match_ipv6_address", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\saddress + \s(?Paccess-list|prefix-list) + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.ipv6.address", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match ipv6 address {{match.ipv6.address.list_type}} {{match.ipv6.address.value}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "ipv6": { + "address": { + "list_type": "{{list_type}}", + "value": "{{value}}" + } + } + } + } + } + } + } + } + }, + { + "name": "match_ipv6_nexthop", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\snexthop + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.ipv6.next_hop", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match ipv6 nexthop {{match.ipv6.next_hop}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "ipv6": { + "next_hop": "{{value}}" + } + } + } + } + } + } + } + }, + { + "name": "match_rpki", + "getval": re.compile( + r""" + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\srpki + \s(?P\S+) + *$""", + re.VERBOSE, + ), + "compval": "match.rpki", + "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "match rpki {{match.rpki}}", + "result": { + "route_maps": { + "{{ route_map }}": { + "route_map": '{{ route_map }}', + "entries": { + "{{rule_number}}": { + "rule_number": "{{rule_number}}", + "match": { + "rpki": "{{value}}" + } + } + } + } + } + } + }, ] # fmt: on diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index c702ccdb..f36dadff 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -33,8 +33,7 @@ type: str entries: description: Route Map rules. - aliases: - - rules + aliases: rules type: list elements: dict suboptions: @@ -96,46 +95,36 @@ suboptions: value: type: str - description: Community in 4 octet AS:value format. - local_AS: - type: bool - description: Advertise communities in local AS only (NO_EXPORT_SUBCONFED). - no_advertise: - type: bool - description: Don't advertise this route to any peer (NO_ADVERTISE) - no_expert: - type: bool - description: Don't advertise outside of this AS of confederation boundry (NO_EXPORT) - internet: - type: bool - description: Symbolic Internet community 0. - additive: - type: bool - description: Add the community instead of replacing existing communities. - none: - type: bool - description: none + description: Community in 4 octet AS:value format or it can be from local-AS, no-advertise,no-expert,internet,additive,none. extcommunity_rt: type: str - description: Set route target value. + description: Set route target value.ASN:nn_or_IP_address:nn VPN extended community. extcommunity_soo: type: str - description: Set Site of Origin value. + description: Set Site of Origin value. ASN:nn_or_IP_address:nn VPN extended community ip_next_hop: type: str description: IP address. ipv6_next_hop: - type: str + type: dict description: Nexthop IPv6 address. + suboptions: + ip_type: + description: Global or Local + type: str + choices: ["global", "local"] + value: + description: ipv6 address + type: str large_community: type: str description: Set BGP large community value. local_preference: type: str - description: Border Gateway Protocol (BGP) local preference attribute. + description: Border Gateway Protocol (BGP) local preference attribute.Example <0-4294967295>. metric: type: str - description: Destination routing protocol metric. + description: Destination routing protocol metric. Example <0-4294967295>. metric_type: type: str choices: ['type-1', 'type-2'] @@ -143,19 +132,19 @@ origin: description: Set bgp origin. type: str - choices: [ "ebgp", "ibgp", "incomplete" ] + choices: [ "egp", "igp", "incomplete" ] originator_id: type: str - description: Border Gateway Protocol (BGP) originator ID attribute. + description: Border Gateway Protocol (BGP) originator ID attribute. Orignator IP address. src: type: str - description: Source address for route. + description: Source address for route. Example IP address. tag: type: str - description: Tag value for routing protocol + description: Tag value for routing protocol. Example <1-65535> weight: type: str - description: Border Gateway Protocol (BGP) weight attribute. + description: Border Gateway Protocol (BGP) weight attribute. Example <0-4294967295> match: description: Route parameters to match. type: dict @@ -187,24 +176,25 @@ description: IP address of route to match. type: dict suboptions: - access_list: &access_list - description: IP access-list to match. - type: int - prefix_list: &prefix_list - description: IP prefix-list to match + list_type: &list_type + description: type of list + type: str + choices: ['access-list', 'prefix-list'] + value: &value type: str + description: value of access-list and prefix list next_hop: description: next hop prefix list. type: dict suboptions: - access_list: *access_list - prefix_list: *prefix_list + list_type: *list_type + value: *value route_source: description: IP route-source to match type: dict suboptions: - access_list: *access_list - prefix_list: *prefix_list + list_type: *list_type + value: *value ipv6: description: IPv6 prefix parameters to match. type: dict @@ -213,12 +203,8 @@ description: IPv6 address of route to match. type: dict suboptions: - access_list: - description: IPv6 access-list to match. - type: str - prefix_list: - description: IPv6 prefix-list to match - type: str + list_type: *list_type + value: *value next_hop: description: next-hop ipv6 address IPv6 . type: str @@ -236,24 +222,9 @@ type: str description: Peer IP address . rpki: - type: dict - description: Match RPKI validation result. - suboptions: - rpki_validation: - type: str - description: Match RPKI validation result. - valid: - type: bool - description: valid rpki. - invalid: - type: bool - description: invalid rpki. - notfound: - type: bool - description: notfound rpki. - tag: - type: int - description: Route tag <1-65535> + type: str + description: RPKI validation value. + choices: [ "notfound", "invalid", "valid" ] on_match: type: dict description: Exit policy on matches. diff --git a/tests/integration/targets/vyos_route_maps/defaults/main.yaml b/tests/integration/targets/vyos_route_maps/defaults/main.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/meta/main.yaml b/tests/integration/targets/vyos_route_maps/meta/main.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tasks/main.yaml b/tests/integration/targets/vyos_route_maps/tasks/main.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py new file mode 100644 index 00000000..e69de29b From e996df58ee4a7ed5fd427d9bba28b24d7a52aa8e Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Thu, 6 May 2021 11:16:15 +0530 Subject: [PATCH 06/23] add integration and unit tests --- .../vyos_route_maps/defaults/main.yaml | 3 + .../targets/vyos_route_maps/meta/main.yaml | 0 .../targets/vyos_route_maps/tasks/cli.yaml | 19 +++ .../targets/vyos_route_maps/tasks/main.yaml | 4 + .../vyos_route_maps/tests/cli/_parsed.cfg | 16 ++ .../vyos_route_maps/tests/cli/_populate.yaml | 27 ++++ .../tests/cli/_remove_config.yaml | 10 ++ .../vyos_route_maps/tests/cli/deleted.yaml | 36 +++++ .../tests/cli/empty_config.yaml | 60 +++++++ .../vyos_route_maps/tests/cli/gathered.yaml | 24 +++ .../vyos_route_maps/tests/cli/merged.yaml | 65 ++++++++ .../vyos_route_maps/tests/cli/overridden.yaml | 59 +++++++ .../vyos_route_maps/tests/cli/parsed.yaml | 16 ++ .../vyos_route_maps/tests/cli/rendered.yaml | 45 ++++++ .../vyos_route_maps/tests/cli/replaced.yaml | 59 +++++++ .../targets/vyos_route_maps/vars/main.yaml | 150 ++++++++++++++++++ 16 files changed, 593 insertions(+) delete mode 100644 tests/integration/targets/vyos_route_maps/meta/main.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml diff --git a/tests/integration/targets/vyos_route_maps/defaults/main.yaml b/tests/integration/targets/vyos_route_maps/defaults/main.yaml index e69de29b..852a6bee 100644 --- a/tests/integration/targets/vyos_route_maps/defaults/main.yaml +++ b/tests/integration/targets/vyos_route_maps/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/vyos_route_maps/meta/main.yaml b/tests/integration/targets/vyos_route_maps/meta/main.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml index e69de29b..93eb2fe4 100644 --- a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml +++ b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ 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/vyos_route_maps/tasks/main.yaml b/tests/integration/targets/vyos_route_maps/tasks/main.yaml index e69de29b..b957d2f4 100644 --- a/tests/integration/targets/vyos_route_maps/tasks/main.yaml +++ b/tests/integration/targets/vyos_route_maps/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg index e69de29b..f1a53ca9 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg @@ -0,0 +1,16 @@ +set policy route-map test1 rule 1 description test +set policy route-map test1 rule 1 action permit +set policy route-map test1 rule 1 continue 2 +set policy route-map test1 rule 1 on-match next +set policy route-map test3 rule 1 action permit +set policy route-map test3 rule 1 set local-preference 4 +set policy route-map test3 rule 1 set metric 5 +set policy route-map test3 rule 1 set metric-type type-1 +set policy route-map test3 rule 1 set origin egp +set policy route-map test3 rule 1 set originator-id 192.0.2.34 +set policy route-map test3 rule 1 set tag 5 +set policy route-map test3 rule 1 set weight 4 +set policy route-map test3 rule 1 match metric 1 +set policy route-map test3 rule 1 match peer 192.0.2.32 +set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f +set policy route-map test3 rule 1 match rpki invalid \ No newline at end of file diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml index e69de29b..4aa20aac 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml @@ -0,0 +1,27 @@ +--- +- name: setup + vyos.vyos.vyos_config: + lines: + - set policy route-map test2 rule 1 action 'permit' + - set policy route-map test2 rule 1 description 'test' + - set policy route-map test2 rule 1 on-match next + - set policy route-map test2 rule 2 action 'permit' + - set policy route-map test2 rule 2 on-match goto '4' + - set policy route-map test3 rule 1 action 'permit' + - set policy route-map test3 rule 1 match ipv6 nexthop 'fdda:5cc1:23:4::1f' + - set policy route-map test3 rule 1 match metric '1' + - set policy route-map test3 rule 1 match peer '192.0.2.32' + - set policy route-map test3 rule 1 match rpki 'invalid' + - set policy route-map test3 rule 1 set community 'internet' + - set policy route-map test3 rule 1 set ipv6-next-hop global 'fdda:5cc1:23:4::1f' + - set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' + - set policy route-map test3 rule 1 set local-preference '4' + - set policy route-map test3 rule 1 set metric '5' + - set policy route-map test3 rule 1 set metric-type 'type-1' + - set policy route-map test3 rule 1 set origin 'egp' + - set policy route-map test3 rule 1 set originator-id '192.0.2.34' + - set policy route-map test3 rule 1 set tag '5' + - set policy route-map test3 rule 1 set weight '4' + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml index e69de29b..70e98890 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Remove pre-existing route-maps + vyos.vyos.vyos_config: + lines: + - delete policy route-map test1 + - delete policy route-map test2 + - delete policy route-map test3 + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml new file mode 100644 index 00000000..efcb88ba --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: START vyos_route_maps deleted integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete the provided configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + state: deleted + + - assert: + that: + - result.commands|length == 2 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + + - name: Delete the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml index e69de29b..6d992b8b 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_route_maps empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_route_maps: + config: + state: merged + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_route_maps: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_route_maps: + config: + state: overridden + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_route_maps: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_route_maps: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml new file mode 100644 index 00000000..b73fe233 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START vyos_route_maps gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Gather config from the device in structured format. + register: result + vyos.vyos.vyos_route_maps: + state: gathered + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.changed == false + - result.gathered|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index e69de29b..3b0a2008 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START vyos_route_maps merged integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test1 + entries: + - rule_number: 1 + description: "test" + action: permit + continue: 2 + on_match: + next: True + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 1 + peer: 192.0.2.32 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 16 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml new file mode 100644 index 00000000..01e153f7 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START vyos_route_maps overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Override the existing configuration with the provided running configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 3 + peer: 192.0.2.35 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + state: overridden + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 9 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Override the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml new file mode 100644 index 00000000..47cb4cc3 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START vyos_route_maps parsed integration tests on connection={{ ansible_connection + }} + +- name: Provide the running configuration for parsing (config to be parsed) + become: true + register: result + vyos.vyos.vyos_route_maps: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - result.parsed|symmetric_difference(merged.after) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml new file mode 100644 index 00000000..1f09fbea --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START vyos_route_maps rendered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test1 + entries: + - rule_number: 1 + description: "test" + action: permit + continue: 2 + on_match: + next: True + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 1 + peer: 192.0.2.32 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml new file mode 100644 index 00000000..f66cf818 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START vyos_route_maps replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 3 + peer: 192.0.2.35 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + state: replaced + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(replaced.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index e69de29b..d043c69d 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -0,0 +1,150 @@ +--- +merged: + commands: + - set policy route-map test1 rule 1 description test + - set policy route-map test1 rule 1 action permit + - set policy route-map test1 rule 1 continue 2 + - set policy route-map test1 rule 1 on-match next + - set policy route-map test3 rule 1 action permit + - set policy route-map test3 rule 1 set local-preference 4 + - set policy route-map test3 rule 1 set metric 5 + - set policy route-map test3 rule 1 set metric-type type-1 + - set policy route-map test3 rule 1 set origin egp + - set policy route-map test3 rule 1 set originator-id 192.0.2.34 + - set policy route-map test3 rule 1 set tag 5 + - set policy route-map test3 rule 1 set weight 4 + - set policy route-map test3 rule 1 match metric 1 + - set policy route-map test3 rule 1 match peer 192.0.2.32 + - set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f + - set policy route-map test3 rule 1 match rpki invalid + + after: + - route_map: "test3" + entries: + - rule_number: 1 + action: "permit" + match: + rpki: "invalid" + metric: 1 + peer: "192.0.2.32" + ipv6: + next_hop: "fdda:5cc1:23:4::1f" + set: + local_preference: "4" + metric: "5" + metric_type: "type-1" + origin: egp + originator_id: "192.0.2.34" + tag: "5" + weight: "4" + - route_map: "test1" + entries: + - rule_number: 1 + description: "test" + action: "permit" + continue: 2 + on_match: + next: true + +replaced: + commands: + - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 + - delete policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f + - set policy route-map test3 rule 1 set local-preference 6 + - set policy route-map test3 rule 1 set metric 4 + - set policy route-map test3 rule 1 set tag 4 + - delete policy route-map test3 rule 1 set community internet + - set policy route-map test3 rule 1 match metric 3 + - set policy route-map test3 rule 1 match peer 192.0.2.35 + + after: + - route_map: test2 + entries: + - rule_number: 1 + description: "test" + action: permit + on_match: + next: True + - rule_number: 1 + action: permit + on_match: + goto: 4 + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 3 + peer: 192.0.2.35 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + + +overridden: + commands: + - delete policy route-map test2 + - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 + - delete policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f + - set policy route-map test3 rule 1 set local-preference 6 + - set policy route-map test3 rule 1 set metric 4 + - set policy route-map test3 rule 1 set tag 4 + - delete policy route-map test3 rule 1 set community internet + - set policy route-map test3 rule 1 match metric 3 + - set policy route-map test3 rule 1 match peer 192.0.2.35 + + + after: + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 3 + peer: 192.0.2.35 + ipv6: + next_hop: fdda:5cc1:23:4::1f + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + + +deleted: + commands: + - delete policy route-map test2 + - delete policy route-map test3 + after: [] + +rendered: + commands: + - set policy route-map test1 rule 1 description test + - set policy route-map test1 rule 1 action permit + - set policy route-map test1 rule 1 continue 2 + - set policy route-map test1 rule 1 on-match next + - set policy route-map test3 rule 1 action permit + - set policy route-map test3 rule 1 set local-preference 4 + - set policy route-map test3 rule 1 set metric 5 + - set policy route-map test3 rule 1 set metric-type type-1 + - set policy route-map test3 rule 1 set origin egp + - set policy route-map test3 rule 1 set originator-id 192.0.2.34 + - set policy route-map test3 rule 1 set tag 5 + - set policy route-map test3 rule 1 set weight 4 + - set policy route-map test3 rule 1 match metric 1 + - set policy route-map test3 rule 1 match peer 192.0.2.32 + - set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f + - set policy route-map test3 rule 1 match rpki invalid + From baff2cd22cfc8df1ac04640d22df10aca4ef15fa Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Thu, 6 May 2021 14:12:52 +0530 Subject: [PATCH 07/23] Add uts for vyos_route_maps --- .../vyos/fixtures/vyos_route_maps_config.cfg | 23 + .../network/vyos/test_vyos_route_maps.py | 634 ++++++++++++++++++ 2 files changed, 657 insertions(+) diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg index e69de29b..72427ccf 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg @@ -0,0 +1,23 @@ +set policy route-map test1 rule 1 action 'permit' +set policy route-map test1 rule 1 description 'test' +set policy route-map test1 rule 1 on-match next +set policy route-map test1 rule 2 action 'permit' +set policy route-map test1 rule 2 on-match goto '4' +set policy route-map test3 rule 1 action 'permit' +set policy route-map test3 rule 1 match interface 'eth2' +set policy route-map test3 rule 1 match ipv6 nexthop 'fdda:5cc1:23:4::1f' +set policy route-map test3 rule 1 match metric '1' +set policy route-map test3 rule 1 match peer '1.1.1.2' +set policy route-map test3 rule 1 match rpki 'invalid' +set policy route-map test3 rule 1 set bgp-extcommunity-rt '22:11' +set policy route-map test3 rule 1 set community 'internet' +set policy route-map test3 rule 1 set ipv6-next-hop global 'fdda:5cc1:23:4::1f' +set policy route-map test3 rule 1 set ip-next-hop '10.20.10.20' +set policy route-map test3 rule 1 set local-preference '4' +set policy route-map test3 rule 1 set metric '5' +set policy route-map test3 rule 1 set metric-type 'type-1' +set policy route-map test3 rule 1 set origin 'egp' +set policy route-map test3 rule 1 set originator-id '10.0.2.3' +set policy route-map test3 rule 1 set src '10.0.2.15' +set policy route-map test3 rule 1 set tag '5' +set policy route-map test3 rule 1 set weight '4' \ No newline at end of file diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index e69de29b..6da523ea 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -0,0 +1,634 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.plugins.modules import vyos_route_maps +from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( + set_module_args, +) +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosRouteMapsModule(TestVyosModule): + + module = vyos_route_maps + + def setUp(self): + super(TestVyosRouteMapsModule, self).setUp() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps.Route_mapsFacts.get_config" + ) + + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestVyosRouteMapsModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli", filename=None): + if filename is None: + filename = "vyos_route_maps_config.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_route_maps_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4 + ), + ), + + ], + + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), + ), + dict( + rule_number=2, + action="permit", + on_match=dict(goto=4), + ) + ], + ) + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_route_maps_merged(self): + set_module_args( + dict( + config=[ + dict( + route_map="test2", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.3", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.22", + large_community="10:20:21", + local_preference=4, + metric=5, + metric_type="type-2", + origin="egp", + originator_id="10.0.2.2", + src="10.0.2.15", + tag=4, + weight=4 + ), + ), + + ], + + ) + ], + state="merged", + ) + ) + commands = ['set policy route-map test2 rule 1 action permit', + 'set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11', + 'set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22', + 'set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', + 'set policy route-map test2 rule 1 set large-community 10:20:21', + 'set policy route-map test2 rule 1 set local-preference 4', + 'set policy route-map test2 rule 1 set metric 5', + 'set policy route-map test2 rule 1 set metric-type type-2', + 'set policy route-map test2 rule 1 set origin egp', + 'set policy route-map test2 rule 1 set originator-id 10.0.2.2', + 'set policy route-map test2 rule 1 set src 10.0.2.15', + 'set policy route-map test2 rule 1 set tag 4', + 'set policy route-map test2 rule 1 set weight 4', + 'set policy route-map test2 rule 1 set community internet', + 'set policy route-map test2 rule 1 match interface eth2', + 'set policy route-map test2 rule 1 match metric 1', + 'set policy route-map test2 rule 1 match peer 1.1.1.3', + 'set policy route-map test2 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f', + 'set policy route-map test2 rule 1 match rpki invalid'] + + self.execute_module(changed=True, commands=commands) + + def test_route_maps_replaced(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + metric=1, + peer="1.1.1.3", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.22", + large_community="10:20:21", + local_preference=4, + metric=5, + metric_type="type-2", + origin="egp", + originator_id="10.0.2.2", + src="10.0.2.15", + tag=4, + weight=4 + ), + ), + + ], + + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), + ), + dict( + rule_number=2, + action="permit", + description="test", + on_match=dict(goto=4), + ) + ], + ) + ], + state="replaced", + ) + ) + commands = ['delete policy route-map test3 rule 1 match interface eth2', + 'set policy route-map test1 rule 2 description test', + 'set policy route-map test3 rule 1 set ip-next-hop 10.20.10.22', + 'set policy route-map test3 rule 1 set large-community 10:20:21', + 'set policy route-map test3 rule 1 set metric-type type-2', + 'set policy route-map test3 rule 1 set originator-id 10.0.2.2', + 'set policy route-map test3 rule 1 set tag 4', + 'set policy route-map test3 rule 1 match peer 1.1.1.3'] + self.execute_module(changed=True, commands=commands) + + def test_vyos_route_maps_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4 + ), + ), + + ], + + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), + ), + dict( + rule_number=2, + action="permit", + on_match=dict(goto=4), + ) + ], + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_route_maps_overridden(self): + set_module_args( + dict( + config=[ + dict( + route_map="test2", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + peer="1.1.1.3", + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.22", + large_community="10:20:21", + local_preference=4, + metric=5, + metric_type="type-2", + origin="egp", + originator_id="10.0.2.2", + src="10.0.2.15", + tag=4, + weight=4 + ), + ), + + ], + + ), + ], + state="overridden", + ) + ) + commands = ['delete policy route-map test1', + 'delete policy route-map test3', + 'set policy route-map test2 rule 1 action permit', + 'set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11', + 'set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22', + 'set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', + 'set policy route-map test2 rule 1 set large-community 10:20:21', + 'set policy route-map test2 rule 1 set local-preference 4', + 'set policy route-map test2 rule 1 set metric 5', + 'set policy route-map test2 rule 1 set metric-type type-2', + 'set policy route-map test2 rule 1 set origin egp', + 'set policy route-map test2 rule 1 set originator-id 10.0.2.2', + 'set policy route-map test2 rule 1 set src 10.0.2.15', + 'set policy route-map test2 rule 1 set tag 4', + 'set policy route-map test2 rule 1 set weight 4', + 'set policy route-map test2 rule 1 set community internet', + 'set policy route-map test2 rule 1 match peer 1.1.1.3', + 'set policy route-map test2 rule 1 match rpki invalid'] + self.execute_module(changed=True, commands=commands) + + def test_vyos_route_maps_rendered(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f" + ), + community=dict( + value="internet" + ), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4 + ), + ), + + ], + + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), + ), + dict( + rule_number=2, + action="permit", + on_match=dict(goto=4), + ) + ], + ) + ], + state="rendered", + ) + ) + rendered_cmds=['set policy route-map test3 rule 1 action permit', + 'set policy route-map test3 rule 1 set bgp-extcommunity-rt 22:11', + 'set policy route-map test3 rule 1 set ip-next-hop 10.20.10.20', + 'set policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', + 'set policy route-map test3 rule 1 set local-preference 4', + 'set policy route-map test3 rule 1 set metric 5', + 'set policy route-map test3 rule 1 set metric-type type-1', + 'set policy route-map test3 rule 1 set origin egp', + 'set policy route-map test3 rule 1 set originator-id 10.0.2.3', + 'set policy route-map test3 rule 1 set src 10.0.2.15', + 'set policy route-map test3 rule 1 set tag 5', 'set policy route-map test3 rule 1 set weight 4', + 'set policy route-map test3 rule 1 set community internet', + 'set policy route-map test3 rule 1 match interface eth2', + 'set policy route-map test3 rule 1 match metric 1', + 'set policy route-map test3 rule 1 match peer 1.1.1.2', + 'set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f', + 'set policy route-map test3 rule 1 match rpki invalid', + 'set policy route-map test1 rule 1 description test', + 'set policy route-map test1 rule 1 action permit', + 'set policy route-map test1 rule 1 on-match next', + 'set policy route-map test1 rule 2 action permit', + 'set policy route-map test1 rule 2 on-match goto 4'] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), + sorted(rendered_cmds), + result["rendered"], + ) + + def test_vyos_bgp_global_parsed(self): + + parsed_str = "set policy route-map test1 rule 1 action 'permit'\nset policy route-map test1 rule 1 description " \ + "'test'\nset policy route-map test1 rule 1 on-match next\nset policy route-map test1 rule 2 action " \ + "'permit'\nset policy route-map test1 rule 2 on-match goto '4'\nset policy route-map test3 rule 1 action 'permit'" \ + "\nset policy route-map test3 rule 1 match interface 'eth2'\nset policy route-map test3 rule 1 match ipv6 nexthop" \ + " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 match metric '1'\nset policy route-map test3 rule 1 match peer " \ + "'1.1.1.2'\nset policy route-map test3 rule 1 match rpki 'invalid'\nset policy route-map test3 rule 1 set bgp-extcommunity-rt " \ + "'22:11'\nset policy route-map test3 rule 1 set community 'internet'\nset policy route-map test3 rule 1 set ipv6-next-hop global" \ + " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 set ip-next-hop '10.20.10.20'\nset policy route-map " \ + "test3 rule 1 set local-preference '4'\nset policy route-map test3 rule 1 set metric '5'\nset policy route-map test3 " \ + "rule 1 set metric-type 'type-1'\nset policy route-map test3 rule 1 set origin 'egp'\nset policy route-map test3 rule 1 set originator-id " \ + "'10.0.2.3'\nset policy route-map test3 rule 1 set src '10.0.2.15'" \ + "\nset policy route-map test3 rule 1 set tag '5'\nset policy route-map test3 rule 1 set weight '4'" + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "entries": [ + { + "action": "permit", + "description": "test", + "on_match": { + "next": True + }, + "rule_number": 1 + }, + { + "action": "permit", + "on_match": { + "goto": 4 + }, + "rule_number": 2 + } + ], + "route_map": "test1" + }, + { + "entries": [ + { + "action": "permit", + "match": { + "interface": "eth2", + "ipv6": { + "next_hop": "fdda:5cc1:23:4::1f" + }, + "metric": 1, + "peer": "1.1.1.2", + "rpki": "invalid" + }, + "rule_number": 1, + "set": { + "bgp_extcommunity_rt": "22:11", + "community": { + "value": "internet" + }, + "ip_next_hop": "10.20.10.20", + "ipv6_next_hop": { + "ip_type": "global", + "value": "fdda:5cc1:23:4::1f" + }, + "local_preference": "4", + "metric": "5", + "metric_type": "type-1", + "origin": "egp", + "originator_id": "10.0.2.3", + "src": "10.0.2.15", + "tag": "5", + "weight": "4" + } + } + ], + "route_map": "test3" + } + ] + self.assertEqual(parsed_list, result["parsed"]) + + + def test_vyos_bgp_global_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gathered_list = [ + { + "entries": [ + { + "action": "permit", + "description": "test", + "on_match": { + "next": True + }, + "rule_number": 1 + }, + { + "action": "permit", + "on_match": { + "goto": 4 + }, + "rule_number": 2 + } + ], + "route_map": "test1" + }, + { + "entries": [ + { + "action": "permit", + "match": { + "interface": "eth2", + "ipv6": { + "next_hop": "fdda:5cc1:23:4::1f" + }, + "metric": 1, + "peer": "1.1.1.2", + "rpki": "invalid" + }, + "rule_number": 1, + "set": { + "bgp_extcommunity_rt": "22:11", + "community": { + "value": "internet" + }, + "ip_next_hop": "10.20.10.20", + "ipv6_next_hop": { + "ip_type": "global", + "value": "fdda:5cc1:23:4::1f" + }, + "local_preference": "4", + "metric": "5", + "metric_type": "type-1", + "origin": "egp", + "originator_id": "10.0.2.3", + "src": "10.0.2.15", + "tag": "5", + "weight": "4" + } + } + ], + "route_map": "test3" + } + ] + self.assertEqual(gathered_list, result["gathered"]) \ No newline at end of file From c7bfc9e1ae90be3be071eb0b8b03206864009925 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Thu, 6 May 2021 14:15:40 +0530 Subject: [PATCH 08/23] Add valid comment --- tests/integration/network-integration.cfg | 8 ++++ tests/integration/test-inventory | 38 +++++++++++++++++++ .../network/vyos/test_vyos_route_maps.py | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/integration/test-inventory diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg index d12c1efe..41209074 100644 --- a/tests/integration/network-integration.cfg +++ b/tests/integration/network-integration.cfg @@ -2,3 +2,11 @@ command_timeout = 100 connect_timeout = 100 connect_retry_timeout = 100 + + +[paramiko_connection] +look_for_keys = False + +[defaults] +gathering=no +interpreter_python=/Users/amhatre/ansible_venvs/py3.6.10/bin/python diff --git a/tests/integration/test-inventory b/tests/integration/test-inventory new file mode 100644 index 00000000..d202a177 --- /dev/null +++ b/tests/integration/test-inventory @@ -0,0 +1,38 @@ +[vyos] +127.0.0.1 + +[vyos:vars] +ansible_network_os=vyos.vyos.vyos +ansible_ssh_port=2222 +ansible_user=vyos +ansible_ssh_pass=vyos +ansible_connection=ansible.netcommon.network_cli +ansible_become=true +#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa +ansible_become_method=ansible.netcommon.enable +cli={'transport': 'cli'} +netconf={'transport': 'netconf'} + +[netconf] +iosxr-7.0.2 ansible_port=22 ansible_host=127.0.0.1 ansible_user=vagrant + + +[netconf:vars] +#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa +ansible_become_method=ansible.netcommon.enable +ansible_network_os=cisco.iosxr.iosxr +ansible_ssh_pass=vagrant +cli={'transport': 'cli'} +debug=False +netconf={'transport': 'netconf'} + +#[iosxr:vars:network_cli] +#host=10.8.38.70 +#username=ansible +#password=ansible +#transport=netcon +#[iosxr:vars] +#ansible_network_os=cisco.iosxr.iosxr +#ansible_ssh_username=ansible +#ansible_ssh_password=ansible +#ansible_connection=ansible.netcommon.netconf diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index 6da523ea..f1309688 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -1,4 +1,4 @@ -# (c) 2016 Red Hat Inc. +# (c) 2021 Red Hat Inc. # # This file is part of Ansible # From 3fe41bdc126592b11bbb3182f65a8f3fd5c0813a Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Thu, 6 May 2021 16:42:44 +0530 Subject: [PATCH 09/23] fix linters --- changelogs/fragments/vyos-route-maps.yaml | 3 + .../vyos/argspec/route_maps/route_maps.py | 11 +- .../vyos/config/route_maps/route_maps.py | 14 +- .../vyos/facts/route_maps/route_maps.py | 19 +- .../network/vyos/rm_templates/route_maps.py | 5 +- .../network/vyos/test_vyos_route_maps.py | 524 ++++++++---------- 6 files changed, 275 insertions(+), 301 deletions(-) create mode 100644 changelogs/fragments/vyos-route-maps.yaml diff --git a/changelogs/fragments/vyos-route-maps.yaml b/changelogs/fragments/vyos-route-maps.yaml new file mode 100644 index 00000000..6f4e07f8 --- /dev/null +++ b/changelogs/fragments/vyos-route-maps.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Add vyos_route_maps resource module (https://github.com/ansible-collections/vyos.vyos/pull/156.). diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index ae7bba9e..ddf2b4c9 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -48,7 +48,10 @@ def __init__(self, **kwargs): "rule_number": {"type": "int"}, "call": {"type": "str"}, "description": {"type": "str"}, - "action": {"type": "str", "choices": ["deny", "permit"]}, + "action": { + "type": "str", + "choices": ["deny", "permit"], + }, "continue": {"type": "int"}, "set": { "type": "dict", @@ -192,7 +195,11 @@ def __init__(self, **kwargs): "peer": {"type": "str"}, "rpki": { "type": "str", - "choices": ["notfound", "invalid", "valid"], + "choices": [ + "notfound", + "invalid", + "valid", + ], }, }, }, diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index feec4fe1..19842f25 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -89,7 +89,7 @@ def __init__(self, module): "on_match_next", "match_ipv6_address", "match_ipv6_nexthop", - "match_rpki" + "match_rpki", ] def execute_module(self): @@ -123,12 +123,12 @@ def generate_commands(self): # remove superfluous config for overridden and deleted if self.state in ["overridden", "deleted"]: - #import epdb;epdb.serve() + # import epdb;epdb.serve() for k, have in iteritems(haved): if k not in wantd: self.commands.append( - self._tmplt.render({"route_map": k}, "route_map", True) - ) + self._tmplt.render({"route_map": k}, "route_map", True) + ) for wk, want in iteritems(wantd): self._compare(want=want, have=haved.pop(wk, {})) @@ -149,10 +149,9 @@ def _compare_entries(self, want, have): self.compare(parsers=self.parsers, want=wentry, have=hentry) # remove superfluos entries from have - #for _hk, hentry in iteritems(have): + # for _hk, hentry in iteritems(have): # self.commands.append(self._tmplt.render(hentry, "route_map", True)) - def _route_maps_list_to_dict(self, entry): entry = {x["route_map"]: x for x in entry} for rmap, data in iteritems(entry): @@ -163,6 +162,5 @@ def _route_maps_list_to_dict(self, entry): (rmap, entry.get("rule_number")): entry for entry in data["entries"] } - #import epdb;epdb.serve() + # import epdb;epdb.serve() return entry - diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index 1582ff1b..023e4af4 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -27,11 +27,12 @@ Route_mapsArgs, ) + class Route_mapsFacts(object): """ The vyos route_maps facts class """ - def __init__(self, module, subspec='config', options='options'): + def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Route_mapsArgs.argument_spec spec = deepcopy(self.argument_spec) @@ -46,9 +47,7 @@ def __init__(self, module, subspec='config', options='options'): self.generated_spec = utils.generate_dict(facts_argument_spec) def get_config(self, connection): - return connection.get( - 'show configuration commands | grep route-map' - ) + return connection.get("show configuration commands | grep route-map") def populate_facts(self, connection, ansible_facts, data=None): """ Populate the facts for Route_maps network resource @@ -67,21 +66,21 @@ def populate_facts(self, connection, ansible_facts, data=None): # parse native config using the Route_maps template route_maps_parser = Route_mapsTemplate(lines=data.splitlines()) - if route_maps_parser.parse().get('route_maps'): - objs = list(route_maps_parser.parse().get('route_maps').values()) + if route_maps_parser.parse().get("route_maps"): + objs = list(route_maps_parser.parse().get("route_maps").values()) for item in objs: if item.get("entries"): item["entries"] = list(item["entries"].values()) - ansible_facts['ansible_network_resources'].pop('route_maps', None) + ansible_facts["ansible_network_resources"].pop("route_maps", None) - #import epdb;epdb.serve() + # import epdb;epdb.serve() params = utils.remove_empties( utils.validate_config(self.argument_spec, {"config": objs}) ) if params.get("config"): - facts['route_maps'] = params['config'] - ansible_facts['ansible_network_resources'].update(facts) + facts["route_maps"] = params["config"] + ansible_facts["ansible_network_resources"].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 17366fc4..33e0c083 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -20,11 +20,12 @@ ) - class Route_mapsTemplate(NetworkTemplate): def __init__(self, lines=None): prefix = {"set": "set", "remove": "delete"} - super(Route_mapsTemplate, self).__init__(lines=lines, tmplt=self, prefix=prefix) + super(Route_mapsTemplate, self).__init__( + lines=lines, tmplt=self, prefix=prefix + ) # fmt: off PARSERS = [ diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index f1309688..57d09d86 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -42,7 +42,6 @@ def setUp(self): self.mock_get_resource_connection_config.start() ) - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" ) @@ -77,60 +76,56 @@ def test_vyos_route_maps_merged_idempotent(self): dict( config=[ dict( - route_map="test3", - entries=[ - dict( - rule_number=1, - action="permit", - match=dict( - rpki="invalid", - interface="eth2", - metric=1, - peer="1.1.1.2", - ipv6=dict(next_hop="fdda:5cc1:23:4::1f") - ), - set=dict( - ipv6_next_hop=dict( - ip_type="global", - value="fdda:5cc1:23:4::1f" + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), ), - community=dict( - value="internet" + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f", + ), + community=dict(value="internet"), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4, ), - bgp_extcommunity_rt="22:11", - ip_next_hop="10.20.10.20", - local_preference=4, - metric=5, - metric_type="type-1", - origin="egp", - originator_id="10.0.2.3", - src="10.0.2.15", - tag=5, - weight=4 + ) + ], + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), ), - ), - - ], - - ), - dict( - route_map="test1", - entries=[ - dict( - rule_number=1, - action="permit", - description="test", - on_match=dict(next=True), - ), - dict( - rule_number=2, - action="permit", - on_match=dict(goto=4), - ) - ], - ) - ], - state="merged", + dict( + rule_number=2, + action="permit", + on_match=dict(goto=4), + ), + ], + ), + ], + state="merged", ) ) self.execute_module(changed=False, commands=[]) @@ -150,16 +145,14 @@ def test_route_maps_merged(self): interface="eth2", metric=1, peer="1.1.1.3", - ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), ), set=dict( ipv6_next_hop=dict( ip_type="global", - value="fdda:5cc1:23:4::1f" - ), - community=dict( - value="internet" + value="fdda:5cc1:23:4::1f", ), + community=dict(value="internet"), bgp_extcommunity_rt="22:11", ip_next_hop="10.20.10.22", large_community="10:20:21", @@ -170,36 +163,36 @@ def test_route_maps_merged(self): originator_id="10.0.2.2", src="10.0.2.15", tag=4, - weight=4 + weight=4, ), - ), - + ) ], - ) ], state="merged", ) ) - commands = ['set policy route-map test2 rule 1 action permit', - 'set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11', - 'set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22', - 'set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', - 'set policy route-map test2 rule 1 set large-community 10:20:21', - 'set policy route-map test2 rule 1 set local-preference 4', - 'set policy route-map test2 rule 1 set metric 5', - 'set policy route-map test2 rule 1 set metric-type type-2', - 'set policy route-map test2 rule 1 set origin egp', - 'set policy route-map test2 rule 1 set originator-id 10.0.2.2', - 'set policy route-map test2 rule 1 set src 10.0.2.15', - 'set policy route-map test2 rule 1 set tag 4', - 'set policy route-map test2 rule 1 set weight 4', - 'set policy route-map test2 rule 1 set community internet', - 'set policy route-map test2 rule 1 match interface eth2', - 'set policy route-map test2 rule 1 match metric 1', - 'set policy route-map test2 rule 1 match peer 1.1.1.3', - 'set policy route-map test2 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f', - 'set policy route-map test2 rule 1 match rpki invalid'] + commands = [ + "set policy route-map test2 rule 1 action permit", + "set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11", + "set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22", + "set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f", + "set policy route-map test2 rule 1 set large-community 10:20:21", + "set policy route-map test2 rule 1 set local-preference 4", + "set policy route-map test2 rule 1 set metric 5", + "set policy route-map test2 rule 1 set metric-type type-2", + "set policy route-map test2 rule 1 set origin egp", + "set policy route-map test2 rule 1 set originator-id 10.0.2.2", + "set policy route-map test2 rule 1 set src 10.0.2.15", + "set policy route-map test2 rule 1 set tag 4", + "set policy route-map test2 rule 1 set weight 4", + "set policy route-map test2 rule 1 set community internet", + "set policy route-map test2 rule 1 match interface eth2", + "set policy route-map test2 rule 1 match metric 1", + "set policy route-map test2 rule 1 match peer 1.1.1.3", + "set policy route-map test2 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f", + "set policy route-map test2 rule 1 match rpki invalid", + ] self.execute_module(changed=True, commands=commands) @@ -217,16 +210,14 @@ def test_route_maps_replaced(self): rpki="invalid", metric=1, peer="1.1.1.3", - ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), ), set=dict( ipv6_next_hop=dict( ip_type="global", - value="fdda:5cc1:23:4::1f" - ), - community=dict( - value="internet" + value="fdda:5cc1:23:4::1f", ), + community=dict(value="internet"), bgp_extcommunity_rt="22:11", ip_next_hop="10.20.10.22", large_community="10:20:21", @@ -237,12 +228,10 @@ def test_route_maps_replaced(self): originator_id="10.0.2.2", src="10.0.2.15", tag=4, - weight=4 + weight=4, ), - ), - + ) ], - ), dict( route_map="test1", @@ -258,85 +247,83 @@ def test_route_maps_replaced(self): action="permit", description="test", on_match=dict(goto=4), - ) + ), ], - ) + ), ], state="replaced", ) ) - commands = ['delete policy route-map test3 rule 1 match interface eth2', - 'set policy route-map test1 rule 2 description test', - 'set policy route-map test3 rule 1 set ip-next-hop 10.20.10.22', - 'set policy route-map test3 rule 1 set large-community 10:20:21', - 'set policy route-map test3 rule 1 set metric-type type-2', - 'set policy route-map test3 rule 1 set originator-id 10.0.2.2', - 'set policy route-map test3 rule 1 set tag 4', - 'set policy route-map test3 rule 1 match peer 1.1.1.3'] + commands = [ + "delete policy route-map test3 rule 1 match interface eth2", + "set policy route-map test1 rule 2 description test", + "set policy route-map test3 rule 1 set ip-next-hop 10.20.10.22", + "set policy route-map test3 rule 1 set large-community 10:20:21", + "set policy route-map test3 rule 1 set metric-type type-2", + "set policy route-map test3 rule 1 set originator-id 10.0.2.2", + "set policy route-map test3 rule 1 set tag 4", + "set policy route-map test3 rule 1 match peer 1.1.1.3", + ] self.execute_module(changed=True, commands=commands) def test_vyos_route_maps_replaced_idempotent(self): - set_module_args( - dict( - config=[ - dict( - route_map="test3", - entries=[ - dict( - rule_number=1, - action="permit", - match=dict( - rpki="invalid", - interface="eth2", - metric=1, - peer="1.1.1.2", - ipv6=dict(next_hop="fdda:5cc1:23:4::1f") - ), - set=dict( - ipv6_next_hop=dict( - ip_type="global", - value="fdda:5cc1:23:4::1f" - ), - community=dict( - value="internet" - ), - bgp_extcommunity_rt="22:11", - ip_next_hop="10.20.10.20", - local_preference=4, - metric=5, - metric_type="type-1", - origin="egp", - originator_id="10.0.2.3", - src="10.0.2.15", - tag=5, - weight=4 - ), + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + rule_number=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), ), - - ], - - ), - dict( - route_map="test1", - entries=[ - dict( - rule_number=1, - action="permit", - description="test", - on_match=dict(next=True), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f", + ), + community=dict(value="internet"), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4, ), - dict( - rule_number=2, - action="permit", - on_match=dict(goto=4), - ) - ], - ) - ], - state="replaced", - ) + ) + ], + ), + dict( + route_map="test1", + entries=[ + dict( + rule_number=1, + action="permit", + description="test", + on_match=dict(next=True), + ), + dict( + rule_number=2, + action="permit", + on_match=dict(goto=4), + ), + ], + ), + ], + state="replaced", ) - self.execute_module(changed=False, commands=[]) + ) + self.execute_module(changed=False, commands=[]) def test_route_maps_overridden(self): set_module_args( @@ -348,18 +335,13 @@ def test_route_maps_overridden(self): dict( rule_number=1, action="permit", - match=dict( - rpki="invalid", - peer="1.1.1.3", - ), + match=dict(rpki="invalid", peer="1.1.1.3"), set=dict( ipv6_next_hop=dict( ip_type="global", - value="fdda:5cc1:23:4::1f" - ), - community=dict( - value="internet" + value="fdda:5cc1:23:4::1f", ), + community=dict(value="internet"), bgp_extcommunity_rt="22:11", ip_next_hop="10.20.10.22", large_community="10:20:21", @@ -370,35 +352,35 @@ def test_route_maps_overridden(self): originator_id="10.0.2.2", src="10.0.2.15", tag=4, - weight=4 + weight=4, ), - ), - + ) ], - - ), + ) ], state="overridden", ) ) - commands = ['delete policy route-map test1', - 'delete policy route-map test3', - 'set policy route-map test2 rule 1 action permit', - 'set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11', - 'set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22', - 'set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', - 'set policy route-map test2 rule 1 set large-community 10:20:21', - 'set policy route-map test2 rule 1 set local-preference 4', - 'set policy route-map test2 rule 1 set metric 5', - 'set policy route-map test2 rule 1 set metric-type type-2', - 'set policy route-map test2 rule 1 set origin egp', - 'set policy route-map test2 rule 1 set originator-id 10.0.2.2', - 'set policy route-map test2 rule 1 set src 10.0.2.15', - 'set policy route-map test2 rule 1 set tag 4', - 'set policy route-map test2 rule 1 set weight 4', - 'set policy route-map test2 rule 1 set community internet', - 'set policy route-map test2 rule 1 match peer 1.1.1.3', - 'set policy route-map test2 rule 1 match rpki invalid'] + commands = [ + "delete policy route-map test1", + "delete policy route-map test3", + "set policy route-map test2 rule 1 action permit", + "set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11", + "set policy route-map test2 rule 1 set ip-next-hop 10.20.10.22", + "set policy route-map test2 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f", + "set policy route-map test2 rule 1 set large-community 10:20:21", + "set policy route-map test2 rule 1 set local-preference 4", + "set policy route-map test2 rule 1 set metric 5", + "set policy route-map test2 rule 1 set metric-type type-2", + "set policy route-map test2 rule 1 set origin egp", + "set policy route-map test2 rule 1 set originator-id 10.0.2.2", + "set policy route-map test2 rule 1 set src 10.0.2.15", + "set policy route-map test2 rule 1 set tag 4", + "set policy route-map test2 rule 1 set weight 4", + "set policy route-map test2 rule 1 set community internet", + "set policy route-map test2 rule 1 match peer 1.1.1.3", + "set policy route-map test2 rule 1 match rpki invalid", + ] self.execute_module(changed=True, commands=commands) def test_vyos_route_maps_rendered(self): @@ -416,16 +398,14 @@ def test_vyos_route_maps_rendered(self): interface="eth2", metric=1, peer="1.1.1.2", - ipv6=dict(next_hop="fdda:5cc1:23:4::1f") + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), ), set=dict( ipv6_next_hop=dict( ip_type="global", - value="fdda:5cc1:23:4::1f" - ), - community=dict( - value="internet" + value="fdda:5cc1:23:4::1f", ), + community=dict(value="internet"), bgp_extcommunity_rt="22:11", ip_next_hop="10.20.10.20", local_preference=4, @@ -435,12 +415,10 @@ def test_vyos_route_maps_rendered(self): originator_id="10.0.2.3", src="10.0.2.15", tag=5, - weight=4 + weight=4, ), - ), - + ) ], - ), dict( route_map="test1", @@ -455,35 +433,38 @@ def test_vyos_route_maps_rendered(self): rule_number=2, action="permit", on_match=dict(goto=4), - ) + ), ], - ) + ), ], state="rendered", ) ) - rendered_cmds=['set policy route-map test3 rule 1 action permit', - 'set policy route-map test3 rule 1 set bgp-extcommunity-rt 22:11', - 'set policy route-map test3 rule 1 set ip-next-hop 10.20.10.20', - 'set policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f', - 'set policy route-map test3 rule 1 set local-preference 4', - 'set policy route-map test3 rule 1 set metric 5', - 'set policy route-map test3 rule 1 set metric-type type-1', - 'set policy route-map test3 rule 1 set origin egp', - 'set policy route-map test3 rule 1 set originator-id 10.0.2.3', - 'set policy route-map test3 rule 1 set src 10.0.2.15', - 'set policy route-map test3 rule 1 set tag 5', 'set policy route-map test3 rule 1 set weight 4', - 'set policy route-map test3 rule 1 set community internet', - 'set policy route-map test3 rule 1 match interface eth2', - 'set policy route-map test3 rule 1 match metric 1', - 'set policy route-map test3 rule 1 match peer 1.1.1.2', - 'set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f', - 'set policy route-map test3 rule 1 match rpki invalid', - 'set policy route-map test1 rule 1 description test', - 'set policy route-map test1 rule 1 action permit', - 'set policy route-map test1 rule 1 on-match next', - 'set policy route-map test1 rule 2 action permit', - 'set policy route-map test1 rule 2 on-match goto 4'] + rendered_cmds = [ + "set policy route-map test3 rule 1 action permit", + "set policy route-map test3 rule 1 set bgp-extcommunity-rt 22:11", + "set policy route-map test3 rule 1 set ip-next-hop 10.20.10.20", + "set policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f", + "set policy route-map test3 rule 1 set local-preference 4", + "set policy route-map test3 rule 1 set metric 5", + "set policy route-map test3 rule 1 set metric-type type-1", + "set policy route-map test3 rule 1 set origin egp", + "set policy route-map test3 rule 1 set originator-id 10.0.2.3", + "set policy route-map test3 rule 1 set src 10.0.2.15", + "set policy route-map test3 rule 1 set tag 5", + "set policy route-map test3 rule 1 set weight 4", + "set policy route-map test3 rule 1 set community internet", + "set policy route-map test3 rule 1 match interface eth2", + "set policy route-map test3 rule 1 match metric 1", + "set policy route-map test3 rule 1 match peer 1.1.1.2", + "set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f", + "set policy route-map test3 rule 1 match rpki invalid", + "set policy route-map test1 rule 1 description test", + "set policy route-map test1 rule 1 action permit", + "set policy route-map test1 rule 1 on-match next", + "set policy route-map test1 rule 2 action permit", + "set policy route-map test1 rule 2 on-match goto 4", + ] result = self.execute_module(changed=False) self.assertEqual( sorted(result["rendered"]), @@ -493,18 +474,20 @@ def test_vyos_route_maps_rendered(self): def test_vyos_bgp_global_parsed(self): - parsed_str = "set policy route-map test1 rule 1 action 'permit'\nset policy route-map test1 rule 1 description " \ - "'test'\nset policy route-map test1 rule 1 on-match next\nset policy route-map test1 rule 2 action " \ - "'permit'\nset policy route-map test1 rule 2 on-match goto '4'\nset policy route-map test3 rule 1 action 'permit'" \ - "\nset policy route-map test3 rule 1 match interface 'eth2'\nset policy route-map test3 rule 1 match ipv6 nexthop" \ - " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 match metric '1'\nset policy route-map test3 rule 1 match peer " \ - "'1.1.1.2'\nset policy route-map test3 rule 1 match rpki 'invalid'\nset policy route-map test3 rule 1 set bgp-extcommunity-rt " \ - "'22:11'\nset policy route-map test3 rule 1 set community 'internet'\nset policy route-map test3 rule 1 set ipv6-next-hop global" \ - " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 set ip-next-hop '10.20.10.20'\nset policy route-map " \ - "test3 rule 1 set local-preference '4'\nset policy route-map test3 rule 1 set metric '5'\nset policy route-map test3 " \ - "rule 1 set metric-type 'type-1'\nset policy route-map test3 rule 1 set origin 'egp'\nset policy route-map test3 rule 1 set originator-id " \ - "'10.0.2.3'\nset policy route-map test3 rule 1 set src '10.0.2.15'" \ - "\nset policy route-map test3 rule 1 set tag '5'\nset policy route-map test3 rule 1 set weight '4'" + parsed_str = ( + "set policy route-map test1 rule 1 action 'permit'\nset policy route-map test1 rule 1 description " + "'test'\nset policy route-map test1 rule 1 on-match next\nset policy route-map test1 rule 2 action " + "'permit'\nset policy route-map test1 rule 2 on-match goto '4'\nset policy route-map test3 rule 1 action 'permit'" + "\nset policy route-map test3 rule 1 match interface 'eth2'\nset policy route-map test3 rule 1 match ipv6 nexthop" + " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 match metric '1'\nset policy route-map test3 rule 1 match peer " + "'1.1.1.2'\nset policy route-map test3 rule 1 match rpki 'invalid'\nset policy route-map test3 rule 1 set bgp-extcommunity-rt " + "'22:11'\nset policy route-map test3 rule 1 set community 'internet'\nset policy route-map test3 rule 1 set ipv6-next-hop global" + " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 set ip-next-hop '10.20.10.20'\nset policy route-map " + "test3 rule 1 set local-preference '4'\nset policy route-map test3 rule 1 set metric '5'\nset policy route-map test3 " + "rule 1 set metric-type 'type-1'\nset policy route-map test3 rule 1 set origin 'egp'\nset policy route-map test3 rule 1 set originator-id " + "'10.0.2.3'\nset policy route-map test3 rule 1 set src '10.0.2.15'" + "\nset policy route-map test3 rule 1 set tag '5'\nset policy route-map test3 rule 1 set weight '4'" + ) set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = [ @@ -513,20 +496,16 @@ def test_vyos_bgp_global_parsed(self): { "action": "permit", "description": "test", - "on_match": { - "next": True - }, - "rule_number": 1 + "on_match": {"next": True}, + "rule_number": 1, }, { "action": "permit", - "on_match": { - "goto": 4 - }, - "rule_number": 2 - } + "on_match": {"goto": 4}, + "rule_number": 2, + }, ], - "route_map": "test1" + "route_map": "test1", }, { "entries": [ @@ -534,23 +513,19 @@ def test_vyos_bgp_global_parsed(self): "action": "permit", "match": { "interface": "eth2", - "ipv6": { - "next_hop": "fdda:5cc1:23:4::1f" - }, + "ipv6": {"next_hop": "fdda:5cc1:23:4::1f"}, "metric": 1, "peer": "1.1.1.2", - "rpki": "invalid" + "rpki": "invalid", }, "rule_number": 1, "set": { "bgp_extcommunity_rt": "22:11", - "community": { - "value": "internet" - }, + "community": {"value": "internet"}, "ip_next_hop": "10.20.10.20", "ipv6_next_hop": { "ip_type": "global", - "value": "fdda:5cc1:23:4::1f" + "value": "fdda:5cc1:23:4::1f", }, "local_preference": "4", "metric": "5", @@ -559,16 +534,15 @@ def test_vyos_bgp_global_parsed(self): "originator_id": "10.0.2.3", "src": "10.0.2.15", "tag": "5", - "weight": "4" - } + "weight": "4", + }, } ], - "route_map": "test3" - } + "route_map": "test3", + }, ] self.assertEqual(parsed_list, result["parsed"]) - def test_vyos_bgp_global_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) @@ -578,20 +552,16 @@ def test_vyos_bgp_global_gathered(self): { "action": "permit", "description": "test", - "on_match": { - "next": True - }, - "rule_number": 1 + "on_match": {"next": True}, + "rule_number": 1, }, { "action": "permit", - "on_match": { - "goto": 4 - }, - "rule_number": 2 - } + "on_match": {"goto": 4}, + "rule_number": 2, + }, ], - "route_map": "test1" + "route_map": "test1", }, { "entries": [ @@ -599,23 +569,19 @@ def test_vyos_bgp_global_gathered(self): "action": "permit", "match": { "interface": "eth2", - "ipv6": { - "next_hop": "fdda:5cc1:23:4::1f" - }, + "ipv6": {"next_hop": "fdda:5cc1:23:4::1f"}, "metric": 1, "peer": "1.1.1.2", - "rpki": "invalid" + "rpki": "invalid", }, "rule_number": 1, "set": { "bgp_extcommunity_rt": "22:11", - "community": { - "value": "internet" - }, + "community": {"value": "internet"}, "ip_next_hop": "10.20.10.20", "ipv6_next_hop": { "ip_type": "global", - "value": "fdda:5cc1:23:4::1f" + "value": "fdda:5cc1:23:4::1f", }, "local_preference": "4", "metric": "5", @@ -624,11 +590,11 @@ def test_vyos_bgp_global_gathered(self): "originator_id": "10.0.2.3", "src": "10.0.2.15", "tag": "5", - "weight": "4" - } + "weight": "4", + }, } ], - "route_map": "test3" - } + "route_map": "test3", + }, ] - self.assertEqual(gathered_list, result["gathered"]) \ No newline at end of file + self.assertEqual(gathered_list, result["gathered"]) From 1b5708c7c7c4af52c237903b5d8de34943531f70 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Thu, 6 May 2021 20:49:04 +0530 Subject: [PATCH 10/23] fix linters --- .../vyos/argspec/route_maps/route_maps.py | 3 +- .../vyos/config/route_maps/route_maps.py | 12 +- .../vyos/facts/route_maps/route_maps.py | 5 +- .../network/vyos/rm_templates/route_maps.py | 6 +- plugins/modules/vyos_route_maps.py | 658 +++++++++++++++++- .../vyos_route_maps/tests/cli/_parsed.cfg | 1 - .../vyos_route_maps/tests/cli/_populate.yaml | 2 - .../vyos_route_maps/tests/cli/merged.yaml | 4 +- .../vyos_route_maps/tests/cli/overridden.yaml | 4 +- .../vyos_route_maps/tests/cli/rendered.yaml | 2 - .../vyos_route_maps/tests/cli/replaced.yaml | 4 +- .../targets/vyos_route_maps/vars/main.yaml | 28 - 12 files changed, 672 insertions(+), 57 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index ddf2b4c9..649d43d2 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -28,8 +28,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_route_maps module - """ + """The arg spec for the vyos_route_maps module""" def __init__(self, **kwargs): pass diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index 19842f25..55cc7f5c 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -93,7 +93,7 @@ def __init__(self, module): ] def execute_module(self): - """ Execute the module + """Execute the module :rtype: A dictionary :returns: The result from module execution @@ -104,8 +104,8 @@ 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 = self._route_maps_list_to_dict(self.want) haved = self._route_maps_list_to_dict(self.have) @@ -135,9 +135,9 @@ 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 Route_maps network resource. + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Route_maps network resource. """ w_entries = want.get("entries", {}) h_entries = have.get("entries", {}) diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index 023e4af4..d1b2a74b 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -29,8 +29,7 @@ class Route_mapsFacts(object): - """ The vyos route_maps facts class - """ + """The vyos route_maps facts class""" def __init__(self, module, subspec="config", options="options"): self._module = module @@ -50,7 +49,7 @@ def get_config(self, connection): return connection.get("show configuration commands | grep route-map") def populate_facts(self, connection, ansible_facts, data=None): - """ Populate the facts for Route_maps network resource + """Populate the facts for Route_maps network resource :param connection: the device connection :param ansible_facts: Facts dictionary diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 33e0c083..13faec72 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -8,9 +8,9 @@ __metaclass__ = type """ -The Route_maps parser templates file. This contains -a list of parser definitions and associated functions that -facilitates both facts gathering and native command generation for +The Route_maps 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. """ diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index f36dadff..d8629eb1 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -33,7 +33,7 @@ type: str entries: description: Route Map rules. - aliases: rules + aliases: ["rules"] type: list elements: dict suboptions: @@ -259,6 +259,662 @@ default: merged """ EXAMPLES = """ +# Using merged +# Before state + +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# vyos@vyos:~$ + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test1 + entries: + - rule_number: 1 + description: "test" + action: permit + continue: 2 + on_match: + next: True + - route_map: test3 + entries: + - rule_number: 1 + action: permit + match: + rpki: invalid + metric: 1 + peer: 192.0.2.32 + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: merged +# After State +# vyos@vyos:~$ show configuration commands | match "set policy route-maps" +# set policy route-map test1 rule 1 description test +# set policy route-map test1 rule 1 action permit +# set policy route-map test1 rule 1 continue 2 +# set policy route-map test1 rule 1 on-match next +# set policy route-map test3 rule 1 action permit +# set policy route-map test3 rule 1 set local-preference 4 +# set policy route-map test3 rule 1 set metric 5 +# set policy route-map test3 rule 1 set metric-type type-1 +# set policy route-map test3 rule 1 set origin egp +# set policy route-map test3 rule 1 set originator-id 192.0.2.34 +# set policy route-map test3 rule 1 set tag 5 +# set policy route-map test3 rule 1 set weight 4 +# set policy route-map test3 rule 1 match metric 1 +# set policy route-map test3 rule 1 match peer 192.0.2.32 +# set policy route-map test3 rule 1 match rpki invalid + +# "after": [ +# { +# "entries": [ +# { +# "action": "permit", +# "continue": 2, +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# } +# ], +# "route_map": "test1" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 1, +# "peer": "192.0.2.32", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "4", +# "metric": "5", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "5", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "before": {}, +# "changed": true, +# "commands": [ +# "set policy route-map test1 rule 1 description test", +# "set policy route-map test1 rule 1 action permit", +# "set policy route-map test1 rule 1 continue 2", +# "set policy route-map test1 rule 1 on-match next", +# "set policy route-map test3 rule 1 action permit", +# "set policy route-map test3 rule 1 set local-preference 4", +# "set policy route-map test3 rule 1 set metric 5", +# "set policy route-map test3 rule 1 set metric-type type-1", +# "set policy route-map test3 rule 1 set origin egp", +# "set policy route-map test3 rule 1 set originator-id 192.0.2.34", +# "set policy route-map test3 rule 1 set tag 5", +# "set policy route-map test3 rule 1 set weight 4", +# "set policy route-map test3 rule 1 match metric 1", +# "set policy route-map test3 rule 1 match peer 192.0.2.32", +# "set policy route-map test3 rule 1 match rpki invalid" +# ], + +# Using replaced: +# -------------- + +# Before state: +# vyos@vyos:~$ show configuration commands | match "set route-map policy" +# set policy route-map test2 rule 1 action 'permit' +# set policy route-map test2 rule 1 description 'test' +# set policy route-map test2 rule 1 on-match next +# set policy route-map test2 rule 2 action 'permit' +# set policy route-map test2 rule 2 on-match goto '4' +# set policy route-map test3 rule 1 action 'permit' +# set policy route-map test3 rule 1 match metric '1' +# set policy route-map test3 rule 1 match peer '192.0.2.32' +# set policy route-map test3 rule 1 match rpki 'invalid' +# set policy route-map test3 rule 1 set community 'internet' +# set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' +# set policy route-map test3 rule 1 set local-preference '4' +# set policy route-map test3 rule 1 set metric '5' +# set policy route-map test3 rule 1 set metric-type 'type-1' +# set policy route-map test3 rule 1 set origin 'egp' +# set policy route-map test3 rule 1 set originator-id '192.0.2.34' +# set policy route-map test3 rule 1 set tag '5' +# set policy route-map test3 rule 1 set weight '4' +# +# - name: Replace the provided configuration with the exisiting running configuration +# register: result +# vyos.vyos.vyos_route_maps: &id001 +# config: +# - route_map: test3 +# entries: +# - rule_number: 1 +# action: permit +# match: +# rpki: invalid +# metric: 3 +# peer: 192.0.2.35 +# set: +# local_preference: 6 +# metric: 4 +# metric_type: "type-1" +# origin: egp +# originator_id: 192.0.2.34 +# tag: 4 +# weight: 4 +# state: replaced +# After state: + +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# set policy route-map test3 rule 1 set local-preference 6 +# set policy route-map test3 rule 1 set metric 4 +# set policy route-map test3 rule 1 set tag 4 +# set policy route-map test3 rule 1 match metric 3 +# set policy route-map test3 rule 1 match peer 192.0.2.35 +# vyos@vyos:~$ +# +# +# Module Execution: +# +# "after": [ +# { +# "entries": [ +# { +# "action": "permit", +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# }, +# { +# "action": "permit", +# "on_match": { +# "goto": 4 +# }, +# "rule_number": 2 +# } +# ], +# "route_map": "test2" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 3, +# "peer": "192.0.2.35", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "6", +# "metric": "4", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "4", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "before": [ +# { +# "entries": [ +# { +# "action": "permit", +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# }, +# { +# "action": "permit", +# "on_match": { +# "goto": 4 +# }, +# "rule_number": 2 +# } +# ], +# "route_map": "test2" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 1, +# "peer": "192.0.2.32", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "community": { +# "value": "internet" +# }, +# "ip_next_hop": "192.0.2.33", +# "local_preference": "4", +# "metric": "5", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "5", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "changed": true, +# "commands": [ +# "delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33", +# "set policy route-map test3 rule 1 set local-preference 6", +# "set policy route-map test3 rule 1 set metric 4", +# "set policy route-map test3 rule 1 set tag 4", +# "delete policy route-map test3 rule 1 set community internet", +# "set policy route-map test3 rule 1 match metric 3", +# "set policy route-map test3 rule 1 match peer 192.0.2.35" +# ], +# +# Using deleted: +# ------------- + +# Before state: +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# set policy route-map test3 rule 1 set local-preference 6 +# set policy route-map test3 rule 1 set metric 4 +# set policy route-map test3 rule 1 set tag 4 +# set policy route-map test3 rule 1 match metric 3 +# set policy route-map test3 rule 1 match peer 192.0.2.35 +# vyos@vyos:~$ +# +# - name: Delete the provided configuration +# register: result +# vyos.vyos.vyos_route_maps: +# config: +# state: deleted +# After state: + +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# vyos@vyos:~$ +# +# +# Module Execution: +# +# "after": {}, +# "before": [ +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 3, +# "peer": "192.0.2.35", +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "6", +# "metric": "4", +# "tag": "4", +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "changed": true, +# "commands": [ +# "delete policy route-map test3" +# ], +# +# using gathered: +# -------------- +# +# Before state: +# vyos@vyos:~$ show configuration commands | match "set policy route-maps" +# set policy route-map test1 rule 1 description test +# set policy route-map test1 rule 1 action permit +# set policy route-map test1 rule 1 continue 2 +# set policy route-map test1 rule 1 on-match next +# set policy route-map test3 rule 1 action permit +# set policy route-map test3 rule 1 set local-preference 4 +# set policy route-map test3 rule 1 set metric 5 +# set policy route-map test3 rule 1 set metric-type type-1 +# set policy route-map test3 rule 1 set origin egp +# set policy route-map test3 rule 1 set originator-id 192.0.2.34 +# set policy route-map test3 rule 1 set tag 5 +# set policy route-map test3 rule 1 set weight 4 +# set policy route-map test3 rule 1 match metric 1 +# set policy route-map test3 rule 1 match peer 192.0.2.32 +# set policy route-map test3 rule 1 match rpki invalid +# +# - name: gather configs +# vyos.vyos.vyos_route_maps: +# state: gathered + +# "gathered": [ +# { +# "entries": [ +# { +# "action": "permit", +# "continue": 2, +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# } +# ], +# "route_map": "test1" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 1, +# "peer": "192.0.2.32", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "4", +# "metric": "5", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "5", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ] + +# Using parsed: +# ------------ + +# parsed.cfg +# set policy route-map test1 rule 1 description test +# set policy route-map test1 rule 1 action permit +# set policy route-map test1 rule 1 continue 2 +# set policy route-map test1 rule 1 on-match next +# set policy route-map test3 rule 1 action permit +# set policy route-map test3 rule 1 set local-preference 4 +# set policy route-map test3 rule 1 set metric 5 +# set policy route-map test3 rule 1 set metric-type type-1 +# set policy route-map test3 rule 1 set origin egp +# set policy route-map test3 rule 1 set originator-id 192.0.2.34 +# set policy route-map test3 rule 1 set tag 5 +# set policy route-map test3 rule 1 set weight 4 +# set policy route-map test3 rule 1 match metric 1 +# set policy route-map test3 rule 1 match peer 192.0.2.32 +# set policy route-map test3 rule 1 match rpki invalid +# +# - name: parse configs +# vyos.vyos.vyos_route_maps: +# running_config: "{{ lookup('file', './parsed.cfg') }}" +# state: parsed +# tags: +# - parsed +# +# Module execution: +# "parsed": [ +# { +# "entries": [ +# { +# "action": "permit", +# "continue": 2, +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# } +# ], +# "route_map": "test1" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 1, +# "peer": "192.0.2.32", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "4", +# "metric": "5", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "5", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ] +# +# +# Using rendered: +# -------------- +# - name: Structure provided configuration into device specific commands +# register: result +# vyos.vyos.vyos_route_maps: &id001 +# config: +# - route_map: test1 +# entries: +# - rule_number: 1 +# description: "test" +# action: permit +# continue: 2 +# on_match: +# next: True +# - route_map: test3 +# entries: +# - rule_number: 1 +# action: permit +# match: +# rpki: invalid +# metric: 1 +# peer: 192.0.2.32 +# set: +# local_preference: 4 +# metric: 5 +# metric_type: "type-1" +# origin: egp +# originator_id: 192.0.2.34 +# tag: 5 +# weight: 4 +# state: rendered +# Module Execution: +# "rendered": [ +# "set policy route-map test1 rule 1 description test", +# "set policy route-map test1 rule 1 action permit", +# "set policy route-map test1 rule 1 continue 2", +# "set policy route-map test1 rule 1 on-match next", +# "set policy route-map test3 rule 1 action permit", +# "set policy route-map test3 rule 1 set local-preference 4", +# "set policy route-map test3 rule 1 set metric 5", +# "set policy route-map test3 rule 1 set metric-type type-1", +# "set policy route-map test3 rule 1 set origin egp", +# "set policy route-map test3 rule 1 set originator-id 192.0.2.34", +# "set policy route-map test3 rule 1 set tag 5", +# "set policy route-map test3 rule 1 set weight 4", +# "set policy route-map test3 rule 1 match metric 1", +# "set policy route-map test3 rule 1 match peer 192.0.2.32", +# "set policy route-map test3 rule 1 match rpki invalid" +# ] +# +# +# Using overridden: +# -------------- +# Before state: +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# set policy route-map test2 rule 1 action 'permit' +# set policy route-map test2 rule 1 description 'test' +# set policy route-map test2 rule 1 on-match next +# set policy route-map test2 rule 2 action 'permit' +# set policy route-map test2 rule 2 on-match goto '4' +# set policy route-map test3 rule 1 action 'permit' +# set policy route-map test3 rule 1 match metric '1' +# set policy route-map test3 rule 1 match peer '192.0.2.32' +# set policy route-map test3 rule 1 match rpki 'invalid' +# set policy route-map test3 rule 1 set community 'internet' +# set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' +# set policy route-map test3 rule 1 set local-preference '4' +# set policy route-map test3 rule 1 set metric '5' +# set policy route-map test3 rule 1 set metric-type 'type-1' +# set policy route-map test3 rule 1 set origin 'egp' +# set policy route-map test3 rule 1 set originator-id '192.0.2.34' +# set policy route-map test3 rule 1 set tag '5' +# set policy route-map test3 rule 1 set weight '4' +# +# - name: Override the existing configuration with the provided running configuration +# register: result +# vyos.vyos.vyos_route_maps: &id001 +# config: +# - route_map: test3 +# entries: +# - rule_number: 1 +# action: permit +# match: +# rpki: invalid +# metric: 3 +# peer: 192.0.2.35 +# set: +# local_preference: 6 +# metric: 4 +# metric_type: "type-1" +# origin: egp +# originator_id: 192.0.2.34 +# tag: 4 +# weight: 4 +# state: overridden +# After state: + +# vyos@vyos:~$ show configuration commands | match "set policy route-map" +# set policy route-map test3 rule 1 set metric-type 'type-1' +# set policy route-map test3 rule 1 set origin 'egp' +# set policy route-map test3 rule 1 set originator-id '192.0.2.34' +# set policy route-map test3 rule 1 set weight '4' +# set policy route-map test3 rule 1 set local-preference 6 +# set policy route-map test3 rule 1 set metric 4 +# set policy route-map test3 rule 1 set tag 4 +# set policy route-map test3 rule 1 match metric 3 +# set policy route-map test3 rule 1 match peer 192.0.2.35 +# set policy route-map test3 rule 1 match rpki 'invalid' + +# Module Execution: +# "after": [ +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 3, +# "peer": "192.0.2.35", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "local_preference": "6", +# "metric": "4", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "4", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "before": [ +# { +# "entries": [ +# { +# "action": "permit", +# "description": "test", +# "on_match": { +# "next": true +# }, +# "rule_number": 1 +# }, +# { +# "action": "permit", +# "on_match": { +# "goto": 4 +# }, +# "rule_number": 2 +# } +# ], +# "route_map": "test2" +# }, +# { +# "entries": [ +# { +# "action": "permit", +# "match": { +# "metric": 1, +# "peer": "192.0.2.32", +# "rpki": "invalid" +# }, +# "rule_number": 1, +# "set": { +# "community": { +# "value": "internet" +# }, +# "ip_next_hop": "192.0.2.33", +# "local_preference": "4", +# "metric": "5", +# "metric_type": "type-1", +# "origin": "egp", +# "originator_id": "192.0.2.34", +# "tag": "5", +# "weight": "4" +# } +# } +# ], +# "route_map": "test3" +# } +# ], +# "changed": true, +# "commands": [ +# "delete policy route-map test2", +# "delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33", +# "set policy route-map test3 rule 1 set local-preference 6", +# "set policy route-map test3 rule 1 set metric 4", +# "set policy route-map test3 rule 1 set tag 4", +# "delete policy route-map test3 rule 1 set community internet", +# "set policy route-map test3 rule 1 match metric 3", +# "set policy route-map test3 rule 1 match peer 192.0.2.35" +# ], +# + """ from ansible.module_utils.basic import AnsibleModule diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg index f1a53ca9..43ecbec5 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg @@ -12,5 +12,4 @@ set policy route-map test3 rule 1 set tag 5 set policy route-map test3 rule 1 set weight 4 set policy route-map test3 rule 1 match metric 1 set policy route-map test3 rule 1 match peer 192.0.2.32 -set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f set policy route-map test3 rule 1 match rpki invalid \ No newline at end of file diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml index 4aa20aac..cb29bdc8 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml @@ -8,12 +8,10 @@ - set policy route-map test2 rule 2 action 'permit' - set policy route-map test2 rule 2 on-match goto '4' - set policy route-map test3 rule 1 action 'permit' - - set policy route-map test3 rule 1 match ipv6 nexthop 'fdda:5cc1:23:4::1f' - set policy route-map test3 rule 1 match metric '1' - set policy route-map test3 rule 1 match peer '192.0.2.32' - set policy route-map test3 rule 1 match rpki 'invalid' - set policy route-map test3 rule 1 set community 'internet' - - set policy route-map test3 rule 1 set ipv6-next-hop global 'fdda:5cc1:23:4::1f' - set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' - set policy route-map test3 rule 1 set local-preference '4' - set policy route-map test3 rule 1 set metric '5' diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index 3b0a2008..41e5a4f5 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -27,8 +27,6 @@ rpki: invalid metric: 1 peer: 192.0.2.32 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 4 metric: 5 @@ -45,7 +43,7 @@ - assert: that: - - result.commands|length == 16 + - result.commands|length == 15 - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml index 01e153f7..b62b4d29 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -21,8 +21,6 @@ rpki: invalid metric: 3 peer: 192.0.2.35 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 6 metric: 4 @@ -39,7 +37,7 @@ - assert: that: - - result.commands|length == 9 + - result.commands|length == 8 - result.changed == true - result.commands|symmetric_difference(overridden.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml index 1f09fbea..dfec6c72 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -27,8 +27,6 @@ rpki: invalid metric: 1 peer: 192.0.2.32 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 4 metric: 5 diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml index f66cf818..1a21fcfe 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml @@ -21,8 +21,6 @@ rpki: invalid metric: 3 peer: 192.0.2.35 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 6 metric: 4 @@ -39,7 +37,7 @@ - assert: that: - - result.commands|length == 8 + - result.commands|length == 7 - result.changed == true - result.commands|symmetric_difference(replaced.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index d043c69d..af24da76 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -15,7 +15,6 @@ merged: - set policy route-map test3 rule 1 set weight 4 - set policy route-map test3 rule 1 match metric 1 - set policy route-map test3 rule 1 match peer 192.0.2.32 - - set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f - set policy route-map test3 rule 1 match rpki invalid after: @@ -27,8 +26,6 @@ merged: rpki: "invalid" metric: 1 peer: "192.0.2.32" - ipv6: - next_hop: "fdda:5cc1:23:4::1f" set: local_preference: "4" metric: "5" @@ -49,7 +46,6 @@ merged: replaced: commands: - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 - - delete policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f - set policy route-map test3 rule 1 set local-preference 6 - set policy route-map test3 rule 1 set metric 4 - set policy route-map test3 rule 1 set tag 4 @@ -77,8 +73,6 @@ replaced: rpki: invalid metric: 3 peer: 192.0.2.35 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 6 metric: 4 @@ -93,7 +87,6 @@ overridden: commands: - delete policy route-map test2 - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 - - delete policy route-map test3 rule 1 set ipv6-next-hop global fdda:5cc1:23:4::1f - set policy route-map test3 rule 1 set local-preference 6 - set policy route-map test3 rule 1 set metric 4 - set policy route-map test3 rule 1 set tag 4 @@ -111,8 +104,6 @@ overridden: rpki: invalid metric: 3 peer: 192.0.2.35 - ipv6: - next_hop: fdda:5cc1:23:4::1f set: local_preference: 6 metric: 4 @@ -129,22 +120,3 @@ deleted: - delete policy route-map test3 after: [] -rendered: - commands: - - set policy route-map test1 rule 1 description test - - set policy route-map test1 rule 1 action permit - - set policy route-map test1 rule 1 continue 2 - - set policy route-map test1 rule 1 on-match next - - set policy route-map test3 rule 1 action permit - - set policy route-map test3 rule 1 set local-preference 4 - - set policy route-map test3 rule 1 set metric 5 - - set policy route-map test3 rule 1 set metric-type type-1 - - set policy route-map test3 rule 1 set origin egp - - set policy route-map test3 rule 1 set originator-id 192.0.2.34 - - set policy route-map test3 rule 1 set tag 5 - - set policy route-map test3 rule 1 set weight 4 - - set policy route-map test3 rule 1 match metric 1 - - set policy route-map test3 rule 1 match peer 192.0.2.32 - - set policy route-map test3 rule 1 match ipv6 nexthop fdda:5cc1:23:4::1f - - set policy route-map test3 rule 1 match rpki invalid - From ffe2c21f68ce559644359c308e35acda9f738857 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Fri, 7 May 2021 18:31:35 +0530 Subject: [PATCH 11/23] Address review comments --- .../vyos/argspec/route_maps/route_maps.py | 15 +- .../vyos/config/route_maps/route_maps.py | 4 +- .../network/vyos/rm_templates/route_maps.py | 361 +++++++++--------- plugins/modules/vyos_route_maps.py | 66 ++-- tests/integration/network-integration.cfg | 10 +- .../vyos_route_maps/tests/cli/merged.yaml | 6 +- .../vyos_route_maps/tests/cli/overridden.yaml | 2 +- .../vyos_route_maps/tests/cli/rendered.yaml | 6 +- .../vyos_route_maps/tests/cli/replaced.yaml | 2 +- .../targets/vyos_route_maps/vars/main.yaml | 14 +- tests/integration/test-inventory | 38 -- .../network/vyos/test_vyos_route_maps.py | 40 +- 12 files changed, 255 insertions(+), 309 deletions(-) delete mode 100644 tests/integration/test-inventory diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 649d43d2..c7e937cb 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -44,14 +44,11 @@ def __init__(self, **kwargs): "type": "list", "elements": "dict", "options": { - "rule_number": {"type": "int"}, + "sequence": {"type": "int"}, "call": {"type": "str"}, "description": {"type": "str"}, - "action": { - "type": "str", - "choices": ["deny", "permit"], - }, - "continue": {"type": "int"}, + "action": {"type": "str", "choices": ["deny", "permit"]}, + "continue_sequence": {"type": "int"}, "set": { "type": "dict", "options": { @@ -194,11 +191,7 @@ def __init__(self, **kwargs): "peer": {"type": "str"}, "rpki": { "type": "str", - "choices": [ - "notfound", - "invalid", - "valid", - ], + "choices": ["notfound", "invalid", "valid"], }, }, }, diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index 55cc7f5c..d0524fec 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -50,7 +50,7 @@ def __init__(self, module): "call", "description", "action", - "continue", + "continue_sequence", "set_aggregator_ip", "set_aggregator_as", "set_as_path_exclude", @@ -159,7 +159,7 @@ def _route_maps_list_to_dict(self, entry): for x in data["entries"]: x.update({"route_map": rmap}) data["entries"] = { - (rmap, entry.get("rule_number")): entry + (rmap, entry.get("sequence")): entry for entry in data["entries"] } # import epdb;epdb.serve() diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index 13faec72..f2fabfcc 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -39,7 +39,6 @@ def __init__(self, lines=None): ), "compval": "route_map", "setval": "policy route-map {{route_map}}", - "remval": "policy route-map {{route_map}}", "result": { "route_maps": { "{{ route_map }}": { @@ -49,23 +48,23 @@ def __init__(self, lines=None): }, }, { - "name": "rule_number", + "name": "sequence", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+) *$""", re.VERBOSE, ), - "compval": "rule_number", - "setval": "policy route-map {{route_map}} rule {{rule_number}}", + "compval": "sequence", + "setval": "policy route-map {{route_map}} rule {{sequence}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}" + "sequence": "{{sequence}}" } } } @@ -76,19 +75,19 @@ def __init__(self, lines=None): "name": "call", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scall\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scall\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map}} rule {{rule_number}} call {{call}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} call {{call}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "call": "{{call}}" } } @@ -100,19 +99,19 @@ def __init__(self, lines=None): "name": "description", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sdescription\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sdescription\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map}} rule {{rule_number}} description {{description}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} description {{description}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "description": "{{description}}" } } @@ -124,19 +123,19 @@ def __init__(self, lines=None): "name": "action", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\saction\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\saction\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map}} rule {{rule_number}} action {{action}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} action {{action}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "action": "{{action}}" } } @@ -145,23 +144,23 @@ def __init__(self, lines=None): } }, { - "name": "continue", + "name": "continue_sequence", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scontinue\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\scontinue\s(?P\S+) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map}} rule {{rule_number}} continue {{continue}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} continue {{continue_sequence}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", - "continue": "{{continue}}" + "sequence": "{{sequence}}", + "continue_sequence": "{{continue}}" } } } @@ -172,20 +171,20 @@ def __init__(self, lines=None): "name": "on_match_next", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\snext(?P) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\snext(?P) *$""", re.VERBOSE, ), "compval": "on_match.next", - "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match next", + "setval": "policy route-map {{route_map}} rule {{sequence}} on-match next", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "on_match": { "next": "{{True if next is defined}}" } @@ -199,20 +198,20 @@ def __init__(self, lines=None): "name": "on_match_goto", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\sgoto\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\sgoto\s(?P\S+) *$""", re.VERBOSE, ), "compval": "on_match.goto", - "setval": "policy route-map {{route_map}} rule {{rule_number}} on-match goto {{on_match.goto}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} on-match goto {{on_match.goto}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "on_match": { "goto": "{{goto}}" } @@ -226,20 +225,20 @@ def __init__(self, lines=None): "name": "set_aggregator_ip", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sip\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sip\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.aggregator.ip", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator ip {{set.aggregator.ip}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} set aggregator ip {{set.aggregator.ip}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "aggregator": { "ip": "{{ip}}" @@ -255,20 +254,20 @@ def __init__(self, lines=None): "name": "set_aggregator_as", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sas\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\saggregator\sas\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.aggregator.as", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set aggregator as {{set.aggregator.as}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} set aggregator as {{set.aggregator.as}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "aggregator": { "as": "{{as}}" @@ -284,20 +283,20 @@ def __init__(self, lines=None): "name": "set_as_path_exclude", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-exclude\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-exclude\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.as_path_exclude", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-exclude {{set.as_path_exclude}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} set as-path-exclude {{set.as_path_exclude}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "as_path_exclude": "{{as}}" } @@ -311,20 +310,20 @@ def __init__(self, lines=None): "name": "set_as_path_prepend", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-prepend\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sas-path-prepend\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.as_path_prepend", - "setval": "policy route-map {{route_map}} rule {{rule_number}} set as-path-prepend {{set.as_path_prepend}}", + "setval": "policy route-map {{route_map}} rule {{sequence}} set as-path-prepend {{set.as_path_prepend}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "as_path_prepend": "{{as}}" } @@ -338,19 +337,19 @@ def __init__(self, lines=None): "name": "set_atomic_aggregate", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\satomic-aggregate(?P) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\satomic-aggregate(?P) *$""", re.VERBOSE, ), - "setval": "policy route-map {{route_map}} rule {{rule_number}} set atomic-aggregate", + "setval": "policy route-map {{route_map}} rule {{sequence}} set atomic-aggregate", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "atomic_aggregate": "{{True if as is defined}}" } @@ -364,21 +363,21 @@ def __init__(self, lines=None): "name": "set_bgp_extcommunity_rt", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sbgp-extcommunity-rt\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sbgp-extcommunity-rt\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.bgp_extcommunity_rt", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set bgp-extcommunity-rt {{set.bgp_extcommunity_rt}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "bgp_extcommunity_rt": "{{bgp}}" } @@ -392,21 +391,21 @@ def __init__(self, lines=None): "name": "set_comm_list", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\scomm-list\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\scomm-list\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.comm_list.comm_list", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set comm-list comm-list {{set.comm_list.comm_list}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "comm_list": {"comm_list": "{{comm_list}}"} } @@ -420,21 +419,21 @@ def __init__(self, lines=None): "name": "set_comm_list_delete", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\sdelete(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scomm-list\sdelete(?P\S+) *$""", re.VERBOSE, ), "compval": "set.comm_list.comm_list", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set comm-list delete", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "comm_list": {"delete": "{{True if delete is defined}}"} } @@ -448,21 +447,21 @@ def __init__(self, lines=None): "name": "set_extcommunity_rt", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-rt\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-rt\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.extcommunity_rt", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set extcommunity-rt {{set.extcommunity_rt}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "extcommunity_rt": "{{extcommunity_rt}}" } @@ -476,21 +475,21 @@ def __init__(self, lines=None): "name": "set_extcommunity_soo", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-soo\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sextcommunity-soo\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.extcommunity_soo", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set extcommunity-soo {{set.extcommunity_soo}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "extcommunity_soo": "{{set.extcommunity_soo}}" } @@ -504,21 +503,21 @@ def __init__(self, lines=None): "name": "set_ip_next_hop", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sip-next-hop\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sip-next-hop\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.ip_next_hop", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set ip-next-hop {{set.ip_next_hop}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "ip_next_hop": "{{ip_next_hop}}" } @@ -532,23 +531,23 @@ def __init__(self, lines=None): "name": "set_ipv6_next_hop", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sipv6-next-hop + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sipv6-next-hop \s(?Pglobal|local) \s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.ipv6_next_hop", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set ipv6-next-hop {{set.ipv6_next_hop.ip_type}} {{set.ipv6_next_hop.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "ipv6_next_hop": { "ip_type": "{{type}}", @@ -565,21 +564,21 @@ def __init__(self, lines=None): "name": "set_large_community", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slarge-community\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slarge-community\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.large_community", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set large-community {{set.large_community}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "large_community": "{{large_community}}" } @@ -593,21 +592,21 @@ def __init__(self, lines=None): "name": "set_local_preference", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slocal-preference\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\slocal-preference\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.local_preference", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set local-preference {{set.local_preference}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "local_preference": "{{local_preference}}" } @@ -621,21 +620,21 @@ def __init__(self, lines=None): "name": "set_metric", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.metric", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set metric {{set.metric}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "metric": "{{metric}}" } @@ -649,21 +648,21 @@ def __init__(self, lines=None): "name": "set_metric_type", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric-type\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\smetric-type\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.metric_type", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set metric-type {{set.metric_type}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "metric_type": "{{metric_type}}" } @@ -677,21 +676,21 @@ def __init__(self, lines=None): "name": "set_origin", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sorigin\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sorigin\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.origin", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set origin {{set.origin}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "origin": "{{origin}}" } @@ -705,21 +704,21 @@ def __init__(self, lines=None): "name": "set_originator_id", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\soriginator-id\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\soriginator-id\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.originator_id", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set originator-id {{set.originator_id}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "originator_id": "{{originator_id}}" } @@ -733,21 +732,21 @@ def __init__(self, lines=None): "name": "set_src", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\ssrc\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\ssrc\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.src", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set src {{set.src}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "src": "{{src}}" } @@ -761,21 +760,21 @@ def __init__(self, lines=None): "name": "set_tag", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\stag\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\stag\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.tag", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set tag {{set.tag}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "tag": "{{tag}}" } @@ -789,21 +788,21 @@ def __init__(self, lines=None): "name": "set_weight", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sweight\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\sweight\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.weight", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set weight {{set.weight}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "weight": "{{weight}}" } @@ -817,21 +816,21 @@ def __init__(self, lines=None): "name": "set_community", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scommunity\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\sset\scommunity\s(?P\S+) *$""", re.VERBOSE, ), "compval": "set.community.value", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "set community {{set.community.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "set": { "community": { "value": "{{value}}", @@ -847,21 +846,21 @@ def __init__(self, lines=None): "name": "match_as_path", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sas-path\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sas-path\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.as_path", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match as-path {{match.as_path}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "as_path": "{{as_path}}" } @@ -875,21 +874,21 @@ def __init__(self, lines=None): "name": "match_community_community_list", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\scommunity-list\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\scommunity-list\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.community.community_list", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match community community-list {{match.community.community_list}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "community": {"community_list": "{{community_list}}"} } @@ -903,21 +902,21 @@ def __init__(self, lines=None): "name": "match_community_exact_match", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\sexact-match(?P) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\scommunity\sexact-match(?P) *$""", re.VERBOSE, ), "compval": "match.community.exact_match", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match community exact-match", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "community": {"exact_match": "{{True if exact_match is defined}}"} } @@ -931,21 +930,21 @@ def __init__(self, lines=None): "name": "match_extcommunity", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sextcommunity\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sextcommunity\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.extcommunity", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match extcommunity {{match.extcommunity}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "extcommunity": "{{extcommunity}}" } @@ -959,21 +958,21 @@ def __init__(self, lines=None): "name": "match_interface", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sinterface\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sinterface\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.interface", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match interface {{match.interface}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "interface": "{{interface}}" } @@ -987,21 +986,21 @@ def __init__(self, lines=None): "name": "match_large_community_large_community_list", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\slarge-community\slarge-community-list\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\slarge-community\slarge-community-list\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.large_community_large_community_list", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match large-community large-community-list {{match.large_community_large_community_list}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "large_community_large_community_list": "{{lc}}" } @@ -1015,21 +1014,21 @@ def __init__(self, lines=None): "name": "match_metric", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\smetric\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\smetric\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.metric", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match metric {{match.metric}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "metric": "{{metric}}" } @@ -1043,21 +1042,21 @@ def __init__(self, lines=None): "name": "match_origin", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sorigin\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sorigin\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.origin", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match origin {{match.origin}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "origin": "{{origin}}" } @@ -1071,21 +1070,21 @@ def __init__(self, lines=None): "name": "match_peer", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\speer\s(?P\S+) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\speer\s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.peer", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match peer {{match.peer}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": + "{{sequence}}": { - "rule_number": "{{rule_number}}", + "sequence": "{{sequence}}", "match": { "peer": "{{peer}}" } @@ -1099,22 +1098,22 @@ def __init__(self, lines=None): "name": "match_ip_address", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\saddress + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\saddress \s(?Paccess-list|prefix-list) \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.ip.address", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match ip address {{match.ip.address.list_type}} {{match.ip.address.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "ip": { "address": { @@ -1133,22 +1132,22 @@ def __init__(self, lines=None): "name": "match_ip_next_hop", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\snexthop + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\snexthop \s(?Paccess-list|prefix-list) \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.ip.next_hop", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match ip nexthop {{match.ip.next_hop.list_type}} {{match.ip.next_hop.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "ip": { "next_hop": { @@ -1167,22 +1166,22 @@ def __init__(self, lines=None): "name": "match_ip_route_source", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\sroute-source + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sip\sroute-source \s(?Paccess-list|prefix-list) \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.ip.route_source", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match ip route-source {{match.ip.route_source.list_type}} {{match.ip.route_source.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "ip": { "route_source": { @@ -1201,22 +1200,22 @@ def __init__(self, lines=None): "name": "match_ipv6_address", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\saddress + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\saddress \s(?Paccess-list|prefix-list) \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.ipv6.address", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match ipv6 address {{match.ipv6.address.list_type}} {{match.ipv6.address.value}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "ipv6": { "address": { @@ -1235,21 +1234,21 @@ def __init__(self, lines=None): "name": "match_ipv6_nexthop", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\snexthop + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\sipv6\snexthop \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.ipv6.next_hop", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match ipv6 nexthop {{match.ipv6.next_hop}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "ipv6": { "next_hop": "{{value}}" @@ -1265,21 +1264,21 @@ def __init__(self, lines=None): "name": "match_rpki", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\srpki + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\smatch\srpki \s(?P\S+) *$""", re.VERBOSE, ), "compval": "match.rpki", - "setval": "policy route-map {{route_map}} rule {{rule_number}} " + "setval": "policy route-map {{route_map}} rule {{sequence}} " "match rpki {{match.rpki}}", "result": { "route_maps": { "{{ route_map }}": { "route_map": '{{ route_map }}', "entries": { - "{{rule_number}}": { - "rule_number": "{{rule_number}}", + "{{sequence}}": { + "sequence": "{{sequence}}", "match": { "rpki": "{{value}}" } diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index d8629eb1..b642cce3 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -33,13 +33,13 @@ type: str entries: description: Route Map rules. - aliases: ["rules"] + aliases: rules type: list elements: dict suboptions: - rule_number: + sequence: type: int - description: Route-map rule number + description: Route map rule number <1-65535>. call: description: Route map name type: str @@ -50,8 +50,8 @@ description: Action for matching routes type: str choices: ["deny", "permit"] - continue: - description: Route map rule number <1-65535>. + continue_sequence: + description: Continue on a different entry within the route-map. type: int set: description: Route parameters. @@ -270,7 +270,7 @@ config: - route_map: test1 entries: - - rule_number: 1 + - sequence: 1 description: "test" action: permit continue: 2 @@ -278,7 +278,7 @@ next: True - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid @@ -316,12 +316,12 @@ # "entries": [ # { # "action": "permit", -# "continue": 2, +# "continue_sequence": 2, # "description": "test", # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # } # ], # "route_map": "test1" @@ -335,7 +335,7 @@ # "peer": "192.0.2.32", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "4", # "metric": "5", @@ -400,7 +400,7 @@ # config: # - route_map: test3 # entries: -# - rule_number: 1 +# - sequence: 1 # action: permit # match: # rpki: invalid @@ -437,14 +437,14 @@ # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # }, # { # "action": "permit", # "on_match": { # "goto": 4 # }, -# "rule_number": 2 +# "sequence": 2 # } # ], # "route_map": "test2" @@ -458,7 +458,7 @@ # "peer": "192.0.2.35", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "6", # "metric": "4", @@ -482,14 +482,14 @@ # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # }, # { # "action": "permit", # "on_match": { # "goto": 4 # }, -# "rule_number": 2 +# "sequence": 2 # } # ], # "route_map": "test2" @@ -503,7 +503,7 @@ # "peer": "192.0.2.32", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "community": { # "value": "internet" @@ -568,7 +568,7 @@ # "metric": 3, # "peer": "192.0.2.35", # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "6", # "metric": "4", @@ -608,18 +608,18 @@ # - name: gather configs # vyos.vyos.vyos_route_maps: # state: gathered - + # "gathered": [ # { # "entries": [ # { # "action": "permit", -# "continue": 2, +# "continue_sequence": 2, # "description": "test", # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # } # ], # "route_map": "test1" @@ -633,7 +633,7 @@ # "peer": "192.0.2.32", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "4", # "metric": "5", @@ -682,12 +682,12 @@ # "entries": [ # { # "action": "permit", -# "continue": 2, +# "continue_sequence": 2, # "description": "test", # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # } # ], # "route_map": "test1" @@ -701,7 +701,7 @@ # "peer": "192.0.2.32", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "4", # "metric": "5", @@ -726,15 +726,15 @@ # config: # - route_map: test1 # entries: -# - rule_number: 1 +# - sequence: 1 # description: "test" # action: permit -# continue: 2 +# continue_sequence: 2 # on_match: # next: True # - route_map: test3 # entries: -# - rule_number: 1 +# - sequence: 1 # action: permit # match: # rpki: invalid @@ -798,7 +798,7 @@ # config: # - route_map: test3 # entries: -# - rule_number: 1 +# - sequence: 1 # action: permit # match: # rpki: invalid @@ -838,7 +838,7 @@ # "peer": "192.0.2.35", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "local_preference": "6", # "metric": "4", @@ -862,14 +862,14 @@ # "on_match": { # "next": true # }, -# "rule_number": 1 +# "sequence": 1 # }, # { # "action": "permit", # "on_match": { # "goto": 4 # }, -# "rule_number": 2 +# "sequence": 2 # } # ], # "route_map": "test2" @@ -883,7 +883,7 @@ # "peer": "192.0.2.32", # "rpki": "invalid" # }, -# "rule_number": 1, +# "sequence": 1, # "set": { # "community": { # "value": "internet" diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg index 41209074..18ae1283 100644 --- a/tests/integration/network-integration.cfg +++ b/tests/integration/network-integration.cfg @@ -1,12 +1,4 @@ [persistent_connection] command_timeout = 100 connect_timeout = 100 -connect_retry_timeout = 100 - - -[paramiko_connection] -look_for_keys = False - -[defaults] -gathering=no -interpreter_python=/Users/amhatre/ansible_venvs/py3.6.10/bin/python +connect_retry_timeout = 100 \ No newline at end of file diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index 41e5a4f5..999e7b88 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -13,15 +13,15 @@ config: - route_map: test1 entries: - - rule_number: 1 + - sequence: 1 description: "test" action: permit - continue: 2 + continue_sequence: 2 on_match: next: True - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml index b62b4d29..b5ddf86e 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -15,7 +15,7 @@ config: - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml index dfec6c72..d7648a13 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -13,15 +13,15 @@ config: - route_map: test1 entries: - - rule_number: 1 + - sequence: 1 description: "test" action: permit - continue: 2 + continue_sequence: 2 on_match: next: True - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml index 1a21fcfe..2f3d8d19 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml @@ -15,7 +15,7 @@ config: - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index af24da76..8f1b2437 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -20,7 +20,7 @@ merged: after: - route_map: "test3" entries: - - rule_number: 1 + - sequence: 1 action: "permit" match: rpki: "invalid" @@ -36,10 +36,10 @@ merged: weight: "4" - route_map: "test1" entries: - - rule_number: 1 + - sequence: 1 description: "test" action: "permit" - continue: 2 + continue_sequence: 2 on_match: next: true @@ -56,18 +56,18 @@ replaced: after: - route_map: test2 entries: - - rule_number: 1 + - sequence: 1 description: "test" action: permit on_match: next: True - - rule_number: 1 + - sequence: 1 action: permit on_match: goto: 4 - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid @@ -98,7 +98,7 @@ overridden: after: - route_map: test3 entries: - - rule_number: 1 + - sequence: 1 action: permit match: rpki: invalid diff --git a/tests/integration/test-inventory b/tests/integration/test-inventory deleted file mode 100644 index d202a177..00000000 --- a/tests/integration/test-inventory +++ /dev/null @@ -1,38 +0,0 @@ -[vyos] -127.0.0.1 - -[vyos:vars] -ansible_network_os=vyos.vyos.vyos -ansible_ssh_port=2222 -ansible_user=vyos -ansible_ssh_pass=vyos -ansible_connection=ansible.netcommon.network_cli -ansible_become=true -#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa -ansible_become_method=ansible.netcommon.enable -cli={'transport': 'cli'} -netconf={'transport': 'netconf'} - -[netconf] -iosxr-7.0.2 ansible_port=22 ansible_host=127.0.0.1 ansible_user=vagrant - - -[netconf:vars] -#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa -ansible_become_method=ansible.netcommon.enable -ansible_network_os=cisco.iosxr.iosxr -ansible_ssh_pass=vagrant -cli={'transport': 'cli'} -debug=False -netconf={'transport': 'netconf'} - -#[iosxr:vars:network_cli] -#host=10.8.38.70 -#username=ansible -#password=ansible -#transport=netcon -#[iosxr:vars] -#ansible_network_os=cisco.iosxr.iosxr -#ansible_ssh_username=ansible -#ansible_ssh_password=ansible -#ansible_connection=ansible.netcommon.netconf diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index 57d09d86..827ade2e 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -79,7 +79,7 @@ def test_vyos_route_maps_merged_idempotent(self): route_map="test3", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict( rpki="invalid", @@ -112,13 +112,13 @@ def test_vyos_route_maps_merged_idempotent(self): route_map="test1", entries=[ dict( - rule_number=1, + sequence=1, action="permit", description="test", on_match=dict(next=True), ), dict( - rule_number=2, + sequence=2, action="permit", on_match=dict(goto=4), ), @@ -138,7 +138,7 @@ def test_route_maps_merged(self): route_map="test2", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict( rpki="invalid", @@ -204,7 +204,7 @@ def test_route_maps_replaced(self): route_map="test3", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict( rpki="invalid", @@ -237,13 +237,13 @@ def test_route_maps_replaced(self): route_map="test1", entries=[ dict( - rule_number=1, + sequence=1, action="permit", description="test", on_match=dict(next=True), ), dict( - rule_number=2, + sequence=2, action="permit", description="test", on_match=dict(goto=4), @@ -274,7 +274,7 @@ def test_vyos_route_maps_replaced_idempotent(self): route_map="test3", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict( rpki="invalid", @@ -307,13 +307,13 @@ def test_vyos_route_maps_replaced_idempotent(self): route_map="test1", entries=[ dict( - rule_number=1, + sequence=1, action="permit", description="test", on_match=dict(next=True), ), dict( - rule_number=2, + sequence=2, action="permit", on_match=dict(goto=4), ), @@ -333,7 +333,7 @@ def test_route_maps_overridden(self): route_map="test2", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict(rpki="invalid", peer="1.1.1.3"), set=dict( @@ -391,7 +391,7 @@ def test_vyos_route_maps_rendered(self): route_map="test3", entries=[ dict( - rule_number=1, + sequence=1, action="permit", match=dict( rpki="invalid", @@ -424,13 +424,13 @@ def test_vyos_route_maps_rendered(self): route_map="test1", entries=[ dict( - rule_number=1, + sequence=1, action="permit", description="test", on_match=dict(next=True), ), dict( - rule_number=2, + sequence=2, action="permit", on_match=dict(goto=4), ), @@ -497,12 +497,12 @@ def test_vyos_bgp_global_parsed(self): "action": "permit", "description": "test", "on_match": {"next": True}, - "rule_number": 1, + "sequence": 1, }, { "action": "permit", "on_match": {"goto": 4}, - "rule_number": 2, + "sequence": 2, }, ], "route_map": "test1", @@ -518,7 +518,7 @@ def test_vyos_bgp_global_parsed(self): "peer": "1.1.1.2", "rpki": "invalid", }, - "rule_number": 1, + "sequence": 1, "set": { "bgp_extcommunity_rt": "22:11", "community": {"value": "internet"}, @@ -553,12 +553,12 @@ def test_vyos_bgp_global_gathered(self): "action": "permit", "description": "test", "on_match": {"next": True}, - "rule_number": 1, + "sequence": 1, }, { "action": "permit", "on_match": {"goto": 4}, - "rule_number": 2, + "sequence": 2, }, ], "route_map": "test1", @@ -574,7 +574,7 @@ def test_vyos_bgp_global_gathered(self): "peer": "1.1.1.2", "rpki": "invalid", }, - "rule_number": 1, + "sequence": 1, "set": { "bgp_extcommunity_rt": "22:11", "community": {"value": "internet"}, From 6e727d2c7158591e2a55c9882d580134ea87c44f Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Fri, 7 May 2021 18:42:41 +0530 Subject: [PATCH 12/23] fix linters --- .../network/vyos/argspec/route_maps/route_maps.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index c7e937cb..790f5e61 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -47,7 +47,10 @@ def __init__(self, **kwargs): "sequence": {"type": "int"}, "call": {"type": "str"}, "description": {"type": "str"}, - "action": {"type": "str", "choices": ["deny", "permit"]}, + "action": { + "type": "str", + "choices": ["deny", "permit"], + }, "continue_sequence": {"type": "int"}, "set": { "type": "dict", @@ -191,7 +194,11 @@ def __init__(self, **kwargs): "peer": {"type": "str"}, "rpki": { "type": "str", - "choices": ["notfound", "invalid", "valid"], + "choices": [ + "notfound", + "invalid", + "valid", + ], }, }, }, From bd8cae26ddefe705a694ff7001577c8e2d30cc8f Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Fri, 7 May 2021 19:02:06 +0530 Subject: [PATCH 13/23] Remove unwanted lines --- .../network/vyos/config/route_maps/route_maps.py | 6 ------ tests/integration/network-integration.cfg | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py index d0524fec..5e4bbea9 100644 --- a/plugins/module_utils/network/vyos/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/config/route_maps/route_maps.py @@ -123,7 +123,6 @@ def generate_commands(self): # remove superfluous config for overridden and deleted if self.state in ["overridden", "deleted"]: - # import epdb;epdb.serve() for k, have in iteritems(haved): if k not in wantd: self.commands.append( @@ -148,10 +147,6 @@ def _compare_entries(self, want, have): hentry = have.pop(wk, {}) self.compare(parsers=self.parsers, want=wentry, have=hentry) - # remove superfluos entries from have - # for _hk, hentry in iteritems(have): - # self.commands.append(self._tmplt.render(hentry, "route_map", True)) - def _route_maps_list_to_dict(self, entry): entry = {x["route_map"]: x for x in entry} for rmap, data in iteritems(entry): @@ -162,5 +157,4 @@ def _route_maps_list_to_dict(self, entry): (rmap, entry.get("sequence")): entry for entry in data["entries"] } - # import epdb;epdb.serve() return entry diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg index 18ae1283..d12c1efe 100644 --- a/tests/integration/network-integration.cfg +++ b/tests/integration/network-integration.cfg @@ -1,4 +1,4 @@ [persistent_connection] command_timeout = 100 connect_timeout = 100 -connect_retry_timeout = 100 \ No newline at end of file +connect_retry_timeout = 100 From a9ae97a529f21aa2c95fe4eca0d0d7a7a6eb59c6 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 11:42:47 +0530 Subject: [PATCH 14/23] fix tests --- plugins/modules/vyos_route_maps.py | 8 ++++---- .../targets/vyos_route_maps/tests/cli/_parsed.cfg | 3 +-- .../targets/vyos_route_maps/tests/cli/_populate.yaml | 1 - .../targets/vyos_route_maps/tests/cli/merged.yaml | 1 - .../targets/vyos_route_maps/tests/cli/overridden.yaml | 1 - .../targets/vyos_route_maps/tests/cli/rendered.yaml | 1 - .../targets/vyos_route_maps/tests/cli/replaced.yaml | 1 - tests/integration/targets/vyos_route_maps/vars/main.yaml | 6 ------ tests/sanity/ignore-2.12.txt | 6 ++++++ 9 files changed, 11 insertions(+), 17 deletions(-) create mode 100644 tests/sanity/ignore-2.12.txt diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index b642cce3..85f71d54 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -33,7 +33,7 @@ type: str entries: description: Route Map rules. - aliases: rules + aliases: ["rules"] type: list elements: dict suboptions: @@ -604,7 +604,7 @@ # set policy route-map test3 rule 1 match metric 1 # set policy route-map test3 rule 1 match peer 192.0.2.32 # set policy route-map test3 rule 1 match rpki invalid -# +# # - name: gather configs # vyos.vyos.vyos_route_maps: # state: gathered @@ -675,7 +675,7 @@ # state: parsed # tags: # - parsed -# +# # Module execution: # "parsed": [ # { @@ -791,7 +791,7 @@ # set policy route-map test3 rule 1 set originator-id '192.0.2.34' # set policy route-map test3 rule 1 set tag '5' # set policy route-map test3 rule 1 set weight '4' -# +# # - name: Override the existing configuration with the provided running configuration # register: result # vyos.vyos.vyos_route_maps: &id001 diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg index 43ecbec5..9d7f83eb 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg @@ -11,5 +11,4 @@ set policy route-map test3 rule 1 set originator-id 192.0.2.34 set policy route-map test3 rule 1 set tag 5 set policy route-map test3 rule 1 set weight 4 set policy route-map test3 rule 1 match metric 1 -set policy route-map test3 rule 1 match peer 192.0.2.32 -set policy route-map test3 rule 1 match rpki invalid \ No newline at end of file +set policy route-map test3 rule 1 match peer 192.0.2.32 \ No newline at end of file diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml index cb29bdc8..927e5a6d 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml @@ -10,7 +10,6 @@ - set policy route-map test3 rule 1 action 'permit' - set policy route-map test3 rule 1 match metric '1' - set policy route-map test3 rule 1 match peer '192.0.2.32' - - set policy route-map test3 rule 1 match rpki 'invalid' - set policy route-map test3 rule 1 set community 'internet' - set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' - set policy route-map test3 rule 1 set local-preference '4' diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index 999e7b88..52fd6cec 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -24,7 +24,6 @@ - sequence: 1 action: permit match: - rpki: invalid metric: 1 peer: 192.0.2.32 set: diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml index b5ddf86e..f014cf19 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -18,7 +18,6 @@ - sequence: 1 action: permit match: - rpki: invalid metric: 3 peer: 192.0.2.35 set: diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml index d7648a13..cb4c4539 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -24,7 +24,6 @@ - sequence: 1 action: permit match: - rpki: invalid metric: 1 peer: 192.0.2.32 set: diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml index 2f3d8d19..1675ec5b 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml @@ -18,7 +18,6 @@ - sequence: 1 action: permit match: - rpki: invalid metric: 3 peer: 192.0.2.35 set: diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index 8f1b2437..24f7eaba 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -15,7 +15,6 @@ merged: - set policy route-map test3 rule 1 set weight 4 - set policy route-map test3 rule 1 match metric 1 - set policy route-map test3 rule 1 match peer 192.0.2.32 - - set policy route-map test3 rule 1 match rpki invalid after: - route_map: "test3" @@ -23,7 +22,6 @@ merged: - sequence: 1 action: "permit" match: - rpki: "invalid" metric: 1 peer: "192.0.2.32" set: @@ -70,7 +68,6 @@ replaced: - sequence: 1 action: permit match: - rpki: invalid metric: 3 peer: 192.0.2.35 set: @@ -101,7 +98,6 @@ overridden: - sequence: 1 action: permit match: - rpki: invalid metric: 3 peer: 192.0.2.35 set: @@ -113,10 +109,8 @@ overridden: tag: 4 weight: 4 - deleted: commands: - delete policy route-map test2 - delete policy route-map test3 after: [] - diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt new file mode 100644 index 00000000..d9ecb5c8 --- /dev/null +++ b/tests/sanity/ignore-2.12.txt @@ -0,0 +1,6 @@ +plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip +plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip +plugins/modules/vyos_bgp_global.py validate-modules:no-log-needed # temporary workaround for no-log +plugins/modules/vyos_ospf_interfaces.py validate-modules:no-log-needed # temporary workaround for no-log +plugins/modules/vyos_ospfv2.py validate-modules:no-log-needed # temporary workaround for no-log From 626779c96d8c1ad955e9b57f4848c5ec6cbc136b Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 12:53:08 +0530 Subject: [PATCH 15/23] fix sanity --- tests/sanity/ignore-2.10.txt | 2 ++ tests/sanity/ignore-2.11.txt | 2 ++ tests/sanity/ignore-2.12.txt | 2 ++ tests/sanity/ignore-2.9.txt | 2 ++ 4 files changed, 8 insertions(+) diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index a44822bd..eb1bfe4b 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -1,3 +1,5 @@ plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index a44822bd..eb1bfe4b 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -1,3 +1,5 @@ plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 7b5088be..fd067195 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,3 +1,5 @@ plugins/modules/vyos_bgp_global.py validate-modules:no-log-needed # temporary workaround for no-log plugins/modules/vyos_ospf_interfaces.py validate-modules:no-log-needed # temporary workaround for no-log plugins/modules/vyos_ospfv2.py validate-modules:no-log-needed # temporary workaround for no-log +plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 68064bb3..de543fe2 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -13,3 +13,5 @@ plugins/modules/vyos_lldp_interface.py validate-modules:invalid-documentation # plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip +plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip From 73a70600a42b47cde36ad71bf34ed227454fb980 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 12:55:14 +0530 Subject: [PATCH 16/23] fix sanity Please enter the commit message for your changes. Lines starting --- tests/sanity/ignore-2.10.txt | 1 + tests/sanity/ignore-2.11.txt | 1 + tests/sanity/ignore-2.12.txt | 1 + tests/sanity/ignore-2.9.txt | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index eb1bfe4b..69f4063f 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -3,3 +3,4 @@ plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py comp plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip +plugins/modules/vyos_route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index eb1bfe4b..69f4063f 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -3,3 +3,4 @@ plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py comp plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip +plugins/modules/vyos_route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index fd067195..de150425 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -3,3 +3,4 @@ plugins/modules/vyos_ospf_interfaces.py validate-modules:no-log-needed # tempora plugins/modules/vyos_ospfv2.py validate-modules:no-log-needed # temporary workaround for no-log plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip +plugins/modules/vyos_route_maps.py import-2.6!skip diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index de543fe2..7178a200 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -15,3 +15,4 @@ plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py comp plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip +plugins/modules/vyos_route_maps.py import-2.6!skip From 4ccbda7b99c7e472ac980f8e08713d63afd56a20 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 15:31:51 +0530 Subject: [PATCH 17/23] fix sanity --- .../vyos/argspec/route_maps/route_maps.py | 14 ++++------- .../vyos/facts/route_maps/route_maps.py | 1 - plugins/modules/vyos_route_maps.py | 2 +- .../vyos_route_maps/tests/cli/merged.yaml | 2 +- tests/sanity/ignore-2.12.txt | 6 ++--- .../network/vyos/test_vyos_route_maps.py | 24 +++---------------- 6 files changed, 12 insertions(+), 37 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 790f5e61..36ab1fba 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -28,7 +28,8 @@ class Route_mapsArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_route_maps module""" + """The arg spec for the vyos_route_maps module + """ def __init__(self, **kwargs): pass @@ -47,10 +48,7 @@ def __init__(self, **kwargs): "sequence": {"type": "int"}, "call": {"type": "str"}, "description": {"type": "str"}, - "action": { - "type": "str", - "choices": ["deny", "permit"], - }, + "action": {"type": "str", "choices": ["deny", "permit"]}, "continue_sequence": {"type": "int"}, "set": { "type": "dict", @@ -194,11 +192,7 @@ def __init__(self, **kwargs): "peer": {"type": "str"}, "rpki": { "type": "str", - "choices": [ - "notfound", - "invalid", - "valid", - ], + "choices": ["notfound", "invalid", "valid"], }, }, }, diff --git a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py index d1b2a74b..51e8f978 100644 --- a/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/facts/route_maps/route_maps.py @@ -16,7 +16,6 @@ from copy import deepcopy -from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( utils, ) diff --git a/plugins/modules/vyos_route_maps.py b/plugins/modules/vyos_route_maps.py index 85f71d54..bca8383d 100644 --- a/plugins/modules/vyos_route_maps.py +++ b/plugins/modules/vyos_route_maps.py @@ -14,7 +14,7 @@ DOCUMENTATION = """ module: vyos_route_maps -version_added: 2.0.2 +version_added: 2.3.0 short_description: Route Map Resource Module. description: - This module manages route map configurations on devices running VYOS. diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index 52fd6cec..ec9f7498 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -42,7 +42,7 @@ - assert: that: - - result.commands|length == 15 + - result.commands|length == 14 - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index de150425..69f4063f 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,6 +1,6 @@ -plugins/modules/vyos_bgp_global.py validate-modules:no-log-needed # temporary workaround for no-log -plugins/modules/vyos_ospf_interfaces.py validate-modules:no-log-needed # temporary workaround for no-log -plugins/modules/vyos_ospfv2.py validate-modules:no-log-needed # temporary workaround for no-log +plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip +plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip plugins/modules/vyos_route_maps.py import-2.6!skip diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index 827ade2e..76731995 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -472,12 +472,10 @@ def test_vyos_route_maps_rendered(self): result["rendered"], ) - def test_vyos_bgp_global_parsed(self): + def test_yos_route_maps_parsed(self): parsed_str = ( - "set policy route-map test1 rule 1 action 'permit'\nset policy route-map test1 rule 1 description " - "'test'\nset policy route-map test1 rule 1 on-match next\nset policy route-map test1 rule 2 action " - "'permit'\nset policy route-map test1 rule 2 on-match goto '4'\nset policy route-map test3 rule 1 action 'permit'" + "set policy route-map test3 rule 1 action 'permit'" "\nset policy route-map test3 rule 1 match interface 'eth2'\nset policy route-map test3 rule 1 match ipv6 nexthop" " 'fdda:5cc1:23:4::1f'\nset policy route-map test3 rule 1 match metric '1'\nset policy route-map test3 rule 1 match peer " "'1.1.1.2'\nset policy route-map test3 rule 1 match rpki 'invalid'\nset policy route-map test3 rule 1 set bgp-extcommunity-rt " @@ -491,22 +489,6 @@ def test_vyos_bgp_global_parsed(self): set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = [ - { - "entries": [ - { - "action": "permit", - "description": "test", - "on_match": {"next": True}, - "sequence": 1, - }, - { - "action": "permit", - "on_match": {"goto": 4}, - "sequence": 2, - }, - ], - "route_map": "test1", - }, { "entries": [ { @@ -543,7 +525,7 @@ def test_vyos_bgp_global_parsed(self): ] self.assertEqual(parsed_list, result["parsed"]) - def test_vyos_bgp_global_gathered(self): + def test_vyos_route_maps_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) gathered_list = [ From f85307e961473703ca6300bc5ce09c42094b8338 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 17:27:16 +0530 Subject: [PATCH 18/23] fix integration --- plugins/module_utils/network/vyos/rm_templates/route_maps.py | 2 +- .../targets/vyos_route_maps/tests/cli/_parsed.cfg | 1 - .../targets/vyos_route_maps/tests/cli/_populate.yaml | 1 - .../targets/vyos_route_maps/tests/cli/merged.yaml | 4 +--- .../targets/vyos_route_maps/tests/cli/rendered.yaml | 2 -- tests/integration/targets/vyos_route_maps/vars/main.yaml | 5 ----- 6 files changed, 2 insertions(+), 13 deletions(-) diff --git a/plugins/module_utils/network/vyos/rm_templates/route_maps.py b/plugins/module_utils/network/vyos/rm_templates/route_maps.py index f2fabfcc..3ab18b43 100644 --- a/plugins/module_utils/network/vyos/rm_templates/route_maps.py +++ b/plugins/module_utils/network/vyos/rm_templates/route_maps.py @@ -171,7 +171,7 @@ def __init__(self, lines=None): "name": "on_match_next", "getval": re.compile( r""" - ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\snext(?P) + ^set\spolicy\sroute-map\s(?P\S+)\srule\s(?P\d+)\son-match\s(?Pnext) *$""", re.VERBOSE, ), diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg index 9d7f83eb..a4aa4d39 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg @@ -1,7 +1,6 @@ set policy route-map test1 rule 1 description test set policy route-map test1 rule 1 action permit set policy route-map test1 rule 1 continue 2 -set policy route-map test1 rule 1 on-match next set policy route-map test3 rule 1 action permit set policy route-map test3 rule 1 set local-preference 4 set policy route-map test3 rule 1 set metric 5 diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml index 927e5a6d..9ef975f0 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml @@ -4,7 +4,6 @@ lines: - set policy route-map test2 rule 1 action 'permit' - set policy route-map test2 rule 1 description 'test' - - set policy route-map test2 rule 1 on-match next - set policy route-map test2 rule 2 action 'permit' - set policy route-map test2 rule 2 on-match goto '4' - set policy route-map test3 rule 1 action 'permit' diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml index ec9f7498..2b869697 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -17,8 +17,6 @@ description: "test" action: permit continue_sequence: 2 - on_match: - next: True - route_map: test3 entries: - sequence: 1 @@ -42,7 +40,7 @@ - assert: that: - - result.commands|length == 14 + - result.commands|length == 13 - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml index cb4c4539..7d194d98 100644 --- a/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -17,8 +17,6 @@ description: "test" action: permit continue_sequence: 2 - on_match: - next: True - route_map: test3 entries: - sequence: 1 diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index 24f7eaba..291ed14b 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -4,7 +4,6 @@ merged: - set policy route-map test1 rule 1 description test - set policy route-map test1 rule 1 action permit - set policy route-map test1 rule 1 continue 2 - - set policy route-map test1 rule 1 on-match next - set policy route-map test3 rule 1 action permit - set policy route-map test3 rule 1 set local-preference 4 - set policy route-map test3 rule 1 set metric 5 @@ -38,8 +37,6 @@ merged: description: "test" action: "permit" continue_sequence: 2 - on_match: - next: true replaced: commands: @@ -57,8 +54,6 @@ replaced: - sequence: 1 description: "test" action: permit - on_match: - next: True - sequence: 1 action: permit on_match: From b67f44b9cb1da275e30c19d8a7c9d5652daf2560 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 18:16:36 +0530 Subject: [PATCH 19/23] fix linters --- .../network/vyos/argspec/route_maps/route_maps.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 36ab1fba..65eaaa83 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -48,7 +48,10 @@ def __init__(self, **kwargs): "sequence": {"type": "int"}, "call": {"type": "str"}, "description": {"type": "str"}, - "action": {"type": "str", "choices": ["deny", "permit"]}, + "action": { + "type": "str", + "choices": ["deny", "permit"], + }, "continue_sequence": {"type": "int"}, "set": { "type": "dict", @@ -192,7 +195,11 @@ def __init__(self, **kwargs): "peer": {"type": "str"}, "rpki": { "type": "str", - "choices": ["notfound", "invalid", "valid"], + "choices": [ + "notfound", + "invalid", + "valid", + ], }, }, }, From ebeedda6ffd0e124f0be02645f81daf292b78a53 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 19:30:46 +0530 Subject: [PATCH 20/23] fix linters --- .../module_utils/network/vyos/argspec/route_maps/route_maps.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py index 65eaaa83..790f5e61 100644 --- a/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py @@ -28,8 +28,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 - """The arg spec for the vyos_route_maps module - """ + """The arg spec for the vyos_route_maps module""" def __init__(self, **kwargs): pass From f599cb6a68aa9759b80ec8bd1d5380c393a9d1d3 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 20:19:09 +0530 Subject: [PATCH 21/23] fix linters --- .../targets/vyos_route_maps/vars/main.yaml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/integration/targets/vyos_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml index 291ed14b..5a0d0278 100644 --- a/tests/integration/targets/vyos_route_maps/vars/main.yaml +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -74,18 +74,16 @@ replaced: tag: 4 weight: 4 - overridden: commands: - - delete policy route-map test2 - - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 - - set policy route-map test3 rule 1 set local-preference 6 - - set policy route-map test3 rule 1 set metric 4 - - set policy route-map test3 rule 1 set tag 4 - - delete policy route-map test3 rule 1 set community internet - - set policy route-map test3 rule 1 match metric 3 - - set policy route-map test3 rule 1 match peer 192.0.2.35 - + - delete policy route-map test2 + - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 + - set policy route-map test3 rule 1 set local-preference 6 + - set policy route-map test3 rule 1 set metric 4 + - set policy route-map test3 rule 1 set tag 4 + - delete policy route-map test3 rule 1 set community internet + - set policy route-map test3 rule 1 match metric 3 + - set policy route-map test3 rule 1 match peer 192.0.2.35 after: - route_map: test3 From d0a215b7ab7ba8ce36591b7e9a12d8d118d52c6d Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Mon, 10 May 2021 23:31:54 +0530 Subject: [PATCH 22/23] Fix testing --- tests/integration/network-integration.cfg | 8 ++ .../vyos_route_maps/tests/cli/rtt.yaml | 81 ++++++++++++++ tests/integration/test-inventory | 15 +++ .../vyos/fixtures/vyos_route_maps_config.cfg | 5 - .../network/vyos/test_vyos_route_maps.py | 100 ++++++------------ 5 files changed, 136 insertions(+), 73 deletions(-) create mode 100644 tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml create mode 100644 tests/integration/test-inventory diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg index d12c1efe..41209074 100644 --- a/tests/integration/network-integration.cfg +++ b/tests/integration/network-integration.cfg @@ -2,3 +2,11 @@ command_timeout = 100 connect_timeout = 100 connect_retry_timeout = 100 + + +[paramiko_connection] +look_for_keys = False + +[defaults] +gathering=no +interpreter_python=/Users/amhatre/ansible_venvs/py3.6.10/bin/python diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml new file mode 100644 index 00000000..2a95f1f2 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml @@ -0,0 +1,81 @@ +--- +- debug: + msg: START vyos_route_maps merged integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: baseconfig + vyos.vyos.vyos_route_maps: + config: + - route_map: test1 + entries: + - sequence: 1 + description: "test" + action: permit + continue_sequence: 2 + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 1 + peer: 192.0.2.32 + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - baseconfig.commands|length == 13 + - baseconfig.changed == true + - baseconfig.commands|symmetric_difference(merged.commands) == [] + - baseconfig.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Merge the existing configuration with the provided running configuration + register: result + vyos.vyos.vyos_route_maps: + config: + - route_map: test2 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + + - name: Revert back to base config using facts round trip + become: true + register: revert + vyos.vyos.vyos_route_maps: + config: "{{ ansible_facts['network_resources']['route_maps'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: baseconfig.after == revert.after + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/test-inventory b/tests/integration/test-inventory new file mode 100644 index 00000000..a9ffe8eb --- /dev/null +++ b/tests/integration/test-inventory @@ -0,0 +1,15 @@ +[vyos] +127.0.0.1 + +[vyos:vars] +ansible_network_os=vyos.vyos.vyos +ansible_ssh_port=2222 +ansible_user=vyos +ansible_ssh_pass=vyos +ansible_connection=ansible.netcommon.network_cli +ansible_become=true +#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa +ansible_become_method=ansible.netcommon.enable +cli={'transport': 'cli'} +netconf={'transport': 'netconf'} + diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg index 72427ccf..c7fd9efb 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_route_maps_config.cfg @@ -1,8 +1,3 @@ -set policy route-map test1 rule 1 action 'permit' -set policy route-map test1 rule 1 description 'test' -set policy route-map test1 rule 1 on-match next -set policy route-map test1 rule 2 action 'permit' -set policy route-map test1 rule 2 on-match goto '4' set policy route-map test3 rule 1 action 'permit' set policy route-map test3 rule 1 match interface 'eth2' set policy route-map test3 rule 1 match ipv6 nexthop 'fdda:5cc1:23:4::1f' diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index 76731995..6485d97a 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -107,23 +107,7 @@ def test_vyos_route_maps_merged_idempotent(self): ), ) ], - ), - dict( - route_map="test1", - entries=[ - dict( - sequence=1, - action="permit", - description="test", - on_match=dict(next=True), - ), - dict( - sequence=2, - action="permit", - on_match=dict(goto=4), - ), - ], - ), + ) ], state="merged", ) @@ -233,30 +217,12 @@ def test_route_maps_replaced(self): ) ], ), - dict( - route_map="test1", - entries=[ - dict( - sequence=1, - action="permit", - description="test", - on_match=dict(next=True), - ), - dict( - sequence=2, - action="permit", - description="test", - on_match=dict(goto=4), - ), - ], - ), ], state="replaced", ) ) commands = [ "delete policy route-map test3 rule 1 match interface eth2", - "set policy route-map test1 rule 2 description test", "set policy route-map test3 rule 1 set ip-next-hop 10.20.10.22", "set policy route-map test3 rule 1 set large-community 10:20:21", "set policy route-map test3 rule 1 set metric-type type-2", @@ -303,22 +269,6 @@ def test_vyos_route_maps_replaced_idempotent(self): ) ], ), - dict( - route_map="test1", - entries=[ - dict( - sequence=1, - action="permit", - description="test", - on_match=dict(next=True), - ), - dict( - sequence=2, - action="permit", - on_match=dict(goto=4), - ), - ], - ), ], state="replaced", ) @@ -362,7 +312,6 @@ def test_route_maps_overridden(self): ) ) commands = [ - "delete policy route-map test1", "delete policy route-map test3", "set policy route-map test2 rule 1 action permit", "set policy route-map test2 rule 1 set bgp-extcommunity-rt 22:11", @@ -529,22 +478,6 @@ def test_vyos_route_maps_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) gathered_list = [ - { - "entries": [ - { - "action": "permit", - "description": "test", - "on_match": {"next": True}, - "sequence": 1, - }, - { - "action": "permit", - "on_match": {"goto": 4}, - "sequence": 2, - }, - ], - "route_map": "test1", - }, { "entries": [ { @@ -580,3 +513,34 @@ def test_vyos_route_maps_gathered(self): }, ] self.assertEqual(gathered_list, result["gathered"]) + + def test_vyos_route_maps_deleted(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + sequence=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + ), + set=dict( + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4, + ), + ) + ], + ), + ], + state="deleted", + ) + ) + commands = ["delete policy route-map test3"] + self.execute_module(changed=True, commands=commands) From fec12abcdd02520617dee481a4062dcac8bb1bd0 Mon Sep 17 00:00:00 2001 From: ashwini-mhatre Date: Tue, 11 May 2021 11:52:52 +0530 Subject: [PATCH 23/23] Address review comments --- tests/integration/network-integration.cfg | 8 ---- tests/integration/test-inventory | 15 ------- .../network/vyos/test_vyos_route_maps.py | 43 +++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) delete mode 100644 tests/integration/test-inventory diff --git a/tests/integration/network-integration.cfg b/tests/integration/network-integration.cfg index 41209074..d12c1efe 100644 --- a/tests/integration/network-integration.cfg +++ b/tests/integration/network-integration.cfg @@ -2,11 +2,3 @@ command_timeout = 100 connect_timeout = 100 connect_retry_timeout = 100 - - -[paramiko_connection] -look_for_keys = False - -[defaults] -gathering=no -interpreter_python=/Users/amhatre/ansible_venvs/py3.6.10/bin/python diff --git a/tests/integration/test-inventory b/tests/integration/test-inventory deleted file mode 100644 index a9ffe8eb..00000000 --- a/tests/integration/test-inventory +++ /dev/null @@ -1,15 +0,0 @@ -[vyos] -127.0.0.1 - -[vyos:vars] -ansible_network_os=vyos.vyos.vyos -ansible_ssh_port=2222 -ansible_user=vyos -ansible_ssh_pass=vyos -ansible_connection=ansible.netcommon.network_cli -ansible_become=true -#ansible_ssh_private_key_file=/Users/amhatre/.ssh/id_rsa -ansible_become_method=ansible.netcommon.enable -cli={'transport': 'cli'} -netconf={'transport': 'netconf'} - diff --git a/tests/unit/modules/network/vyos/test_vyos_route_maps.py b/tests/unit/modules/network/vyos/test_vyos_route_maps.py index 6485d97a..17c605ed 100644 --- a/tests/unit/modules/network/vyos/test_vyos_route_maps.py +++ b/tests/unit/modules/network/vyos/test_vyos_route_maps.py @@ -332,6 +332,49 @@ def test_route_maps_overridden(self): ] self.execute_module(changed=True, commands=commands) + def test_vyos_route_maps_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + route_map="test3", + entries=[ + dict( + sequence=1, + action="permit", + match=dict( + rpki="invalid", + interface="eth2", + metric=1, + peer="1.1.1.2", + ipv6=dict(next_hop="fdda:5cc1:23:4::1f"), + ), + set=dict( + ipv6_next_hop=dict( + ip_type="global", + value="fdda:5cc1:23:4::1f", + ), + community=dict(value="internet"), + bgp_extcommunity_rt="22:11", + ip_next_hop="10.20.10.20", + local_preference=4, + metric=5, + metric_type="type-1", + origin="egp", + originator_id="10.0.2.3", + src="10.0.2.15", + tag=5, + weight=4, + ), + ) + ], + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + def test_vyos_route_maps_rendered(self): set_module_args( dict(