From 7330ab8062545478e3b1951c94ae4c98008244ea Mon Sep 17 00:00:00 2001 From: John R Barker Date: Fri, 20 Jan 2017 20:17:35 +0000 Subject: [PATCH] Correctly call get_config (#20452) * Correctly call get_config * remove debug * Check for empty flags and LocalAnsibleModule * Peter's feedback --- lib/ansible/modules/network/ios/_ios_template.py | 6 +++--- lib/ansible/modules/network/ios/ios_config.py | 6 +++--- test/units/modules/network/ios/test_ios_template.py | 8 ++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/ios/_ios_template.py b/lib/ansible/modules/network/ios/_ios_template.py index 0b00a406f6..cb1b246e56 100644 --- a/lib/ansible/modules/network/ios/_ios_template.py +++ b/lib/ansible/modules/network/ios/_ios_template.py @@ -150,7 +150,7 @@ def get_current_config(module): flags = ['all'] else: flags = [] - return get_config(flags=flags) + return get_config(module=module, flags=flags) def main(): """ main entry point for module execution @@ -182,7 +182,7 @@ def main(): result = {'changed': False} if module.params['backup']: - result['__backup__'] = get_config() + result['__backup__'] = get_config(module=module) if not module.params['force']: contents = get_current_config(module) @@ -195,7 +195,7 @@ def main(): if commands: if not module.check_mode: - load_config(commands) + load_config(module, commands) result['changed'] = True result['updates'] = commands diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index ea397b8a08..b582794f30 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -366,8 +366,8 @@ def main(): if match != 'none': config, have_banners = get_running_config(module) path = module.params['parents'] - configobjs = candidate.difference(config, path=path,match=match, - replace=replace) + configobjs = candidate.difference(config, path=path, match=match, + replace=replace) else: configobjs = candidate.items have_banners = {} @@ -398,7 +398,7 @@ def main(): result['changed'] = True if module.params['backup']: - result['__backup__'] = get_config() + result['__backup__'] = get_config(module=module) if module.params['save']: if not module.check_mode: diff --git a/test/units/modules/network/ios/test_ios_template.py b/test/units/modules/network/ios/test_ios_template.py index d1e59aafdf..38692f635c 100644 --- a/test/units/modules/network/ios/test_ios_template.py +++ b/test/units/modules/network/ios/test_ios_template.py @@ -29,7 +29,7 @@ from ansible.errors import AnsibleModuleExit from ansible.modules.network.ios import _ios_template from ansible.module_utils import basic from ansible.module_utils._text import to_bytes - +from ansible.module_utils.local import LocalAnsibleModule def set_module_args(args): args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) @@ -118,7 +118,11 @@ class TestIosTemplateModule(unittest.TestCase): src = load_fixture('ios_template_config.cfg') set_module_args(dict(src=src, include_defaults=False)) self.execute_module() - self.get_config.assert_called_with(flags=[]) + _, kwargs = self.get_config.call_args + # Ensure flags doesn't contain "default", or any other value + self.assertEqual(kwargs['flags'], []) + self.assertIsInstance(kwargs['module'], LocalAnsibleModule) + def test_ios_template_backup(self): set_module_args(dict(backup=True))