Commit Graph

36 Commits

Author SHA1 Message Date
David Wilson 57012e0f72 Add mitogen.core.now() and use it everywhere; closes #614. 2019-08-10 17:36:10 +01:00
David Wilson 711f46aee9 tests: move tty_create_child tests together 2019-08-04 12:14:48 +01:00
David Wilson 6da991fae9 [stream-refactor] Py3.x test fixes 2019-07-28 15:57:07 +01:00
David Wilson f039c81bb0 [stream-refactor] rename Process attrs, fix up more create_child_test 2019-07-22 18:30:51 +01:00
David Wilson 8d1b01d8ef Refactor Stream, introduce quasi-asynchronous connect, much more
Split Stream into many, many classes

  * mitogen.parent.Connection: Handles connection setup logic only.
    * Maintain references to stdout and stderr streams.
    * Manages TimerList timer to cancel connection attempt after
      deadline
    * Blocking setup code replaced by async equivalents running on the
      broker

  * mitogen.parent.Options: Tracks connection-specific options. This
    keeps the connection class small, but more importantly, it is
    generic to the future desire to build and execute command lines
    without starting a full connection.

  * mitogen.core.Protocol: Handles program behaviour relating to events
    on a stream. Protocol performs no IO of its own, instead deferring
    it to Stream and Side. This makes testing much easier, and means
    libssh can reimplement Stream and Side to reuse MitogenProtocol

  * mitogen.core.MitogenProtocol: Guts of the old Mitogen stream
    implementtion

  * mitogen.core.BufferedWriter: Guts of the old Mitogen buffered
    transmit implementation, made generic

  * mitogen.core.DelineatedProtocol: Guts of the old IoLogger, knows how
    to split up input and pass it on to a
    on_line_received()/on_partial_line_received() callback.

  * mitogen.parent.BootstrapProtocol: Asynchronous equivalent of the old
    blocking connect code. Waits for various prompts (MITO001 etc) and
    writes the bootstrap using a BufferedWriter. On success, switches
    the stream to MitogenProtocol.

  * mitogen.core.Message: move encoding parts of MitogenProtocol out to
    Message (where it belongs) and write a bunch of new tests for
    pickling.

  * The bizarre Stream.construct() is gone now, Option.__init__ is its
    own constructor. Should fix many LGTM errors.

* Update all connection methods:  Every connection method is updated to
  use async logic, defining protocols as required to handle interactive
  prompts like in SSH or su. Add new real integration tests for at least
  doas and su.

* Eliminate manual fd management: File descriptors are trapped in file
  objects at their point of origin, and Side is updated to use file
  objects rather than raw descriptors. This eliminates a whole class of
  bugs where unrelated FDs could be closed by the wrong component. Now
  an FD's open/closed status is fused to it everywhere in the library.

* Halve file descriptor usage: now FD open/close state is tracked by
  its file object, we don't need to duplicate FDs everywhere so that
  receive/transmit side can be closed independently. Instead both sides
  back on to the same file object. Closes #26, Closes #470.

* Remove most uses of dup/dup2: Closes #256. File descriptors are
  trapped in a common file object and shared among classes. The
  remaining few uses for dup/dup2 are as close to minimal as possible.

* Introduce mitogen.parent.Process: uniform interface for subprocesses
  created either via mitogen.fork or the subprocess module. Remove all
  the crap where we steal a pid from subprocess guts. Now we use
  subprocess to manage its processes as it should be. Closes #169 by
  using the new Timers facility to poll for a slow-to-exit subprocess.

* Fix su password race: Closes #363. DelineatedProtocol naturally
  retries partially received lines, preventing the cause of the original
  race.

* Delete old blocking IO utility functions
  iter_read()/write_all()/discard_until().

