Skip to content

Commit

Permalink
Fixes population of wrong data forward_router_address attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
roverflow committed Sep 13, 2024
1 parent 07e8398 commit 42e7919
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/ios_static_routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- ios_static_routes - Fixes an issue where metric_distance is being populated in the forward_router_address attribute.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, lines=None, module=None):
(\s(?P<dest>\S+))
(\s(?P<netmask>\S+))
(\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+))?
(\s(?P<forward_router_address>(?!multicast|dhcp|global|tag|track|permanent|name)\S+))?
(\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+)))? # Had to add ip validation due to it picking up numbers as forward_router_address and negate just numbers
(\s(?P<distance_metric>\d+))?
(\stag\s(?P<tag>\d+))?
(\s(?P<permanent>permanent))?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30
14 changes: 14 additions & 0 deletions tests/integration/targets/ios_static_routes/tests/cli/parsed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- ansible.builtin.debug:
msg: START ios_static_routes parsed integration test

- name: Ios_static_routes parsed - play
register: result
cisco.ios.ios_static_routes:
running_config: "{{ lookup('file', '_parsed.cfg') }}"
state: parsed

- ansible.builtin.assert:
that:
- result.changed == false
- parsed_data == result['parsed']
16 changes: 16 additions & 0 deletions tests/integration/targets/ios_static_routes/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ gathered:
name: route_2
- forward_router_address: 198.51.101.3
name: route_3
parsed_data:
- address_families:
- afi: ipv4
routes:
- dest: 198.51.100.0/24
next_hops:
- distance_metric: 175
forward_router_address: 198.51.101.1
multicast: true
name: replaced_route
tag: 70
- dest: 192.168.1.0/24
next_hops:
- forward_router_address: 10.0.0.1
interface: GigabitEthernet0/1.22
tag: 30
rtt:
override_commands:
- 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
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/modules/network/ios/test_ios_static_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2214,3 +2214,47 @@ def test_ios_static_route_gathered(self):
self.maxDiff = None
print(result["gathered"])
self.assertEqual(sorted(result["gathered"]), sorted(gathered))

def test_ios_static_route_gathered_2(self):
self.execute_show_command.return_value = dedent(
"""\
ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30
""",
)
set_module_args(dict(state="gathered"))
gathered = [
{'address_families':
[
{
'afi': 'ipv4',
'routes': [
{
'next_hops': [
{
'forward_router_address': '198.51.101.1',
'distance_metric': 175,
'tag': 70,
'name': 'replaced_route',
'multicast': True
}
],
'dest': '198.51.100.0/24'
},
{
'next_hops': [
{
'interface': 'GigabitEthernet0/1.22',
'forward_router_address': '10.0.0.1',
'tag': 30
}
],
'dest': '192.168.1.0/24'
}
]
}
]
}
]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["gathered"]), sorted(gathered))

0 comments on commit 42e7919

Please sign in to comment.