added integration tests for vyos_facts (#26748)

* broke vyos facts into two files

* list vyos facts when failing

* dynamically determine ip

* broke up assert
pull/27904/merge
David Newswanger 7 years ago committed by Ricardo Carrillo Cruz
parent bd4f08823d
commit b985c34dd4

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

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

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

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

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

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

Loading…
Cancel
Save