Fix nxos_acl module and add IT tests ()

* Fix nxos_acl module and add IT tests

* Add nxos_acl test

* Add additional properties to test
This commit is contained in:
Mike Wiebe 2017-06-29 14:55:08 -04:00 committed by Nathaniel Case
parent 54c64deaab
commit 240de965ee
10 changed files with 168 additions and 6 deletions
lib/ansible/modules/network/nxos
test/integration
nxos.yaml
targets
nxos_acl
prepare_nxos_tests/tasks

View file

@ -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

View file

@ -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']" }

View file

@ -0,0 +1,2 @@
---
testcase: "*"

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_nxos_tests

View file

@ -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

View file

@ -0,0 +1,3 @@
---
- { include: cli.yaml, tags: ['cli'] }
- { include: nxapi.yaml, tags: ['nxapi'] }

View file

@ -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 }}"

View file

@ -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"

View file

@ -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"

View file

@ -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