added nxos_smoke tests (#36647)

* added nxos_smoke tests

* add connection information, check length of output

* updated name of task
pull/37253/head
David Newswanger 6 years ago committed by GitHub
parent b440544e73
commit 5e827f4cc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
testcase: "*"
test_items: []

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

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

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

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

@ -0,0 +1,160 @@
---
# nxos_config -> NetworkConfig, dumps
# nxos_static_route -> CustomNetworkConfig
# hit NetworkConfig
# Select interface for test
- debug: msg="START connection={{ ansible_connection }} common/common_config.yaml"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- set_fact: intname="{{ nxos_int1 }}"
- name: setup
nxos_config:
commands:
- no description
- no shutdown
parents:
- "interface {{ intname }}"
match: none
provider: "{{ connection }}"
- name: collect any backup files
find: &backups
paths: "{{ role_path }}/backup"
pattern: "{{ inventory_hostname_short }}_config*"
connection: local
register: backup_files
- name: delete backup files
file:
path: "{{ item.path }}"
state: absent
with_items: "{{backup_files.files|default([])}}"
- name: configure device with config
nxos_config:
commands:
- description this is a test
- shutdown
parents:
- "interface {{ intname }}"
backup: yes
provider: "{{ connection }}"
register: result
- assert:
that:
- "result.changed == true"
- "result.updates is defined"
- name: collect any backup files
find: *backups
connection: local
register: backup_files
- assert:
that:
- "backup_files.files is defined"
# hit block/sublevel sections
- name: setup
nxos_config: &clear
lines: no ip access-list test
provider: "{{ connection }}"
match: none
ignore_errors: yes
# hit NetworkConfig._diff_exact
- name: configure sub level command using block replace - exact
nxos_config:
lines:
- 10 permit ip 1.1.1.1/32 any log
- 20 permit ip 2.2.2.2/32 any log
- 30 permit ip 3.3.3.3/32 any log
- 40 permit ip 4.4.4.4/32 any log
parents: ip access-list test
replace: block
provider: "{{ connection }}"
match: exact
register: result
- assert:
that:
- "result.changed == true"
- "'ip access-list test' in result.updates"
- "'10 permit ip 1.1.1.1/32 any log' in result.updates"
- "'20 permit ip 2.2.2.2/32 any log' in result.updates"
- "'30 permit ip 3.3.3.3/32 any log' in result.updates"
- "'40 permit ip 4.4.4.4/32 any log' in result.updates"
# hit NetworkConfig._diff_strict
- name: configure sub level command using block replace strict
nxos_config:
lines:
- 10 permit ip 1.1.1.1/32 any log
- 20 permit ip 2.2.2.2/32 any log
- 30 permit ip 3.3.3.3/32 any log
- 40 permit ip 4.4.4.4/32 any log
parents: ip access-list test
replace: block
provider: "{{ connection }}"
match: strict
register: result
- name: teardown
nxos_config: *clear
# hit CustomNetworkConfig
- block:
- name: create static route
nxos_static_route: &configure
prefix: "192.168.20.64/24"
next_hop: "3.3.3.3"
route_name: testing
pref: 100
tag: 5500
vrf: testing
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: remove static route
nxos_static_route: &remove
prefix: "192.168.20.64/24"
next_hop: "3.3.3.3"
route_name: testing
pref: 100
tag: 5500
vrf: testing
state: absent
provider: "{{ connection }}"
register: result
- assert: *true
always:
- name: remove static route
nxos_static_route:
prefix: "192.168.20.64/24"
next_hop: "3.3.3.3"
route_name: testing
pref: 100
tag: 5500
vrf: testing
state: absent
provider: "{{ connection }}"
ignore_errors: yes
- name: remove static route aggregate
nxos_static_route:
aggregate:
- { prefix: "192.168.22.64/24", next_hop: "3.3.3.3" }
- { prefix: "192.168.24.64/24", next_hop: "3.3.3.3" }
state: absent
provider: "{{ connection }}"
ignore_errors: yes

@ -0,0 +1,101 @@
---
# nxos_command -> ComplexList
# nxos_config -> to_list
# nxos_interface -> conditional, remove_default_spec
- debug: msg="START connection={{ ansible_connection }} common/common_utils.yaml"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
# hit ComplexList
- name: test contains operator
nxos_command:
commands:
- show version
# hit to_list()
- name: setup
nxos_config:
lines: hostname switch
provider: "{{ connection }}"
match: none
- name: configure top level command
nxos_config:
lines: hostname foo
provider: "{{ connection }}"
register: result
- assert:
that:
- "result.changed == true"
- "'hostname foo' in result.updates"
- name: setup
nxos_config:
lines: hostname switch
provider: "{{ connection }}"
match: none
# hit conditional()
- set_fact: testint1="{{ nxos_int1 }}"
- set_fact: testint2="{{ nxos_int2 }}"
- name: "Setup: Put interfaces into a default state"
nxos_config:
lines:
- "default interface {{ testint1 }}"
- "default interface {{ testint2 }}"
provider: "{{ connection }}"
ignore_errors: yes
register: result
- name: Check intent arguments
nxos_interface:
name: "{{ testint2 }}"
admin_state: up
tx_rate: ge(0)
rx_rate: ge(0)
provider: "{{ connection }}"
register: result
- assert:
that:
- "result.failed == false"
- name: Check intent arguments (failed condition)
nxos_interface:
name: "{{ testint2 }}"
admin_state: down
tx_rate: gt(0)
rx_rate: lt(0)
provider: "{{ connection }}"
ignore_errors: yes
register: result
- assert:
that:
- "result.failed == true"
- "'tx_rate gt(0)' in result.failed_conditions"
- "'rx_rate lt(0)' in result.failed_conditions"
- name: aggregate definition of interface
nxos_interface:
aggregate:
- { name: "{{ testint1 }}", description: "Test aggregation on first interface" }
- { name: "{{ testint2 }}", mode: layer3 }
provider: "{{ connection }}"
register: result
- assert:
that:
- "result.changed == true"
- name: "TearDown: Put interfaces into a default state"
nxos_config:
lines:
- "default interface {{ testint1 }}"
- "default interface {{ testint2 }}"
provider: "{{ connection }}"
ignore_errors: yes

@ -0,0 +1,24 @@
---
- debug: msg="START connection={{ ansible_connection }} common/misc_tests.yaml"
- debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local"
- name: hit conditional for lists of 10 or more commands
nxos_command:
commands:
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
- show hostname
provider: "{{ connection }}"
register: result
- assert:
that:
- result.stdout|length == 10
Loading…
Cancel
Save