Added integration tests for the following modules: (#55523)

- exos_facts
- exos_command
- exos_config
This commit is contained in:
Ruturaj Vyawahare 2019-08-28 10:48:32 -04:00 committed by Nathaniel Case
parent 7a1237781d
commit f872c61712
27 changed files with 755 additions and 0 deletions

View file

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

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- 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"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- 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=httpapi"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

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

View file

@ -0,0 +1,16 @@
---
- debug: msg="START common/multiple.yaml on connection={{ ansible_connection }}"
- name: run multiple commands on remote nodes
exos_command:
commands:
- show version
- show ports no-refresh
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END common/multiple.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,17 @@
---
- debug: msg="START common/prompt.yaml on connection={{ ansible_connection }}"
- name: run command that requires answering a prompt
exos_command:
commands:
- command: 'clear license-info'
prompt: 'Are you sure.*'
answer: 'Yes'
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END common/prompt.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,14 @@
---
- debug: msg="START common/single.yaml on connection={{ ansible_connection }}"
- name: run show version on remote devices
exos_command:
commands: show version
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END common/single.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,15 @@
---
- debug: msg="START common/waitfor.yaml on connection={{ ansible_connection }}"
- name: run show version and check to see if output contains ExtremeXOS
exos_command:
commands: show version
wait_for: result[0] contains ExtremeXOS
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END common/waitfor.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,20 @@
---
- debug: msg="START common/waitfor_multiple.yaml on connection={{ ansible_connection }}"
- name: run multiple commands and evaluate the output
exos_command:
commands:
- show version
- show ports no-refresh
wait_for:
- result[0] contains ExtremeXOS
- result[1] contains 20
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- debug: msg="END common/waitfor_multiple.yaml on connection={{ ansible_connection }}"

View file

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

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- 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"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test cases (connection=httpapi)
include: "{{ test_case_to_run }} ansible_connection=httpapi"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

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

View file

@ -0,0 +1,242 @@
#
# Module devmgr configuration.
#
configure snmp sysName "Switch2"
configure snmp sysContact "support@extremenetworks.com, +1 888 257 3000"
configure sys-recovery-level switch reset
#
# Module vlan configuration.
#
configure vlan default delete ports all
configure vr VR-Default delete ports 1-54
configure vr VR-Default add ports 1-54
configure vlan default delete ports 2,4-7,10-13
create vlan "ansible_500"
configure vlan ansible_500 tag 500
create vlan "ansible_600"
configure vlan ansible_600 tag 600
create vlan "ansible_700"
configure vlan ansible_700 tag 700
configure ports 2 description-string "MasterUplink"
configure ports 49 auto off speed 10000 duplex full
configure ports 50 auto off speed 10000 duplex full
configure ports 51 auto off speed 10000 duplex full
configure ports 52 auto off speed 10000 duplex full
configure vlan Default add ports 1,3,8-9,14-54 untagged
#
# Module mcmgr configuration.
#
#
# Module otm configuration.
#
#
# Module fdb configuration.
#
#
# Module rtmgr configuration.
#
#
# Module policy configuration.
#
#
# Module aaa configuration.
#
#
# Module acl configuration.
#
configure access-list zone SYSTEM application VlanManager application-priority 18
configure access-list zone SYSTEM application SlppGuard application-priority 19
#
# Module bfd configuration.
#
#
# Module bgp configuration.
#
#
# Module cfgmgr configuration.
#
enable cli history expansion permanent
#
# Module dosprotect configuration.
#
#
# Module dot1ag configuration.
#
#
# Module eaps configuration.
#
#
# Module edp configuration.
#
#
# Module elrp configuration.
#
#
# Module ems configuration.
#
#
# Module epm configuration.
#
#
# Module erps configuration.
#
#
# Module esrp configuration.
#
#
# Module ethoam configuration.
#
#
# Module etmon configuration.
#
#
# Module exsshd configuration.
#
enable ssh2
#
# Module gptp configuration.
#
#
# Module hal configuration.
#
#
# Module idMgr configuration.
#
#
# Module ipSecurity configuration.
#
#
# Module ipfix configuration.
#
#
# Module lldp configuration.
#
#
# Module mrp configuration.
#
#
# Module msdp configuration.
#
#
# Module netLogin configuration.
#
#
# Module netTools configuration.
#
#
# Module nodealias configuration.
#
#
# Module ntp configuration.
#
#
# Module ospf configuration.
#
#
# Module ospfv3 configuration.
#
#
# Module pim configuration.
#
#
# Module poe configuration.
#
#
# Module rip configuration.
#
#
# Module ripng configuration.
#
#
# Module snmpMaster configuration.
#
configure snmpv3 engine-id 03:00:04:96:97:f4:fa
#
# Module stp configuration.
#
#
# Module synce configuration.
#
#
# Module techSupport configuration.
#
#
# Module telnetd configuration.
#
#
# Module tftpd configuration.
#
#
# Module thttpd configuration.
#
#
# Module twamp configuration.
#
#
# Module vmt configuration.
#
#
# Module vrrp configuration.
#
#
# Module vsm configuration.
#
#
# Module vpex configuration.
#

View file

@ -0,0 +1,35 @@
---
- debug: msg="START common/backup.yaml on connection={{ ansible_connection }}"
- name: configure vlan
exos_config:
lines:
- create vlan 100
backup: yes
backup_options:
filename: backup.cfg
dir_path: '{{ role_path }}'
register: result
- set_fact: content="{{ lookup('file', '{{ role_path }}/backup.cfg') }}"
- name: Assert local file creation
assert:
that:
- "content is search('Module devmgr')"
- name: delete configurable backup file path
file:
path: "{{ role_path }}/backup.cfg"
state: absent
- name: Restore original configuration
exos_config:
lines:
- delete vlan 100
- name: Save the configuration to startup
exos_config:
save_when: modified
- debug: msg="END common/backup.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,32 @@
---
- debug: msg="START common/diff_against_file.yaml on connection={{ ansible_connection }}"
- name: Setup a configuration
exos_config:
lines:
- "create vlan 100"
- debug: msg="{{ role_path }}"
- set_fact: master="{{ lookup('file', '{{ role_path }}/templates/master.cfg') }}"
- name: check the running-config against master config
exos_config:
diff_against: intended
intended_config: "{{ master }}"
diff: yes
register: result
- assert:
that:
- "result.diff.before is defined"
- "result.diff.before is search('configure vlan VLAN_0100 tag 100')"
- "result.diff.after is defined"
- name: Restore original configuration
exos_config:
lines:
- "delete vlan 100"
- name: Save the configuration to startup
exos_config:
save_when: modified
- debug: msg="END common/diff_against_file.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,42 @@
---
- debug: msg="START cli/diff_against_startup.yaml on connection={{ ansible_connection }}"
- name: Make a configuration and save it to startup
exos_config:
lines:
- "create vlan 100"
- name: Save the configuration to startup
exos_config:
save_when: modified
- name: Make a configuration change without saving into running config
exos_config:
lines:
- "create vlan 200"
- name: check the startup-config against the running-config
exos_config:
diff_against: startup
diff_ignore_lines:
- ntp clock .*
diff: yes
register: result
- assert:
that:
- "result.diff.before is defined"
- "result.diff.after is defined"
- "result.diff.before is search('configure vlan VLAN_0100 tag 100')"
- "result.diff.after is search('configure vlan VLAN_0200 tag 200')"
- name: Restore and save original config
exos_config:
lines:
- "delete vlan 100"
- "delete vlan 200"
- name: Save the configuration to startup
exos_config:
save_when: modified
- debug: msg="END cli/diff_against_startup.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,51 @@
---
- debug: msg="START common/save_config.yaml on connection={{ ansible_connection }}"
- name: Setup by creating VLAN
exos_config:
lines:
- create vlan 200
- name: Saving modified configuration in primary.cfg for the next startup
exos_config:
save_when: modified
register: result
- assert:
that:
- "result.changed == True"
- name: Get the config file
exos_command:
commands: show switch
register: result
- name: Get the startup config file
set_fact: config_selected='{{ result.stdout[0] | regex_search('(Config Selected:)\s+(\w+)', '\\2')}}'
- name: Check if the primary config file has the changes
exos_command:
commands: "debug cfgmgr show configuration file {{ config_selected.0 }}"
register: result
- assert:
that:
- "result.stdout[0] is search('configure vlan VLAN_0200 tag 200')"
- name: Idempotent save configuration
exos_config:
save_when: modified
register: result
- assert:
that:
- "result.changed == False"
- name: Restore initial state by deleting vlan
exos_config:
lines: delete vlan 200
- name: Restore orignal primary cfg
exos_config:
save_when: modified
- debug: msg="END common/save_config.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,35 @@
---
- debug: msg="START common/sysname.yaml"
- name: Get intial SysName
exos_command:
commands: show switch | grep SysName
register: sysname_init
- name: configure SNMP system name
exos_config:
lines: configure snmp sysName "{{ inventory_hostname }}"
register: result
- assert:
that:
- "result.commands[0] is search('configure')"
- "result.changed == True"
- name: Idempotency of SNMP system name configuration
exos_config:
lines: configure snmp sysName "{{ inventory_hostname }}"
register: result
- assert:
that:
- "result.changed == False"
- set_fact: old_sysname='{{ sysname_init.stdout[0] | regex_search('([^\s]+$)') }}'
- name: Restore inital sysName
exos_config:
lines: 'configure snmp sysName {{ old_sysname }}'
- name: Save the configuration to startup
exos_config:
save_when: modified
- debug: msg="END common/sysname.yaml"

View file

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

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- 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"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

@ -0,0 +1,16 @@
---
- name: collect all common test cases
find:
paths: "{{ role_path }}/tests/common"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- 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=httpapi"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

View file

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

View file

@ -0,0 +1,27 @@
---
- debug:
msg: "START common/basic.yaml on connection={{ ansible_connection }}"
- name: Collect facts
exos_facts:
gather_subset: all
register: result
- debug: "msg={{ result }}"
- assert:
that:
# _facts modules should never report a change
- "result.changed == false"
# Correct subsets are present
- "'config' in result.ansible_facts.ansible_net_gather_subset"
- "'hardware' in result.ansible_facts.ansible_net_gather_subset"
- "'default' in result.ansible_facts.ansible_net_gather_subset"
- "'interfaces' in result.ansible_facts.ansible_net_gather_subset"
# Check that these facts not only are present, but are valid (positive integers)
- "result.ansible_facts.ansible_net_memfree_mb > 1"
- "result.ansible_facts.ansible_net_memtotal_mb > 1"
- debug:
msg: "END common/basic.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,28 @@
---
- debug: msg="START common/default_facts.yaml on connection={{ ansible_connection }}"
- name: test getting default facts
exos_facts:
register: result
- assert:
that:
# _facts modules should never report a change
- "result.changed == false"
# Correct subsets are present
- "'hardware' in result.ansible_facts.ansible_net_gather_subset"
- "'default' in result.ansible_facts.ansible_net_gather_subset"
- "'interfaces' in result.ansible_facts.ansible_net_gather_subset"
# ... and not present
- "'config' not in result.ansible_facts.ansible_net_gather_subset"
# Items from those subsets are present
- "result.ansible_facts.ansible_net_memtotal_mb > 10" #hw
- "result.ansible_facts.ansible_net_interfaces | length > 1" # more than one interface returned
# ... and not present
- "result.ansible_facts.ansible_net_config is not defined" # config
- debug: msg="END common/default_facts.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,40 @@
---
- debug: msg="START common/invalid_subset.yaml on connection={{ ansible_connection }}"
- name: test invalid subset (foobar)
exos_facts:
gather_subset:
- "foobar"
register: result
ignore_errors: true
- assert:
that:
# Failures shouldn't return changes
- "result.changed == false"
# It's a failure
- "result.failed == true"
# Sensible Failure message
- "result.msg == 'Subset must be one of [config, default, hardware, interfaces], got foobar'"
- name: test subset specified multiple times
exos_facts:
gather_subset:
- "!hardware"
- "hardware"
register: result
ignore_errors: true
- assert:
that:
# Failures shouldn't return changes
- "result.changed == false"
# It's a failure
- "result.failed == true"
# Sensible Failure message
- "result.msg == 'Bad subset'"
ignore_errors: true
- debug: msg="END common/invalid_subset.yaml on connection={{ ansible_connection }}"

View file

@ -0,0 +1,27 @@
---
- debug: msg="START common/not_hardware_facts.yaml on connection={{ ansible_connection }}"
- name: test not hardware
exos_facts:
gather_subset:
- "!hardware"
register: result
- assert:
that:
# _facts modules should never report a change
- "result.changed == false"
# Correct subsets are present
- "'config' in result.ansible_facts.ansible_net_gather_subset"
- "'default' in result.ansible_facts.ansible_net_gather_subset"
- "'interfaces' in result.ansible_facts.ansible_net_gather_subset"
# ... and not present
- "'hardware' not in result.ansible_facts.ansible_net_gather_subset"
# Items from those subsets are present
- "result.ansible_facts.ansible_net_interfaces | length > 1" # more than one interface returned
- debug: msg="END common/not_hardware_facts.yaml on connection={{ ansible_connection }}"