diff --git a/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py b/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py index ea719ecc..277be868 100644 --- a/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py +++ b/plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function - __metaclass__ = type ############################################# @@ -19,10 +18,10 @@ # # To update the argspec make the desired changes # in the documentation in the module file and re-run -# ansible.content_builder commenting out +# ansible.content_builder commenting out # the path to external 'docstring' in build.yaml. # -############################################## +############################################## """ The arg spec for the iosxr_route_maps module @@ -30,7 +29,8 @@ class Route_mapsArgs(object): # pylint: disable=R0903 - """The arg spec for the iosxr_route_maps module""" + """The arg spec for the iosxr_route_maps module + """ argument_spec = { "config": { @@ -118,10 +118,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "ingress_replication": {"type": "bool"}, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, @@ -214,6 +214,23 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": {"type": "int"}, + "advertise": {"type": "bool"}, + "install": {"type": "bool"}, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -334,10 +351,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "ingress_replication": {"type": "bool"}, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, @@ -430,6 +447,23 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": {"type": "int"}, + "advertise": {"type": "bool"}, + "install": {"type": "bool"}, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -551,10 +585,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "options": { "ingress_replication": {"type": "bool"}, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, @@ -647,6 +681,23 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": {"type": "int"}, + "advertise": {"type": "bool"}, + "install": {"type": "bool"}, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -702,10 +753,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -772,29 +823,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, "mldp_inband": {"type": "bool"}, "mldp_partitioned_mp2mp": { - "type": "bool", + "type": "bool" }, "mldp_partitioned_p2mp": { - "type": "bool", + "type": "bool" }, "p2mp_te": {"type": "bool"}, "p2mp_te_default": { - "type": "bool", + "type": "bool" }, "p2mp_te_partitioned": { - "type": "bool", + "type": "bool" }, "pim_default": {"type": "bool"}, "sr_p2mp": {"type": "bool"}, @@ -813,7 +864,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -827,10 +878,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -866,10 +917,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "external": {"type": "bool"}, "internal": {"type": "bool"}, "rib_metric_as_external": { - "type": "bool", + "type": "bool" }, "rib_metric_as_internal": { - "type": "bool", + "type": "bool" }, "type_1": {"type": "bool"}, "type_2": {"type": "bool"}, @@ -879,7 +930,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "next_hop": { "type": "dict", "options": { - "address": {"type": "str"}, + "address": {"type": "str"} }, }, "origin": { @@ -891,6 +942,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": { + "type": "int" + }, + "advertise": { + "type": "bool" + }, + "install": { + "type": "bool" + }, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -919,7 +993,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -946,10 +1020,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1016,29 +1090,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, "mldp_inband": {"type": "bool"}, "mldp_partitioned_mp2mp": { - "type": "bool", + "type": "bool" }, "mldp_partitioned_p2mp": { - "type": "bool", + "type": "bool" }, "p2mp_te": {"type": "bool"}, "p2mp_te_default": { - "type": "bool", + "type": "bool" }, "p2mp_te_partitioned": { - "type": "bool", + "type": "bool" }, "pim_default": {"type": "bool"}, "sr_p2mp": {"type": "bool"}, @@ -1057,7 +1131,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -1071,10 +1145,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1110,10 +1184,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "external": {"type": "bool"}, "internal": {"type": "bool"}, "rib_metric_as_external": { - "type": "bool", + "type": "bool" }, "rib_metric_as_internal": { - "type": "bool", + "type": "bool" }, "type_1": {"type": "bool"}, "type_2": {"type": "bool"}, @@ -1123,7 +1197,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "next_hop": { "type": "dict", "options": { - "address": {"type": "str"}, + "address": {"type": "str"} }, }, "origin": { @@ -1135,6 +1209,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": { + "type": "int" + }, + "advertise": { + "type": "bool" + }, + "install": { + "type": "bool" + }, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -1163,7 +1260,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -1191,10 +1288,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1261,29 +1358,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, "mldp_inband": {"type": "bool"}, "mldp_partitioned_mp2mp": { - "type": "bool", + "type": "bool" }, "mldp_partitioned_p2mp": { - "type": "bool", + "type": "bool" }, "p2mp_te": {"type": "bool"}, "p2mp_te_default": { - "type": "bool", + "type": "bool" }, "p2mp_te_partitioned": { - "type": "bool", + "type": "bool" }, "pim_default": {"type": "bool"}, "sr_p2mp": {"type": "bool"}, @@ -1302,7 +1399,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -1316,10 +1413,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1355,10 +1452,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "external": {"type": "bool"}, "internal": {"type": "bool"}, "rib_metric_as_external": { - "type": "bool", + "type": "bool" }, "rib_metric_as_internal": { - "type": "bool", + "type": "bool" }, "type_1": {"type": "bool"}, "type_2": {"type": "bool"}, @@ -1368,7 +1465,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "next_hop": { "type": "dict", "options": { - "address": {"type": "str"}, + "address": {"type": "str"} }, }, "origin": { @@ -1380,6 +1477,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": { + "type": "int" + }, + "advertise": { + "type": "bool" + }, + "install": { + "type": "bool" + }, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -1408,7 +1528,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -1434,10 +1554,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1504,29 +1624,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "ingress_replication_default": { - "type": "bool", + "type": "bool" }, "ingress_replication_partitioned": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "mldp_default": {"type": "bool"}, "mldp_inband": {"type": "bool"}, "mldp_partitioned_mp2mp": { - "type": "bool", + "type": "bool" }, "mldp_partitioned_p2mp": { - "type": "bool", + "type": "bool" }, "p2mp_te": {"type": "bool"}, "p2mp_te_default": { - "type": "bool", + "type": "bool" }, "p2mp_te_partitioned": { - "type": "bool", + "type": "bool" }, "pim_default": {"type": "bool"}, "sr_p2mp": {"type": "bool"}, @@ -1545,7 +1665,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, @@ -1559,10 +1679,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "delay": {"type": "int"}, "reliability": {"type": "int"}, "effective_bandwith": { - "type": "int", + "type": "int" }, "max_transmission": { - "type": "int", + "type": "int" }, }, }, @@ -1598,10 +1718,10 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "external": {"type": "bool"}, "internal": {"type": "bool"}, "rib_metric_as_external": { - "type": "bool", + "type": "bool" }, "rib_metric_as_internal": { - "type": "bool", + "type": "bool" }, "type_1": {"type": "bool"}, "type_2": {"type": "bool"}, @@ -1611,7 +1731,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "next_hop": { "type": "dict", "options": { - "address": {"type": "str"}, + "address": {"type": "str"} }, }, "origin": { @@ -1623,6 +1743,29 @@ class Route_mapsArgs(object): # pylint: disable=R0903 }, }, "ospf_metric": {"type": "int"}, + "path_selection": { + "type": "dict", + "options": { + "all": {"type": "bool"}, + "backup": { + "type": "dict", + "options": { + "backup_decimal": { + "type": "int" + }, + "advertise": { + "type": "bool" + }, + "install": { + "type": "bool" + }, + }, + }, + "best_path": {"type": "bool"}, + "group_best": {"type": "bool"}, + "multiplath": {"type": "bool"}, + }, + }, "path_color": {"type": "bool"}, "qos_group": {"type": "int"}, "rib_metric": {"type": "int"}, @@ -1651,7 +1794,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "ingress_replication": { - "type": "bool", + "type": "bool" }, "mldp": {"type": "bool"}, "p2mp_te": {"type": "bool"}, diff --git a/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py b/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py index 43602bc1..59febff9 100644 --- a/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py @@ -80,6 +80,11 @@ def __init__(self, module): "set.next_hop", "set.origin", "set.ospf_metric", + "set.path_selection.all", + "set.path_selection.backup", + "set.path_selection.best_path", + "set.path_selection.group_best", + "set.path_selection.multiplath", "set.path_color", "set.qos_group", "set.rib_metric", @@ -120,13 +125,13 @@ def generate_commands(self): for k, want in iteritems(wantd): if self.state == "purged": # for purged state - if haved.get(k): + if haved.pop(k, {}): self._handle_purged(k) else: # for all other states self._compare(want=want, have=haved.pop(k, {}), policy_name=k) - # clean anything that is surplus - if self.state == "overridden": + # clean anything that is surplus, if state purged clean all have if want is empty + if self.state == "overridden" or (self.state == "purged" and not wantd): for h, haved in iteritems(haved): self._handle_purged(h) @@ -238,17 +243,17 @@ def process_apply(apply_conf): if cond == "global": temp_rmap[cond] = rm_conf else: - temp_rmap[cond + "_" + (rm_conf.get("condition").replace(" ", "_"))] = ( - rm_conf - ) + temp_rmap[ + cond + "_" + (rm_conf.get("condition").replace(" ", "_")) + ] = rm_conf elif cond == "elseif": for elif_config in rm_conf: if elif_config.get("apply"): elif_config["apply"] = process_apply(elif_config.get("apply")) elif_config["conf_type"] = cond - temp_rmap[cond + "_" + (elif_config.get("condition").replace(" ", "_"))] = ( - elif_config - ) + temp_rmap[ + cond + "_" + (elif_config.get("condition").replace(" ", "_")) + ] = elif_config elif ( cond == "else" ): # wanted to do recursion but the overall performance is better this way diff --git a/plugins/module_utils/network/iosxr/facts/route_maps/route_maps.py b/plugins/module_utils/network/iosxr/facts/route_maps/route_maps.py index 84de199f..aeda889b 100644 --- a/plugins/module_utils/network/iosxr/facts/route_maps/route_maps.py +++ b/plugins/module_utils/network/iosxr/facts/route_maps/route_maps.py @@ -34,7 +34,7 @@ def __init__(self, module, subspec="config", options="options"): self.argument_spec = Route_mapsArgs.argument_spec def get_policynames(self, connection): - return connection.get("show running-config | include route-policyx") + return connection.get("show running-config | include route-policy") def get_policydata(self, connection, name): return connection.get(f"show running-config route-policy {name}") @@ -231,7 +231,7 @@ def populate_facts(self, connection, ansible_facts, data=None): route_maps_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) - facts["route_maps"] = params["config"] + facts["route_maps"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/iosxr/rm_templates/route_maps.py b/plugins/module_utils/network/iosxr/rm_templates/route_maps.py index c2068254..09d384ab 100644 --- a/plugins/module_utils/network/iosxr/rm_templates/route_maps.py +++ b/plugins/module_utils/network/iosxr/rm_templates/route_maps.py @@ -803,6 +803,106 @@ def __init__(self, lines=None, module=None): }, }, }, + { + "name": "set.path_selection.all", + "getval": re.compile( + r""" + \s*set\spath-selection\sall\sadvertise + $""", re.VERBOSE, + ), + "setval": "set path-selection all advertise", + "result": { + "policies": { + "set": { + "path_selection": { + "all": True, + }, + }, + }, + }, + }, + { + "name": "set.path_selection.backup", + "getval": re.compile( + r""" + \s*set\spath-selection\sbackup + (\s(?P\d+))? + (\s(?Padvertise))? + (\s(?Pinstall))? + $""", re.VERBOSE, + ), + "setval": "set path-selection backup" + "{{ (' ' + rib-metric-as-external|string ) if set.path_selection.backup.backup_decimal is defined else '' }}" + "{{ (' advertise' ) if set.path_selection.backup.advertise|d(False) is defined else '' }}" + "{{ (' install' ) if set.path_selection.backup.install|d(False) is defined else '' }}", + "result": { + "policies": { + "set": { + "path_selection": { + "backup": { + "backup_decimal": "{{ backup_decimal }}", + "advertise": "{{ not not advertise }}", + "install": "{{ not not install }}", + }, + }, + }, + }, + }, + }, + { + "name": "set.path_selection.best_path", + "getval": re.compile( + r""" + \s*set\spath-selection\sbest-path + $""", re.VERBOSE, + ), + "setval": "set path-selection best_path", + "result": { + "policies": { + "set": { + "path_selection": { + "best_path": True, + }, + }, + }, + }, + }, + { + "name": "set.path_selection.group_best", + "getval": re.compile( + r""" + \s*set\spath-selection\sbest-path\sadvertise + $""", re.VERBOSE, + ), + "setval": "set path-selection group-best advertise", + "result": { + "policies": { + "set": { + "path_selection": { + "group_best": True, + }, + }, + }, + }, + }, + { + "name": "set.path_selection.multiplath", + "getval": re.compile( + r""" + \s*set\spath-selection\smultiplath\sadvertise + $""", re.VERBOSE, + ), + "setval": "set path-selection multiplath advertise", + "result": { + "policies": { + "set": { + "path_selection": { + "multiplath": True, + }, + }, + }, + }, + }, { "name": "set.path_color", "getval": re.compile( diff --git a/plugins/modules/iosxr_route_maps.py b/plugins/modules/iosxr_route_maps.py index e5ee78e0..a927da72 100644 --- a/plugins/modules/iosxr_route_maps.py +++ b/plugins/modules/iosxr_route_maps.py @@ -10,7 +10,6 @@ from __future__ import absolute_import, division, print_function - __metaclass__ = type DOCUMENTATION = """ @@ -355,6 +354,35 @@ ospf_metric: description: OSPF metric attribute type: int + path_selection: + description: BGP path selection + type: dict + suboptions: + all: + type: bool + description: BGP all advertise + backup: + description: BGP backup + type: dict + suboptions: + backup_decimal: + type: int + description: <1>, decimal number 1 + advertise: + type: bool + description: Advertise the path + install: + type: bool + description: Install the path + best_path: + type: bool + description: BGP best path + group_best: + type: bool + description: BGP group-best advertise + multiplath: + type: bool + description: BGP multipath advertise path_color: description: BGP Path Color for RIB (path-color external-reach) type: bool @@ -1422,7 +1450,6 @@ """ from ansible.module_utils.basic import AnsibleModule - from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.route_maps.route_maps import ( Route_mapsArgs, ) diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/_parsed.cfg b/tests/integration/targets/iosxr_route_maps/tests/common/_parsed.cfg index 6500fb5d..43a8633b 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/_parsed.cfg +++ b/tests/integration/targets/iosxr_route_maps/tests/common/_parsed.cfg @@ -1,8 +1,19 @@ +route-policy COMPLEX_ROUTE_POLICY + if destination in A_RANDOM_POLICY_DUMMY then + drop + else + if destination in A_RANDOM_POLICY then + pass + else + drop + endif + endif +end-policy +! route-policy SIMPLE_GLOBAL_ROUTE_POLICY - set weight 20000 - set local-preference 200 - set community (11011:1001) additive apply A_NEW_ROUTE_POLICY + set community (11011:1001) additive + set weight 20000 end-policy ! route-policy SIMPLE_CONDITION_ROUTE_POLICY @@ -13,24 +24,10 @@ route-policy SIMPLE_CONDITION_ROUTE_POLICY endif end-policy ! -route-policy COMPLEX_ROUTE_POLICY - if as-path in (ios-regex '_3117_', ios-regex '_600_') then - drop - else - if destination in A_RANDOM_POLICY then - pass - set community (101010:1) additive - set local-preference 200 - else - drop - endif - endif -end-policy -! route-policy COMPLEX_CONDITION_ROUTE_POLICY if community matches-any (9119:1001) or community matches-any (11100:1001) then drop else pass endif -end-policy +end-policy \ No newline at end of file diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/_populate_config.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/_populate_config.yaml index ef1d6df1..8ff2a3ef 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/_populate_config.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/_populate_config.yaml @@ -1,38 +1,41 @@ --- -- name: "Setup route-policy base configuration" - cisco.iosxr.iosxr_config: - lines: - - "route-policy SIMPLE_GLOBAL_ROUTE_POLICY" - - "apply A_NEW_ROUTE_POLICY" - - "set community (11011:1001) additive" - - "set weight 20000" - - "end-policy" - - "route-policy SIMPLE_CONDITION_ROUTE_POLICY" - - "if destination in SIMPLE_CONDITION_ROUTE_POLICY then" - - "pass" - - "else" - - "drop" - - "endif" - - "end-policy" - - "route-policy COMPLEX_ROUTE_POLICY" - - "if as-path in (ios-regex '_3117_', ios-regex '_600_') then" - - "drop" - - "else" - - "if destination in A_RANDOM_POLICY then" - - "pass" - - "set community (101010:1) additive" - - "else" - - "drop" - - "endif" - - "endif" - - "end-policy" - - "route-policy COMPLEX_CONDITION_ROUTE_POLICY" - - "if community matches-any (9119:1001) or community matches-any (11100:1001) then" - - "drop" - - "else" - - "pass" - - "endif" - - "end-policy" +- name: Populate with simple overridden + cisco.iosxr.iosxr_route_maps: + state: overridden + config: + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + if: + condition: destination in A_RANDOM_POLICY_DUMMY + drop: true + name: COMPLEX_ROUTE_POLICY + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: SIMPLE_CONDITION_ROUTE_POLICY + - else: + global: + pass: true + if: + condition: community matches-any (9119:1001) or community matches-any (11100:1001) + drop: true + name: COMPLEX_CONDITION_ROUTE_POLICY vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/_remove_config.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/_remove_config.yaml index 2f0ca32b..8e65198b 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/_remove_config.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/_remove_config.yaml @@ -1,10 +1,7 @@ --- -- name: "Remove iosxr_route_maps configuration" - cisco.iosxr.iosxr_config: - lines: - - "no route-policy SIMPLE_GLOBAL_ROUTE_POLICY" - - "no route-policy COMPLEX_ROUTE_POLICY" - - "no route-policy SIMPLE_CONDITION_ROUTE_POLICY" - - "no route-policy COMPLEX_CONDITION_ROUTE_POLICY" +- name: Purge all ( risky ) + cisco.iosxr.iosxr_route_maps: + config: [] + state: purged vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/gathered.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/gathered.yaml index 7b63fae0..9c8f5253 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/gathered.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/gathered.yaml @@ -2,8 +2,6 @@ - ansible.builtin.debug: msg: START iosxr_route_maps gathered integration tests on connection={{ ansible_connection }} -- ansible.builtin.include_tasks: _remove_config.yaml - - ansible.builtin.include_tasks: _populate_config.yaml - block: diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/merged.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/merged.yaml index 1aa87fad..af29c72b 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/merged.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/merged.yaml @@ -5,10 +5,20 @@ - ansible.builtin.include_tasks: _remove_config.yaml - block: - - name: Merge route-policy configuration + - name: Simple merge selective cisco.iosxr.iosxr_route_maps: state: merged config: + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + if: + condition: destination in A_RANDOM_POLICY_DUMMY + drop: true + name: COMPLEX_ROUTE_POLICY - global: apply: - route_policy: A_NEW_ROUTE_POLICY @@ -25,20 +35,6 @@ condition: destination in SIMPLE_CONDITION_ROUTE_POLICY pass: true name: SIMPLE_CONDITION_ROUTE_POLICY - - else: - else: - drop: true - if: - condition: destination in A_RANDOM_POLICY - pass: true - set: - community: - additive: true - community_name: (101010:1) - if: - condition: as-path in (ios-regex '_3117_', ios-regex '_600_') - drop: true - name: COMPLEX_ROUTE_POLICY - else: global: pass: true diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/overridden.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/overridden.yaml index 1ce536eb..989d80e5 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/overridden.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/overridden.yaml @@ -2,12 +2,10 @@ - ansible.builtin.debug: msg: Start iosxr_route_maps overridden integration tests connection={{ ansible_connection}} -- ansible.builtin.include_tasks: _remove_config.yaml - - ansible.builtin.include_tasks: _populate_config.yaml - block: - - name: Merge route-policy configuration + - name: Override the route-policy configuration cisco.iosxr.iosxr_route_maps: state: overridden config: @@ -16,17 +14,9 @@ - route_policy: A_NEW_ROUTE_POLICY set: community: - additive: true - community_name: (11011:1001) + community_name: test_comm_name weight: 20000 - name: SIMPLE_GLOBAL_ROUTE_POLICY - - else: - global: - drop: true - if: - condition: destination in SIMPLE_CONDITION_ROUTE_POLICY - pass: true - name: SIMPLE_CONDITION_ROUTE_POLICY + name: SIMPLE_GLOBAL_ROUTE_POLICY_overridden - else: else: drop: true @@ -35,34 +25,26 @@ pass: true set: community: - additive: true - community_name: (101010:1) + community_name: test_comm_name if: condition: as-path in (ios-regex '_3117_', ios-regex '_600_') drop: true - name: COMPLEX_ROUTE_POLICY - - else: - global: - pass: true - if: - condition: community matches-any (9119:1001) or community matches-any (11100:1001) - drop: true - name: COMPLEX_CONDITION_ROUTE_POLICY + name: COMPLEX_ROUTE_POLICY_overridden register: result - name: Assert that correct set of commands were generated ansible.builtin.assert: that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - replaced['after'] == result['after'] + - overridden['after'] == result['after'] - name: Assert that before dicts are correctly generated ansible.builtin.assert: that: - - merged['after'] == result['before'] + - overridden['before'] == result['before'] always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/parsed.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/parsed.yaml index c7bd220a..6ac7207f 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/parsed.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/parsed.yaml @@ -2,7 +2,7 @@ - ansible.builtin.debug: msg: START iosxr_ntp_global parsed integration tests on connection={{ ansible_connection }} -- name: Parse externally provided ntp_global configuration +- name: Parse externally provided route-policy configuration register: result cisco.iosxr.iosxr_route_maps: running_config: "{{ lookup('file', './_parsed.cfg') }}" diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/purged.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/purged.yaml index 9b396b9d..10b32782 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/purged.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/purged.yaml @@ -2,12 +2,11 @@ - ansible.builtin.debug: msg: Start iosxr_route_maps deleted integration tests connection={{ ansible_connection}} -- ansible.builtin.include_tasks: _remove_config.yaml - - ansible.builtin.include_tasks: _populate_config.yaml - block: - name: Purge or remove route-policy configuration + register: result cisco.iosxr.iosxr_route_maps: &deleted state: purged config: diff --git a/tests/integration/targets/iosxr_route_maps/tests/common/rendered.yaml b/tests/integration/targets/iosxr_route_maps/tests/common/rendered.yaml index e977fcf0..253f92b4 100644 --- a/tests/integration/targets/iosxr_route_maps/tests/common/rendered.yaml +++ b/tests/integration/targets/iosxr_route_maps/tests/common/rendered.yaml @@ -5,6 +5,7 @@ - ansible.builtin.include_tasks: _remove_config.yaml - name: Render route-policy configuration + register: result cisco.iosxr.iosxr_route_maps: state: rendered config: @@ -49,4 +50,4 @@ - name: Assert that correct set of commands were rendered ansible.builtin.assert: that: - - merged['commands'] == result['rendered'] + - rendered['commands'] == result['rendered'] diff --git a/tests/integration/targets/iosxr_route_maps/vars/main.yaml b/tests/integration/targets/iosxr_route_maps/vars/main.yaml index bf6faa70..32adaa35 100644 --- a/tests/integration/targets/iosxr_route_maps/vars/main.yaml +++ b/tests/integration/targets/iosxr_route_maps/vars/main.yaml @@ -6,25 +6,24 @@ merged: - set community (11011:1001) additive - set weight 20000 - end-policy - - route-policy SIMPLE_CONDITION_ROUTE_POLICY - - if destination in SIMPLE_CONDITION_ROUTE_POLICY then - - pass - - else - - drop - - endif - - end-policy - route-policy COMPLEX_ROUTE_POLICY - - if as-path in (ios-regex '_3117_', ios-regex '_600_') then + - if destination in A_RANDOM_POLICY_DUMMY then - drop - else - if destination in A_RANDOM_POLICY then - pass - - set community (101010:1) additive - else - drop - endif - endif - end-policy + - route-policy SIMPLE_CONDITION_ROUTE_POLICY + - if destination in SIMPLE_CONDITION_ROUTE_POLICY then + - pass + - else + - drop + - endif + - end-policy - route-policy COMPLEX_CONDITION_ROUTE_POLICY - if community matches-any (9119:1001) or community matches-any (11100:1001) then - drop @@ -32,8 +31,17 @@ merged: - pass - endif - end-policy - after: + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + if: + condition: destination in A_RANDOM_POLICY_DUMMY + drop: true + name: COMPLEX_ROUTE_POLICY - global: apply: - route_policy: A_NEW_ROUTE_POLICY @@ -50,6 +58,38 @@ merged: condition: destination in SIMPLE_CONDITION_ROUTE_POLICY pass: true name: SIMPLE_CONDITION_ROUTE_POLICY + - else: + global: + pass: true + if: + condition: community matches-any (9119:1001) or community matches-any (11100:1001) + drop: true + name: COMPLEX_CONDITION_ROUTE_POLICY + +overridden: + commands: + - route-policy SIMPLE_GLOBAL_ROUTE_POLICY_overridden + - apply A_NEW_ROUTE_POLICY + - set community test_comm_name + - set weight 20000 + - end-policy + - route-policy COMPLEX_ROUTE_POLICY_overridden + - if as-path in (ios-regex '_3117_', ios-regex '_600_') then + - drop + - else + - if destination in A_RANDOM_POLICY then + - pass + - set community test_comm_name + - else + - drop + - endif + - endif + - end-policy + - no route-policy COMPLEX_ROUTE_POLICY + - no route-policy SIMPLE_GLOBAL_ROUTE_POLICY + - no route-policy SIMPLE_CONDITION_ROUTE_POLICY + - no route-policy COMPLEX_CONDITION_ROUTE_POLICY + after: - else: else: drop: true @@ -58,12 +98,46 @@ merged: pass: true set: community: - additive: true - community_name: (101010:1) + community_name: test_comm_name if: condition: as-path in (ios-regex '_3117_', ios-regex '_600_') drop: true + name: COMPLEX_ROUTE_POLICY_overridden + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + community_name: test_comm_name + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY_overridden + before: + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + if: + condition: destination in A_RANDOM_POLICY_DUMMY + drop: true name: COMPLEX_ROUTE_POLICY + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: SIMPLE_CONDITION_ROUTE_POLICY - else: global: pass: true @@ -124,3 +198,10 @@ deleted: condition: destination in SIMPLE_CONDITION_ROUTE_POLICY pass: true name: SIMPLE_CONDITION_ROUTE_POLICY + - else: + global: + pass: true + if: + condition: community matches-any (9119:1001) or community matches-any (11100:1001) + drop: true + name: COMPLEX_CONDITION_ROUTE_POLICY