From babec35faafe18c6e30515c28cd569c65b90cefd Mon Sep 17 00:00:00 2001 From: saichint Date: Tue, 8 Aug 2017 09:40:22 -0700 Subject: [PATCH] Fix nxos_vtp_password and nxos_vrf_interface for remove idempotency tests (#27724) * fixes for 27600 27676 * add sanity tests --- .../network/nxos/nxos_vrf_interface.py | 4 +- .../modules/network/nxos/nxos_vtp_password.py | 5 +- .../nxos_vrf_interface/tasks/main.yaml | 8 ++- .../nxos_vrf_interface/tests/cli/sanity.yaml | 39 +----------- .../tests/common/sanity.yaml | 61 +++++++++++++++++++ .../tests/nxapi/sanity.yaml | 39 +----------- .../targets/nxos_vtp_password/tasks/main.yaml | 8 ++- .../nxos_vtp_password/tests/cli/sanity.yaml | 30 +-------- .../tests/common/sanity.yaml | 57 +++++++++++++++++ .../nxos_vtp_password/tests/nxapi/sanity.yaml | 30 +-------- 10 files changed, 145 insertions(+), 136 deletions(-) create mode 100644 test/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml create mode 100644 test/integration/targets/nxos_vtp_password/tests/common/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index f6a3973ada1..d6b55d4c6f7 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -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.', diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_password.py b/lib/ansible/modules/network/nxos/nxos_vtp_password.py index f7e161475ac..dde4293a884 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_password.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_password.py @@ -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: diff --git a/test/integration/targets/nxos_vrf_interface/tasks/main.yaml b/test/integration/targets/nxos_vrf_interface/tasks/main.yaml index 4b0f8c64d90..fea9337c14c 100644 --- a/test/integration/targets/nxos_vrf_interface/tasks/main.yaml +++ b/test/integration/targets/nxos_vrf_interface/tasks/main.yaml @@ -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'] } diff --git a/test/integration/targets/nxos_vrf_interface/tests/cli/sanity.yaml b/test/integration/targets/nxos_vrf_interface/tests/cli/sanity.yaml index d7abe2b6f7f..5cdeee4a98f 100644 --- a/test/integration/targets/nxos_vrf_interface/tests/cli/sanity.yaml +++ b/test/integration/targets/nxos_vrf_interface/tests/cli/sanity.yaml @@ -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 diff --git a/test/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml b/test/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml new file mode 100644 index 00000000000..9bfe740f093 --- /dev/null +++ b/test/integration/targets/nxos_vrf_interface/tests/common/sanity.yaml @@ -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" diff --git a/test/integration/targets/nxos_vrf_interface/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vrf_interface/tests/nxapi/sanity.yaml index 162d000406a..d239bab0f8f 100644 --- a/test/integration/targets/nxos_vrf_interface/tests/nxapi/sanity.yaml +++ b/test/integration/targets/nxos_vrf_interface/tests/nxapi/sanity.yaml @@ -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 diff --git a/test/integration/targets/nxos_vtp_password/tasks/main.yaml b/test/integration/targets/nxos_vtp_password/tasks/main.yaml index 4b0f8c64d90..fea9337c14c 100644 --- a/test/integration/targets/nxos_vtp_password/tasks/main.yaml +++ b/test/integration/targets/nxos_vtp_password/tasks/main.yaml @@ -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'] } diff --git a/test/integration/targets/nxos_vtp_password/tests/cli/sanity.yaml b/test/integration/targets/nxos_vtp_password/tests/cli/sanity.yaml index f96cb146c7a..3e930f98dd7 100644 --- a/test/integration/targets/nxos_vtp_password/tests/cli/sanity.yaml +++ b/test/integration/targets/nxos_vtp_password/tests/cli/sanity.yaml @@ -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 diff --git a/test/integration/targets/nxos_vtp_password/tests/common/sanity.yaml b/test/integration/targets/nxos_vtp_password/tests/common/sanity.yaml new file mode 100644 index 00000000000..b35a876dc33 --- /dev/null +++ b/test/integration/targets/nxos_vtp_password/tests/common/sanity.yaml @@ -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" diff --git a/test/integration/targets/nxos_vtp_password/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vtp_password/tests/nxapi/sanity.yaml index 8851b213bee..326d4cafcea 100644 --- a/test/integration/targets/nxos_vtp_password/tests/nxapi/sanity.yaml +++ b/test/integration/targets/nxos_vtp_password/tests/nxapi/sanity.yaml @@ -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