assert: allow list of strings in msg or failed_msg (#50531)

Added check for assert module for msg and failed_msg as a list or string types.

Fixes: #48547

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-03-05 11:12:17 +05:30 committed by GitHub
parent b74295d25f
commit d39f35c1d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- Added check for assert module for msg and failed_msg as a list or string types.

View file

@ -46,14 +46,20 @@ class ActionModule(ActionBase):
fail_msg = self._task.args.get('fail_msg', self._task.args.get('msg')) fail_msg = self._task.args.get('fail_msg', self._task.args.get('msg'))
if fail_msg is None: if fail_msg is None:
fail_msg = 'Assertion failed' fail_msg = 'Assertion failed'
elif not isinstance(fail_msg, string_types): elif isinstance(fail_msg, list):
raise AnsibleError('Incorrect type for fail_msg or msg, expected string and got %s' % type(fail_msg)) if not all(isinstance(x, string_types) for x in fail_msg):
raise AnsibleError('Type of one of the elements in fail_msg or msg list is not string type')
elif not isinstance(fail_msg, (string_types, list)):
raise AnsibleError('Incorrect type for fail_msg or msg, expected a string or list and got %s' % type(fail_msg))
success_msg = self._task.args.get('success_msg') success_msg = self._task.args.get('success_msg')
if success_msg is None: if success_msg is None:
success_msg = 'All assertions passed' success_msg = 'All assertions passed'
elif not isinstance(success_msg, string_types): elif isinstance(success_msg, list):
raise AnsibleError('Incorrect type for success_msg, expected string and got %s' % type(success_msg)) if not all(isinstance(x, string_types) for x in success_msg):
raise AnsibleError('Type of one of the elements in success_msg list is not string type')
elif not isinstance(success_msg, (string_types, list)):
raise AnsibleError('Incorrect type for success_msg, expected a string or list and got %s' % type(success_msg))
quiet = boolean(self._task.args.get('quiet', False), strict=False) quiet = boolean(self._task.args.get('quiet', False), strict=False)