Skip to content

Commit

Permalink
fix tests make them simple
Browse files Browse the repository at this point in the history
  • Loading branch information
KB-perByte committed Oct 13, 2024
1 parent d153418 commit 6ecfd7e
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 205 deletions.
291 changes: 217 additions & 74 deletions plugins/module_utils/network/iosxr/argspec/route_maps/route_maps.py

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions plugins/module_utils/network/iosxr/config/route_maps/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
100 changes: 100 additions & 0 deletions plugins/module_utils/network/iosxr/rm_templates/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<backup_decimal>\d+))?
(\s(?P<advertise>advertise))?
(\s(?P<install>install))?
$""", 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(
Expand Down
31 changes: 29 additions & 2 deletions plugins/modules/iosxr_route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = """
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down
33 changes: 15 additions & 18 deletions tests/integration/targets/iosxr_route_maps/tests/common/_parsed.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 6ecfd7e

Please sign in to comment.