diff --git a/lib/ansible/plugins/netconf/__init__.py b/lib/ansible/plugins/netconf/__init__.py
index b55bafbb121..39af3850ce7 100644
--- a/lib/ansible/plugins/netconf/__init__.py
+++ b/lib/ansible/plugins/netconf/__init__.py
@@ -223,9 +223,9 @@ class NetconfBase(AnsiblePlugin):
"""
if rpc_command is None:
raise ValueError('rpc_command value must be provided')
- req = fromstring(rpc_command)
- resp = self.m.dispatch(req, source=source, filter=filter)
- return resp.data_xml if resp.data_ele else resp.xml
+
+ resp = self.m.dispatch(fromstring(rpc_command), source=source, filter=filter)
+ return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
@ensure_connected
def lock(self, target="candidate"):
diff --git a/test/integration/targets/junos_facts/tests/netconf/facts.yaml b/test/integration/targets/junos_facts/tests/netconf/facts.yaml
index c22a7a039d3..e687f32cd35 100644
--- a/test/integration/targets/junos_facts/tests/netconf/facts.yaml
+++ b/test/integration/targets/junos_facts/tests/netconf/facts.yaml
@@ -50,7 +50,7 @@
- assert:
that:
- "result.failed == true"
- - "result.msg == 'Subset must be one of [config, default, hardware, interfaces, ofacts], got test'"
+ - "'Subset must be one of' in result.msg"
- name: Collect config facts from device in set format
junos_facts:
diff --git a/test/integration/targets/junos_lldp/tests/netconf/basic.yaml b/test/integration/targets/junos_lldp/tests/netconf/basic.yaml
index 42e6701b78d..d57c9c411c8 100644
--- a/test/integration/targets/junos_lldp/tests/netconf/basic.yaml
+++ b/test/integration/targets/junos_lldp/tests/netconf/basic.yaml
@@ -1,119 +1,138 @@
---
- debug: msg="START junos_lldp netconf/basic.yaml on connection={{ ansible_connection }}"
-- name: setup - Disable lldp and remove it's configuration
- junos_lldp:
- state: absent
- provider: "{{ netconf }}"
-
-- name: Enable lldp
- junos_lldp:
- state: present
- provider: "{{ netconf }}"
+- name: get supported protocols
+ junos_command:
+ commands: show lldp
register: result
+ ignore_errors: yes
-- assert:
- that:
- - "result.changed == true"
+- name: lldp supported
+ set_fact:
+ lldp_supported: True
+ when: not result.failed
-- name: Enable lldp (idempotent)
- junos_lldp:
- state: present
- provider: "{{ netconf }}"
- register: result
+- name: lldp not supported
+ set_fact:
+ lldp_supported: False
+ when: result.failed
-- assert:
- that:
- - "result.changed == false"
+- block:
+ - name: setup - Disable lldp and remove it's configuration
+ junos_lldp:
+ state: absent
+ provider: "{{ netconf }}"
-- name: configure lldp parameters and enable lldp
- junos_lldp:
- interval: 10
- hold_multiplier: 5
- transmit_delay: 2
- state: present
- provider: "{{ netconf }}"
- register: result
+ - name: Enable lldp
+ junos_lldp:
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *advertisement-interval 10")
- - result.diff.prepared is search("\+ *transmit-delay 2")
- - result.diff.prepared is search("\+ *hold-multiplier 5")
+ - assert:
+ that:
+ - "result.changed == true"
-- name: configure lldp parameters and enable lldp(idempotent)
- junos_lldp:
- interval: 10
- hold_multiplier: 5
- transmit_delay: 2
- state: present
- provider: "{{ netconf }}"
- register: result
+ - name: Enable lldp (idempotent)
+ junos_lldp:
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == false"
+ - assert:
+ that:
+ - "result.changed == false"
-- name: configure lldp parameters and disable lldp
- junos_lldp:
- interval: 10
- hold_multiplier: 5
- transmit_delay: 2
- state: disabled
- provider: "{{ netconf }}"
- register: result
+ - name: configure lldp parameters and enable lldp
+ junos_lldp:
+ interval: 10
+ hold_multiplier: 5
+ transmit_delay: 2
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *disable")
- - "'advertisement-interval 10;' not in result.diff.prepared"
- - "'transmit-delay 2;' not in result.diff.prepared"
- - "'hold-multiplier 5;' not in result.diff.prepared"
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *advertisement-interval 10")
+ - result.diff.prepared is search("\+ *transmit-delay 2")
+ - result.diff.prepared is search("\+ *hold-multiplier 5")
-- name: configure lldp parameters and enable lldp
- junos_lldp:
- interval: 10
- hold_multiplier: 5
- transmit_delay: 2
- state: enabled
- provider: "{{ netconf }}"
- register: result
+ - name: configure lldp parameters and enable lldp(idempotent)
+ junos_lldp:
+ interval: 10
+ hold_multiplier: 5
+ transmit_delay: 2
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\- *disable")
- - "'advertisement-interval 10;' not in result.diff.prepared"
- - "'transmit-delay 2;' not in result.diff.prepared"
- - "'hold-multiplier 5;' not in result.diff.prepared"
+ - assert:
+ that:
+ - "result.changed == false"
-- name: Remove lldp configuration and diable lldp
- junos_lldp:
- interval: 10
- hold_multiplier: 5
- transmit_delay: 2
- state: absent
- provider: "{{ netconf }}"
- register: result
+ - name: configure lldp parameters and disable lldp
+ junos_lldp:
+ interval: 10
+ hold_multiplier: 5
+ transmit_delay: 2
+ state: disabled
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *disable")
- - result.diff.prepared is search("\- *advertisement-interval 10")
- - result.diff.prepared is search("\- *transmit-delay 2")
- - result.diff.prepared is search("\- *hold-multiplier 5")
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *disable")
+ - "'advertisement-interval 10;' not in result.diff.prepared"
+ - "'transmit-delay 2;' not in result.diff.prepared"
+ - "'hold-multiplier 5;' not in result.diff.prepared"
-- name: Remove lldp (idempotent)
- junos_lldp:
- state: absent
- provider: "{{ netconf }}"
- register: result
+ - name: configure lldp parameters and enable lldp
+ junos_lldp:
+ interval: 10
+ hold_multiplier: 5
+ transmit_delay: 2
+ state: enabled
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == false"
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\- *disable")
+ - "'advertisement-interval 10;' not in result.diff.prepared"
+ - "'transmit-delay 2;' not in result.diff.prepared"
+ - "'hold-multiplier 5;' not in result.diff.prepared"
+
+ - name: Remove lldp configuration and diable lldp
+ junos_lldp:
+ interval: 10
+ hold_multiplier: 5
+ transmit_delay: 2
+ state: absent
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *disable")
+ - result.diff.prepared is search("\- *advertisement-interval 10")
+ - result.diff.prepared is search("\- *transmit-delay 2")
+ - result.diff.prepared is search("\- *hold-multiplier 5")
+
+ - name: Remove lldp (idempotent)
+ junos_lldp:
+ state: absent
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == false"
+
+ when: lldp_supported
- debug: msg="END junos_lldp netconf/basic.yaml on connection={{ ansible_connection }}"
diff --git a/test/integration/targets/junos_lldp/tests/netconf/net_lldp.yaml b/test/integration/targets/junos_lldp/tests/netconf/net_lldp.yaml
index 4b5d3682516..31cbc153707 100644
--- a/test/integration/targets/junos_lldp/tests/netconf/net_lldp.yaml
+++ b/test/integration/targets/junos_lldp/tests/netconf/net_lldp.yaml
@@ -3,25 +3,42 @@
# Add minimal testcase to check args are passed correctly to
# implementation module and module run is successful.
-
-- name: setup - Disable lldp - setup
- net_lldp:
- state: absent
- provider: "{{ netconf }}"
-
-- name: Enable lldp using platform agnostic module
- net_lldp:
- state: present
- provider: "{{ netconf }}"
+- name: get supported protocols
+ junos_command:
+ commands: show lldp
register: result
+ ignore_errors: yes
-- assert:
- that:
- - "result.changed == true"
+- name: lldp supported
+ set_fact:
+ lldp_supported: True
+ when: not result.failed
-- name: setup - Disable lldp - teardown
- net_lldp:
- state: absent
- provider: "{{ netconf }}"
+- name: lldp not supported
+ set_fact:
+ lldp_supported: False
+ when: result.failed
+
+- block:
+ - name: setup - Disable lldp - setup
+ net_lldp:
+ state: absent
+ provider: "{{ netconf }}"
+
+ - name: Enable lldp using platform agnostic module
+ net_lldp:
+ state: present
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == true"
+
+ - name: setup - Disable lldp - teardown
+ net_lldp:
+ state: absent
+ provider: "{{ netconf }}"
+ when: lldp_supported
- debug: msg="START junos netconf/net_lldp.yaml on connection={{ ansible_connection }}"
diff --git a/test/integration/targets/junos_lldp_interface/tests/netconf/basic.yaml b/test/integration/targets/junos_lldp_interface/tests/netconf/basic.yaml
index 260fb0fecbc..e864c05ee66 100644
--- a/test/integration/targets/junos_lldp_interface/tests/netconf/basic.yaml
+++ b/test/integration/targets/junos_lldp_interface/tests/netconf/basic.yaml
@@ -1,106 +1,124 @@
---
- debug: msg="START junos_lldp_interface netconf/basic.yaml on connection={{ ansible_connection }}"
-- name: setup - Remove lldp interface configuration
- junos_lldp_interface:
- name: ge-0/0/5
- state: absent
- provider: "{{ netconf }}"
-
-- name: lldp interface configuration
- junos_lldp_interface:
- name: ge-0/0/5
- state: present
- provider: "{{ netconf }}"
+- name: get supported protocols
+ junos_command:
+ commands: show lldp
register: result
+ ignore_errors: yes
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *interface ge-0/0/5")
+- name: lldp supported
+ set_fact:
+ lldp_supported: True
+ when: not result.failed
-- name: lldp interface configuration (idempotent)
- junos_lldp_interface:
- name: ge-0/0/5
- state: present
- provider: "{{ netconf }}"
- register: result
+- name: lldp not supported
+ set_fact:
+ lldp_supported: False
+ when: result.failed
-- assert:
- that:
- - "result.changed == false"
+- block:
+ - name: setup - Remove lldp interface configuration
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: absent
+ provider: "{{ netconf }}"
-- name: Deactivate lldp interface configuration
- junos_lldp_interface:
- name: ge-0/0/5
- state: present
- active: False
- provider: "{{ netconf }}"
- register: result
+ - name: lldp interface configuration
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("! *inactive[:] interface ge-0/0/5")
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *interface ge-0/0/5")
-- name: Activate lldp interface configuration
- junos_lldp_interface:
- name: ge-0/0/5
- state: present
- active: True
- provider: "{{ netconf }}"
- register: result
+ - name: lldp interface configuration (idempotent)
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: present
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("! *active[:] interface ge-0/0/5")
+ - assert:
+ that:
+ - "result.changed == false"
-- name: Disable lldp on particular interface
- junos_lldp_interface:
- name: ge-0/0/5
- state: disabled
- provider: "{{ netconf }}"
- register: result
+ - name: Deactivate lldp interface configuration
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: present
+ active: False
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *disable")
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("! *inactive[:] interface ge-0/0/5")
-- name: Enable lldp on particular interface
- junos_lldp_interface:
- name: ge-0/0/5
- state: enabled
- provider: "{{ netconf }}"
- register: result
+ - name: Activate lldp interface configuration
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: present
+ active: True
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\- *disable")
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("! *active[:] interface ge-0/0/5")
-- name: Delete lldp on particular interface
- junos_lldp_interface:
- name: ge-0/0/5
- state: absent
- provider: "{{ netconf }}"
- register: result
+ - name: Disable lldp on particular interface
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: disabled
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\- *interface ge-0/0/5")
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *disable")
-- name: Delete lldp on particular interface (idempotent)
- junos_lldp_interface:
- name: ge-0/0/5
- state: absent
- provider: "{{ netconf }}"
- register: result
+ - name: Enable lldp on particular interface
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: enabled
+ provider: "{{ netconf }}"
+ register: result
-- assert:
- that:
- - "result.changed == false"
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\- *disable")
+
+ - name: Delete lldp on particular interface
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: absent
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\- *interface ge-0/0/5")
+
+ - name: Delete lldp on particular interface (idempotent)
+ junos_lldp_interface:
+ name: ge-0/0/5
+ state: absent
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == false"
+ when: lldp_supported
- debug: msg="END junos_lldp_interface netconf/basic.yaml on connection={{ ansible_connection }}"
diff --git a/test/integration/targets/junos_lldp_interface/tests/netconf/net_lldp_interface.yaml b/test/integration/targets/junos_lldp_interface/tests/netconf/net_lldp_interface.yaml
index e1219654b63..b628ea1b1e6 100644
--- a/test/integration/targets/junos_lldp_interface/tests/netconf/net_lldp_interface.yaml
+++ b/test/integration/targets/junos_lldp_interface/tests/netconf/net_lldp_interface.yaml
@@ -4,28 +4,46 @@
# Add minimal testcase to check args are passed correctly to
# implementation module and module run is successful.
-- name: setup - Remove lldp interface configuration
- net_lldp_interface:
- name: ge-0/0/5
- state: absent
- provider: "{{ netconf }}"
-
-- name: lldp interface configuration using platform agnostic module
- net_lldp_interface:
- name: ge-0/0/5
- state: present
- provider: "{{ netconf }}"
+- name: get supported protocols
+ junos_command:
+ commands: show lldp
register: result
+ ignore_errors: yes
-- assert:
- that:
- - "result.changed == true"
- - result.diff.prepared is search("\+ *interface ge-0/0/5")
+- name: lldp supported
+ set_fact:
+ lldp_supported: True
+ when: not result.failed
-- name: teardown - Remove lldp interface configuration
- net_lldp_interface:
- name: ge-0/0/5
- state: absent
- provider: "{{ netconf }}"
+- name: lldp not supported
+ set_fact:
+ lldp_supported: False
+ when: result.failed
+
+- block:
+ - name: setup - Remove lldp interface configuration
+ net_lldp_interface:
+ name: ge-0/0/5
+ state: absent
+ provider: "{{ netconf }}"
+
+ - name: lldp interface configuration using platform agnostic module
+ net_lldp_interface:
+ name: ge-0/0/5
+ state: present
+ provider: "{{ netconf }}"
+ register: result
+
+ - assert:
+ that:
+ - "result.changed == true"
+ - result.diff.prepared is search("\+ *interface ge-0/0/5")
+
+ - name: teardown - Remove lldp interface configuration
+ net_lldp_interface:
+ name: ge-0/0/5
+ state: absent
+ provider: "{{ netconf }}"
+ when: lldp_supported
- debug: msg="END junos netconf/net_lldp_interface.yaml on connection={{ ansible_connection }}"
diff --git a/test/integration/targets/junos_rpc/tests/netconf/rpc.yaml b/test/integration/targets/junos_rpc/tests/netconf/rpc.yaml
index e1d50a6f0d0..4f51b33d308 100644
--- a/test/integration/targets/junos_rpc/tests/netconf/rpc.yaml
+++ b/test/integration/targets/junos_rpc/tests/netconf/rpc.yaml
@@ -10,14 +10,14 @@
- assert:
that:
- "result.changed == false"
- - "'\nem0\n' in result['xml']"
+ - "'\nem0\n' in result['xml']"
- - "'\nlo0\n' not in result['xml']"
+ - "'\nlo0\n' in result['xml']"
+ - "'\nem0\n' not in result['xml']"
+ - "'\fxp0\n' not in result['xml']"
- name: Execute RPC on device and get output in text format
junos_rpc:
@@ -40,14 +41,14 @@
- "result.changed == false"
- "result.output is defined"
- "result.output_lines is defined"
- - "'Physical interface: em0' in result['output']"
+ - "'Physical interface' 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
+ interface-name: lo0
media: True
provider: "{{ netconf }}"
register: result
@@ -56,7 +57,7 @@
that:
- "result.changed == false"
- "result.output is defined"
- - "result['output']['interface-information'][0]['physical-interface'][0]['name'][0]['data'] == \"em0\""
+ - "result['output']['interface-information'][0]['physical-interface'][0]['name'][0]['data'] == \"lo0\""
- name: Execute invalid RPC
junos_rpc:
diff --git a/test/integration/targets/netconf_config/tests/junos/basic.yaml b/test/integration/targets/netconf_config/tests/junos/basic.yaml
index 63e972d2e1c..c9d4d169db6 100644
--- a/test/integration/targets/netconf_config/tests/junos/basic.yaml
+++ b/test/integration/targets/netconf_config/tests/junos/basic.yaml
@@ -27,11 +27,22 @@
that:
- "result.changed == false"
-- name: configure syslog file replace
+- name: replace default operation fail
netconf_config:
content: "{{ syslog_config_replace }}"
default_operation: 'replace'
register: result
+ ignore_errors: yes
+
+- assert:
+ that:
+ - "result.failed == true"
+ - "'Missing mandatory statement' in result.msg"
+
+- name: replace syslog config with operation key in content
+ netconf_config:
+ content: "{{ syslog_config_replace }}"
+ register: result
- assert:
that:
@@ -55,7 +66,7 @@
- name: save config
netconf_config:
backup: yes
- register: result
+ register: result
- assert:
that:
diff --git a/test/integration/targets/netconf_config/tests/junos/fixtures/config.yml b/test/integration/targets/netconf_config/tests/junos/fixtures/config.yml
index a25d45a98c3..86de0f9da5c 100644
--- a/test/integration/targets/netconf_config/tests/junos/fixtures/config.yml
+++ b/test/integration/targets/netconf_config/tests/junos/fixtures/config.yml
@@ -24,7 +24,7 @@ syslog_config_replace: |
-
+
test_netconf_config