From d2446cbf0fa4ab92f8bf2f380b939f597db628be Mon Sep 17 00:00:00 2001 From: anasbadaha <43231942+anasbadaha@users.noreply.github.com> Date: Fri, 21 Dec 2018 08:24:10 +0200 Subject: [PATCH] Fix Issue #39598 (#49982) * Fix Issue #39598 Signed-off-by: Anas Badaha * Fix unit test for onyx_config Signed-off-by: Anas Badaha * Add comments for save running config Signed-off-by: Anas Badaha * Enhance onyx_config bug fix Signed-off-by: Anas Badaha * Fix result['changed'] = True comment Signed-off-by: Anas Badaha --- lib/ansible/modules/network/onyx/onyx_config.py | 16 +++++++--------- .../modules/network/onyx/test_onyx_config.py | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/network/onyx/onyx_config.py b/lib/ansible/modules/network/onyx/onyx_config.py index 2144ba02b43..8a42ce0586a 100644 --- a/lib/ansible/modules/network/onyx/onyx_config.py +++ b/lib/ansible/modules/network/onyx/onyx_config.py @@ -159,6 +159,7 @@ def run(module, result): else: configobjs = candidate.items + total_commands = [] if configobjs: commands = dumps(configobjs, 'commands').split('\n') @@ -169,18 +170,15 @@ def run(module, result): if module.params['after']: commands.extend(module.params['after']) - result['updates'] = commands - - # send the configuration commands to the device and merge - # them with the current running config - if not module.check_mode: - load_config(module, commands) - result['changed'] = True + total_commands.extend(commands) + result['updates'] = total_commands if module.params['save']: - if not module.check_mode: - run_commands(module, 'configuration write') + total_commands.append('configuration write') + if total_commands: result['changed'] = True + if not module.check_mode: + load_config(module, total_commands) def main(): diff --git a/test/units/modules/network/onyx/test_onyx_config.py b/test/units/modules/network/onyx/test_onyx_config.py index 3bdb980c475..f645034e5cf 100644 --- a/test/units/modules/network/onyx/test_onyx_config.py +++ b/test/units/modules/network/onyx/test_onyx_config.py @@ -71,12 +71,12 @@ class TestOnyxConfigModule(TestOnyxModule): self.assertIn('__backup__', result) def test_onyx_config_save(self): - set_module_args(dict(save='yes')) + set_module_args(dict(lines=['hostname foo'], save='yes')) self.execute_module(changed=True) - self.assertEqual(self.run_commands.call_count, 1) + self.assertEqual(self.run_commands.call_count, 0) self.assertEqual(self.get_config.call_count, 1) - self.assertEqual(self.load_config.call_count, 0) - args = self.run_commands.call_args[0][1] + self.assertEqual(self.load_config.call_count, 1) + args = self.load_config.call_args[0][1] self.assertIn('configuration write', args) def test_onyx_config_lines_wo_parents(self):