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
This commit is contained in:
parent
54c64deaab
commit
240de965ee
10 changed files with 168 additions and 6 deletions
|
@ -227,7 +227,6 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
|
||||
def execute_show_command(command, module):
|
||||
if module.params['transport'] == 'cli':
|
||||
command += ' | json'
|
||||
cmds = [command]
|
||||
body = run_commands(module, cmds)
|
||||
|
|
|
@ -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']" }
|
||||
|
|
2
test/integration/targets/nxos_acl/defaults/main.yaml
Normal file
2
test/integration/targets/nxos_acl/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
2
test/integration/targets/nxos_acl/meta/main.yml
Normal file
2
test/integration/targets/nxos_acl/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nxos_tests
|
15
test/integration/targets/nxos_acl/tasks/cli.yaml
Normal file
15
test/integration/targets/nxos_acl/tasks/cli.yaml
Normal 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
|
3
test/integration/targets/nxos_acl/tasks/main.yaml
Normal file
3
test/integration/targets/nxos_acl/tasks/main.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
- { include: nxapi.yaml, tags: ['nxapi'] }
|
28
test/integration/targets/nxos_acl/tasks/nxapi.yaml
Normal file
28
test/integration/targets/nxos_acl/tasks/nxapi.yaml
Normal 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 }}"
|
48
test/integration/targets/nxos_acl/tests/cli/sanity.yaml
Normal file
48
test/integration/targets/nxos_acl/tests/cli/sanity.yaml
Normal 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"
|
61
test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml
Normal file
61
test/integration/targets/nxos_acl/tests/nxapi/sanity.yaml
Normal 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"
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue