From 83be12992316ba481ee74bd6a733c5cbde9e45ac Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 25 Mar 2019 11:18:33 +0530 Subject: [PATCH] helper: raise Exception when ds is not dict type (#53936) Signed-off-by: Abhijeet Kasurde --- lib/ansible/playbook/helpers.py | 2 +- test/units/playbook/test_helpers.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index dd49713b08..12b18ae62b 100644 --- a/lib/ansible/playbook/helpers.py +++ b/lib/ansible/playbook/helpers.py @@ -102,7 +102,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h task_list = [] for task_ds in ds: if not isinstance(task_ds, dict): - AnsibleAssertionError('The ds (%s) should be a dict but was a %s' % (ds, type(ds))) + raise AnsibleAssertionError('The ds (%s) should be a dict but was a %s' % (ds, type(ds))) if 'block' in task_ds: t = Block.load( diff --git a/test/units/playbook/test_helpers.py b/test/units/playbook/test_helpers.py index 3dbe3986c1..e5cbe14ce9 100644 --- a/test/units/playbook/test_helpers.py +++ b/test/units/playbook/test_helpers.py @@ -97,6 +97,11 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks): self.assertRaises(AssertionError, helpers.load_list_of_tasks, ds, self.mock_play, block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None) + def test_ds_not_dict(self): + ds = [[]] + self.assertRaises(AssertionError, helpers.load_list_of_tasks, + ds, self.mock_play, block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None) + def test_empty_task(self): ds = [{}] self.assertRaisesRegexp(errors.AnsibleParserError,