From bdb75cd82c81c641e40703ed1e2088a5153ce051 Mon Sep 17 00:00:00 2001 From: saichint Date: Thu, 26 Apr 2018 10:02:14 -0700 Subject: [PATCH] Integration Tests only: nxos_snmp_contact (#39318) * add integration test cases for snmp_contact * removing unnecessary files --- test/integration/nxos.yaml | 9 +++ .../nxos_snmp_contact/defaults/main.yaml | 2 + .../targets/nxos_snmp_contact/meta/main.yml | 2 + .../targets/nxos_snmp_contact/tasks/cli.yaml | 33 ++++++++++ .../targets/nxos_snmp_contact/tasks/main.yaml | 3 + .../nxos_snmp_contact/tasks/nxapi.yaml | 27 ++++++++ .../tests/common/sanity.yaml | 64 +++++++++++++++++++ 7 files changed, 140 insertions(+) create mode 100644 test/integration/targets/nxos_snmp_contact/defaults/main.yaml create mode 100644 test/integration/targets/nxos_snmp_contact/meta/main.yml create mode 100644 test/integration/targets/nxos_snmp_contact/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_snmp_contact/tasks/main.yaml create mode 100644 test/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index 49c8cb0a2a..509dad851d 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -536,6 +536,15 @@ failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_community' ]" test_failed: true + - block: + - include_role: + name: nxos_snmp_contact + when: "limit_to in ['*', 'nxos_snmp_contact']" + rescue: + - set_fact: + failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_contact' ]" + test_failed: true + - block: - include_role: name: nxos_snmp_location diff --git a/test/integration/targets/nxos_snmp_contact/defaults/main.yaml b/test/integration/targets/nxos_snmp_contact/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_snmp_contact/meta/main.yml b/test/integration/targets/nxos_snmp_contact/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_snmp_contact/tasks/cli.yaml b/test/integration/targets/nxos_snmp_contact/tasks/cli.yaml new file mode 100644 index 0000000000..edbff7dfaf --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/tasks/cli.yaml @@ -0,0 +1,33 @@ +--- +- name: collect common cli test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: collect cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + connection: local + 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 cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli connection={}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ cli }}" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_snmp_contact/tasks/main.yaml b/test/integration/targets/nxos_snmp_contact/tasks/main.yaml new file mode 100644 index 0000000000..4b0f8c64d9 --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml b/test/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml new file mode 100644 index 0000000000..68e96a2942 --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/tasks/nxapi.yaml @@ -0,0 +1,27 @@ +--- +- name: collect common nxapi test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: collect nxapi test cases + find: + paths: "{{ role_path }}/tests/nxapi" + patterns: "{{ testcase }}.yaml" + connection: local + 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 }}" + +- name: run test cases (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml b/test/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml new file mode 100644 index 0000000000..b7265f21bd --- /dev/null +++ b/test/integration/targets/nxos_snmp_contact/tests/common/sanity.yaml @@ -0,0 +1,64 @@ +--- +- debug: msg="START connection={{ ansible_connection }} nxos_snmp_community sanity test" +- debug: msg="Using provider={{ connection.transport }}" + when: ansible_connection == "local" + +- name: Setup - Remove snmp_contact if configured + nxos_snmp_contact: &remove + contact: Test + state: absent + provider: "{{ connection }}" + +- block: + + - name: Configure snmp contact + nxos_snmp_contact: &config + contact: Testing + state: present + provider: "{{ connection }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: Idempotence Check + nxos_snmp_contact: *config + register: result + + - assert: &false + that: + - "result.changed == false" + + - name: Change snmp contact + nxos_snmp_contact: &config1 + contact: Test + state: present + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: Idempotence Check + nxos_snmp_contact: *config1 + register: result + + - assert: *false + + - name: Remove snmp contact + nxos_snmp_contact: *remove + register: result + + - assert: *true + + - name: Idempotence Check + nxos_snmp_contact: *remove + register: result + + - assert: *false + + always: + - name: Cleanup + nxos_snmp_contact: *remove + + - debug: msg="END connection={{ ansible_connection }} nxos_snmp_community sanity test"