Merge remote-tracking branch 'origin/602-recover-taskvars'
* origin/602-recover-taskvars:
issue #602: update Changelog
issue #602: recover task_vars for synchronize and meta: reset_connection
ansible: remove cutpasted docstring
[linear2] merge fallout: restore optimization from #491 / 7b129e857
This commit is contained in:
commit
c9d890b865
|
@ -46,6 +46,7 @@ import mitogen.core
|
|||
import mitogen.fork
|
||||
import mitogen.utils
|
||||
|
||||
import ansible_mitogen.mixins
|
||||
import ansible_mitogen.parsing
|
||||
import ansible_mitogen.process
|
||||
import ansible_mitogen.services
|
||||
|
@ -405,15 +406,6 @@ CONNECTION_METHOD = {
|
|||
}
|
||||
|
||||
|
||||
class Broker(mitogen.master.Broker):
|
||||
"""
|
||||
WorkerProcess maintains at most 2 file descriptors, therefore does not need
|
||||
the exuberant syscall expense of EpollPoller, so override it and restore
|
||||
the poll() poller.
|
||||
"""
|
||||
poller_class = mitogen.core.Poller
|
||||
|
||||
|
||||
class CallChain(mitogen.parent.CallChain):
|
||||
"""
|
||||
Extend :class:`mitogen.parent.CallChain` to additionally cause the
|
||||
|
@ -542,6 +534,47 @@ class Connection(ansible.plugins.connection.ConnectionBase):
|
|||
self.loader_basedir = loader_basedir
|
||||
self._mitogen_reset(mode='put')
|
||||
|
||||
def _get_task_vars(self):
|
||||
"""
|
||||
More information is needed than normally provided to an Ansible
|
||||
connection. For proxied connections, intermediary configuration must
|
||||
be inferred, and for any connection the configured Python interpreter
|
||||
must be known.
|
||||
|
||||
There is no clean way to access this information that would not deviate
|
||||
from the running Ansible version. The least invasive method known is to
|
||||
reuse the running task's task_vars dict.
|
||||
|
||||
This method walks the stack to find task_vars of the Action plugin's
|
||||
run(), or if no Action is present, from Strategy's _execute_meta(), as
|
||||
in the case of 'meta: reset_connection'. The stack is walked in
|
||||
addition to subclassing Action.run()/on_action_run(), as it is possible
|
||||
for new connections to be constructed in addition to the preconstructed
|
||||
connection passed into any running action.
|
||||
"""
|
||||
f = sys._getframe()
|
||||
|
||||
while f:
|
||||
if f.f_code.co_name == 'run':
|
||||
f_locals = f.f_locals
|
||||
f_self = f_locals.get('self')
|
||||
if isinstance(f_self, ansible_mitogen.mixins.ActionModuleMixin):
|
||||
task_vars = f_locals.get('task_vars')
|
||||
if task_vars:
|
||||
LOG.debug('recovered task_vars from Action')
|
||||
return task_vars
|
||||
elif f.f_code.co_name == '_execute_meta':
|
||||
f_all_vars = f.f_locals.get('all_vars')
|
||||
if isinstance(f_all_vars, dict):
|
||||
LOG.debug('recovered task_vars from meta:')
|
||||
return f_all_vars
|
||||
|
||||
f = f.f_back
|
||||
|
||||
LOG.warning('could not recover task_vars. This means some connection '
|
||||
'settings may erroneously be reset to their defaults. '
|
||||
'Please report a bug if you encounter this message.')
|
||||
|
||||
def get_task_var(self, key, default=None):
|
||||
"""
|
||||
Fetch the value of a task variable related to connection configuration,
|
||||
|
@ -553,12 +586,13 @@ class Connection(ansible.plugins.connection.ConnectionBase):
|
|||
does not make sense to extract connection-related configuration for the
|
||||
delegated-to machine from them.
|
||||
"""
|
||||
if self._task_vars:
|
||||
task_vars = self._task_vars or self._get_task_vars()
|
||||
if task_vars is not None:
|
||||
if self.delegate_to_hostname is None:
|
||||
if key in self._task_vars:
|
||||
return self._task_vars[key]
|
||||
if key in task_vars:
|
||||
return task_vars[key]
|
||||
else:
|
||||
delegated_vars = self._task_vars['ansible_delegated_vars']
|
||||
delegated_vars = task_vars['ansible_delegated_vars']
|
||||
if self.delegate_to_hostname in delegated_vars:
|
||||
task_vars = delegated_vars[self.delegate_to_hostname]
|
||||
if key in task_vars:
|
||||
|
|
|
@ -26,14 +26,6 @@
|
|||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
Classes to detect each case from [0] and prepare arguments necessary for the
|
||||
corresponding Runner class within the target, including preloading requisite
|
||||
files/modules known missing.
|
||||
|
||||
[0] "Ansible Module Architecture", developing_program_flow_modules.html
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
|
|
@ -294,6 +294,15 @@ def get_cpu_count(default=None):
|
|||
return cpu_count
|
||||
|
||||
|
||||
class Broker(mitogen.master.Broker):
|
||||
"""
|
||||
WorkerProcess maintains at most 2 file descriptors, therefore does not need
|
||||
the exuberant syscall expense of EpollPoller, so override it and restore
|
||||
the poll() poller.
|
||||
"""
|
||||
poller_class = mitogen.core.Poller
|
||||
|
||||
|
||||
class Binding(object):
|
||||
"""
|
||||
Represent a bound connection for a particular inventory hostname. When
|
||||
|
@ -530,7 +539,7 @@ class ClassicWorkerModel(WorkerModel):
|
|||
See WorkerModel.get_binding().
|
||||
"""
|
||||
if self.broker is None:
|
||||
self.broker = mitogen.master.Broker()
|
||||
self.broker = Broker()
|
||||
|
||||
path = self._listener_for_name(inventory_name)
|
||||
if path != self.listener_path:
|
||||
|
|
|
@ -94,6 +94,11 @@ Mitogen for Ansible
|
|||
for Unicode file contents. Now the file may contain data in any single byte
|
||||
encoding.
|
||||
|
||||
* `#602 <https://github.com/dw/mitogen/issues/602>`_: connection configuration
|
||||
is more accurately inferred for `meta: reset_connection`, the `synchronize`
|
||||
module, and for any other action plug-ins that establish new connections of
|
||||
their own.
|
||||
|
||||
* `7ae926b3 <https://github.com/dw/mitogen/commit/7ae926b3>`_: the
|
||||
``lineinfile`` module began leaking writable temporary file descriptors since
|
||||
Ansible 2.7.0. When ``lineinfile`` was used to create or modify a script, and
|
||||
|
@ -157,6 +162,7 @@ Mitogen would not be possible without the support of users. A huge thanks for
|
|||
bug reports, testing, features and fixes in this release contributed by
|
||||
`Andreas Hubert <https://github.com/peshay>`_.
|
||||
`Anton Markelov <https://github.com/strangeman>`_,
|
||||
`Dave Cottlehuber <https://github.com/dch>`_,
|
||||
`Nigel Metheringham <https://github.com/nigelm>`_,
|
||||
`Orion Poplawski <https://github.com/opoplawski>`_,
|
||||
`Pieter Voet <https://github.com/pietervoet/>`_,
|
||||
|
|
Loading…
Reference in New Issue