diff --git a/changelogs/fragments/fix_bgp_asdot_error.yml b/changelogs/fragments/fix_bgp_asdot_error.yml new file mode 100644 index 000000000..26b8dfcd7 --- /dev/null +++ b/changelogs/fragments/fix_bgp_asdot_error.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ios_bgp_global - Fixes an issue where the 'number' attribute in 'local_as' parameter failed to parse ASDOT notation, causing a 'float to int' conversion error. diff --git a/docs/cisco.ios.ios_bgp_global_module.rst b/docs/cisco.ios.ios_bgp_global_module.rst index f3ec41e59..4f9135a10 100644 --- a/docs/cisco.ios.ios_bgp_global_module.rst +++ b/docs/cisco.ios.ios_bgp_global_module.rst @@ -4800,6 +4800,25 @@ Parameters + +
+ asn + +
+ string +
+ + + + +
Autonomous system number for local BGP routes
+
Please refer vendor documentation for valid values
+ + + + + +
dual_as @@ -4898,6 +4917,7 @@ Parameters +
DEPRECATED: This option is deprecated and will be removed at/as of jan 2027. Use 'asn' instead.
AS number used as local AS
Please refer vendor documentation for valid values
diff --git a/plugins/module_utils/network/ios/argspec/bgp_global/bgp_global.py b/plugins/module_utils/network/ios/argspec/bgp_global/bgp_global.py index 1a6047041..eb72f7687 100644 --- a/plugins/module_utils/network/ios/argspec/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/ios/argspec/bgp_global/bgp_global.py @@ -500,7 +500,12 @@ class Bgp_globalArgs(object): # pylint: disable=R0903 "type": "dict", "options": { "set": {"type": "bool"}, - "number": {"type": "int"}, + "number": { + "type": "int", + "removed_at_date": "2027-01-31", + "removed_from_collection": "cisco.ios", + }, + "asn": {"type": "str"}, "dual_as": {"type": "bool"}, "no_prepend": { "type": "dict", diff --git a/plugins/module_utils/network/ios/config/bgp_global/bgp_global.py b/plugins/module_utils/network/ios/config/bgp_global/bgp_global.py index 36c9bf89a..6cb3986df 100644 --- a/plugins/module_utils/network/ios/config/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/ios/config/bgp_global/bgp_global.py @@ -456,3 +456,8 @@ def handle_deprecates(self, want, is_nbr=False): _want_nbrs = want.get("neighbors", {}) for nbr in _want_nbrs: nbr = self.handle_deprecates(nbr, is_nbr=True) + else: + if "local_as" in want: + if "number" in want["local_as"]: + want["local_as"]["asn"] = str(want["local_as"].pop("number")) + return want diff --git a/plugins/module_utils/network/ios/rm_templates/bgp_global.py b/plugins/module_utils/network/ios/rm_templates/bgp_global.py index 641a02240..2dcf1b570 100644 --- a/plugins/module_utils/network/ios/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/ios/rm_templates/bgp_global.py @@ -1582,7 +1582,7 @@ def __init__(self, lines=None, module=None): "getval": re.compile( r""" \sneighbor\s(?P\S+)\s(?Plocal-as) - (\s(?P\S+))? + (\s(?P\S+))? (\s(?Pdual-as))? (\s(?Pno-prepend))? (\s(?Preplace-as))? @@ -1590,7 +1590,7 @@ def __init__(self, lines=None, module=None): re.VERBOSE, ), "setval": "neighbor {{ neighbor_address }} local-as" - "{{ (' ' + local_as.number|string) if local_as.number is defined else '' }}" + "{{ (' ' + local_as.asn|string) if local_as.asn is defined else '' }}" "{{ (' dual-as') if local_as.dual_as is defined else '' }}" "{{ (' no-prepend') if local_as.no_prepend.set is defined else '' }}" "{{ (' replace-as') if local_as.no_prepend.replace_as is defined else '' }}", @@ -1600,7 +1600,7 @@ def __init__(self, lines=None, module=None): "neighbor_address": "{{ neighbor_address }}", "local_as": { "set": "{{ not not local_as }}", - "number": "{{ number }}", + "asn": "{{ asn }}", "dual_as": "{{ not not dual_as }}", "no_prepend": { "set": "{{ not not no_prepend }}", diff --git a/plugins/modules/ios_bgp_global.py b/plugins/modules/ios_bgp_global.py index 9ea931db7..98093449b 100644 --- a/plugins/modules/ios_bgp_global.py +++ b/plugins/modules/ios_bgp_global.py @@ -970,9 +970,15 @@ type: bool number: description: + - "DEPRECATED: This option is deprecated and will be removed at/as of jan 2027. Use 'asn' instead." - AS number used as local AS - Please refer vendor documentation for valid values type: int + asn: + description: + - Autonomous system number for local BGP routes + - Please refer vendor documentation for valid values + type: str dual_as: description: Accept either real AS or local AS from the ebgp peer type: bool diff --git a/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml b/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml index f7fd02ba4..ffe4b52ef 100644 --- a/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml +++ b/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml @@ -11,6 +11,7 @@ config: as_number: 65000 bgp: + asnotation: true default: ipv4_unicast: false route_target: @@ -27,6 +28,22 @@ remote_as: 100 shutdown: set: false + - neighbor_address: 192.0.2.1 + remote_as: "500.65083" + local_as: + asn: "501.65083" + no_prepend: + replace_as: true + set: true + set: true + - neighbor_address: 192.0.2.2 + remote_as: 500 + local_as: + number: 501 + no_prepend: + replace_as: true + set: true + set: true timers: keepalive: 100 holdtime: 200 diff --git a/tests/integration/targets/ios_bgp_global/vars/main.yaml b/tests/integration/targets/ios_bgp_global/vars/main.yaml index 71dd2788f..5720d1c34 100644 --- a/tests/integration/targets/ios_bgp_global/vars/main.yaml +++ b/tests/integration/targets/ios_bgp_global/vars/main.yaml @@ -11,10 +11,15 @@ merged: - bgp log-neighbor-changes - neighbor 198.0.2.1 remote-as 100 - neighbor 198.0.2.1 description merge neighbor - + - bgp asnotation dot + - neighbor 192.0.2.1 remote-as 500.65083 + - neighbor 192.0.2.1 local-as 501.65083 no-prepend replace-as + - neighbor 192.0.2.2 remote-as 500 + - neighbor 192.0.2.2 local-as 501 no-prepend replace-as after: as_number: "65000" bgp: + asnotation: true default: ipv4_unicast: false route_target: @@ -26,6 +31,22 @@ merged: time: 50 log_neighbor_changes: true neighbors: + - local_as: + no_prepend: + replace_as: true + set: true + asn: "501.65083" + set: true + neighbor_address: "192.0.2.1" + remote_as: "500.65083" + - local_as: + no_prepend: + replace_as: true + set: true + asn: "501" + set: true + neighbor_address: "192.0.2.2" + remote_as: "500" - description: merge neighbor neighbor_address: 198.0.2.1 remote_as: "100" diff --git a/tests/unit/modules/network/ios/test_ios_bgp_global.py b/tests/unit/modules/network/ios/test_ios_bgp_global.py index 947adf2ef..94ad5314e 100644 --- a/tests/unit/modules/network/ios/test_ios_bgp_global.py +++ b/tests/unit/modules/network/ios/test_ios_bgp_global.py @@ -797,3 +797,132 @@ def test_ios_bgp_global_action_states_no_default(self): commands = ["router bgp 6500", "no neighbor 192.0.2.2 shutdown"] result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_asdot_merged(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + asnotation=True, + log_neighbor_changes=True, + graceful_shutdown=dict( + neighbors=dict(time=50), + local_preference=100, + community="100", + ), + ), + neighbors=[ + dict( + neighbor_address="192.0.2.1", + remote_as="500.65083", + local_as=dict( + asn="501.7843", + no_prepend=dict( + replace_as=True, + set=True, + ), + set=True, + ), + ), + ], + ), + state="merged", + ), + ) + commands = [ + "router bgp 65000", + "bgp asnotation dot", + "bgp log-neighbor-changes", + "bgp graceful-shutdown all neighbors 50 local-preference 100 community 100", + "neighbor 192.0.2.1 remote-as 500.65083", + "neighbor 192.0.2.1 local-as 501.7843 no-prepend replace-as", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_merged_number(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + asnotation=True, + log_neighbor_changes=True, + graceful_shutdown=dict( + neighbors=dict(time=50), + local_preference=100, + community="100", + ), + ), + neighbors=[ + dict( + neighbor_address="192.0.2.1", + remote_as=500, + local_as=dict( + number=501, + no_prepend=dict( + replace_as=True, + set=True, + ), + set=True, + ), + ), + ], + ), + state="merged", + ), + ) + commands = [ + "router bgp 65000", + "bgp asnotation dot", + "bgp log-neighbor-changes", + "bgp graceful-shutdown all neighbors 50 local-preference 100 community 100", + "neighbor 192.0.2.1 remote-as 500", + "neighbor 192.0.2.1 local-as 501 no-prepend replace-as", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_merged_asn(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + asnotation=True, + log_neighbor_changes=True, + graceful_shutdown=dict( + neighbors=dict(time=50), + local_preference=100, + community="100", + ), + ), + neighbors=[ + dict( + neighbor_address="192.0.2.1", + remote_as="500.65083", + local_as=dict( + asn="501", + no_prepend=dict( + replace_as=True, + set=True, + ), + set=True, + ), + ), + ], + ), + state="merged", + ), + ) + commands = [ + "router bgp 65000", + "bgp asnotation dot", + "bgp log-neighbor-changes", + "bgp graceful-shutdown all neighbors 50 local-preference 100 community 100", + "neighbor 192.0.2.1 remote-as 500.65083", + "neighbor 192.0.2.1 local-as 501 no-prepend replace-as", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands))