diff --git a/test/integration/targets/vyos_facts/defaults/main.yaml b/test/integration/targets/vyos_facts/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/vyos_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/vyos_facts/tasks/cli.yaml b/test/integration/targets/vyos_facts/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/vyos_facts/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/vyos_facts/tasks/main.yaml b/test/integration/targets/vyos_facts/tasks/main.yaml new file mode 100644 index 0000000000..415c99d8b1 --- /dev/null +++ b/test/integration/targets/vyos_facts/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml b/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml new file mode 100644 index 0000000000..16850cbf8b --- /dev/null +++ b/test/integration/targets/vyos_facts/tests/cli/basic_facts.yaml @@ -0,0 +1,45 @@ +- name: get host name + vyos_command: + commands: + - show host name + register: vyos_host + +- name: get version info + vyos_command: + commands: + - show version + register: vyos_version + +- name: collect all facts from the device + vyos_facts: + gather_subset: all + register: result + +- name: "check that hostname is present" + assert: + that: + # hostname + - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] + +- name: "check that subsets are present" + assert: + that: + # subsets + - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'config' in result.ansible_facts.ansible_net_gather_subset" + +- name: "check that version info is present" + assert: + that: + # version info + - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] + - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] + - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] + +- name: "check that config info is present" + assert: + that: + # config info + - result.ansible_facts.ansible_net_commits is defined + - result.ansible_facts.ansible_net_config is defined diff --git a/test/integration/targets/vyos_facts/tests/cli/neighbors_facts.yaml b/test/integration/targets/vyos_facts/tests/cli/neighbors_facts.yaml new file mode 100644 index 0000000000..a16b3a9d97 --- /dev/null +++ b/test/integration/targets/vyos_facts/tests/cli/neighbors_facts.yaml @@ -0,0 +1,51 @@ +- name: get eth0 ip address + vyos_command: + commands: + - show interfaces ethernet eth0 + register: eth0_ip + +# if there is no ip assigned to eth0, skip this +- block: + - set_fact: + vyos_lldp_node: "{{ eth0_ip.stdout_lines[0][2] | regex_replace('.*inet ', '') | regex_replace('/.*', '') }}" + + - name: start LLDP + vyos_config: + lines: + - set service lldp + - set service lldp management-address {{ vyos_lldp_node }} + + - debug: var=vyos_lldp_node + + - name: wait for LLDP to start up. If this fails check that vyos_lldp_node is a valid ip address + vyos_command: + commands: + - show lldp neighbors detail + register: neighbors + until: neighbors.stdout_lines[0]|length > 3 + retries: 5 + delay: 5 + + - name: collect neighbor facts from the device + vyos_facts: + gather_subset: neighbors + # provider: {{ cli }} + register: result + + - debug: var=result.ansible_facts.ansible_net_neighbors + + + - name: check ansible_net_neighbors + assert: + that: + - result.ansible_facts.ansible_net_neighbors is defined + # - result.ansible_facts.ansible_net_neighbors.eth0 is defined + - result.ansible_facts.ansible_net_neighbors|length > 0 + + always: + - name: stop lldp + vyos_config: + lines: + - delete service lldp + - delete service lldp management-address {{ vyos_lldp_node }} + when: "'inet' in eth0_ip.stdout[0]" diff --git a/test/integration/vyos.yaml b/test/integration/vyos.yaml index d7382b9f72..909f979db3 100644 --- a/test/integration/vyos.yaml +++ b/test/integration/vyos.yaml @@ -114,6 +114,15 @@ failed_modules: "{{ failed_modules }} + [ 'vyos_interface' ]" test_failed: true + - block: + - include_role: + name: vyos_facts + when: "limit_to in ['*', 'vyos_facts']" + rescue: + - set_fact: + failed_modules: "{{ failed_modules }} + [ 'vyos_facts' ]" + test_failed: true + ########### - debug: var=failed_modules when: test_failed