From 81f0b70f11ec6b5ebcc56cdf709261662a70ad0b Mon Sep 17 00:00:00 2001 From: hexdump0x0200 <43333029+hexdump0x0200@users.noreply.github.com> Date: Tue, 18 Jun 2019 16:41:15 +0700 Subject: [PATCH] junos_netconf: fix check mode, fixes #57929 (#57930) --- .../modules/network/junos/junos_netconf.py | 9 +---- .../junos_netconf/tests/cli/changeport.yaml | 25 ++++++++++++ .../junos_netconf/tests/cli/netconf.yaml | 38 +++++++++++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_netconf.py b/lib/ansible/modules/network/junos/junos_netconf.py index 9d6dc5db978..011935041ec 100644 --- a/lib/ansible/modules/network/junos/junos_netconf.py +++ b/lib/ansible/modules/network/junos/junos_netconf.py @@ -149,18 +149,11 @@ def map_params_to_obj(module): def load_config(module, config, commit=False): conn = get_connection(module) try: - resp = conn.edit_config(to_list(config) + ['top']) + resp = conn.edit_config(to_list(config) + ['top'], commit) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) diff = resp.get('diff', '') - if diff: - if commit: - commit_configuration(module) - - else: - discard_changes(module) - return to_text(diff, errors='surrogate_then_replace').strip() diff --git a/test/integration/targets/junos_netconf/tests/cli/changeport.yaml b/test/integration/targets/junos_netconf/tests/cli/changeport.yaml index aee2cae92ba..a6c42ed190c 100644 --- a/test/integration/targets/junos_netconf/tests/cli/changeport.yaml +++ b/test/integration/targets/junos_netconf/tests/cli/changeport.yaml @@ -59,4 +59,29 @@ - name: Ensure we can communicate over netconf include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false" +- name: Change port (check mode) + junos_netconf: + state: present + netconf_port: 12345 + register: result + check_mode: true + +- assert: + that: + - "result.changed == true" + +- name: wait for netconf server to come up + pause: + seconds: 10 + +- name: Ensure we can NOT communicate over non-default port + include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=12345 is_ignore_errors=true" + +- assert: + that: + - "result.failed == true" + +- name: Ensure we can communicate over default port + include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false" + - debug: msg="END netconf/changeport.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/junos_netconf/tests/cli/netconf.yaml b/test/integration/targets/junos_netconf/tests/cli/netconf.yaml index 95db4deeae6..9cc69ba356a 100644 --- a/test/integration/targets/junos_netconf/tests/cli/netconf.yaml +++ b/test/integration/targets/junos_netconf/tests/cli/netconf.yaml @@ -25,6 +25,23 @@ - name: Ensure we can communicate over netconf include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false" +- name: Disable netconf (check mode) + junos_netconf: + state: absent + register: result + check_mode: yes + +- assert: + that: + - "result.changed == true" + +- name: wait for persistent socket to timeout + pause: + seconds: 120 + +- name: Ensure we can communicate over netconf + include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=false" + # Disable netconf - name: Disable netconf junos_netconf: @@ -55,6 +72,27 @@ that: - "result.failed == true" +- name: Enable netconf (check mode) + junos_netconf: + state: present + register: result + check_mode: yes + +- assert: + that: + - "result.changed == true" + +- name: wait for netconf server to come up + pause: + seconds: 10 + +- name: Ensure we can NOT talk via netconf + include: "{{ role_path }}/tests/utils/junos_command.yaml ansible_connection=netconf ansible_port=830 is_ignore_errors=true" + +- assert: + that: + - "result.failed == true" + - name: re-enable netconf junos_netconf: state: present