From f872c617124cb27908be5ce96bcbd9cc7796df38 Mon Sep 17 00:00:00 2001 From: Ruturaj Vyawahare Date: Wed, 28 Aug 2019 10:48:32 -0400 Subject: [PATCH] Added integration tests for the following modules: (#55523) - exos_facts - exos_command - exos_config --- .../targets/exos_command/defaults/main.yaml | 3 + .../targets/exos_command/tasks/cli.yaml | 16 ++ .../targets/exos_command/tasks/httpapi.yaml | 16 ++ .../targets/exos_command/tasks/main.yaml | 3 + .../exos_command/tests/common/multiple.yaml | 16 ++ .../exos_command/tests/common/prompt.yaml | 17 ++ .../exos_command/tests/common/single.yaml | 14 + .../exos_command/tests/common/waitfor.yaml | 15 ++ .../tests/common/waitfor_multiple.yaml | 20 ++ .../targets/exos_config/defaults/main.yaml | 3 + .../targets/exos_config/tasks/cli.yaml | 16 ++ .../targets/exos_config/tasks/httpapi.yaml | 16 ++ .../targets/exos_config/tasks/main.yaml | 3 + .../targets/exos_config/templates/master.cfg | 242 ++++++++++++++++++ .../exos_config/tests/common/backup.yaml | 35 +++ .../tests/common/diff_against_file.yaml | 32 +++ .../tests/common/diff_against_startup.yaml | 42 +++ .../exos_config/tests/common/save_config.yaml | 51 ++++ .../exos_config/tests/common/sysname.yaml | 35 +++ .../targets/exos_facts/defaults/main.yaml | 3 + .../targets/exos_facts/tasks/cli.yaml | 16 ++ .../targets/exos_facts/tasks/httpapi.yaml | 16 ++ .../targets/exos_facts/tasks/main.yaml | 3 + .../exos_facts/tests/common/basic.yaml | 27 ++ .../tests/common/default_facts.yaml | 28 ++ .../tests/common/invalid_subset.yaml | 40 +++ .../tests/common/not_hardware_facts.yaml | 27 ++ 27 files changed, 755 insertions(+) create mode 100644 test/integration/targets/exos_command/defaults/main.yaml create mode 100644 test/integration/targets/exos_command/tasks/cli.yaml create mode 100644 test/integration/targets/exos_command/tasks/httpapi.yaml create mode 100644 test/integration/targets/exos_command/tasks/main.yaml create mode 100644 test/integration/targets/exos_command/tests/common/multiple.yaml create mode 100644 test/integration/targets/exos_command/tests/common/prompt.yaml create mode 100644 test/integration/targets/exos_command/tests/common/single.yaml create mode 100644 test/integration/targets/exos_command/tests/common/waitfor.yaml create mode 100644 test/integration/targets/exos_command/tests/common/waitfor_multiple.yaml create mode 100644 test/integration/targets/exos_config/defaults/main.yaml create mode 100644 test/integration/targets/exos_config/tasks/cli.yaml create mode 100644 test/integration/targets/exos_config/tasks/httpapi.yaml create mode 100644 test/integration/targets/exos_config/tasks/main.yaml create mode 100644 test/integration/targets/exos_config/templates/master.cfg create mode 100644 test/integration/targets/exos_config/tests/common/backup.yaml create mode 100644 test/integration/targets/exos_config/tests/common/diff_against_file.yaml create mode 100644 test/integration/targets/exos_config/tests/common/diff_against_startup.yaml create mode 100644 test/integration/targets/exos_config/tests/common/save_config.yaml create mode 100644 test/integration/targets/exos_config/tests/common/sysname.yaml create mode 100644 test/integration/targets/exos_facts/defaults/main.yaml create mode 100644 test/integration/targets/exos_facts/tasks/cli.yaml create mode 100644 test/integration/targets/exos_facts/tasks/httpapi.yaml create mode 100644 test/integration/targets/exos_facts/tasks/main.yaml create mode 100644 test/integration/targets/exos_facts/tests/common/basic.yaml create mode 100644 test/integration/targets/exos_facts/tests/common/default_facts.yaml create mode 100644 test/integration/targets/exos_facts/tests/common/invalid_subset.yaml create mode 100644 test/integration/targets/exos_facts/tests/common/not_hardware_facts.yaml diff --git a/test/integration/targets/exos_command/defaults/main.yaml b/test/integration/targets/exos_command/defaults/main.yaml new file mode 100644 index 00000000000..9ef5ba51651 --- /dev/null +++ b/test/integration/targets/exos_command/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/exos_command/tasks/cli.yaml b/test/integration/targets/exos_command/tasks/cli.yaml new file mode 100644 index 00000000000..5068fbcf9bd --- /dev/null +++ b/test/integration/targets/exos_command/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/exos_command/tasks/httpapi.yaml b/test/integration/targets/exos_command/tasks/httpapi.yaml new file mode 100644 index 00000000000..7435ff0f0c5 --- /dev/null +++ b/test/integration/targets/exos_command/tasks/httpapi.yaml @@ -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 diff --git a/test/integration/targets/exos_command/tasks/main.yaml b/test/integration/targets/exos_command/tasks/main.yaml new file mode 100644 index 00000000000..c6e0ab2af4c --- /dev/null +++ b/test/integration/targets/exos_command/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: httpapi.yaml, tags:['httpapi']} diff --git a/test/integration/targets/exos_command/tests/common/multiple.yaml b/test/integration/targets/exos_command/tests/common/multiple.yaml new file mode 100644 index 00000000000..ce763ddc403 --- /dev/null +++ b/test/integration/targets/exos_command/tests/common/multiple.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_command/tests/common/prompt.yaml b/test/integration/targets/exos_command/tests/common/prompt.yaml new file mode 100644 index 00000000000..51fe17cedeb --- /dev/null +++ b/test/integration/targets/exos_command/tests/common/prompt.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_command/tests/common/single.yaml b/test/integration/targets/exos_command/tests/common/single.yaml new file mode 100644 index 00000000000..73976229ace --- /dev/null +++ b/test/integration/targets/exos_command/tests/common/single.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_command/tests/common/waitfor.yaml b/test/integration/targets/exos_command/tests/common/waitfor.yaml new file mode 100644 index 00000000000..f1c390ae57b --- /dev/null +++ b/test/integration/targets/exos_command/tests/common/waitfor.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_command/tests/common/waitfor_multiple.yaml b/test/integration/targets/exos_command/tests/common/waitfor_multiple.yaml new file mode 100644 index 00000000000..575ca35fc01 --- /dev/null +++ b/test/integration/targets/exos_command/tests/common/waitfor_multiple.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_config/defaults/main.yaml b/test/integration/targets/exos_config/defaults/main.yaml new file mode 100644 index 00000000000..9ef5ba51651 --- /dev/null +++ b/test/integration/targets/exos_config/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/exos_config/tasks/cli.yaml b/test/integration/targets/exos_config/tasks/cli.yaml new file mode 100644 index 00000000000..5068fbcf9bd --- /dev/null +++ b/test/integration/targets/exos_config/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/exos_config/tasks/httpapi.yaml b/test/integration/targets/exos_config/tasks/httpapi.yaml new file mode 100644 index 00000000000..7ce2b1dad3d --- /dev/null +++ b/test/integration/targets/exos_config/tasks/httpapi.yaml @@ -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 diff --git a/test/integration/targets/exos_config/tasks/main.yaml b/test/integration/targets/exos_config/tasks/main.yaml new file mode 100644 index 00000000000..c6e0ab2af4c --- /dev/null +++ b/test/integration/targets/exos_config/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: httpapi.yaml, tags:['httpapi']} diff --git a/test/integration/targets/exos_config/templates/master.cfg b/test/integration/targets/exos_config/templates/master.cfg new file mode 100644 index 00000000000..f11db04f707 --- /dev/null +++ b/test/integration/targets/exos_config/templates/master.cfg @@ -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. +# diff --git a/test/integration/targets/exos_config/tests/common/backup.yaml b/test/integration/targets/exos_config/tests/common/backup.yaml new file mode 100644 index 00000000000..7a7623d35d0 --- /dev/null +++ b/test/integration/targets/exos_config/tests/common/backup.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_config/tests/common/diff_against_file.yaml b/test/integration/targets/exos_config/tests/common/diff_against_file.yaml new file mode 100644 index 00000000000..b09a70edbd7 --- /dev/null +++ b/test/integration/targets/exos_config/tests/common/diff_against_file.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_config/tests/common/diff_against_startup.yaml b/test/integration/targets/exos_config/tests/common/diff_against_startup.yaml new file mode 100644 index 00000000000..39bd288fe3c --- /dev/null +++ b/test/integration/targets/exos_config/tests/common/diff_against_startup.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_config/tests/common/save_config.yaml b/test/integration/targets/exos_config/tests/common/save_config.yaml new file mode 100644 index 00000000000..a83646f9a40 --- /dev/null +++ b/test/integration/targets/exos_config/tests/common/save_config.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_config/tests/common/sysname.yaml b/test/integration/targets/exos_config/tests/common/sysname.yaml new file mode 100644 index 00000000000..26ef19ee51f --- /dev/null +++ b/test/integration/targets/exos_config/tests/common/sysname.yaml @@ -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" diff --git a/test/integration/targets/exos_facts/defaults/main.yaml b/test/integration/targets/exos_facts/defaults/main.yaml new file mode 100644 index 00000000000..9ef5ba51651 --- /dev/null +++ b/test/integration/targets/exos_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/exos_facts/tasks/cli.yaml b/test/integration/targets/exos_facts/tasks/cli.yaml new file mode 100644 index 00000000000..5068fbcf9bd --- /dev/null +++ b/test/integration/targets/exos_facts/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/exos_facts/tasks/httpapi.yaml b/test/integration/targets/exos_facts/tasks/httpapi.yaml new file mode 100644 index 00000000000..7435ff0f0c5 --- /dev/null +++ b/test/integration/targets/exos_facts/tasks/httpapi.yaml @@ -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 diff --git a/test/integration/targets/exos_facts/tasks/main.yaml b/test/integration/targets/exos_facts/tasks/main.yaml new file mode 100644 index 00000000000..c6e0ab2af4c --- /dev/null +++ b/test/integration/targets/exos_facts/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: httpapi.yaml, tags:['httpapi']} diff --git a/test/integration/targets/exos_facts/tests/common/basic.yaml b/test/integration/targets/exos_facts/tests/common/basic.yaml new file mode 100644 index 00000000000..e888a7f6a2d --- /dev/null +++ b/test/integration/targets/exos_facts/tests/common/basic.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_facts/tests/common/default_facts.yaml b/test/integration/targets/exos_facts/tests/common/default_facts.yaml new file mode 100644 index 00000000000..3507407d912 --- /dev/null +++ b/test/integration/targets/exos_facts/tests/common/default_facts.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_facts/tests/common/invalid_subset.yaml b/test/integration/targets/exos_facts/tests/common/invalid_subset.yaml new file mode 100644 index 00000000000..52dfe65d170 --- /dev/null +++ b/test/integration/targets/exos_facts/tests/common/invalid_subset.yaml @@ -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 }}" diff --git a/test/integration/targets/exos_facts/tests/common/not_hardware_facts.yaml b/test/integration/targets/exos_facts/tests/common/not_hardware_facts.yaml new file mode 100644 index 00000000000..1f28c7833c9 --- /dev/null +++ b/test/integration/targets/exos_facts/tests/common/not_hardware_facts.yaml @@ -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 }}"