Skip to content

Commit 7655d04

Browse files
Fixes population of wrong data forward_router_address attribute (#1114)
* Fixes population of wrong data forward_router_address attribute * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix sanity * added more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c6597f7 commit 7655d04

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- ios_static_routes - Fix processing of metric_distance as it was wrongly populated under the forward_router_address attribute.

plugins/module_utils/network/ios/rm_templates/static_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, lines=None, module=None):
3838
(\s(?P<dest>\S+))
3939
(\s(?P<netmask>\S+))
4040
(\s(?P<interface>(ACR|ATM-ACR|Analysis-Module|AppNav-Compress|AppNav-UnCompress|Async|Auto-Template|BD-VIF|BDI|BVI|Bluetooth|CDMA-Ix|CEM-ACR|CEM-PG|CTunnel|Container|Dialer|EsconPhy|Ethernet-Internal|Fcpa|Filter|Filtergroup|GigabitEthernet|TenGigabitEthernet|IMA-ACR|LongReachEthernet|Loopback|Lspvif|MFR|Multilink|NVI|Null|PROTECTION_GROUP|Port-channel|Portgroup|Pos-channel|SBC|SDH_ACR|SERIAL-ACR|SONET_ACR|SSLVPN-VIF|SYSCLOCK|Serial-PG|Service-Engine|TLS-VIF|Tunnel|VPN|Vif|Vir-cem-ACR|Virtual-PPP|Virtual-TokenRing)\S+))?
41-
(\s(?P<forward_router_address>(?!multicast|dhcp|global|tag|track|permanent|name)\S+))?
41+
(\s(?P<forward_router_address>(?!multicast|dhcp|global|tag|track|permanent|name)(?!(?<!\d\.)\b\d+\b(?!\.\d))(\d{1,3}(\.\d{1,3}){3}|\S+)))?
4242
(\s(?P<distance_metric>\d+))?
4343
(\stag\s(?P<tag>\d+))?
4444
(\s(?P<permanent>permanent))?
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
2+
ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- ansible.builtin.debug:
3+
msg: START ios_static_routes parsed integration test
4+
5+
- name: Ios_static_routes parsed - play
6+
register: result
7+
cisco.ios.ios_static_routes:
8+
running_config: "{{ lookup('file', '_parsed.cfg') }}"
9+
state: parsed
10+
11+
- ansible.builtin.assert:
12+
that:
13+
- result.changed == false
14+
- parsed_data == result['parsed']

tests/integration/targets/ios_static_routes/vars/main.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ gathered:
8181
name: route_2
8282
- forward_router_address: 198.51.101.3
8383
name: route_3
84+
parsed_data:
85+
- address_families:
86+
- afi: ipv4
87+
routes:
88+
- dest: 198.51.100.0/24
89+
next_hops:
90+
- distance_metric: 175
91+
forward_router_address: 198.51.101.1
92+
multicast: true
93+
name: replaced_route
94+
tag: 70
95+
- dest: 192.168.1.0/24
96+
next_hops:
97+
- forward_router_address: 10.0.0.1
98+
interface: GigabitEthernet0/1.22
99+
tag: 30
84100
rtt:
85101
override_commands:
86102
- ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.12 tag 10 name new_rtt_vrf track 150

tests/unit/modules/network/ios/test_ios_static_routes.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,3 +2214,95 @@ def test_ios_static_route_gathered(self):
22142214
self.maxDiff = None
22152215
print(result["gathered"])
22162216
self.assertEqual(sorted(result["gathered"]), sorted(gathered))
2217+
2218+
def test_ios_static_route_gathered_2(self):
2219+
self.execute_show_command.return_value = dedent(
2220+
"""\
2221+
ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
2222+
ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30
2223+
""",
2224+
)
2225+
set_module_args(dict(state="gathered"))
2226+
gathered = [
2227+
{
2228+
"address_families": [
2229+
{
2230+
"afi": "ipv4",
2231+
"routes": [
2232+
{
2233+
"next_hops": [
2234+
{
2235+
"forward_router_address": "198.51.101.1",
2236+
"distance_metric": 175,
2237+
"tag": 70,
2238+
"name": "replaced_route",
2239+
"multicast": True,
2240+
},
2241+
],
2242+
"dest": "198.51.100.0/24",
2243+
},
2244+
{
2245+
"next_hops": [
2246+
{
2247+
"interface": "GigabitEthernet0/1.22",
2248+
"forward_router_address": "10.0.0.1",
2249+
"tag": 30,
2250+
},
2251+
],
2252+
"dest": "192.168.1.0/24",
2253+
},
2254+
],
2255+
},
2256+
],
2257+
},
2258+
]
2259+
result = self.execute_module(changed=False)
2260+
self.assertEqual(sorted(result["gathered"]), sorted(gathered))
2261+
2262+
def test_ios_static_route_overridden_2(self):
2263+
self.execute_show_command.return_value = dedent(
2264+
"""\
2265+
ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
2266+
ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30
2267+
""",
2268+
)
2269+
set_module_args(
2270+
dict(
2271+
config=[
2272+
{
2273+
"address_families": [
2274+
{
2275+
"afi": "ipv4",
2276+
"routes": [
2277+
{
2278+
"next_hops": [
2279+
{
2280+
"forward_router_address": "198.51.101.20",
2281+
"distance_metric": 175,
2282+
"tag": 70,
2283+
"name": "replaced_route",
2284+
"track": 150,
2285+
},
2286+
{
2287+
"forward_router_address": "198.51.101.3",
2288+
"name": "merged_route_3",
2289+
},
2290+
],
2291+
"dest": "198.51.100.0/24",
2292+
},
2293+
],
2294+
},
2295+
],
2296+
},
2297+
],
2298+
state="overridden",
2299+
),
2300+
)
2301+
commands = [
2302+
"ip route 198.51.100.0 255.255.255.0 198.51.101.20 175 tag 70 name replaced_route track 150",
2303+
"ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3",
2304+
"no ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast",
2305+
"no ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30",
2306+
]
2307+
result = self.execute_module(changed=True)
2308+
self.assertEqual(sorted(result["commands"]), sorted(commands))

0 commit comments

Comments
 (0)