1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #24251 save config only if it is changed (#24345)

* Fixes #24251 save config only if it is changed

Save to startup configuration only when it is different
from running configuration.

* Fix unit test issue
This commit is contained in:
Ganesh Nalawade 2017-05-16 19:54:36 +05:30 committed by GitHub
parent c6533d4da9
commit f5d865a208
3 changed files with 10 additions and 5 deletions

View file

@ -331,8 +331,10 @@ def main():
if module.params['save']: if module.params['save']:
if not module.check_mode: if not module.check_mode:
run_commands(module, ['copy running-config startup-config']) response = run_commands(module, ['show running-config diffs'])
result['changed'] = True if len(response[0]):
run_commands(module, ['copy running-config startup-config'])
result['changed'] = True
module.exit_json(**result) module.exit_json(**result)

View file

@ -382,8 +382,10 @@ def main():
if module.params['save']: if module.params['save']:
if not module.check_mode: if not module.check_mode:
run_commands(module, ['copy running-config startup-config\r']) response = run_commands(module, ['show archive config differences'])
result['changed'] = True if response[0].find('!No changes were found') < 0:
run_commands(module, ['copy running-config startup-config\r'])
result['changed'] = True
module.exit_json(**result) module.exit_json(**result)

View file

@ -69,9 +69,10 @@ class TestIosConfigModule(TestIosModule):
self.assertIn('__backup__', result) self.assertIn('__backup__', result)
def test_ios_config_save(self): def test_ios_config_save(self):
self.run_commands.return_value = "Hostname foo"
set_module_args(dict(save=True)) set_module_args(dict(save=True))
self.execute_module(changed=True) self.execute_module(changed=True)
self.assertEqual(self.run_commands.call_count, 1) self.assertEqual(self.run_commands.call_count, 2)
self.assertEqual(self.get_config.call_count, 0) self.assertEqual(self.get_config.call_count, 0)
self.assertEqual(self.load_config.call_count, 0) self.assertEqual(self.load_config.call_count, 0)
args = self.run_commands.call_args[0][1] args = self.run_commands.call_args[0][1]