From 68134cc635f04acd29dde0a957a3e3ed80e1fdf1 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Fri, 15 Jun 2018 00:25:58 +0530 Subject: [PATCH] Don't retrieve config in running_config when config is provided for diff stable 2.5 (#41557) * don't retrieve config in running_config when config is provided for diff (#41400) * don't retrieve config in running_config when config is provided for diff Signed-off-by: Trishna Guha * fix for eos, nxos Signed-off-by: Trishna Guha * add integration test Signed-off-by: Trishna Guha (cherry picked from commit 8ab0d654f3eb44c715af8d8701eb3246d2abf419) * add changelog Signed-off-by: Trishna Guha --- .../ios_nxos_eos_config_module_bugfix.yaml | 2 ++ lib/ansible/modules/network/eos/eos_config.py | 4 +-- lib/ansible/modules/network/ios/ios_config.py | 4 +-- .../modules/network/nxos/nxos_config.py | 4 +-- .../templates/basic/base_running_config | 9 +++++ .../templates/basic/intended_running_config | 9 +++++ .../targets/ios_config/tests/cli/diff.yaml | 29 ++++++++++++++++ .../templates/basic/base_running_config | 10 ++++++ .../templates/basic/intended_running_config | 10 ++++++ .../targets/nxos_config/tests/cli/diff.yaml | 33 +++++++++++++++++++ 10 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/ios_nxos_eos_config_module_bugfix.yaml create mode 100644 test/integration/targets/ios_config/templates/basic/base_running_config create mode 100644 test/integration/targets/ios_config/templates/basic/intended_running_config create mode 100644 test/integration/targets/ios_config/tests/cli/diff.yaml create mode 100644 test/integration/targets/nxos_config/templates/basic/base_running_config create mode 100644 test/integration/targets/nxos_config/templates/basic/intended_running_config create mode 100644 test/integration/targets/nxos_config/tests/cli/diff.yaml diff --git a/changelogs/fragments/ios_nxos_eos_config_module_bugfix.yaml b/changelogs/fragments/ios_nxos_eos_config_module_bugfix.yaml new file mode 100644 index 00000000000..e3ae8d04999 --- /dev/null +++ b/changelogs/fragments/ios_nxos_eos_config_module_bugfix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Don't retrieve config in running_config when config is provided for diff (https://github.com/ansible/ansible/pull/41400) diff --git a/lib/ansible/modules/network/eos/eos_config.py b/lib/ansible/modules/network/eos/eos_config.py index 01e02a61902..055d8702d88 100644 --- a/lib/ansible/modules/network/eos/eos_config.py +++ b/lib/ansible/modules/network/eos/eos_config.py @@ -431,7 +431,7 @@ def main(): result['changed'] = True - running_config = None + running_config = module.params['running_config'] startup_config = None diff_ignore_lines = module.params['diff_ignore_lines'] @@ -456,7 +456,7 @@ def main(): output = run_commands(module, {'command': 'show running-config', 'output': 'text'}) contents = output[0] else: - contents = running_config.config_text + contents = running_config # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index 788f13ff1cd..74a74160a91 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -515,7 +515,7 @@ def main(): result['changed'] = True - running_config = None + running_config = module.params['running_config'] startup_config = None diff_ignore_lines = module.params['diff_ignore_lines'] @@ -538,7 +538,7 @@ def main(): output = run_commands(module, 'show running-config') contents = output[0] else: - contents = running_config.config_text + contents = running_config # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) diff --git a/lib/ansible/modules/network/nxos/nxos_config.py b/lib/ansible/modules/network/nxos/nxos_config.py index 4370873c5c1..c6559556948 100644 --- a/lib/ansible/modules/network/nxos/nxos_config.py +++ b/lib/ansible/modules/network/nxos/nxos_config.py @@ -454,7 +454,7 @@ def main(): result['changed'] = True - running_config = None + running_config = module.params['running_config'] startup_config = None diff_ignore_lines = module.params['diff_ignore_lines'] @@ -483,7 +483,7 @@ def main(): output = execute_show_commands(module, 'show running-config') contents = output[0] else: - contents = running_config.config_text + contents = running_config # recreate the object in order to process diff_ignore_lines running_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) diff --git a/test/integration/targets/ios_config/templates/basic/base_running_config b/test/integration/targets/ios_config/templates/basic/base_running_config new file mode 100644 index 00000000000..37254dc9634 --- /dev/null +++ b/test/integration/targets/ios_config/templates/basic/base_running_config @@ -0,0 +1,9 @@ +version 15.6 +service timestamps debug datetime msec +service timestamps log datetime msec +no service password-encryption +! +hostname an-ios-01.ansible.com +! +boot-start-marker +boot-end-marker diff --git a/test/integration/targets/ios_config/templates/basic/intended_running_config b/test/integration/targets/ios_config/templates/basic/intended_running_config new file mode 100644 index 00000000000..bdad8d3d8b0 --- /dev/null +++ b/test/integration/targets/ios_config/templates/basic/intended_running_config @@ -0,0 +1,9 @@ +version 15.6 +service timestamps debug datetime msec +service timestamps log datetime msec +no service password-encryption +! +hostname an-ios-02.ansible.com +! +boot-start-marker +boot-end-marker diff --git a/test/integration/targets/ios_config/tests/cli/diff.yaml b/test/integration/targets/ios_config/tests/cli/diff.yaml new file mode 100644 index 00000000000..9121f55fba2 --- /dev/null +++ b/test/integration/targets/ios_config/tests/cli/diff.yaml @@ -0,0 +1,29 @@ +--- +- debug: msg="START cli/diff.yaml on connection={{ ansible_connection }}" + +- name: ios_config diff against retrieved config + ios_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config') }}" + diff: true + register: result + +- assert: + that: + - "'hostname an-ios-02.ansible.com' in result['diff']['after']" + - "'hostname {{ shorter_hostname }}' in result['diff']['before']" + +- name: ios_config diff against provided running_config + ios_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config') }}" + running_config: "{{ lookup('file', '{{ role_path }}/templates/basic/base_running_config') }}" + diff: true + register: result + +- assert: + that: + - "'hostname an-ios-02.ansible.com' in result['diff']['after']" + - "'hostname an-ios-01.ansible.com' in result['diff']['before']" + +- debug: msg="END cli/diff.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/nxos_config/templates/basic/base_running_config b/test/integration/targets/nxos_config/templates/basic/base_running_config new file mode 100644 index 00000000000..563371d9d0b --- /dev/null +++ b/test/integration/targets/nxos_config/templates/basic/base_running_config @@ -0,0 +1,10 @@ +version 7.0(3)I6(1) +hostname an-nxos9k-02.ansible.com +vdc an-nxos9k-02 id 1 + limit-resource vlan minimum 16 maximum 4094 + limit-resource vrf minimum 2 maximum 4096 + limit-resource port-channel minimum 0 maximum 511 + limit-resource u4route-mem minimum 96 maximum 96 + limit-resource u6route-mem minimum 24 maximum 24 + limit-resource m4route-mem minimum 58 maximum 58 + limit-resource m6route-mem minimum 8 maximum 8 diff --git a/test/integration/targets/nxos_config/templates/basic/intended_running_config b/test/integration/targets/nxos_config/templates/basic/intended_running_config new file mode 100644 index 00000000000..ab96584bf35 --- /dev/null +++ b/test/integration/targets/nxos_config/templates/basic/intended_running_config @@ -0,0 +1,10 @@ +version 7.0(3)I6(1) +hostname an-nxos9k-01.ansible.com +vdc an-nxos9k-01 id 1 + limit-resource vlan minimum 16 maximum 4094 + limit-resource vrf minimum 2 maximum 4096 + limit-resource port-channel minimum 0 maximum 511 + limit-resource u4route-mem minimum 96 maximum 96 + limit-resource u6route-mem minimum 24 maximum 24 + limit-resource m4route-mem minimum 58 maximum 58 + limit-resource m6route-mem minimum 8 maximum 8 diff --git a/test/integration/targets/nxos_config/tests/cli/diff.yaml b/test/integration/targets/nxos_config/tests/cli/diff.yaml new file mode 100644 index 00000000000..21c164bd73f --- /dev/null +++ b/test/integration/targets/nxos_config/tests/cli/diff.yaml @@ -0,0 +1,33 @@ +--- +- debug: msg="START cli/diff.yaml on connection={{ ansible_connection }}" + +- name: setup hostname + nxos_config: + lines: hostname switch + +- name: nxos_config diff against retrieved config + nxos_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config') }}" + diff: true + register: result + +- assert: + that: + - "'hostname an-nxos9k-01.ansible.com' in result['diff']['after']" + - "'hostname switch' in result['diff']['before']" + +- name: nxos_config diff against provided running_config + nxos_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config') }}" + running_config: "{{ lookup('file', '{{ role_path }}/templates/basic/base_running_config') }}" + diff: true + register: result + +- assert: + that: + - "'hostname an-nxos9k-01.ansible.com' in result['diff']['after']" + - "'hostname an-nxos9k-02.ansible.com' in result['diff']['before']" + +- debug: msg="END cli/diff.yaml on connection={{ ansible_connection }}"