Move persistent connections to only use registered variables (#45616)

* Try to intuit proper plugins to send to ansible-connection

* Move sub-plugins to init so that vars will be populated in executor

* Fix connection unit tests
This commit is contained in:
Nathaniel Case 2018-09-20 09:56:43 -04:00 committed by GitHub
commit 406b59aeba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 98 additions and 109 deletions

View file

@ -300,7 +300,7 @@ class NetworkConnectionBase(ConnectionBase):
self._local = connection_loader.get('local', play_context, '/dev/null')
self._local.set_options()
self._implementation_plugins = []
self._sub_plugins = []
self._cached_variables = (None, None, None)
# reconstruct the socket_path and set instance values accordingly
@ -312,16 +312,12 @@ class NetworkConnectionBase(ConnectionBase):
return self.__dict__[name]
except KeyError:
if not name.startswith('_'):
for plugin in self._implementation_plugins:
method = getattr(plugin, name, None)
for plugin in self._sub_plugins:
method = getattr(plugin['obj'], name, None)
if method is not None:
return method
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
def _connect(self):
self.set_implementation_plugin_options(*self._cached_variables)
self._cached_variables = (None, None, None)
def exec_command(self, cmd, in_data=None, sudoable=True):
return self._local.exec_command(cmd, in_data, sudoable)
@ -345,25 +341,16 @@ class NetworkConnectionBase(ConnectionBase):
def close(self):
if self._connected:
self._connected = False
self._implementation_plugins = []
def set_options(self, task_keys=None, var_options=None, direct=None):
super(NetworkConnectionBase, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
if self._implementation_plugins:
self.set_implementation_plugin_options(task_keys, var_options, direct)
else:
self._cached_variables = (task_keys, var_options, direct)
def set_implementation_plugin_options(self, task_keys=None, var_options=None, direct=None):
'''
initialize implementation plugin options
'''
for plugin in self._implementation_plugins:
try:
plugin.set_options(task_keys=task_keys, var_options=var_options, direct=direct)
except AttributeError:
pass
for plugin in self._sub_plugins:
if plugin['type'] != 'external':
try:
plugin['obj'].set_options(task_keys=task_keys, var_options=var_options, direct=direct)
except AttributeError:
pass
def _update_connection_state(self):
'''