From 240de965ee9c7463bf3c700bfaae847acfae05fc Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Thu, 29 Jun 2017 14:55:08 -0400 Subject: [PATCH] Fix nxos_acl module and add IT tests (#25966) * Fix nxos_acl module and add IT tests * Add nxos_acl test * Add additional properties to test --- lib/ansible/modules/network/nxos/nxos_acl.py | 3 +- test/integration/nxos.yaml | 1 + .../targets/nxos_acl/defaults/main.yaml | 2 + .../targets/nxos_acl/meta/main.yml | 2 + .../targets/nxos_acl/tasks/cli.yaml | 15 +++++ .../targets/nxos_acl/tasks/main.yaml | 3 + .../targets/nxos_acl/tasks/nxapi.yaml | 28 +++++++++ .../targets/nxos_acl/tests/cli/sanity.yaml | 48 +++++++++++++++ .../targets/nxos_acl/tests/nxapi/sanity.yaml | 61 +++++++++++++++++++ .../targets/prepare_nxos_tests/tasks/main.yml | 11 ++-- 10 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 test/integration/targets/nxos_acl/defaults/main.yaml create mode 100644 test/integration/targets/nxos_acl/meta/main.yml create mode 100644 test/integration/targets/nxos_acl/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_acl/tasks/main.yaml create mode 100644 test/integration/targets/nxos_acl/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_acl/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_acl.py b/lib/ansible/modules/network/nxos/nxos_acl.py index 280dd10603..e5b6c26f5a 100644 --- a/lib/ansible/modules/network/nxos/nxos_acl.py +++ b/lib/ansible/modules/network/nxos/nxos_acl.py @@ -227,8 +227,7 @@ from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): - if module.params['transport'] == 'cli': - command += ' | json' + command += ' | json' cmds = [command] body = run_commands(module, cmds) return body diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index 99aa73fb2e..3005389662 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -20,3 +20,4 @@ - { role: nxos_interface, when: "limit_to in ['*', 'nxos_interface']" } - { role: nxos_user, when: "limit_to in ['*', 'nxos_user']" } - { role: nxos_banner, when: "limit_to in ['*', 'nxos_banner']" } + - { role: nxos_acl, when: "limit_to in ['*', 'nxos_acl']" } diff --git a/test/integration/targets/nxos_acl/defaults/main.yaml b/test/integration/targets/nxos_acl/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/nxos_acl/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_acl/meta/main.yml b/test/integration/targets/nxos_acl/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_acl/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_acl/tasks/cli.yaml b/test/integration/targets/nxos_acl/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/nxos_acl/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_acl/tasks/main.yaml b/test/integration/targets/nxos_acl/tasks/main.yaml new file mode 100644 index 0000000000..4b0f8c64d9 --- /dev/null +++ b/test/integration/targets/nxos_acl/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_acl/tasks/nxapi.yaml b/test/integration/targets/nxos_acl/tasks/nxapi.yaml new file mode 100644 index 0000000000..ea525379f7 --- /dev/null +++ b/test/integration/targets/nxos_acl/tasks/nxapi.yaml @@ -0,0 +1,28 @@ +--- +- name: collect all nxapi test cases + find: + paths: "{{ role_path }}/tests/nxapi" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: enable nxapi + nxos_config: + lines: + - feature nxapi + - nxapi http port 80 + provider: "{{ cli }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +- name: disable nxapi + nxos_config: + lines: + - no feature nxapi + provider: "{{ cli }}" diff --git a/test/integration/targets/nxos_acl/tests/cli/sanity.yaml b/test/integration/targets/nxos_acl/tests/cli/sanity.yaml new file mode 100644 index 0000000000..f8ef234b8d --- /dev/null +++ b/test/integration/targets/nxos_acl/tests/cli/sanity.yaml @@ -0,0 +1,48 @@ +--- +- debug: msg="START TRANSPORT:CLI nxos_acl sanity test" + +- name: "Setup: Cleanup possibly existing acl." + nxos_acl: &remove + name: TEST_ACL + seq: 10 + state: absent + provider: "{{ cli }}" + ignore_errors: yes + +- name: "Configure ACL" + nxos_acl: &configure + name: TEST_ACL + seq: 10 + action: permit + proto: tcp + src: 1.1.1.1/24 + dest: any + state: present + provider: "{{ cli }}" + register: result + +- assert: &true + that: + - "result.changed == true" + +- name: "Check Idempotence" + nxos_acl: *configure + register: result + +- assert: &false + that: + - "result.changed == false" + +- name: "Remove ACL" + nxos_acl: *remove + register: result + +- assert: *true + +- name: "Check Idempotence" + nxos_acl: *remove + register: result + +- assert: *false + +- debug: msg="END TRANSPORT:CLI nxos_acl sanity test" diff --git a/test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml new file mode 100644 index 0000000000..9f561394c2 --- /dev/null +++ b/test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml @@ -0,0 +1,61 @@ +--- +- debug: msg="START TRANSPORT:NXAPI nxos_acl sanity test" + +- name: "Setup: Cleanup possibly existing acl." + nxos_acl: &remove + name: TEST_ACL + seq: 10 + state: absent + provider: "{{ nxapi }}" + ignore_errors: yes + +- name: "Configure ACL" + nxos_acl: &configure + name: TEST_ACL + seq: 10 + action: permit + proto: tcp + src: 1.1.1.1/24 + src_port_op: range + src_port1: 5 + src_port2: 20 + ack: 'enable' + dscp: 'af43' + dest: any + urg: 'enable' + psh: 'enable' + established: 'enable' + log: 'enable' + fin: 'enable' + rst: 'enable' + syn: 'enable' + time_range: 'ans-range' + state: present + provider: "{{ nxapi }}" + register: result + +- assert: &true + that: + - "result.changed == true" + +- name: "Check Idempotence" + nxos_acl: *configure + register: result + +- assert: &false + that: + - "result.changed == false" + +- name: "Remove ACL" + nxos_acl: *remove + register: result + +- assert: *true + +- name: "Check Idempotence" + nxos_acl: *remove + register: result + +- assert: *false + +- debug: msg="END TRANSPORT:NXAPI nxos_acl sanity test" diff --git a/test/integration/targets/prepare_nxos_tests/tasks/main.yml b/test/integration/targets/prepare_nxos_tests/tasks/main.yml index ec806bd057..80b60240e0 100644 --- a/test/integration/targets/prepare_nxos_tests/tasks/main.yml +++ b/test/integration/targets/prepare_nxos_tests/tasks/main.yml @@ -1,6 +1,9 @@ +# NXAPI is enabled differently on NX-OS platforms. +# Try both commands to enable NXAPI and ignore any errors. - name: enable nxapi on remote device - nxos_nxapi: - http: yes - sandbox: yes - state: present + nxos_config: + lines: + - feature cli + - feature cli sandbox provider: "{{ cli }}" + ignore_errors: yes