Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish5tri committed Oct 17, 2024
1 parent c0aeb5a commit 6eb6318
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 98 deletions.
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
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": "str"},
"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,8 +970,14 @@
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
Expand Down
17 changes: 0 additions & 17 deletions tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
config:
as_number: 65000
bgp:
asnotation: true
default:
ipv4_unicast: false
route_target:
Expand All @@ -28,22 +27,6 @@
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: 0 additions & 22 deletions tests/integration/targets/ios_bgp_global/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ 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 @@ -32,22 +26,6 @@ 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
107 changes: 52 additions & 55 deletions tests/unit/modules/network/ios/test_ios_bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,53 +791,50 @@ def test_ios_bgp_global_action_states_no_default(self):
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_ios_bgp_global_asdot_parsed(self):
def test_ios_bgp_global_asdot_merged(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
""",
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="parsed",
state="merged",
),
)
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"])
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_asdot_merged(self):
def test_ios_bgp_global_merged_number(self):
set_module_args(
dict(
config=dict(
Expand All @@ -854,9 +851,9 @@ def test_ios_bgp_global_asdot_merged(self):
neighbors=[
dict(
neighbor_address="192.0.2.1",
remote_as="500.65083",
remote_as=500,
local_as=dict(
number="501.65083",
number=501,
no_prepend=dict(
replace_as=True,
set=True,
Expand All @@ -874,13 +871,13 @@ def test_ios_bgp_global_asdot_merged(self):
"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",
"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_int_merged(self):
def test_ios_bgp_global_merged_asn(self):
set_module_args(
dict(
config=dict(
Expand All @@ -899,7 +896,7 @@ def test_ios_bgp_global_int_merged(self):
neighbor_address="192.0.2.1",
remote_as="500.65083",
local_as=dict(
number="501",
asn="501",
no_prepend=dict(
replace_as=True,
set=True,
Expand All @@ -923,7 +920,7 @@ def test_ios_bgp_global_int_merged(self):
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

def test_ios_bgp_global_asdot_rendered(self):
def test_ios_bgp_global_merged_num(self):
set_module_args(
dict(
config=dict(
Expand All @@ -940,9 +937,9 @@ def test_ios_bgp_global_asdot_rendered(self):
neighbors=[
dict(
neighbor_address="192.0.2.1",
remote_as="500.65083",
remote_as="600.65083",
local_as=dict(
number="501.65083",
number="701",
no_prepend=dict(
replace_as=True,
set=True,
Expand All @@ -952,16 +949,16 @@ def test_ios_bgp_global_asdot_rendered(self):
),
],
),
state="rendered",
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",
"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=False)
self.assertEqual(sorted(result["rendered"]), sorted(commands))
result = self.execute_module(changed=True)
self.assertEqual(sorted(result["commands"]), sorted(commands))

0 comments on commit 6eb6318

Please sign in to comment.