mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #7630/0589c841 backport][stable-6] Fix and re-enable cmd_runner tests (#7651)
Fix and re-enable cmd_runner tests (#7630)
Fix cmd_runner tests.
(cherry picked from commit 0589c84176
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
1f60829b9d
commit
e13f9c1092
3 changed files with 57 additions and 2 deletions
|
@ -0,0 +1,56 @@
|
|||
# Copyright 2012, Dag Wieers <dag@wieers.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.playbook.conditional import Conditional
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
''' Fail with custom message '''
|
||||
|
||||
_requires_connection = False
|
||||
|
||||
_VALID_ARGS = frozenset(('msg', 'that'))
|
||||
|
||||
def _make_safe(self, text):
|
||||
# A simple str(text) won't do it since AnsibleUnsafeText is clever :-)
|
||||
return ''.join(chr(ord(x)) for x in text)
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
if 'that' not in self._task.args:
|
||||
raise AnsibleError('conditional required in "that" string')
|
||||
|
||||
fail_msg = 'Assertion failed'
|
||||
success_msg = 'All assertions passed'
|
||||
|
||||
thats = self._task.args['that']
|
||||
|
||||
cond = Conditional(loader=self._loader)
|
||||
result['_ansible_verbose_always'] = True
|
||||
|
||||
for that in thats:
|
||||
cond.when = [str(self._make_safe(that))]
|
||||
test_result = cond.evaluate_conditional(templar=self._templar, all_vars=task_vars)
|
||||
if not test_result:
|
||||
result['failed'] = True
|
||||
result['evaluated_to'] = test_result
|
||||
result['assertion'] = that
|
||||
|
||||
result['msg'] = fail_msg
|
||||
|
||||
return result
|
||||
|
||||
result['changed'] = False
|
||||
result['msg'] = success_msg
|
||||
return result
|
|
@ -3,4 +3,3 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/2
|
||||
disabled # TODO
|
||||
|
|
|
@ -24,5 +24,5 @@
|
|||
ignore_errors: "{{ item.expect_error | default(omit) }}"
|
||||
|
||||
- name: check results ({{ item.name }})
|
||||
assert:
|
||||
_unsafe_assert:
|
||||
that: "{{ item.assertions }}"
|
||||
|
|
Loading…
Reference in a new issue