Closes #26
Closes #147
Closes #169
Closes #256
Closes #363
Closes #419
Closes #470
2019-07-22 18:30:51 +01:00
David Wilson 101e1c17b1 issue #477: stop using fork() in parent_test, compatible enumerate(). 2019-01-26 01:39:07 +00:00
David Wilson 9f10695ee2 issue #477: Popen.terminate() polyfill for Py2.4. 2019-01-26 01:38:03 +00:00
David Wilson a4c7a98dd9 parent: cope with broken /dev/pts on Linux; closes #462. 2019-01-18 21:05:38 +00:00
David Wilson f1661abe4e tests: make IterReadTest a little more robust 2018-11-07 00:38:47 +00:00
David Wilson cd6486b0e9 tests: fix more DisconnectTest raciness. 2018-11-05 13:00:47 +00:00
David Wilson cf97932fad core: dead messages have optional body, use it everywhere; closes #387. 2018-11-04 15:26:25 +00:00
David Wilson b0dd628f07 issue #406: parent_test fixes, NameError in log_fd_calls(). 2018-11-03 19:49:13 +00:00
David Wilson 70c550f50c issue #406: close stdout pipes in parent_test 2018-11-03 15:02:54 +00:00
David Wilson 8a0b343760 issue #406: test for FD leak after every TestCase 2018-11-03 13:28:37 +00:00
David Wilson 48e8f1f7aa tests: Pythonize write_all_consumer.py 2018-10-30 23:12:16 +00:00
David Wilson f53e7dd637 tests: Pythonize another shell script. 2018-10-30 23:09:06 +00:00
David Wilson 332d128651 tests: get rid of some more shell 2018-10-30 23:06:32 +00:00
David Wilson b70c57a2cb tests: fix wstatus_to_str() test on 3.x
Now they use enums.
2018-10-26 11:22:33 +01:00
David Wilson 7647c95f34 issue #76: add one more test for indirect siblings 2018-10-25 13:25:27 +01:00
David Wilson 431051f69b issue #76: parent: broadcast DEL_ROUTE to interested parties
Now rather than simply propagate DEL_ROUTE upwards towards the parent,
we broadcast it downward to any stream that ever sent a message toward
any of the routes that have just become disconnected.
2018-10-23 23:09:33 +01:00
David Wilson 3aa5c4c53d issue #373: parse the child process wait status
Don't log the raw waitpid() result, convert it to a useful string first.
2018-10-03 13:51:11 +01:00
David Wilson c4c6ae88a4 parent: raise a descriptive error when openpty fails. 2018-09-08 20:53:11 +01:00
David Wilson 06e2e846c5 parent: don't generate illegal default remote names.
getpass.getuser() output may contain slashes, which must be avoided as
they break virtualenv when present in argv[0].

Closes #344.
2018-08-18 16:43:59 +01:00
David Wilson 4ff47d6a93 parent: more 2/3x format fixes 2018-07-07 14:55:47 +01:00
David Wilson 6b4e047017 tests: 3.x parent_test fixes. 2018-07-07 14:55:47 +01:00
David Wilson 00edf0d66d core: have ExternalContext accept a config dict rather than kwargs.
The parameter lists had gotten out of control.
2018-05-23 16:24:38 +01:00
David Wilson 7c5bbc5168 setns: support changing user.
To match existing third party plugin.
2018-04-29 00:38:53 +01:00
David Wilson 1be03eb458 parent: change create_child interface.
To allow for additional arguments.
2018-04-27 03:50:03 +01:00
David Wilson e56608ab91 parent: don't wait for SIGTERM to complete. 2018-04-21 19:39:12 +01:00
David Wilson 9fe14e841c parent: reap the child process if connection fails
For example if no response is received in :attr:`connect_timeout`
seconds, the child would be left running.
2018-04-21 15:01:23 +00:00
David Wilson e43c6c531b Mostly implement hybrid TTY/socket mode for sudo and SSH.
Presently there is still no mechanism to add :attr:`tty_stream` to the
multiplexer after connection is successful, but for now it's not
expected that anything will be logged to it anyway.

Closes #148.
2018-04-18 21:40:24 +01:00
David Wilson c6284e00e9 Use subprocess to start child processes; closes #185. 2018-04-18 16:32:06 +00:00
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 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
Alex Willmer f4405c6bbc Split IterReadTest & WriteAllTest into test_parent
This matches their respective functions under test, which now reside in
mitogen.parent.
2018-03-19 21:58:29 +05:45