diff --git a/changelogs/fragments/ios_static_routes.yaml b/changelogs/fragments/ios_static_routes.yaml index becf97b14..5400b7f41 100644 --- a/changelogs/fragments/ios_static_routes.yaml +++ b/changelogs/fragments/ios_static_routes.yaml @@ -1,3 +1,3 @@ --- bugfixes: - - ios_static_routes - Fixes an issue where metric_distance is being populated in the forward_router_address attribute. + - ios_static_routes - Fix processing of metric_distance as it was wrongly populated under 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 0d80613da..c314447ec 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,6 @@ 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+))? - # Had to add ip validation due to it picking up numbers as forward_router_address and negate just numbers (\s(?P(?!multicast|dhcp|global|tag|track|permanent|name)(?!(?\d+))? (\stag\s(?P\d+))? 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 17bd2c2e9..8ddb93101 100644 --- a/tests/unit/modules/network/ios/test_ios_static_routes.py +++ b/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -2258,3 +2258,48 @@ def test_ios_static_route_gathered_2(self): ] result = self.execute_module(changed=False) self.assertEqual(sorted(result["gathered"]), sorted(gathered)) + + def test_ios_static_route_overridden_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(config=[ + { + "address_families": [ + { + "afi": "ipv4", + "routes": [ + { + "next_hops": [ + { + "forward_router_address": "198.51.101.20", + "distance_metric": 175, + "tag": 70, + "name": "replaced_route", + "track": 150, + }, + { + "forward_router_address": "198.51.101.3", + "name": "merged_route_3", + }, + ], + "dest": "198.51.100.0/24", + }, + ], + }, + ], + }, + ], + state="overridden" + )) + commands = [ + 'ip route 198.51.100.0 255.255.255.0 198.51.101.20 175 tag 70 name replaced_route track 150', + 'ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3', + 'no ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast', + 'no ip route 192.168.1.0 255.255.255.0 GigabitEthernet0/1.22 10.0.0.1 tag 30' + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) \ No newline at end of file