mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
New ansible module netconf_rpc (#40358)
* New ansible module netconf_rpc * add integration test for module netconf_rpc * pep8/meta-data corrections * usage of jxmlease for all XML processing separation of attributes "rpc" and "content" * removed unused imports improved error handling * fixed pep8 * usage of ast.literal_eval instead of eval added description to SROS integration test for cases commented out
This commit is contained in:
parent
ea4a78b2a1
commit
387a23c3d1
13 changed files with 561 additions and 19 deletions
2
test/integration/targets/netconf_rpc/defaults/main.yaml
Normal file
2
test/integration/targets/netconf_rpc/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
4
test/integration/targets/netconf_rpc/meta/main.yml
Normal file
4
test/integration/targets/netconf_rpc/meta/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
dependencies:
|
||||
- { role: prepare_junos_tests, when: ansible_network_os == 'junos' }
|
||||
- { role: prepare_iosxr_tests, when: ansible_network_os == 'iosxr' }
|
16
test/integration/targets/netconf_rpc/tasks/iosxr.yaml
Normal file
16
test/integration/targets/netconf_rpc/tasks/iosxr.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/iosxr"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
connection: local
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=netconf)
|
||||
include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
16
test/integration/targets/netconf_rpc/tasks/junos.yaml
Normal file
16
test/integration/targets/netconf_rpc/tasks/junos.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/junos"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
connection: local
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=netconf)
|
||||
include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
4
test/integration/targets/netconf_rpc/tasks/main.yaml
Normal file
4
test/integration/targets/netconf_rpc/tasks/main.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
- { include: junos.yaml, when: ansible_network_os == 'junos', tags: ['netconf'] }
|
||||
- { include: iosxr.yaml, when: ansible_network_os == 'iosxr', tags: ['netconf'] }
|
||||
- { include: sros.yaml, when: ansible_network_os == 'sros', tags: ['netconf'] }
|
16
test/integration/targets/netconf_rpc/tasks/sros.yaml
Normal file
16
test/integration/targets/netconf_rpc/tasks/sros.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/sros"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
connection: local
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=netconf)
|
||||
include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- debug: msg="START netconf_rpc iosxr/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: discard changes
|
||||
netconf_rpc:
|
||||
rpc: discard-changes
|
||||
|
||||
- debug: msg="END netconf_rpc iosxr/basic.yaml on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- debug: msg="START netconf_rpc junos/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: discard changes
|
||||
netconf_rpc:
|
||||
rpc: discard-changes
|
||||
|
||||
- debug: msg="END netconf_rpc junos/basic.yaml on connection={{ ansible_connection }}"
|
188
test/integration/targets/netconf_rpc/tests/sros/basic.yaml
Normal file
188
test/integration/targets/netconf_rpc/tests/sros/basic.yaml
Normal file
|
@ -0,0 +1,188 @@
|
|||
---
|
||||
- debug: msg="START netconf_rpc sros/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: lock candidate (content is dict)
|
||||
netconf_rpc:
|
||||
rpc: lock
|
||||
content:
|
||||
target:
|
||||
candidate:
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- name: discard changes (w/o content)
|
||||
netconf_rpc:
|
||||
rpc: discard-changes
|
||||
display: xml
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- name: unlock candidate (content is dict as json)
|
||||
netconf_rpc:
|
||||
rpc: unlock
|
||||
xmlns: "urn:ietf:params:xml:ns:netconf:base:1.0"
|
||||
content: "{'target': {'candidate': None}}"
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "{{ result['output']['rpc-reply'] is defined}}"
|
||||
- "{{ result['output']['rpc-reply']['ok'] is defined}}"
|
||||
|
||||
- name: validate candidate (content is single line of XML)
|
||||
netconf_rpc:
|
||||
rpc: validate
|
||||
content: "<source><candidate/></source>"
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "{{ result['output']['rpc-reply'] is defined}}"
|
||||
- "{{ result['output']['rpc-reply']['ok'] is defined}}"
|
||||
|
||||
- name: copy running to startup
|
||||
netconf_rpc:
|
||||
rpc: copy-config
|
||||
content:
|
||||
source:
|
||||
running:
|
||||
target:
|
||||
startup:
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- name: get schema list (content is multiple lines of XML)
|
||||
netconf_rpc:
|
||||
rpc: get
|
||||
content: |
|
||||
<filter>
|
||||
<netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
|
||||
<schemas/>
|
||||
</netconf-state>
|
||||
</filter>
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "{{ result['output']['data'] is defined}}"
|
||||
- "{{ result['output']['data']['netconf-state'] is defined}}"
|
||||
- "{{ result['output']['data']['netconf-state']['schemas'] is defined}}"
|
||||
- "{{ result['output']['data']['netconf-state']['schemas']['schema'] is defined}}"
|
||||
|
||||
# The following two test-cases have been validated against a pre-release implementation.
|
||||
# To make this playbook work with the regular Nokia SROS 16.0 release, those test-cases
|
||||
# have been commented out. As soon the <get-schema> operation is supported by SROS
|
||||
# those test-cases shall be included.
|
||||
|
||||
#- name: get-schema
|
||||
# netconf_rpc:
|
||||
# rpc: get-schema
|
||||
# xmlns: urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring
|
||||
# content:
|
||||
# identifier: ietf-netconf
|
||||
# version: "2011-06-01"
|
||||
# register: result
|
||||
# connection: netconf
|
||||
|
||||
#- name: get schema using XML request
|
||||
# netconf_rpc:
|
||||
# rpc: "get-schema"
|
||||
# xmlns: "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"
|
||||
# content: |
|
||||
# <identifier>ietf-netconf-monitoring</identifier>
|
||||
# <version>2010-10-04</version>
|
||||
# display: pretty
|
||||
# register: result
|
||||
# connection: netconf
|
||||
|
||||
- name: Failure scenario, unsupported content (xpath value)
|
||||
netconf_rpc:
|
||||
rpc: get
|
||||
content: schemas/schema[identifier=ietf-netconf-monitoring]
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'unsupported content value' in result.msg"
|
||||
|
||||
- name: Failure scenario, unsupported content type (list)
|
||||
netconf_rpc:
|
||||
rpc: get
|
||||
content:
|
||||
- value1
|
||||
- value2
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'unsupported content data-type' in result.msg"
|
||||
|
||||
- name: Failure scenario, RPC is close-session
|
||||
netconf_rpc:
|
||||
rpc: close-session
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'unsupported operation' in result.msg"
|
||||
|
||||
- name: Failure scenario, attribute rpc missing
|
||||
netconf_rpc:
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'missing required arguments' in result.msg"
|
||||
|
||||
- name: Failure scenario, attribute rpc is None
|
||||
netconf_rpc:
|
||||
rpc:
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'must not be None' in result.msg"
|
||||
|
||||
- name: Failure scenario, attribute rpc is zero-length string
|
||||
netconf_rpc:
|
||||
rpc: ""
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'must not be empty' in result.msg"
|
||||
|
||||
- name: Failure scenario, attribute rpc only contains white-spaces
|
||||
netconf_rpc:
|
||||
rpc: " "
|
||||
display: json
|
||||
register: result
|
||||
connection: netconf
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'must not be empty' in result.msg"
|
||||
|
||||
- debug: msg="END netconf_rpc sros/basic.yaml on connection={{ ansible_connection }}"
|
Loading…
Add table
Add a link
Reference in a new issue