mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
b74295d25f
commit
d39f35c1d6
2 changed files with 12 additions and 4 deletions
2
changelogs/fragments/48547-assert-incorrect_msg_type.yml
Normal file
2
changelogs/fragments/48547-assert-incorrect_msg_type.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- Added check for assert module for msg and failed_msg as a list or string types.
|
|
@ -46,14 +46,20 @@ class ActionModule(ActionBase):
|
|||
fail_msg = self._task.args.get('fail_msg', self._task.args.get('msg'))
|
||||
if fail_msg is None:
|
||||
fail_msg = 'Assertion failed'
|
||||
elif not isinstance(fail_msg, string_types):
|
||||
raise AnsibleError('Incorrect type for fail_msg or msg, expected string and got %s' % type(fail_msg))
|
||||
elif isinstance(fail_msg, list):
|
||||
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')
|
||||
if success_msg is None:
|
||||
success_msg = 'All assertions passed'
|
||||
elif not isinstance(success_msg, string_types):
|
||||
raise AnsibleError('Incorrect type for success_msg, expected string and got %s' % type(success_msg))
|
||||
elif isinstance(success_msg, list):
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue