forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for nxos_acl_interface (ansible#26616)
* Add integration tests for nxos_acl_interface
- Loading branch information
Showing
9 changed files
with
340 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/integration/targets/nxos_acl_interface/defaults/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
testcase: "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
- prepare_nxos_tests |
15 changes: 15 additions & 0 deletions
15
test/integration/targets/nxos_acl_interface/tasks/cli.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
- { include: cli.yaml, tags: ['cli'] } | ||
- { include: nxapi.yaml, tags: ['nxapi'] } |
28 changes: 28 additions & 0 deletions
28
test/integration/targets/nxos_acl_interface/tasks/nxapi.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }}" |
118 changes: 118 additions & 0 deletions
118
test/integration/targets/nxos_acl_interface/tests/cli/sanity.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
- debug: msg="START TRANSPORT:CLI nxos_acl_interface sanity test" | ||
|
||
# Select interface for test | ||
- set_fact: intname="{{ nxos_int1 }}" | ||
|
||
- name: "Interface selected for this test" | ||
debug: msg="{{ intname }}" | ||
|
||
- name: "Setup: Put interface into a default state" | ||
nxos_config: &default | ||
lines: | ||
- "default interface {{ intname }}" | ||
provider: "{{ cli }}" | ||
ignore_errors: yes | ||
|
||
- name: "Setup: Cleanup possibly existing acl" | ||
nxos_acl: &remove | ||
name: ANSIBLE_ACL | ||
seq: 10 | ||
state: absent | ||
provider: "{{ cli }}" | ||
ignore_errors: yes | ||
|
||
- name: Configure Supporting ACL | ||
nxos_acl: | ||
name: ANSIBLE_ACL | ||
seq: 10 | ||
action: permit | ||
proto: tcp | ||
src: 1.1.1.1/24 | ||
dest: any | ||
provider: "{{ cli }}" | ||
|
||
- block: | ||
- name: Configure acl interface egress | ||
nxos_acl_interface: &configure_egr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: egress | ||
state: present | ||
provider: "{{ cli }}" | ||
register: result | ||
|
||
- assert: &true | ||
that: | ||
- "result.changed == true" | ||
|
||
- name: "Check Idempotence egress" | ||
nxos_acl_interface: *configure_egr | ||
register: result | ||
|
||
- assert: &false | ||
that: | ||
- "result.changed == false" | ||
|
||
- name: Configure acl interface ingress | ||
nxos_acl_interface: &configure_ingr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: ingress | ||
state: present | ||
provider: "{{ cli }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence ingress" | ||
nxos_acl_interface: *configure_ingr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
- name: Cleanup acl interface egress | ||
nxos_acl_interface: &cleanup_egr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: egress | ||
state: absent | ||
provider: "{{ cli }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence egress cleanup" | ||
nxos_acl_interface: *cleanup_egr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
- name: Cleanup acl interface ingress | ||
nxos_acl_interface: &cleanup_ingr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: ingress | ||
state: absent | ||
provider: "{{ cli }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence ingress cleanup" | ||
nxos_acl_interface: *cleanup_ingr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
rescue: | ||
- name: Put test interface into default state. | ||
nxos_config: *default | ||
ignore_errors: yes | ||
|
||
- name: Remove possible configured ACL | ||
nxos_acl: *remove | ||
ignore_errors: yes | ||
|
||
always: | ||
- debug: msg="END TRANSPORT:CLI nxos_acl_interface sanity test" |
118 changes: 118 additions & 0 deletions
118
test/integration/targets/nxos_acl_interface/tests/nxapi/sanity.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
- debug: msg="START TRANSPORT:NXAPI nxos_acl_interface sanity test" | ||
|
||
# Select interface for test | ||
- set_fact: intname="{{ nxos_int1 }}" | ||
|
||
- name: "Interface selected for this test" | ||
debug: msg="{{ intname }}" | ||
|
||
- name: "Setup: Put interface into a default state" | ||
nxos_config: &default | ||
lines: | ||
- "default interface {{ intname }}" | ||
provider: "{{ nxapi }}" | ||
ignore_errors: yes | ||
|
||
- name: "Setup: Cleanup possibly existing acl" | ||
nxos_acl: &remove | ||
name: ANSIBLE_ACL | ||
seq: 10 | ||
state: absent | ||
provider: "{{ nxapi }}" | ||
ignore_errors: yes | ||
|
||
- name: Configure Supporting ACL | ||
nxos_acl: | ||
name: ANSIBLE_ACL | ||
seq: 10 | ||
action: permit | ||
proto: tcp | ||
src: 1.1.1.1/24 | ||
dest: any | ||
provider: "{{ nxapi }}" | ||
|
||
- block: | ||
- name: Configure acl interface egress | ||
nxos_acl_interface: &configure_egr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: egress | ||
state: present | ||
provider: "{{ nxapi }}" | ||
register: result | ||
|
||
- assert: &true | ||
that: | ||
- "result.changed == true" | ||
|
||
- name: "Check Idempotence egress" | ||
nxos_acl_interface: *configure_egr | ||
register: result | ||
|
||
- assert: &false | ||
that: | ||
- "result.changed == false" | ||
|
||
- name: Configure acl interface ingress | ||
nxos_acl_interface: &configure_ingr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: ingress | ||
state: present | ||
provider: "{{ nxapi }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence ingress" | ||
nxos_acl_interface: *configure_ingr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
- name: Cleanup acl interface egress | ||
nxos_acl_interface: &cleanup_egr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: egress | ||
state: absent | ||
provider: "{{ nxapi }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence egress cleanup" | ||
nxos_acl_interface: *cleanup_egr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
- name: Cleanup acl interface ingress | ||
nxos_acl_interface: &cleanup_ingr | ||
name: ANSIBLE_ACL | ||
interface: "{{ intname }}" | ||
direction: ingress | ||
state: absent | ||
provider: "{{ nxapi }}" | ||
register: result | ||
|
||
- assert: *true | ||
|
||
- name: "Check Idempotence ingress cleanup" | ||
nxos_acl_interface: *cleanup_ingr | ||
register: result | ||
|
||
- assert: *false | ||
|
||
rescue: | ||
- name: Put test interface into default state. | ||
nxos_config: *default | ||
ignore_errors: yes | ||
|
||
- name: Remove possible configured ACL | ||
nxos_acl: *remove | ||
ignore_errors: yes | ||
|
||
always: | ||
- debug: msg="END TRANSPORT:NXAPI nxos_acl_interface sanity test" |
49 changes: 47 additions & 2 deletions
49
test/integration/targets/prepare_nxos_tests/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,54 @@ | ||
--- | ||
# 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_config: | ||
lines: | ||
- feature cli | ||
- feature cli sandbox | ||
- feature nxapi | ||
provider: "{{ cli }}" | ||
ignore_errors: yes | ||
|
||
# Gather the list of interfaces on this device and make the list | ||
# available for integration tests that need them. | ||
# | ||
# Usage in integration test playbook: | ||
# | ||
# - set_fact: testint="{{ nxos_int1 }}" | ||
# | ||
# - name: "Interface selected for this test" | ||
# debug: msg="{{ testint }}" | ||
# | ||
- name: "Collect interface list" | ||
nxos_command: | ||
commands: ['show interface brief | json'] | ||
provider: "{{ nxapi }}" | ||
timeout: 60 | ||
register: intout | ||
|
||
- set_fact: intdataraw="{{ intout.stdout_lines[0]['TABLE_interface']['ROW_interface'] }}" | ||
- set_fact: nxos_int1="{{ intdataraw[1].interface }}" | ||
- set_fact: nxos_int2="{{ intdataraw[2].interface }}" | ||
- set_fact: nxos_int3="{{ intdataraw[3].interface }}" | ||
|
||
# Get platform information for this device | ||
# | ||
# Usage in integration test playbook: | ||
# | ||
# - name: "nxos platform " | ||
# debug: msg="{{ platform }}" | ||
# | ||
- name: "Gather platform info" | ||
nxos_command: | ||
commands: ['sh inventory | json'] | ||
provider: "{{ cli }}" | ||
register: nxos_inventory_output | ||
|
||
- set_fact: platform="{{ nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'][0]['productid'].split('-')[0] }}" | ||
|
||
# Check if platform is fretta | ||
- set_fact: fretta={% for row in nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'] if 'FM-R' in row['productid'] %}"true"{% endfor %} | ||
when: platform | match("N9K") | ||
|
||
# Set platform to N9K-F for fretta | ||
- set_fact: platform="N9K-F" | ||
when: (platform | match("N9K")) and (fretta | search("true")) |