Commit Graph

25 Commits

Author SHA1 Message Date
David Wilson 8c3b1fcf15 ansible: disable script interpreter processing for new-style
Re: #199
2018-04-21 20:59:36 +01:00
David Wilson c5fe817db2 ansible: tidy up log repr slightly 2018-04-21 18:19:55 +01:00
David Wilson 85e1f5f515 ansible: remove JobResultService, more compatible async jobs; closes #191.
And by "compatible" I mean "terrible". This does not implement async job
timeouts, but I'm not going to bother, upstream async implementation is
so buggy and inconsistent it resists even having its behaviour captured
in tests.
2018-04-20 17:02:48 +01:00
David Wilson f4d791662e ansible: better planner logging, try again 2018-04-17 17:05:41 +01:00
David Wilson a9a2793a49 tests: yep more debug for Travis 2018-04-17 16:50:29 +01:00
David Wilson 1fa377152d ansible: extra planner log messages. 2018-04-17 16:16:24 +01:00
David Wilson c8ce3059d1 ansible: make FileService register method synchronous
On Travis it seems it is possible for the fetch message to reach
FileService before the register message is fully processed.
2018-04-17 12:55:14 +01:00
David Wilson 4a61527774 ansible: more docstrings and call_async() 2018-04-09 03:20:48 +01:00
David Wilson 135b3738ba ansible: don't wait on FileService response
Any (unlikely) execption will show up in the debug logs.
2018-04-09 03:00:47 +01:00
David Wilson 3613162bc0 ansible: enable forking when requested and for async jobs.
Closes #105.
References #155.

mitogen/service.py:
    Refactor services to support individually exposed methods with
    different security policies for each method.

    - @mitogen.service.expose() to expose a method and set its policy
    - @mitogen.service.arg_spec() to validate input.
    - Require basic service message format to be a tuple of
      `(method, kwargs)`, where kwargs is always a dict.
    - Update DeduplicatingService to match the new scheme.

ansible_mitogen/connection.py:
    - Rename 'method' to 'method_name' to disambiguate it from the
      service.call()'s method= argument.

ansible_mitogen/planner.py:
    - Generate an ID for every job, sync or not, and fetch job results
      from JobResultService rather than via the initiating function
      call's return value.
    - Planner subclasses now get to select whether their Runner should
      run in a forked process. The base implementation requests this if
      the 'mitogen_isolation_mode=fork' task variable is present.

ansible_mitogen/runner.py:
    Teach runners to deliver their result via JobResultService executing
    in their indirect parent mux process.

ansible_mitogen/plugins/actions/mitogen_async_status.py:
    Split the implementation up into methods, and more compatibly
    emulate Ansible's existing output.

ansible_mitogen/process.py:
    Mux processes now host JobResultService.

ansible_mitogen/services.py:
    Update existing services to the new mitogen.service scheme, and
    implement JobResultService:

    * listen() method for synchronous jobs. planner.invoke() registers a
      Sender with the service prior to invoking the job, then sleeps
      waiting for the service to write the job result to the
      corresponding Receiver.

    * Non-blocking get() method for implementing mitogen_async_status
      action.

    * Child-accessible push() method for delivering task results.

ansible_mitogen/target.py:
    New helpers for spawning a virginal subprocess on startup, from
    which asynchronous and mitogen_task_isolation=fork jobs are forked.
    Necessary to avoid a task inheriting potentially
    polluted/monkey-patched parent environment, since remaining jobs
    continue to run in the original child process.

docs/ansible.rst:
    Add/merge/remove some behaviours/risks.

tests/ansible/integration:
    New tests for forking/async.
2018-04-09 00:03:09 +01:00
David Wilson 71057c78f9 ansible: rename helpers.py to target.py, to reflect its purpose 2018-04-08 19:34:03 +01:00
David Wilson e0381606af Ensure remote_tmp is respected everywhere.
Logic is still somewhat different from Ansible: we don't have to care
about sudo/non-sudo cases, etc.
2018-04-04 14:05:57 +01:00
David Wilson 0e648dbd53 ansible: tidy up planner.py. 2018-04-02 11:35:39 +01:00
David Wilson fe9bf1d81d ansible: match Ansible behaviour when script lacks interpreter line. 2018-04-02 08:08:14 +00:00
David Wilson 047458a8b3 "examples": start adding structure to regression tests. 2018-04-02 08:12:39 +01:00
David Wilson 470d8399a3 ansible: document planner.Planner. 2018-04-01 22:31:45 +01:00
David Wilson 822502125d issue #106: 2.3.x compatible get_shebang-alike. 2018-04-01 22:04:05 +01:00
David Wilson a98a51a328 issue #106: handle JSONARGS modules too. 2018-04-01 21:20:58 +01:00
David Wilson 8cc20856a8 issue #106: support custom new-style modules + 'reexec by default'
Rather than assume any structure about the Python code:

* Delete the exit_json/fail_json monkeypatches.
* Patch SystemExit rather than a magic monkeypatch-thrown exception
* Setup fake cStringIO stdin, stdout, stderr and return those along with
  SystemExit exit status
* Setup _ANSIBLE_ARGS as we used to, since we still want to override
  that with '{}' to prevent accidental import hangs, but also provide
  the same string via sys.stdin.
* Compile the module bytecode once and re-execute it for every
  invocation. May change this back again later, once some benchmarks are
  done.
* Remove the fixups stuff for now, it's handled by ^ above.

Should support any "somewhat new style" Python module, including those
that just give up and dump stuff to stdout directly.
2018-04-01 21:10:04 +01:00
David Wilson a954d54644 issue #106: support old-style too. 2018-04-01 19:01:18 +01:00
David Wilson 16b64392e2 issue #106: support WANT_JSON modules. 2018-04-01 18:19:34 +01:00
David Wilson 0dd5e04eae issue #106: partially working BinaryRunner/Planner.
Refactor planner.py to look a lot more like runner.py. This 'structural
cutpaste' looks messy -- probably we can simplify this code, even though
it's pretty simple already.
2018-04-01 16:39:10 +01:00
David Wilson 43e4f5009a issue #106: remove 2 needless Invocation attributes. 2018-04-01 16:39:10 +01:00
David Wilson c891ab078a issue #106: working old-style native module execution
Still abusing Python import mechanism, but one big step closer to
eliminating that.
2018-04-01 16:39:10 +01:00
David Wilson 3dc90b7618 issue #106: import skeletal planner module. 2018-03-30 16:06:23 +05:45