8000 nxos_bgp_neighbor: Add bfd support by chrisvanheuveln · Pull Request #56932 · ansible/ansible · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

nxos_bgp_neighbor: Add bfd support #56932

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

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
description:
description:
- Description of the neighbor.
bfd:
description:
- Enables/Disables BFD for a given neighbor.
- "Dependency: 'feature bfd'"
version_added: "2.9"
type: str
choices: ['enable', 'disable']
connected_check:
description:
- Configure whether or not to check for directly connected peer.
Expand Down Expand Up @@ -154,6 +161,7 @@
neighbor: 192.0.2.3
local_as: 20
remote_as: 30
bfd: enable
description: "just a description"
update_source: Ethernet1/3
state: present
Expand Down Expand Up @@ -188,6 +196,7 @@
]
PARAM_TO_COMMAND_KEYMAP = {
'asn': 'router bgp',
'bfd': 'bfd',
'capability_negotiation': 'dont-capability-negotiate',
'connected_check': 'disable-connected-check',
'description': 'description',
Expand All @@ -211,6 +220,7 @@
'vrf': 'vrf'
}
PARAM_TO_DEFAULT_KEYMAP = {
'bfd': 'disable',
'shutdown': False,
'dynamic_capability': True,
'timers_keepalive': 60,
Expand Down Expand Up @@ -245,6 +255,8 @@ def get_value(arg, config):
value = 'enable'
elif has_command_val:
value = has_command_val.group('value')
elif arg == 'bfd':
value = 'enable' if has_command else 'disable'
else:
value = ''

Expand Down Expand Up @@ -354,6 +366,9 @@ def state_present(module, existing, proposed, candidate):
proposed['timers_holdtime'])
if command not in commands:
commands.append(command)
elif key == 'bfd':
no_cmd = 'no ' if value == 'disable' else ''
commands.append(no_cmd + key)
else:
command = '{0} {1}'.format(key, value)
commands.append(command)
Expand Down Expand Up @@ -389,6 +404,7 @@ def main():
vrf=dict(required=False, type='str', default='default'),
neighbor=dict(required=True, type='str'),
description=dict(required=False, type='str'),
bfd=dict(required=False, type='str', choices=['enable', 'disable']),
capability_negotiation=dict(required=False, type='bool'),
connected_check=dict(required=False, type='bool'),
dynamic_capability=dict(required=False, type='bool'),
Expand Down Expand Up @@ -442,7 +458,10 @@ def main():
if key not in ['asn', 'vrf', 'neighbor', 'pwd_type']:
if str(value).lower() == 'default':
value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
if existing.get(key) != value:
if key == 'bfd':
if existing.get('bfd', 'disable') != value:
proposed[key] = value
elif existing.get(key) != value:
proposed[key] = value

candidate = CustomNetworkConfig(indent=3)
Expand Down
90 changes: 59 additions & 31 deletions test/integration/targets/nxos_bgp_neighbor/tests/common/sanity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,20 @@
- set_fact: remove_private_asr="replace-as"
when: not titanium

- name: "Enable feature BGP"
- name: "Setup: Disable features"
nxos_feature:
feature: bgp
feature: "{{ item }}"
provider: "{{ connection }}"
state: enabled
ignore_errors: yes

- name: "Setup"
nxos_bgp_neighbor: &removenp
asn: 65535
neighbor: 192.0.2.3
vrf: "{{ item }}"
provider: "{{ connection }}"
state: absent
with_items: "{{ vrfs }}"
state: disabled
loop: ['bgp', 'bfd']
ignore_errors: yes

- name: "Setup"
nxos_bgp_neighbor: &remove
asn: 65535
neighbor: 192.0.2.3/32
vrf: "{{ item }}"
- name: "Setup: Enable features"
nxos_feature:
feature: "{{ item }}"
provider: "{{ connection }}"
state: absent
with_items: "{{ vrfs }}"
ignore_errors: yes
state: enabled
loop: ['bgp', 'bfd']

- block:
- name: "Configure BGP neighbor1"
Expand Down Expand Up @@ -116,7 +104,12 @@
- assert: *false

