Commit Graph

144 Commits

Author SHA1 Message Date
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 b247c320d2 issue #164: rename tests for clarity 2018-04-06 15:10:33 +01:00
David Wilson bc4a6b39bf issue #164: teach debops_tests.sh to use SSH
Login with a non-privileged account over SSH rather than just jumping
straight in as root via Docker.
2018-04-05 22:52:02 +01:00
David Wilson 35fdd97f9a issue #164: utility to print Docker hostname for use from shell scripts. 2018-04-05 20:24:11 +01:00
David Wilson b9d4ec57b3 issue #164: some more ActionMixin tests. 2018-04-05 19:36:08 +01:00
David Wilson 29288b236b issue #164: import run_ansible_playbook.sh. 2018-04-05 19:34:44 +01:00
David Wilson db894478f8 issue #164: make become_flags work without FOO=2 env var. 2018-04-05 17:42:43 +01:00
David Wilson e4b49997d6 issue #164: whups, delete checked in binaries. 2018-04-05 16:34:54 +00:00
David Wilson d068a36c1e issue #164: more dir layout contortions.
all.yml slurps in tests from each file/subdir in the CWD.
2018-04-05 17:32:56 +01:00
David Wilson 680dc1bf68 issue #164: basic connection loader tests. 2018-04-05 17:27:42 +01:00
David Wilson 20ecd0af02 issue #164: fix makefile 2018-04-05 17:27:16 +01:00
David Wilson 48a0938d04 issue #164: add action module to return active strategy. 2018-04-05 17:27:02 +01:00
David Wilson 0247561fc7 issue #164: rename lib/modules 2018-04-05 17:26:43 +01:00
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.
2018-04-05 01:16:34 +01:00
David Wilson c5ca2e87ea issue #164: stop tests on first failure 2018-04-05 00:11:29 +01:00
David Wilson 26cc0f2724 issue #164: fix remote_tmp handling on <2.5 2018-04-04 20:19:46 +01:00
David Wilson 3ebe600389 issue #164: convert "examples" into actual tests
- Add new Travis mode, "ansible_tests.sh" that runs
  integrations/all.yml. Slowly build this up over time to cover more of
  the existing junk.

- Add basic assertions on the output of the existing runner__* files.

- Wire up 2.4.3/2.5.0 jobs in Travis.
2018-04-04 20:01:23 +01:00
David Wilson ae75a0ca8c issue #164: rearrange playbooks a little more 2018-04-04 16:11:19 +01:00
David Wilson 563639961d issue #164: dir structure is gross, but at least tab completion works :> 2018-04-04 16:08:38 +01:00
David Wilson 49aa8834b0 issue #164: split "examples" out into regression/integration tests. 2018-04-04 15:59:29 +01:00
David Wilson 4805f3cf36 issue #164: slightly flatten docker image layers 2018-04-04 14:04:22 +01:00
David Wilson 8ca8b43df1 tests/bench: import "slightly more reliable time" script 2018-04-02 07:30:06 +00:00
David Wilson eb402c8bd4 tests/bench: import wrapper script used for blog charts 2018-04-02 07:26:52 +00:00
David Wilson de27fb3a28 issue #174: test all io_op() logic. 2018-04-01 16:39:10 +01:00
Alex Willmer dc60f05a40 tests: Switch to unit2 test runner, with coverage
This means test files are imported as modules, not run as scripts. THey
can still be run individually if so desired. Test coverage is measured,
and an html report generated in htmlcov/. Test cases are automativally
discovered, so they need not be listed twice. An overall
passed/failed/skipped summary is printed, rather than for each file.

Arguments passed to ./test are passed on to unit2. For instance

    ./test -v

