Skip to content

Commit

Permalink
Fix nxos_vtp_password and nxos_vrf_interface for remove idempotency t…
Browse files Browse the repository at this point in the history
…ests (ansible#27724)

* fixes for 27600 27676

* add sanity tests
  • Loading branch information
saichint authored and Qalthos committed Aug 8, 2017
1 parent 63d0ea3 commit babec35
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 136 deletions.
4 changes: 3 additions & 1 deletion lib/ansible/modules/network/nxos/nxos_vrf_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ def main():
changed = False
end_state = existing

if vrf != existing['vrf'] and state == 'absent':
if not existing['vrf']:
pass
elif vrf != existing['vrf'] and state == 'absent':
module.fail_json(msg='The VRF you are trying to remove '
'from the interface does not exist '
'on that interface.',
Expand Down
5 changes: 4 additions & 1 deletion lib/ansible/modules/network/nxos/nxos_vtp_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ def main():

commands = []
if state == 'absent':
if vtp_password is not None:
# if vtp_password is not set, some devices returns '\\'
if not existing['vtp_password'] or existing['vtp_password'] == '\\':
pass
elif vtp_password is not None:
if existing['vtp_password'] == proposed['vtp_password']:
commands.append(['no vtp password'])
else:
Expand Down
8 changes: 6 additions & 2 deletions test/integration/targets/nxos_vrf_interface/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { include: nxapi.yaml, tags: ['nxapi'] }
# Use block to ensure that both cli and nxapi tests
# will run even if there are failures or errors.
- block:
- { include: cli.yaml, tags: ['cli'] }
always:
- { include: nxapi.yaml, tags: ['nxapi'] }
39 changes: 2 additions & 37 deletions test/integration/targets/nxos_vrf_interface/tests/cli/sanity.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
---
- debug: msg="START TRANSPORT:CLI nxos_vrf_interface sanity test"
- set_fact: connection="{{ cli }}"

# Select interface for test
- set_fact: intname="{{ nxos_int1 }}"

- block:
- name: put interface in L3
nxos_config:
commands:
- no switchport
parents:
- "interface {{ intname }}"
match: none
provider: "{{ cli }}"

- name: Ensure vrf ntc exists on interface
nxos_vrf_interface:
vrf: ntc
interface: "{{ intname }}"
state: present
provider: "{{ cli }}"

- name: Ensure ntc VRF does not exist on interface
nxos_vrf_interface:
vrf: ntc
interface: "{{ intname }}"
state: absent
provider: "{{ cli }}"

always:
- name: put interface in default mode
nxos_config:
lines: "default interface {{ intname }}"
provider: "{{ cli }}"
match: none
ignore_errors: yes

- debug: msg="END TRANSPORT:CLI nxos_vrf_interface sanity test"
- import_tasks: targets/nxos_vrf_interface/tests/common/sanity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vrf_interface sanity test"

# Select interface for test
- set_fact: intname="{{ nxos_int1 }}"

- block:
- name: put interface in L3
nxos_config:
commands:
- no switchport
parents:
- "interface {{ intname }}"
match: none
provider: "{{ connection }}"

- name: Ensure vrf ntc exists on interface
nxos_vrf_interface: &configure
vrf: ntc
interface: "{{ intname }}"
state: present
provider: "{{ connection }}"
register: result

- assert: &true
that:
- "result.changed == true"

- name: "Conf Idempotence"
nxos_vrf_interface: *configure
register: result

- assert: &false
that:
- "result.changed == false"

- name: Ensure ntc VRF does not exist on interface
nxos_vrf_interface: &remove
vrf: ntc
interface: "{{ intname }}"
state: absent
provider: "{{ connection }}"
register: result

- assert: *true

- name: "Remove Idempotence"
nxos_vrf_interface: *remove
register: result

- assert: *false

always:
- name: put interface in default mode
nxos_config:
lines: "default interface {{ intname }}"
provider: "{{ connection }}"
match: none
ignore_errors: yes

- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vrf_interface sanity test"
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
---
- debug: msg="START TRANSPORT:NXAPI nxos_vrf_interface sanity test"
- set_fact: connection="{{ nxapi }}"

# Select interface for test
- set_fact: intname="{{ nxos_int1 }}"

- block:
- name: put interface in L3
nxos_config:
commands:
- no switchport
parents:
- "interface {{ intname }}"
match: none
provider: "{{ nxapi }}"

- name: Ensure vrf ntc exists on interface
nxos_vrf_interface:
vrf: ntc
interface: "{{ intname }}"
state: present
provider: "{{ nxapi }}"

- name: Ensure ntc VRF does not exist on interface
nxos_vrf_interface:
vrf: ntc
interface: "{{ intname }}"
state: absent
provider: "{{ nxapi }}"

always:
- name: put interface in default mode
nxos_config:
lines: "default interface {{ intname }}"
provider: "{{ nxapi }}"
match: none
ignore_errors: yes

- debug: msg="END TRANSPORT:NXAPI nxos_vrf_interface sanity test"
- import_tasks: targets/nxos_vrf_interface/tests/common/sanity.yaml
8 changes: 6 additions & 2 deletions test/integration/targets/nxos_vtp_password/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { include: nxapi.yaml, tags: ['nxapi'] }
# Use block to ensure that both cli and nxapi tests
# will run even if there are failures or errors.
- block:
- { include: cli.yaml, tags: ['cli'] }
always:
- { include: nxapi.yaml, tags: ['nxapi'] }
30 changes: 2 additions & 28 deletions test/integration/targets/nxos_vtp_password/tests/cli/sanity.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
---
- debug: msg="START TRANSPORT:CLI nxos_vtp_password sanity test"
- set_fact: connection="{{ cli }}"

- block:
- name: enable feature vtp
nxos_feature:
feature: vtp
state: enabled
provider: "{{ cli }}"

- name: configure vtp password
nxos_vtp_password:
password: ntc
state: present
provider: "{{ cli }}"

- name: remove vtp password
nxos_vtp_password:
password: ntc
state: absent
provider: "{{ cli }}"

always:
- name: disable feature vtp
nxos_feature:
feature: vtp
state: disabled
provider: "{{ cli }}"

- debug: msg="END TRANSPORT:CLI nxos_vtp_password sanity test"
- import_tasks: targets/nxos_vtp_password/tests/common/sanity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vtp_password sanity test"

- block:
- name: enable feature vtp
nxos_feature:
feature: vtp
state: enabled
provider: "{{ connection }}"

- name: configure vtp domain
nxos_vtp_domain:
domain: testing
provider: "{{ connection }}"

- name: configure vtp password
nxos_vtp_password: &configure
vtp_password: ntc
state: present
provider: "{{ connection }}"
register: result

- assert: &true
that:
- "result.changed == true"

- name: "Conf Idempotence"
nxos_vtp_password: *configure
register: result

- assert: &false
that:
- "result.changed == false"

- name: remove vtp password
nxos_vtp_password: &remove
vtp_password: ntc
state: absent
provider: "{{ connection }}"
register: result

- assert: *true

- name: "Remove Idempotence"
nxos_vtp_password: *remove
register: result

- assert: *false

always:
- name: disable feature vtp
nxos_feature:
feature: vtp
state: disabled
provider: "{{ connection }}"

- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vtp_password sanity test"
30 changes: 2 additions & 28 deletions test/integration/targets/nxos_vtp_password/tests/nxapi/sanity.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
---
- debug: msg="START TRANSPORT:NXAPI nxos_vtp_password sanity test"
- set_fact: connection="{{ nxapi }}"

- block:
- name: enable feature vtp
nxos_feature:
feature: vtp
state: enabled
provider: "{{ nxapi }}"

- name: configure vtp password
nxos_vtp_password:
password: ntc
state: present
provider: "{{ nxapi }}"

- name: remove vtp password
nxos_vtp_password:
password: ntc
state: absent
provider: "{{ nxapi }}"

always:
- name: disable feature vtp
nxos_feature:
feature: vtp
state: disabled
provider: "{{ nxapi }}"

- debug: msg="END TRANSPORT:NXAPI nxos_vtp_password sanity test"
- import_tasks: targets/nxos_vtp_password/tests/common/sanity.yaml

0 comments on commit babec35

Please sign in to comment.