- name: "Remove BGP"
nxos_bgp_neighbor: *remove
nxos_bgp_neighbor: &remove
asn: 65535
neighbor: 192.0.2.3/32
vrf: "{{ item }}"
provider: "{{ connection }}"
state: absent
with_items: "{{ vrfs }}"
register: result

Expand Down Expand Up @@ -291,7 +284,12 @@
- assert: *false

- name: "Remove BGP"
nxos_bgp_neighbor: *removenp
nxos_bgp_neighbor: &removenp
asn: 65535
neighbor: 192.0.2.3
vrf: "{{ item }}"
provider: "{{ connection }}"
state: absent
with_items: "{{ vrfs }}"
register: result

Expand All @@ -304,17 +302,47 @@

- assert: *false

rescue:
- name: "Cleanup BGP"
nxos_bgp_neighbor: *remove
with_items: "{{ vrfs }}"
ignore_errors: yes
- name: "Configure BFD enable"
nxos_bgp_neighbor: &bfd_enable
asn: 65535
neighbor: 192.168.1.1
bfd: enable
DD41 provider: "{{ connection }}"
state: present
register: result

- assert: *true

- name: Check BFD enable Idempotence
nxos_bgp_neighbor: *bfd_enable
register: result

- assert: *false

- name: Configure BFD disable Idempotence
nxos_bgp_neighbor: &bfd_disable
asn: 65535
neighbor: 192.168.1.1
bfd: disable
provider: "{{ connection }}"
state: present
register: result

- assert: *true

- name: Check BFD disable Idempotence
nxos_bgp_neighbor: *bfd_disable
register: result

- assert: *false

always:
- name: "Disable feature bgp"
nxos_feature: &disable_bgp
feature: bgp
- name: "Teardown: Disable features"
nxos_feature:
feature: "{{ item }}"
provider: "{{ connection }}"
state: disabled
loop: ['bgp', 'bfd']
ignore_errors: yes

- debug: msg="END connection={{ ansible_connection }} nxos_bgp_neighbor sanity test"
3 changes: 3 additions & 0 deletions test/units/modules/network/nxos/fixtures/nxos_bgp/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ router bgp 65535
vrf test2
address-family ipv4 unicast
timers bgp 1 10
neighbor 1.1.1.1
neighbor 1.1.1.2
bfd
neighbor 3.3.3.4
remove-private-as all
neighbor 3.3.3.5
Expand Down
22 changes: 22 additions & 0 deletions test/units/modules/network/nxos/test_nxos_bgp_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,32 @@ def load_fixtures(self, commands=None, device=''):
self.get_config.return_value = load_fixture('nxos_bgp', 'config.cfg')
self.load_config.return_value = []

def test_nxos_bgp_neighbor_bfd_1(self):
# None (disable) -> enable
set_module_args(dict(asn=65535, neighbor='1.1.1.1', bfd='enable'))
self.execute_module(changed=True, commands=['router bgp 65535', 'neighbor 1.1.1.1', 'bfd'])

# enable -> enable (idempotence)
set_module_args(dict(asn=65535, neighbor='1.1.1.2', bfd='enable'))
< 74B8 span class='blob-code-inner blob-code-marker ' data-code-marker="+"> self.execute_module(changed=False)

def test_nxos_bgp_neighbor_bfd_2(self):
# enable -> None (disable)
set_module_args(dict(asn=65535, neighbor='1.1.1.2', bfd='disable'))
self.execute_module(changed=True, commands=['router bgp 65535', 'neighbor 1.1.1.2', 'no bfd'])

# None (disable) -> disable (idempotence)
set_module_args(dict(asn=65535, neighbor='1.1.1.1', bfd='disable'))
self.execute_module(changed=False)

def test_nxos_bgp_neighbor(self):
set_module_args(dict(asn=65535, neighbor='192.0.2.3', description='some words'))
self.execute_module(changed=True, commands=['router bgp 65535', 'neighbor 192.0.2.3', 'description some words'])

def test_nxos_bgp_neighbor_absent(self):
set_module_args(dict(asn=65535, neighbor='1.1.1.1', state='absent'))
self.execute_module(changed=True, commands=['router bgp 65535', 'no neighbor 1.1.1.1'])

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=[])
Expand Down
0