will print each test name as it is run.
2018-04-01 01:43:45 +01:00
Alex Willmer 7b8fef5284 tests: Make the tests directory an importable package
Required for test discovery by e.g. unit2, pytest
2018-04-01 01:32:13 +01:00
Alex Willmer a22294dda9 call_function_test: Fix assumption that we run as a script 2018-04-01 01:23:13 +01:00
Alex Willmer 0dcaeb21a2 master_test: Don't assume __file__ points to source code
When run under a test runner the unit tests are imported as modules.
This triggers .pyc generation, after which __file__ resolves to the .pyc
file.
2018-04-01 01:21:42 +01:00
Alex Willmer 841c2b13a1 fakessh_test: Apply timeout decorators to rsync tests
timeoutcontext.timeout uses SIGALRM, hence it will only work on Unix
like operating systems.
2018-04-01 01:17:29 +01:00
David Wilson bbb0f1bbd8 issue #155: fix double-fork behaviour and test it this time. 2018-03-29 23:57:24 +05:45
David Wilson 4c433dbed1 parent_test: Add explanation. 2018-03-29 23:49:45 +05:45
David Wilson bde1778373 tests: merge tty_create_child() test into parent_test and fix hang 2018-03-29 23:36:50 +05:45
David Wilson 6670cba41c Introduce handler policy functions; closes #138.
Now you can specify a function to add_handler() that authenticates the
message header, with has_parent_authority() and is_immediate_child()
built in.
2018-03-29 21:40:33 +05:45
David Wilson f726ef86de tests: first_stage_test regression due to 1ff27ada49 2018-03-29 21:33:18 +05:45
David Wilson 40b978c9b7 core: Fix source verification.
Previously:

* src_id could be spoofed
* auth_id was checked but the message was still delivered!
2018-03-29 20:24:54 +05:45
David Wilson fe614aa966 core: cleanup handlers on broker crash; closes #112. 2018-03-29 19:32:31 +05:45
David Wilson 1ff27ada49 Add maximum message size checks. Closes #151. 2018-03-29 18:54:55 +05:45
David Wilson 80a97fbc9b core: Rename Sender.put() to Sender.send().
Been annoying me for months.
2018-03-29 15:43:48 +05:45
David Wilson 085b3d21bd core: fix call_function_test regression
Second time in 3 weeks. So stupid. This time write tests.
2018-03-29 15:34:20 +05:45
David Wilson 0f29baa077 core: support pickling senders, Receiver.to_sender()
CC @moreati, in case this impacts you
2018-03-29 15:32:40 +05:45
David Wilson 17aef51e6e tests: Import .local() latency test 2018-03-29 14:36:43 +05:45
David Wilson a8a31728a0 tests: Import Latch soak test 2018-03-29 14:31:57 +05:45
David Wilson 03fcf057dd tests: just call log_to_file() from testlib
Now we can run test.sh with MITOGEN_LOG_LEVEL=debug and things just
work.
2018-03-29 07:25:11 +00:00
David Wilson 761cd9eaf8 tests: import tty_create_child_test.py. 2018-03-29 13:03:08 +05:45
David Wilson 7b12f84366 core: support CallError(str) for service.py. 2018-03-29 11:53:02 +05:45
David Wilson fccca54068 tests: ensure OpenSSL is initialized prior to test. 2018-03-27 14:56:03 +05:45
David Wilson 4903052f42 fork: reseed Python/SSL PRNGs
Mac's SSL seems to have a pthread_atfork handler or similar that does
this for us, no clue if Linux is the same.
2018-03-27 11:58:17 +05:45
David Wilson 48351a1889 issue #155: parent: support Context.shutdown(), reap children on exit.
This permits graceful shutdown of individual contexts, without tearing
down everything.

Update mitogen.parent.Stream to also wait for the child to exit, to
prevent the buildup of zombie processes. This introduces a blocking wait
for process exit on the Broker thread, let's see if we can get away with
it. Chances are reasonable that it'll cause needless hangs on heavily
loaded machines.
2018-03-24 19:19:51 +05:45
David Wilson 4f93c6823a issue #155: skeletal fork_test. 2018-03-24 16:28:13 +05:45
David Wilson 2d7821b824 tests: test_stream_name: fix non-localhost Docker 2018-03-22 13:25:56 +05:45