From 42e79195588d96c605e143b3b84fce70b64cbe74 Mon Sep 17 00:00:00 2001 From: roverflow Date: Fri, 13 Sep 2024 19:50:54 +0530 Subject: [PATCH] Fixes population of wrong data forward_router_address attribute --- changelogs/fragments/ios_static_routes.yaml | 3 ++ .../network/ios/rm_templates/static_routes.py | 2 +- .../ios_static_routes/tests/cli/_parsed.cfg | 2 + .../ios_static_routes/tests/cli/parsed.yaml | 14 ++++++ .../targets/ios_static_routes/vars/main.yaml | 16 +++++++ .../network/ios/test_ios_static_routes.py | 44 +++++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ios_static_routes.yaml create mode 100644 tests/integration/targets/ios_static_routes/tests/cli/_parsed.cfg create mode 100644 tests/integration/targets/ios_static_routes/tests/cli/parsed.yaml diff --git a/changelogs/fragments/ios_static_routes.yaml b/changelogs/fragments/ios_static_routes.yaml new file mode 100644 index 000000000..becf97b14 --- /dev/null +++ b/changelogs/fragments/ios_static_routes.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ios_static_routes - Fixes an issue where metric_distance is being populated in the forward_router_address attribute. diff --git a/plugins/module_utils/network/ios/rm_templates/static_routes.py b/plugins/module_utils/network/ios/rm_templates/static_routes.py index 895c8a6b9..8142280f0 100644 --- a/plugins/module_utils/network/ios/rm_templates/static_routes.py +++ b/plugins/module_utils/network/ios/rm_templates/static_routes.py @@ -38,7 +38,7 @@ def __init__(self, lines=None, module=None): (\s(?P\S+)) (\s(?P\S+)) (\s(?P(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(?!multicast|dhcp|global|tag|track|permanent|name)\S+))? + (\s(?P(?!multicast|dhcp|global|tag|track|permanent|name)(?!(?\d+))? (\stag\s(?P\d+))? (\s(?Ppermanent))? diff --git a/tests/integration/targets/ios_static_routes/tests/cli/_parsed.cfg b/tests/integration/targets/ios_static_routes/tests/cli/_parsed.cfg new file mode 100644 index 000000000..acb3fc45b --- /dev/null +++ b/tests/integration/targets/ios_static_routes/tests/cli/_parsed.cfg @@ -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 diff --git a/tests/integration/targets/ios_static_routes/tests/cli/parsed.yaml b/tests/integration/targets/ios_static_routes/tests/cli/parsed.yaml new file mode 100644 index 000000000..c35cc0d8c --- /dev/null +++ b/tests/integration/targets/ios_static_routes/tests/cli/parsed.yaml @@ -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'] diff --git a/tests/integration/targets/ios_static_routes/vars/main.yaml b/tests/integration/targets/ios_static_routes/vars/main.yaml index b682a6eea..801e7336a 100644 --- a/tests/integration/targets/ios_static_routes/vars/main.yaml +++ b/tests/integration/targets/ios_static_routes/vars/main.yaml @@ -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 diff --git a/tests/unit/modules/network/ios/test_ios_static_routes.py b/tests/unit/modules/network/ios/test_ios_static_routes.py index 4bb89cc79..ce0e84afd 100644 --- a/tests/unit/modules/network/ios/test_ios_static_routes.py +++ b/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -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))