1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add junos integration test (#24404)

This commit is contained in:
Ganesh Nalawade 2017-05-09 18:41:48 +05:30 committed by GitHub
parent c5adf08c40
commit 5b3ea6562b
25 changed files with 628 additions and 3 deletions

View file

@ -62,7 +62,7 @@ EXAMPLES = """
junos_rpc:
rpc: get-interface-information
args:
interface: em0
interface-name: em0
media: True
- name: get system information

View file

@ -10,5 +10,7 @@
roles:
- { role: junos_command, when: "limit_to in ['*', 'junos_command']" }
- { role: junos_config, when: "limit_to in ['*', 'junos_config']" }
- { role: junos_facts, when: "limit_to in ['*', 'junos_facts']" }
- { role: junos_netconf, when: "limit_to in ['*', 'junos_netconf']" }
- { role: junos_rpc, when: "limit_to in ['*', 'junos_rpc']" }
- { role: junos_template, when: "limit_to in ['*', 'junos_template']" }

View file

@ -1,3 +1,4 @@
---
- { include: netconf_xml.yaml, tags: ['netconf', 'xml'] }
- { include: netconf_text.yaml, tags: ['netconf', 'text'] }
- { include: netconf_json.yaml, tags: ['netconf', 'json'] }

View file

@ -0,0 +1,15 @@
---
- name: collect netconf_json test cases with json encoding
find:
paths: "{{ role_path }}/tests/netconf_json"
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

View file

@ -1,5 +1,5 @@
---
- name: collect netconf_text test cases with xml encoding
- name: collect netconf_text test cases with text encoding
find:
paths: "{{ role_path }}/tests/netconf_text"
patterns: "{{ testcase }}.yaml"

View file

@ -0,0 +1,21 @@
---
- debug: msg="START netconf_json/bad_operator.yaml"
- name: test bad operator with json encoding
junos_command:
commands:
- show version
- show interfaces fxp0
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] foo fxp0"
format: json
provider: "{{ netconf }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- "result.msg is defined"
- debug: msg="END netconf_json/bad_operator.yaml"

View file

@ -0,0 +1,22 @@
---
- debug: msg="START netconf_json/contains.yaml"
- name: test contains operator with json encoding
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] contains {{ inventory_hostname_short }}"
- "result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] contains fxp0"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/contains.yaml"

View file

@ -0,0 +1,40 @@
---
- debug: msg="START netconf_json/equal.yaml"
- name: test == operator with xml encoding
junos_command:
commands:
- show version
- show interfaces fxp0
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] == {{ inventory_hostname_short }}"
- "result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] == fxp0"
format: json
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test eq operator with json encoding
junos_command:
commands:
- show version
- show interfaces fxp0
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] eq {{ inventory_hostname_short }}"
- "result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] eq fxp0"
format: json
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/equal.yaml"

View file

@ -0,0 +1,38 @@
---
- debug: msg="START netconf_json/greaterthan.yaml"
- name: test gt operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] gt 1500"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test > operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] > 1500"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/greaterthan.yaml"

View file

@ -0,0 +1,38 @@
---
- debug: msg="START netconf_json/greaterthanorequal.yaml"
- name: test ge operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] ge 1514"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test >= operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] >= 1514"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/greaterthanorequal.yaml"

View file

@ -0,0 +1,38 @@
---
- debug: msg="START netconf_json/lessthan.yaml"
- name: test lt operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] lt 9000"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test < operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] lt 9000"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/lessthan.yaml"

View file

@ -0,0 +1,38 @@
---
- debug: msg="START netconf_json/lessthanorequal.yaml"
- name: test le operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] le 1514"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test <= operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[1]['interface-information'][0]['physical-interface'][0]['mtu'][0]['data'] <= 1514"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/lessthanorequal.yaml"

View file

@ -0,0 +1,38 @@
---
- debug: msg="START netconf_json/notequal.yaml"
- name: test neq operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] neq localhost"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: test != operator
junos_command:
commands:
- show version
- show interfaces fxp0
format: json
wait_for:
- "result[0]['software-information'][0]['host-name'][0]['data'] != localhost"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/notequal.yaml"

View file

@ -0,0 +1,32 @@
---
- debug: msg="START netconf_json/output.yaml"
- name: get output for single command
junos_command:
commands: ['show version']
format: json
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- name: get output for multiple commands
junos_command:
commands:
- show version
- show route
format: json
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.stdout is defined"
- "result.stdout_lines is defined"
- debug: msg="END netconf_json/output.yaml"

View file

@ -0,0 +1 @@
set interfaces lo0 unit 0 family inet address 1.1.1.1/32

View file

@ -0,0 +1,15 @@
<interfaces>
<interface>
<name>lo0</name>
<unit>
<name>0</name>
<family>
<inet>
<address>
<name>1.1.1.1/32</name>
</address>
</inet>
</family>
</unit>
</interface>
</interfaces>

View file

@ -8,7 +8,7 @@
- delete interfaces lo0
provider: "{{ netconf }}"
- name: configure device with config
- name: configure device with text config
junos_config:
src: basic/config.j2
provider: "{{ netconf }}"
@ -28,4 +28,77 @@
that:
- "result.changed == false"
- name: teardown
junos_config:
lines:
- delete interfaces lo0
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == true"
- name: configure device with set config
junos_config:
src: basic/config.set
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == true"
- "'address 1.1.1.1/32' in result.diff.prepared"
- name: check device with config
junos_config:
src: basic/config.set
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
junos_config:
lines:
- delete interfaces lo0
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == true"
- name: configure device with xml config
junos_config:
src: basic/config.xml
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == true"
- "'address 1.1.1.1/32' in result.diff.prepared"
- name: check device with config
junos_config:
src: basic/config.xml
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
junos_config:
lines:
- delete interfaces lo0
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == true"
- debug: msg="END netconf/src_basic.yaml"

View file

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

View file

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

View file

@ -0,0 +1,14 @@
- name: collect netconf test cases
find:
paths: "{{ role_path }}/tests/netconf"
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

View file

@ -0,0 +1,103 @@
---
- debug: msg="START netconf/facts.yaml"
- name: Collect default facts from device
junos_facts:
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'ansible_net_hostname' in result['ansible_facts']"
- "'ansible_net_interfaces' in result['ansible_facts']"
- "'ansible_net_memfree_mb' in result['ansible_facts']"
- name: Collect config facts from device
junos_facts:
gather_subset: config
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'ansible_net_config' in result['ansible_facts']"
- "'ansible_net_interfaces' not in result['ansible_facts']"
- "'ansible_net_memfree_mb' not in result['ansible_facts']"
- name: Collect all facts from device except hardware
junos_facts:
gather_subset: "!hardware"
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'ansible_net_config' in result['ansible_facts']"
- "'ansible_net_interfaces' in result['ansible_facts']"
- "'ansible_net_memfree_mb' not in result['ansible_facts']"
- name: Invalid facts subset value
junos_facts:
gather_subset: test
provider: "{{ netconf }}"
ignore_errors: yes
register: result
- assert:
that:
- "result.failed == true"
- "result.msg == 'Subset must be one of [hardware, default, interfaces, config], got test'"
- name: Collect config facts from device in set format
junos_facts:
gather_subset: config
config_format: set
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'set system host-name {{ inventory_hostname_short }}' in result['ansible_facts']['ansible_net_config']"
- name: Collect config facts from device in xml format
junos_facts:
gather_subset: config
config_format: xml
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'<host-name>{{ inventory_hostname_short }}</host-name>' in result['ansible_facts']['ansible_net_config']"
- name: Collect config facts from device in json format
junos_facts:
gather_subset: config
config_format: json
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'\"data\" : \"{{ inventory_hostname_short }}\"' in result['ansible_facts']['ansible_net_config']"
- name: Collect config facts from device in text format
junos_facts:
gather_subset: config
config_format: text
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'system {\n host-name {{ inventory_hostname_short }};' in result['ansible_facts']['ansible_net_config']"
- debug: msg="END netconf/facts.yaml"

View file

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

View file

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

View file

@ -0,0 +1,14 @@
- name: collect netconf test cases
find:
paths: "{{ role_path }}/tests/netconf"
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

View file

@ -0,0 +1,72 @@
---
- debug: msg="START netconf/rpc.yaml"
- name: Execute RPC on device
junos_rpc:
rpc: get-interface-information
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'<name>\nem0\n</name>' in result['xml']"
- "result.output is defined"
- name: Execute RPC with args on device
junos_rpc:
rpc: get-interface-information
args:
interface-name: em0
media: True
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "'<name>\nem0\n</name>' in result['xml']"
- "'<name>\nlo0\n</name>' not in result['xml']"
- name: Execute RPC on device and get output in text format
junos_rpc:
rpc: get-interface-information
output: text
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.output is defined"
- "result.output_lines is defined"
- "'Physical interface: em0' in result['output']"
- name: Execute RPC on device and get output in json format
junos_rpc:
rpc: get-interface-information
output: json
args:
interface-name: em0
media: True
provider: "{{ netconf }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.output is defined"
- "result['output']['interface-information'][0]['physical-interface'][0]['name'][0]['data'] == \"em0\""
- name: Execute invalid RPC
junos_rpc:
rpc: show-interface-information
provider: "{{ netconf }}"
register: result
ignore_errors: yes
- assert:
that:
- "result.failed == true"
- debug: msg="END netconf/rpc.yaml"