issue #164: some more ActionMixin tests.
parent
4a823c7a27
commit
b9d4ec57b3
@ -1,2 +1,4 @@
|
||||
- import_playbook: level_execute_command.yml
|
||||
|
||||
- import_playbook: remote_file_exists.yml
|
||||
- import_playbook: low_level_execute_command.yml
|
||||
- import_playbook: make_tmp_path.yml
|
||||
- import_playbook: transfer_data.yml
|
||||
|
@ -0,0 +1,25 @@
|
||||
|
||||
- hosts: all
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- name: integration/action/make_tmp_path.yml
|
||||
assert:
|
||||
that: true
|
||||
|
||||
- action_passthrough:
|
||||
method: _make_tmp_path
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that: out.result.startswith(ansible_remote_tmp|expanduser)
|
||||
|
||||
- stat:
|
||||
path: "{{out.result}}"
|
||||
register: st
|
||||
|
||||
- assert:
|
||||
that: st.stat.exists and st.stat.isdir and st.stat.mode == "0700"
|
||||
|
||||
- file:
|
||||
path: "{{out.result}}"
|
||||
state: absent
|
@ -0,0 +1,38 @@
|
||||
|
||||
- hosts: all
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- name: integration/action/remote_file_exists.yml
|
||||
assert:
|
||||
that: true
|
||||
|
||||
- file:
|
||||
path: /tmp/does-not-exist
|
||||
state: absent
|
||||
|
||||
- action_passthrough:
|
||||
method: _remote_file_exists
|
||||
args: ['/tmp/does-not-exist']
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that: out.result == False
|
||||
|
||||
# ---
|
||||
|
||||
- copy:
|
||||
dest: /tmp/does-exist
|
||||
content: "I think, therefore I am"
|
||||
|
||||
- action_passthrough:
|
||||
method: _remote_file_exists
|
||||
args: ['/tmp/does-exist']
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that: out.result == True
|
||||
|
||||
- file:
|
||||
path: /tmp/does-exist
|
||||
state: absent
|
||||
|
@ -0,0 +1,47 @@
|
||||
|
||||
- hosts: all
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- name: integration/action/transfer_data.yml
|
||||
file:
|
||||
path: /tmp/transfer-data
|
||||
state: absent
|
||||
|
||||
# Ensure it JSON-encodes dicts.
|
||||
- action_passthrough:
|
||||
method: _transfer_data
|
||||
kwargs:
|
||||
remote_path: /tmp/transfer-data
|
||||
data: {
|
||||
"I am JSON": true
|
||||
}
|
||||
|
||||
- slurp:
|
||||
src: /tmp/transfer-data
|
||||
register: out
|
||||
|
||||
- assert:
|
||||
that: |
|
||||
out.content.decode('base64') == '{"I am JSON": true}'
|
||||
|
||||
|
||||
# Ensure it handles strings.
|
||||
- action_passthrough:
|
||||
method: _transfer_data
|
||||
kwargs:
|
||||
remote_path: /tmp/transfer-data
|
||||
data: "I am text."
|
||||
|
||||
- slurp:
|
||||
src: /tmp/transfer-data
|
||||
register: out
|
||||
|
||||
- debug: msg={{out}}
|
||||
|
||||
- assert:
|
||||
that:
|
||||
out.content.decode('base64') == 'I am text.'
|
||||
|
||||
- file:
|
||||
path: /tmp/transfer-data
|
||||
state: absent
|
@ -0,0 +1,28 @@
|
||||
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
from ansible.plugins.strategy import StrategyBase
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
try:
|
||||
method = getattr(self, self._task.args['method'])
|
||||
args = tuple(self._task.args.get('args', ()))
|
||||
kwargs = self._task.args.get('kwargs', {})
|
||||
|
||||
return {
|
||||
'changed': False,
|
||||
'failed': False,
|
||||
'result': method(*args, **kwargs)
|
||||
}
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return {
|
||||
'changed': False,
|
||||
'failed': True,
|
||||
'msg': str(e),
|
||||
'result': e,
|
||||
}
|
Loading…
Reference in New Issue