From 705d77a9bec7196c5bf35351ad8807b05ed41019 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 8 Sep 2018 22:31:19 +0100 Subject: [PATCH] ansible: remove a bunch more aliasing from connection.py. --- ansible_mitogen/connection.py | 34 ++++++++----------- .../integration/runner/forking_active.yml | 4 +++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 21ecb5f0..a56850cf 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -417,13 +417,18 @@ class Connection(ansible.plugins.connection.ConnectionBase): #: reached via become. context = None - #: mitogen.parent.Context for the login account on the target. This is - #: always the login account, even when become=True. + #: Context for the login account on the target. This is always the login + #: account, even when become=True. login_context = None - #: mitogen.parent.Context connected to the fork parent process in the - #: target user account. - fork_context = None + #: Dict containing init_child() return vaue as recorded at startup by + #: ContextService. Contains: + #: + #: fork_context: Context connected to the fork parent : process in the + #: target account. + #: home_dir: Target context's home directory. + #: temp_dir: A writeable temporary directory path. + init_child_result = None #: Only sudo, su, and doas are supported for now. become_methods = ['sudo', 'su', 'doas'] @@ -448,12 +453,6 @@ class Connection(ansible.plugins.connection.ConnectionBase): #: matching vanilla Ansible behaviour. loader_basedir = None - #: Set after connection to the target context's home directory. - home_dir = None - - #: Set after connection to the target context's home directory. - _temp_dir = None - def __init__(self, play_context, new_stdin, **kwargs): assert ansible_mitogen.process.MuxProcess.unix_listener_path, ( 'Mitogen connection types may only be instantiated ' @@ -495,7 +494,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): @property def homedir(self): self._connect() - return self.home_dir + return self.init_child_result['home_dir'] @property def connected(self): @@ -622,13 +621,11 @@ class Connection(ansible.plugins.connection.ConnectionBase): else: self.login_context = self.context - self.fork_context = dct['init_child_result']['fork_context'] - self.home_dir = dct['init_child_result']['home_dir'] - self._temp_dir = dct['init_child_result']['temp_dir'] + self.init_child_result = dct['init_child_result'] def get_temp_dir(self): self._connect() - return self._temp_dir + return self.init_child_result['temp_dir'] def _connect(self): """ @@ -662,8 +659,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): ) self.context = None - self.fork_context = None - self.login_context = None + self.init_child_result = None if self.broker and not new_task: self.broker.shutdown() self.broker.join() @@ -694,7 +690,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): if kwargs.pop('use_login_context', None): call_context = self.login_context elif kwargs.pop('use_fork_context', None): - call_context = self.fork_context + call_context = self.init_child_result['fork_context'] else: call_context = self.context diff --git a/tests/ansible/integration/runner/forking_active.yml b/tests/ansible/integration/runner/forking_active.yml index 15e6d2bc..e3e63b71 100644 --- a/tests/ansible/integration/runner/forking_active.yml +++ b/tests/ansible/integration/runner/forking_active.yml @@ -5,6 +5,10 @@ # Verify mitogen_task_isolation=fork triggers forking. + - name: get regular process ID. + custom_python_detect_environment: + register: sync_proc1 + - name: get force-forked process ID. custom_python_detect_environment: register: fork_proc1