Commit Graph

126 Commits (0e839fe63c26f6defd9e2c8eaa020a35a5be6201)

Author SHA1 Message Date
David Wilson 20de3489de ansible: tidy up annoying syntax 7 years ago
David Wilson 98ee3e177a ansible: tests for sudo behaviour; closes #143. 7 years ago
David Wilson 4a61527774 ansible: more docstrings and call_async() 7 years ago
David Wilson 6a4ce84c6b ansible: more docstring fixes. 7 years ago
David Wilson 135b3738ba ansible: don't wait on FileService response
Any (unlikely) execption will show up in the debug logs.
7 years ago
David Wilson 70a735f23a ansible: tidy up service.py docstrings. 7 years ago
David Wilson 79b75aabae ansilbe: remove unused class variables 7 years ago
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.
7 years ago
David Wilson 71057c78f9 ansible: rename helpers.py to target.py, to reflect its purpose 7 years ago
David Wilson 7fd88868a6 ansible: raise AnsibleConnectionFailure on connection failure; closes #183
Before:

    $ ANSIBLE_STRATEGY=mitogen ansible -i derp, derp -m setup
    An exception occurred during task execution. To see the full traceback, use -vvv. The error was:     (''.join(bits)[-300:],)
    derp | FAILED! => {
        "msg": "Unexpected failure during module execution.",
        "stdout": ""
    }

After:

    $ ANSIBLE_STRATEGY=mitogen ansible -i derp, derp -m setup
    derp | UNREACHABLE! => {
        "changed": false,
        "msg": "EOF on stream; last 300 bytes received: 'ssh: Could not resolve hostname derp: nodename nor servname provided, or not known\\r\\n'",
        "unreachable": true
    }
7 years ago
David Wilson 4a823c7a27 issue #164: missing cast() for _remote_file_exists(). 7 years ago
David Wilson d503956493 ansible: Remove duplicate casts already done in Connection 7 years ago
David Wilson 6aeb4e9f05 issue #164: precisely emulate Ansible's stdio behaviour.
* Use identical logic to select when stdout/stderr are merged, so
  'stdout', 'stdout_lines', 'stderr', 'stderr_lines' contain the same
  output before/after the extension.

* When stdout/stderr are merged, synthesize carriage returns just like
  the TTY layer.

* Mimic the SSH connection multiplexing message on stderr. Not really
  for user code, but so compare_output_test.sh needs fewer fixups.
7 years ago
David Wilson 26cc0f2724 issue #164: fix remote_tmp handling on <2.5 7 years ago
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.
7 years ago
David Wilson 0e648dbd53 ansible: tidy up planner.py. 7 years ago
David Wilson a731be32a2 ansible: use _ansible_shell_executable in ScriptRunner.
Now we match Ansible error output and exit status. Ansible:

    $ ansible localhost -e end=2 -m custom_binary_single_null
    localhost | FAILED! => {
        "changed": false,
        "module_stderr": "Shared connection to localhost closed.\r\n",
        "module_stdout": "/bin/sh: /Users/dmw/.ansible/tmp/ansible-tmp-1522661797.42-158833651208060/custom_binary_single_null: cannot execute binary file\r\n",
        "msg": "MODULE FAILURE",
        "rc": 126
    }

Mitogen now:

    localhost | FAILED! => {
        "changed": false,
        "module_stderr": "/bin/sh: /var/folders/gw/f6w3dgy16fsg5y4kdthbqycw0000gn/T/ansible_mitogenAYF8LM-binary: cannot execute binary file\n",
        "module_stdout": "",
        "msg": "MODULE FAILURE",
        "rc": 126
    }

Previously:

    localhost | FAILED! => {
        "changed": false,
        "module_stderr": "<type 'exceptions.OSError'>: [Errno 8] Exec format error",
        "module_stdout": "",
        "msg": "MODULE FAILURE",
        "rc": 1
    }
7 years ago
David Wilson 293567e9d5 ansible: fix low_level_execute_command regression. 7 years ago
David Wilson fe9bf1d81d ansible: match Ansible behaviour when script lacks interpreter line. 7 years ago
David Wilson 1fab6d9c25 ansible: permit execve() of temporary files on Linux. 7 years ago
David Wilson 047458a8b3 "examples": start adding structure to regression tests. 7 years ago
David Wilson 380ef7376d ansible: Add support for free strategy. 7 years ago
David Wilson 470d8399a3 ansible: document planner.Planner. 7 years ago
David Wilson 822502125d issue #106: 2.3.x compatible get_shebang-alike. 7 years ago
David Wilson e5723e4f5f ansible: fix _make_tmp_path() regression on 2.3.x.
Due to issue #177.
7 years ago
David Wilson a5e4a6f346 issue #106: move helpers.get_bytecode() into NewStyleRunner 7 years ago
David Wilson a98a51a328 issue #106: handle JSONARGS modules too. 7 years ago
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.
7 years ago
David Wilson a954d54644 issue #106: support old-style too. 7 years ago
David Wilson 16b64392e2 issue #106: support WANT_JSON modules. 7 years ago
David Wilson df6daaf3c4 issue #106: working/semantically compatible binary support. 7 years ago
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.
7 years ago
David Wilson 1a040cf5c0 issue #106: get FileService working. 7 years ago
David Wilson 6aac37e157 issue #106: allow any context to contact FileService.
Also fix privilege check for register command.
7 years ago
David Wilson 8fffb34752 issue #106: helpers.get_file(), command logging.
* Add helpers.get_file() that calls back up into FileService as
  necessary. This is a stopgap measure.

* Add logging to exec_args() to simplify debugging of binary runners.
7 years ago
David Wilson dbaca05ac8 issue #106: Runner module docstring 7 years ago
David Wilson 43e4f5009a issue #106: remove 2 needless Invocation attributes. 7 years ago
David Wilson 2470f486e1 issue 106: ansible: make the context name available
For use later to track/deduplicate streaming uploads to targets.
7 years ago
David Wilson c891ab078a issue #106: working old-style native module execution
Still abusing Python import mechanism, but one big step closer to
eliminating that.
7 years ago
David Wilson 34a37a0ba5 issue #106: ansible: rename and significant pad out runners.py
Aiming to have working NativeRunner and BinaryRunner to begin with.
7 years ago
David Wilson 98c15942f7 issue #177: fix bizarre syntax error in last commit. 7 years ago
David Wilson cf25437019 issue #177: populate Shell.tempdir global on creating a tempdir.
It looks a lot like multiple calls to _make_tmp_path() will result in
multiple temporary directories on the remote machine, only the last of
which will be cleaned up.

We must be bug-for-bug compatible for now, so ignore the problem in the
meantime.
7 years ago
David Wilson 6eed3aa1fa issue #177: fetch and cache HOME value during connection setup.
This ensures only 1 roundtrip is required for every invocation of
_remote_expand_user().
7 years ago
David Wilson 3dc90b7618 issue #106: import skeletal planner module. 7 years ago
David Wilson 28cd17cf56 issue #106: import skeletal new executor. 7 years ago
David Wilson 9067a7b173 ansible: Move setLevel() bits together. 7 years ago
Wesley Moore 3d5bbb9a63 Use become_pass for sudo password 7 years ago
David Wilson 36e1ae15fd issue #172: prevent 'No handlers..' error being printed. 7 years ago
David Wilson e0c4d6b348 ansible: Quick fix for #172. 7 years ago
David Wilson 1ff27ada49 Add maximum message size checks. Closes #151. 7 years ago