From f2c34d51f2442e71a1b515068c242e98e10a7a65 Mon Sep 17 00:00:00 2001 From: David Newswanger Date: Thu, 17 Aug 2017 04:18:00 -0400 Subject: [PATCH] nxos: merge nxapi/cli tests - system, user, vlan, vrf (#28241) * refactor nxos_system * refactor nxos_user * refactor nxos_vlan * refactor nxos_vrf --- .../targets/nxos_system/tasks/cli.yaml | 17 +++-- .../targets/nxos_system/tasks/nxapi.yaml | 17 +++-- .../tests/{cli => common}/set_hostname.yaml | 12 ++-- .../set_lookup_source.yaml-not-on-nxos | 16 ++--- .../nxos_system/tests/nxapi/set_hostname.yaml | 36 ---------- .../nxapi/set_lookup_source.yaml-not-on-nxos | 68 ------------------- .../targets/nxos_user/tasks/cli.yaml | 16 ++++- .../targets/nxos_user/tasks/nxapi.yaml | 18 +++-- .../tests/{cli => common}/basic.yaml | 8 +-- .../targets/nxos_user/tests/nxapi/basic.yaml | 53 --------------- .../targets/nxos_vlan/tasks/cli.yaml | 16 ++++- .../targets/nxos_vlan/tasks/nxapi.yaml | 16 ++++- .../targets/nxos_vlan/tests/cli/sanity.yaml | 4 -- .../targets/nxos_vlan/tests/nxapi/sanity.yaml | 4 -- .../targets/nxos_vrf/tasks/cli.yaml | 16 ++++- .../targets/nxos_vrf/tasks/nxapi.yaml | 16 ++++- .../targets/nxos_vrf/tests/cli/sanity.yaml | 15 ---- .../targets/nxos_vrf/tests/common/sanity.yaml | 15 ++++ .../targets/nxos_vrf/tests/nxapi/sanity.yaml | 15 ---- 19 files changed, 137 insertions(+), 241 deletions(-) rename test/integration/targets/nxos_system/tests/{cli => common}/set_hostname.yaml (62%) rename test/integration/targets/nxos_system/tests/{cli => common}/set_lookup_source.yaml-not-on-nxos (78%) delete mode 100644 test/integration/targets/nxos_system/tests/nxapi/set_hostname.yaml delete mode 100644 test/integration/targets/nxos_system/tests/nxapi/set_lookup_source.yaml-not-on-nxos rename test/integration/targets/nxos_user/tests/{cli => common}/basic.yaml (87%) delete mode 100644 test/integration/targets/nxos_user/tests/nxapi/basic.yaml delete mode 100644 test/integration/targets/nxos_vlan/tests/cli/sanity.yaml delete mode 100644 test/integration/targets/nxos_vlan/tests/nxapi/sanity.yaml delete mode 100644 test/integration/targets/nxos_vrf/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_vrf/tests/common/sanity.yaml delete mode 100644 test/integration/targets/nxos_vrf/tests/nxapi/sanity.yaml diff --git a/test/integration/targets/nxos_system/tasks/cli.yaml b/test/integration/targets/nxos_system/tasks/cli.yaml index 46d86dd6988..0ab3f8f9086 100644 --- a/test/integration/targets/nxos_system/tasks/cli.yaml +++ b/test/integration/targets/nxos_system/tasks/cli.yaml @@ -1,16 +1,25 @@ --- -- name: collect all cli test cases +- name: collect common cli test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect cli test cases find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost + register: cli_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ cli_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ cli }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_system/tasks/nxapi.yaml b/test/integration/targets/nxos_system/tasks/nxapi.yaml index fc67dff2301..e071f293a2b 100644 --- a/test/integration/targets/nxos_system/tasks/nxapi.yaml +++ b/test/integration/targets/nxos_system/tasks/nxapi.yaml @@ -1,10 +1,19 @@ --- -- name: collect all nxapi test cases +- name: collect common nxapi test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect nxapi test cases find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" - register: test_cases - delegate_to: localhost + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" @@ -17,7 +26,7 @@ provider: "{{ cli }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ nxapi }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_system/tests/cli/set_hostname.yaml b/test/integration/targets/nxos_system/tests/common/set_hostname.yaml similarity index 62% rename from test/integration/targets/nxos_system/tests/cli/set_hostname.yaml rename to test/integration/targets/nxos_system/tests/common/set_hostname.yaml index 8d82137d7c0..6c252dba185 100644 --- a/test/integration/targets/nxos_system/tests/cli/set_hostname.yaml +++ b/test/integration/targets/nxos_system/tests/common/set_hostname.yaml @@ -1,16 +1,16 @@ --- -- debug: msg="START cli/set_hostname.yaml" +- debug: msg="START {{ connection.transport }}/set_hostname.yaml" - name: setup nxos_config: lines: hostname switch match: none - provider: "{{ cli }}" + provider: "{{ connection }}" - name: configure hostname nxos_system: hostname: foo - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -20,7 +20,7 @@ - name: verify hostname nxos_system: hostname: foo - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -31,6 +31,6 @@ nxos_config: lines: "hostname {{ inventory_hostname }}" match: none - provider: "{{ cli }}" + provider: "{{ connection }}" -- debug: msg="END cli/set_hostname.yaml" +- debug: msg="END {{ connection.transport }}/set_hostname.yaml" diff --git a/test/integration/targets/nxos_system/tests/cli/set_lookup_source.yaml-not-on-nxos b/test/integration/targets/nxos_system/tests/common/set_lookup_source.yaml-not-on-nxos similarity index 78% rename from test/integration/targets/nxos_system/tests/cli/set_lookup_source.yaml-not-on-nxos rename to test/integration/targets/nxos_system/tests/common/set_lookup_source.yaml-not-on-nxos index 4a39a498827..087209245da 100644 --- a/test/integration/targets/nxos_system/tests/cli/set_lookup_source.yaml-not-on-nxos +++ b/test/integration/targets/nxos_system/tests/common/set_lookup_source.yaml-not-on-nxos @@ -1,5 +1,5 @@ --- -- debug: msg="START cli/set_lookup_source.yaml" +- debug: msg="START {{ connection.transport }}/set_lookup_source.yaml" - name: setup nxos_config: @@ -7,12 +7,12 @@ - no ip domain lookup source-interface - vrf definition ansible match: none - provider: "{{ cli }}" + provider: "{{ connection }}" - name: configure lookup_source nxos_system: lookup_source: Management1 - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -23,7 +23,7 @@ - name: verify lookup_source nxos_system: lookup_source: Management1 - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -35,7 +35,7 @@ lookup_source: - interface: Management1 vrf: ansible - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -50,7 +50,7 @@ lookup_source: - interface: Management1 vrf: ansible - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -63,6 +63,6 @@ - no ip domain lookup source-interface - no vrf definition ansible match: none - provider: "{{ cli }}" + provider: "{{ connection }}" -- debug: msg="END cli/set_lookup_source.yaml" +- debug: msg="END {{ connection.transport }}/set_lookup_source.yaml" diff --git a/test/integration/targets/nxos_system/tests/nxapi/set_hostname.yaml b/test/integration/targets/nxos_system/tests/nxapi/set_hostname.yaml deleted file mode 100644 index 74398c800aa..00000000000 --- a/test/integration/targets/nxos_system/tests/nxapi/set_hostname.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- debug: msg="START nxapi/set_hostname.yaml" - -- name: setup - nxos_config: - lines: hostname switch - match: none - provider: "{{ nxapi }}" - -- name: configure hostname - nxos_system: - hostname: foo - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - "result.changed == true" - -- name: verify hostname - nxos_system: - hostname: foo - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - "result.changed == false" - -- name: teardown - nxos_config: - lines: "hostname {{ inventory_hostname }}" - match: none - provider: "{{ nxapi }}" - -- debug: msg="END nxapi/set_hostname.yaml" diff --git a/test/integration/targets/nxos_system/tests/nxapi/set_lookup_source.yaml-not-on-nxos b/test/integration/targets/nxos_system/tests/nxapi/set_lookup_source.yaml-not-on-nxos deleted file mode 100644 index 7a39bb24923..00000000000 --- a/test/integration/targets/nxos_system/tests/nxapi/set_lookup_source.yaml-not-on-nxos +++ /dev/null @@ -1,68 +0,0 @@ ---- -- debug: msg="START nxapi/set_lookup_source.yaml" - -- name: setup - nxos_config: - lines: - - no ip domain lookup source-interface - - vrf definition ansible - match: none - provider: "{{ nxapi }}" - -- name: configure lookup_source - nxos_system: - lookup_source: Management1 - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - result.changed == true - - "'ip domain lookup source-interface Management1' in result.commands" - -- name: verify lookup_source - nxos_system: - lookup_source: Management1 - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - result.changed == false - -- name: change to vrf - nxos_system: - lookup_source: - - interface: Management1 - vrf: ansible - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - result.changed == true - - "'no ip domain lookup source-interface Management1' in result.commands" - - "'ip domain lookup vrf ansible source-interface Management1' in result.commands" - - result.commands|length == 2 - -- name: verify change to vrf - nxos_system: - lookup_source: - - interface: Management1 - vrf: ansible - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - result.changed == false - -- name: teardown - nxos_config: - lines: - - no ip domain lookup source-interface - - no vrf definition ansible - match: none - provider: "{{ nxapi }}" - -- debug: msg="END nxapi/set_lookup_source.yaml" diff --git a/test/integration/targets/nxos_user/tasks/cli.yaml b/test/integration/targets/nxos_user/tasks/cli.yaml index d675462dd02..0ab3f8f9086 100644 --- a/test/integration/targets/nxos_user/tasks/cli.yaml +++ b/test/integration/targets/nxos_user/tasks/cli.yaml @@ -1,15 +1,25 @@ --- -- name: collect all cli test cases +- name: collect common cli test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect cli test cases find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" - register: test_cases + register: cli_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ cli_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ cli }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_user/tasks/nxapi.yaml b/test/integration/targets/nxos_user/tasks/nxapi.yaml index 5fb9cedaa60..e071f293a2b 100644 --- a/test/integration/targets/nxos_user/tasks/nxapi.yaml +++ b/test/integration/targets/nxos_user/tasks/nxapi.yaml @@ -1,9 +1,19 @@ --- -- name: collect all nxapi test cases +- name: collect common nxapi test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect nxapi test cases find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" - register: test_cases + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" @@ -14,10 +24,9 @@ - feature nxapi - nxapi http port 80 provider: "{{ cli }}" - timeout: 100 - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ nxapi }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run @@ -27,4 +36,3 @@ lines: - no feature nxapi provider: "{{ cli }}" - timeout: 100 diff --git a/test/integration/targets/nxos_user/tests/cli/basic.yaml b/test/integration/targets/nxos_user/tests/common/basic.yaml similarity index 87% rename from test/integration/targets/nxos_user/tests/cli/basic.yaml rename to test/integration/targets/nxos_user/tests/common/basic.yaml index 44a46a28d74..764156a6aca 100644 --- a/test/integration/targets/nxos_user/tests/cli/basic.yaml +++ b/test/integration/targets/nxos_user/tests/common/basic.yaml @@ -6,7 +6,7 @@ - name: ansibletest2 - name: ansibletest3 state: absent - provider: "{{ cli }}" + provider: "{{ connection }}" # Start tests - name: Create user @@ -14,7 +14,7 @@ name: ansibletest1 roles: network-operator state: present - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -30,7 +30,7 @@ - name: ansibletest3 state: present roles: network-admin - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: @@ -44,7 +44,7 @@ - name: ansibletest2 - name: ansibletest3 state: absent - provider: "{{ cli }}" + provider: "{{ connection }}" register: result - assert: diff --git a/test/integration/targets/nxos_user/tests/nxapi/basic.yaml b/test/integration/targets/nxos_user/tests/nxapi/basic.yaml deleted file mode 100644 index 553193955a7..00000000000 --- a/test/integration/targets/nxos_user/tests/nxapi/basic.yaml +++ /dev/null @@ -1,53 +0,0 @@ ---- -- name: Remove old entries of user - nxos_user: - aggregate: - - name: ansibletest1 - - name: ansibletest2 - - name: ansibletest3 - state: absent - provider: "{{ nxapi }}" - -# Start tests -- name: Create user - nxos_user: - name: ansibletest1 - roles: network-operator - state: present - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - 'result.changed == true' - - '"username" in result.commands[0]' - - '"role network-operator" in result.commands[1]' - -- name: Collection of users - nxos_user: - aggregate: - - name: ansibletest2 - - name: ansibletest3 - state: present - roles: network-admin - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - 'result.changed == true' - -- name: tearDown - nxos_user: - aggregate: - - name: ansibletest1 - - name: ansibletest2 - - name: ansibletest3 - state: absent - provider: "{{ nxapi }}" - register: result - -- assert: - that: - - 'result.changed == true' - - '"no username" in result.commands[0]' diff --git a/test/integration/targets/nxos_vlan/tasks/cli.yaml b/test/integration/targets/nxos_vlan/tasks/cli.yaml index d675462dd02..0ab3f8f9086 100644 --- a/test/integration/targets/nxos_vlan/tasks/cli.yaml +++ b/test/integration/targets/nxos_vlan/tasks/cli.yaml @@ -1,15 +1,25 @@ --- -- name: collect all cli test cases +- name: collect common cli test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect cli test cases find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" - register: test_cases + register: cli_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ cli_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ cli }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_vlan/tasks/nxapi.yaml b/test/integration/targets/nxos_vlan/tasks/nxapi.yaml index ea525379f7f..e071f293a2b 100644 --- a/test/integration/targets/nxos_vlan/tasks/nxapi.yaml +++ b/test/integration/targets/nxos_vlan/tasks/nxapi.yaml @@ -1,9 +1,19 @@ --- -- name: collect all nxapi test cases +- name: collect common nxapi test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect nxapi test cases find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" - register: test_cases + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" @@ -16,7 +26,7 @@ provider: "{{ cli }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ nxapi }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_vlan/tests/cli/sanity.yaml b/test/integration/targets/nxos_vlan/tests/cli/sanity.yaml deleted file mode 100644 index d1bc8aa2a9f..00000000000 --- a/test/integration/targets/nxos_vlan/tests/cli/sanity.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- set_fact: connection="{{ cli }}" - -- import_tasks: targets/nxos_vlan/tests/common/sanity.yaml diff --git a/test/integration/targets/nxos_vlan/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vlan/tests/nxapi/sanity.yaml deleted file mode 100644 index 1613c28ce83..00000000000 --- a/test/integration/targets/nxos_vlan/tests/nxapi/sanity.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- set_fact: connection="{{ nxapi }}" - -- import_tasks: targets/nxos_vlan/tests/common/sanity.yaml diff --git a/test/integration/targets/nxos_vrf/tasks/cli.yaml b/test/integration/targets/nxos_vrf/tasks/cli.yaml index d675462dd02..0ab3f8f9086 100644 --- a/test/integration/targets/nxos_vrf/tasks/cli.yaml +++ b/test/integration/targets/nxos_vrf/tasks/cli.yaml @@ -1,15 +1,25 @@ --- -- name: collect all cli test cases +- name: collect common cli test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect cli test cases find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" - register: test_cases + register: cli_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ cli_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ cli }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_vrf/tasks/nxapi.yaml b/test/integration/targets/nxos_vrf/tasks/nxapi.yaml index ea525379f7f..e071f293a2b 100644 --- a/test/integration/targets/nxos_vrf/tasks/nxapi.yaml +++ b/test/integration/targets/nxos_vrf/tasks/nxapi.yaml @@ -1,9 +1,19 @@ --- -- name: collect all nxapi test cases +- name: collect common nxapi test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: collect nxapi test cases find: paths: "{{ role_path }}/tests/nxapi" patterns: "{{ testcase }}.yaml" - register: test_cases + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" - name: set test_items set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" @@ -16,7 +26,7 @@ provider: "{{ cli }}" - name: run test case - include: "{{ test_case_to_run }}" + include: "{{ test_case_to_run }} connection={{ nxapi }}" with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_vrf/tests/cli/sanity.yaml b/test/integration/targets/nxos_vrf/tests/cli/sanity.yaml deleted file mode 100644 index 8b02508be07..00000000000 --- a/test/integration/targets/nxos_vrf/tests/cli/sanity.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- debug: msg="START TRANSPORT:CLI nxos_vrf sanity test" - -- name: Ensure ntc VRF exists on switch - nxos_vrf: - vrf: ntc - provider: "{{ cli }}" - -- name: Ensure ntc VRF does not exist on switch - nxos_vrf: - vrf: ntc - state: absent - provider: "{{ cli }}" - -- debug: msg="END TRANSPORT:CLI nxos_vrf sanity test" diff --git a/test/integration/targets/nxos_vrf/tests/common/sanity.yaml b/test/integration/targets/nxos_vrf/tests/common/sanity.yaml new file mode 100644 index 00000000000..2f6cad64e40 --- /dev/null +++ b/test/integration/targets/nxos_vrf/tests/common/sanity.yaml @@ -0,0 +1,15 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vrf sanity test" + +- name: Ensure ntc VRF exists on switch + nxos_vrf: + vrf: ntc + provider: "{{ connection }}" + +- name: Ensure ntc VRF does not exist on switch + nxos_vrf: + vrf: ntc + state: absent + provider: "{{ connection }}" + +- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vrf sanity test" diff --git a/test/integration/targets/nxos_vrf/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vrf/tests/nxapi/sanity.yaml deleted file mode 100644 index ca7bab19599..00000000000 --- a/test/integration/targets/nxos_vrf/tests/nxapi/sanity.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- debug: msg="START TRANSPORT:NXAPI nxos_vrf sanity test" - -- name: Ensure ntc VRF exists on switch - nxos_vrf: - vrf: ntc - provider: "{{ nxapi }}" - -- name: Ensure ntc VRF does not exist on switch - nxos_vrf: - vrf: ntc - state: absent - provider: "{{ nxapi }}" - -- debug: msg="END TRANSPORT:NXAPI nxos_vrf sanity test"