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 14 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.
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_bgp_global_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,7 @@ Parameters
<b>number</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
<span style="color: purple">string</span>
</div>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class Bgp_globalArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"set": {"type": "bool"},
"number": {"type": "int"},
"number": {"type": "str"},
roverflow marked this conversation as resolved.
Show resolved Hide resolved
roverflow marked this conversation as resolved.
Show resolved Hide resolved
"dual_as": {"type": "bool"},
"no_prepend": {
"type": "dict",
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/ios_bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@
description:
- AS number used as local AS
- Please refer vendor documentation for valid values
type: int
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:
number: "501.65083"
no_prepend:
replace_as: true
set: true
set: true
- neighbor_address: 192.0.2.2
remote_as: 200
local_as:
number: 501
no_prepend:
replace_as: true
set: true
set: true
timers:
keepalive: 100
holdtime: 200
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/targets/ios_bgp_global/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ 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 200
- 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 +32,22 @@ merged:
time: 50
log_neighbor_changes: true
neighbors:
- local_as:
no_prepend:
replace_as: true
set: true
number: "501.65083"
set: true
neighbor_address: "192.0.2.1"
remote_as: "500.65083"
- local_as:
no_prepend:
replace_as: true
set: true
number: "501"
set: true
neighbor_address: "192.0.2.2"
remote_as: "200"
- description: merge neighbor
neighbor_address: 198.0.2.1
remote_as: "100"
Expand Down
175 changes: 175 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,178 @@ 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_parsed(self):
set_module_args(
dict(
running_config=dedent(
"""\
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.65083 no-prepend replace-as
""",
),
state="parsed",
),
)
result = self.execute_module(changed=False)
parsed_list = {
"as_number": "65000",
"bgp": {
"asnotation": True,
"log_neighbor_changes": True,
"default": {"ipv4_unicast": True, "route_target": {"filter": True}},
"graceful_shutdown": {
"neighbors": {"time": 50},
"local_preference": 100,
"community": "100",
},
},
"neighbors": [
{
"neighbor_address": "192.0.2.1",
"remote_as": "500.65083",
"local_as": {
"number": "501.65083",
"no_prepend": {
"replace_as": True,
"set": True,
},
"set": True,
},
},
],
}
self.assertEqual(parsed_list, result["parsed"])

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(
number="501.65083",
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.65083 no-prepend replace-as",
]
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_ios_bgp_global_int_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(
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.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_asdot_rendered(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(
number="501.65083",
no_prepend=dict(
replace_as=True,
set=True,
),
set=True,
),
),
],
),
state="rendered",
),
)
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.65083 no-prepend replace-as",
]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["rendered"]), sorted(commands))
Loading