From 764b4b20ecaec3f14e62b500d6813adb7c409065 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sun, 14 May 2017 17:36:32 +0530 Subject: [PATCH] Fix UnboundLocalError in basic.py * Fix for UnboundLocalError while accessing deprecations in result * Add Unit test Fixes #24592 Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/basic.py | 2 +- .../module_utils/basic/test_deprecate_warn.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 8c53fb5f88..bed5a83c32 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -1999,7 +1999,7 @@ class AnsibleModule(object): else: self.deprecate(d) else: - self.deprecate(d) + self.deprecate(kwargs['deprecations']) if self._deprecations: kwargs['deprecations'] = self._deprecations diff --git a/test/units/module_utils/basic/test_deprecate_warn.py b/test/units/module_utils/basic/test_deprecate_warn.py index d551d92f2a..3338f29964 100644 --- a/test/units/module_utils/basic/test_deprecate_warn.py +++ b/test/units/module_utils/basic/test_deprecate_warn.py @@ -69,3 +69,21 @@ class TestAnsibleModuleWarnDeprecate(unittest.TestCase): {u'msg': u'deprecation4', u'version': '2.4'}, ]) + def test_deprecate_without_list(self): + args = json.dumps(dict(ANSIBLE_MODULE_ARGS={})) + with swap_stdin_and_argv(stdin_data=args): + with swap_stdout(): + + ansible.module_utils.basic._ANSIBLE_ARGS = None + am = ansible.module_utils.basic.AnsibleModule( + argument_spec = dict(), + ) + am._name = 'unittest' + + with self.assertRaises(SystemExit): + am.exit_json(deprecations='Simple deprecation warning') + output = json.loads(sys.stdout.getvalue()) + self.assertTrue('warnings' not in output or output['warnings'] == []) + self.assertEquals(output['deprecations'], [ + {u'msg': u'Simple deprecation warning', u'version': None}, + ])