From df6daaf3c4d0be274eaf2899b591315daa89546e Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 1 Apr 2018 12:56:53 +0100 Subject: [PATCH] issue #106: working/semantically compatible binary support. --- ansible_mitogen/helpers.py | 2 +- ansible_mitogen/mixins.py | 18 +++++++++++------- ansible_mitogen/runner.py | 26 +++++++++++++++++++++----- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ansible_mitogen/helpers.py b/ansible_mitogen/helpers.py index f561c877..270f3244 100644 --- a/ansible_mitogen/helpers.py +++ b/ansible_mitogen/helpers.py @@ -94,7 +94,7 @@ def run_module(kwargs): runner_name = kwargs.pop('runner_name') klass = getattr(ansible_mitogen.runner, runner_name) impl = klass(**kwargs) - return json.dumps(impl.run()) + return impl.run() def _async_main(job_id, runner_name, kwargs): diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index 2ed7139a..831d77eb 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -315,18 +315,22 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): ) ) - def _postprocess_response(self, js): + def _postprocess_response(self, result): """ Apply fixups mimicking ActionBase._execute_module(); this is copied verbatim from action/__init__.py, the guts of _parse_returned_data are garbage and should be removed or reimplemented once tests exist. + + :param dict result: + Dictionary with format:: + + { + "rc": int, + "stdout": "stdout data", + "stderr": "stderr data" + } """ - data = self._parse_returned_data({ - 'rc': 0, - 'stdout': js, - 'stdout_lines': [js], - 'stderr': '' - }) + data = self._parse_returned_data(result) # Cutpasted from the base implementation. if 'stdout' in data and 'stdout_lines' not in data: diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index 84d06297..ad94ef7c 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -87,6 +87,16 @@ class Runner(object): self._env.revert() def _run(self): + """ + The _run() method is expected to return a dictionary in the form of + ActionBase._low_level_execute_command() output, i.e. having:: + + { + "rc": int, + "stdout": "stdout data", + "stderr": "stderr data" + } + """ raise NotImplementedError() def run(self): @@ -224,11 +234,16 @@ class NativeRunner(Runner): # to invoke main explicitly. mod.main() except NativeModuleExit, e: - return e.dct + return { + 'rc': 0, + 'stdout': json.dumps(e.dct), + 'stderr': '', + } return { - 'failed': True, - 'msg': 'ansible_mitogen: module did not exit normally.' + 'rc': 1, + 'stdout': '', + 'stderr': 'ansible_mitogen: module did not exit normally.', } @@ -299,8 +314,9 @@ class BinaryRunner(Runner): ) except Exception, e: return { - 'failed': True, - 'msg': '%s: %s' % (type(e), e), + 'rc': 1, + 'stdout': '', + 'stderr': '%s: %s' % (type(e), e), } return {