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 all 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>DEPRECATED: This option is deprecated and will be removed at/as of jan 2027. Use &#x27;asn&#x27; instead.</div>
<div>AS number used as local AS</div>
<div>Please refer vendor documentation for valid values</div>
</td>
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",
"removed_at_date": "2027-01-31",
"removed_from_collection": "cisco.ios",
},
"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"] = str(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
17 changes: 17 additions & 0 deletions tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
config:
as_number: 65000
bgp:
asnotation: true
default:
ipv4_unicast: false
route_target:
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion tests/integration/targets/ios_bgp_global/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
129 changes: 129 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 @@ -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))
Loading