Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BGP ASDOT notation handling in ios_bgp_global module #1124

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/fix_bgp_asdot_error.yml
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions docs/cisco.ios.ios_bgp_global_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,25 @@ Parameters
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="4">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>asn</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Autonomous system number for local BGP routes</div>
<div>Please refer vendor documentation for valid values</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td class="elbow-placeholder"></td>
<td colspan="4">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>dual_as</b>
Expand Down Expand Up @@ -4898,6 +4917,7 @@ Parameters
<td>
</td>
<td>
<div>{&#x27;DEPRECATED&#x27;: &quot;This option is deprecated and will be removed at/as of jan 2027. Use &#x27;asn&#x27; instead.&quot;}</div>
<div>AS number used as local AS</div>
<div>Please refer vendor documentation for valid values</div>
</td>
Expand Down
15 changes: 15 additions & 0 deletions plugins/action/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ def run(self, tmp=None, task_vars=None):
% self._play_context.connection,
}

# Handle deprecated 'number' parameter
roverflow marked this conversation as resolved.
Show resolved Hide resolved
if "config" in self._task.args and self._task.args["config"] is not None:
config = self._task.args["config"]
if "neighbors" in config:
for neighbor in config["neighbors"]:
if "local_as" in neighbor:
if "number" in neighbor["local_as"]:
display.deprecated(
msg="DEPRECATED: The 'number' option in 'local_as' is deprecated, Use 'asn' instead.",
date="2027-01-01",
collection_name="cisco.ios",
)
neighbor["local_as"]["asn"] = str(neighbor["local_as"]["number"])
del neighbor["local_as"]["number"]

result = super(ActionModule, self).run(task_vars=task_vars)
if warnings:
if "warnings" in result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,12 @@ class Bgp_globalArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"set": {"type": "bool"},
"number": {"type": "int"},
"number": {
"type": "int",
"deprecated_by": "asn",
"removed_at_date": "2027-01-01",
},
"asn": {"type": "str"},
"dual_as": {"type": "bool"},
"no_prepend": {
"type": "dict",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = want["local_as"].pop("number")
return want
6 changes: 3 additions & 3 deletions plugins/module_utils/network/ios/rm_templates/bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,15 +1582,15 @@ def __init__(self, lines=None, module=None):
"getval": re.compile(
r"""
\sneighbor\s(?P<neighbor_address>\S+)\s(?P<local_as>local-as)
(\s(?P<number>\S+))?
(\s(?P<asn>\S+))?
(\s(?P<dual_as>dual-as))?
(\s(?P<no_prepend>no-prepend))?
(\s(?P<replace_as>replace-as))?
$""",
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 '' }}",
Expand All @@ -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 }}",
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/ios_bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
172 changes: 172 additions & 0 deletions tests/unit/modules/network/ios/test_ios_bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,175 @@ 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))

def test_ios_bgp_global_merged_num(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="600.65083",
local_as=dict(
number="701",
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 600.65083",
"neighbor 192.0.2.1 local-as 701 no-prepend replace-as",
]
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))
Loading