mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
nxos_bgp_neighbor: Fix regex &report warnings (#28888)
* Fix over-detection of log-neighbor-as * Report nxos warnings * Update nxos_bgp_neighbor unit tests to test remove-private-as
This commit is contained in:
parent
12700f61e7
commit
8bfdbd0f73
3 changed files with 25 additions and 18 deletions
|
@ -225,7 +225,7 @@ BOOL_PARAMS = [
|
||||||
'dynamic_capability',
|
'dynamic_capability',
|
||||||
'low_memory_exempt',
|
'low_memory_exempt',
|
||||||
'suppress_4_byte_as',
|
'suppress_4_byte_as',
|
||||||
'transport_passive_only'
|
'transport_passive_only',
|
||||||
]
|
]
|
||||||
PARAM_TO_COMMAND_KEYMAP = {
|
PARAM_TO_COMMAND_KEYMAP = {
|
||||||
'asn': 'router bgp',
|
'asn': 'router bgp',
|
||||||
|
@ -261,8 +261,8 @@ PARAM_TO_DEFAULT_KEYMAP = {
|
||||||
|
|
||||||
def get_value(arg, config):
|
def get_value(arg, config):
|
||||||
command = PARAM_TO_COMMAND_KEYMAP[arg]
|
command = PARAM_TO_COMMAND_KEYMAP[arg]
|
||||||
has_command = re.search(r'\s+{0}\s*$'.format(command), config, re.M)
|
has_command = re.search(r'^\s+{0}$'.format(command), config, re.M)
|
||||||
has_command_value = re.search(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
|
has_command_val = re.search(r'(?:\s+{0}\s*)(?P<value>.*)$'.format(command), config, re.M)
|
||||||
|
|
||||||
if arg == 'dynamic_capability':
|
if arg == 'dynamic_capability':
|
||||||
has_no_command = re.search(r'\s+no\s{0}\s*$'.format(command), config, re.M)
|
has_no_command = re.search(r'\s+no\s{0}\s*$'.format(command), config, re.M)
|
||||||
|
@ -276,23 +276,21 @@ def get_value(arg, config):
|
||||||
elif arg == 'log_neighbor_changes':
|
elif arg == 'log_neighbor_changes':
|
||||||
value = ''
|
value = ''
|
||||||
if has_command:
|
if has_command:
|
||||||
if has_command_value:
|
value = 'enable'
|
||||||
value = 'disable'
|
elif has_command_val:
|
||||||
else:
|
value = 'disable'
|
||||||
value = 'enable'
|
|
||||||
|
|
||||||
elif arg == 'remove_private_as':
|
elif arg == 'remove_private_as':
|
||||||
value = 'disable'
|
value = 'disable'
|
||||||
if has_command:
|
if has_command:
|
||||||
if has_command_value:
|
value = 'enable'
|
||||||
value = has_command_value.group('value')
|
elif has_command_val:
|
||||||
else:
|
value = has_command_val.group('value')
|
||||||
value = 'enable'
|
|
||||||
else:
|
else:
|
||||||
value = ''
|
value = ''
|
||||||
|
|
||||||
if has_command_value:
|
if has_command_val:
|
||||||
value = has_command_value.group('value')
|
value = has_command_val.group('value')
|
||||||
|
|
||||||
if command in ['timers', 'password']:
|
if command in ['timers', 'password']:
|
||||||
split_value = value.split()
|
split_value = value.split()
|
||||||
|
@ -495,7 +493,7 @@ def main():
|
||||||
|
|
||||||
if candidate:
|
if candidate:
|
||||||
candidate = candidate.items_text()
|
candidate = candidate.items_text()
|
||||||
load_config(module, candidate)
|
warnings.extend(load_config(module, candidate))
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
result['commands'] = candidate
|
result['commands'] = candidate
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -7,6 +7,8 @@ router bgp 65535
|
||||||
vrf test2
|
vrf test2
|
||||||
address-family ipv4 unicast
|
address-family ipv4 unicast
|
||||||
timers bgp 1 10
|
timers bgp 1 10
|
||||||
|
neighbor 3.3.3.4
|
||||||
|
remove-private-as all
|
||||||
neighbor 3.3.3.5
|
neighbor 3.3.3.5
|
||||||
address-family ipv4 unicast
|
address-family ipv4 unicast
|
||||||
maximum-prefix 30 30
|
maximum-prefix 30 30
|
||||||
|
|
|
@ -42,10 +42,17 @@ class TestNxosBgpNeighborModule(TestNxosModule):
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None, device=''):
|
def load_fixtures(self, commands=None, device=''):
|
||||||
self.get_config.return_value = load_fixture('', 'nxos_bgp_config.cfg')
|
self.get_config.return_value = load_fixture('nxos_bgp', 'config.cfg')
|
||||||
self.load_config.return_value = None
|
self.load_config.return_value = []
|
||||||
|
|
||||||
def test_nxos_bgp_neighbor(self):
|
def test_nxos_bgp_neighbor(self):
|
||||||
set_module_args(dict(asn=65535, neighbor='3.3.3.3', description='some words'))
|
set_module_args(dict(asn=65535, neighbor='3.3.3.3', description='some words'))
|
||||||
result = self.execute_module(changed=True)
|
self.execute_module(changed=True, commands=['router bgp 65535', 'neighbor 3.3.3.3', 'description some words'])
|
||||||
self.assertEqual(result['commands'], ['router bgp 65535', 'neighbor 3.3.3.3', 'description some words'])
|
|
||||||
|
def test_nxos_bgp_neighbor_remove_private_as(self):
|
||||||
|
set_module_args(dict(asn=65535, neighbor='3.3.3.4', remove_private_as='all'))
|
||||||
|
self.execute_module(changed=False, commands=[])
|
||||||
|
|
||||||
|
def test_nxos_bgp_neighbor_remove_private_as_changed(self):
|
||||||
|
set_module_args(dict(asn=65535, neighbor='3.3.3.4', remove_private_as='replace-as'))
|
||||||
|
self.execute_module(changed=True, commands=['router bgp 65535', 'neighbor 3.3.3.4', 'remove-private-as replace-as'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue