windows async changes and tests (#17400)

This commit is contained in:
Matt Davis 2016-09-06 17:38:12 -07:00 committed by GitHub
parent 056a7cb957
commit f239e1e61f
5 changed files with 277 additions and 15 deletions

View file

@ -46,8 +46,8 @@ class ActionModule(ActionBase):
self._cleanup_remote_tmp=True
module_name = self._task.action
async_module_path = self._connection._shell.join_path(tmp, 'async_wrapper')
remote_module_path = self._connection._shell.join_path(tmp, module_name)
env_string = self._compute_environment_string()
@ -57,14 +57,18 @@ class ActionModule(ActionBase):
# configure, upload, and chmod the target module
(module_style, shebang, module_data, module_path) = self._configure_module(module_name=module_name, module_args=module_args, task_vars=task_vars)
remote_module_filename = self._connection._shell.get_remote_filename(module_path)
remote_module_path = self._connection._shell.join_path(tmp, remote_module_filename)
if module_style == 'binary':
self._transfer_file(module_path, remote_module_path)
else:
self._transfer_data(remote_module_path, module_data)
# configure, upload, and chmod the async_wrapper module
(async_module_style, shebang, async_module_data, _) = self._configure_module(module_name='async_wrapper', module_args=dict(), task_vars=task_vars)
self._transfer_data(async_module_path, async_module_data)
(async_module_style, shebang, async_module_data, async_module_path) = self._configure_module(module_name='async_wrapper', module_args=dict(), task_vars=task_vars)
async_module_remote_filename = self._connection._shell.get_remote_filename(async_module_path)
remote_async_module_path = self._connection._shell.join_path(tmp, async_module_remote_filename)
self._transfer_data(remote_async_module_path, async_module_data)
argsfile = None
if module_style in ('non_native_want_json', 'binary'):
@ -75,7 +79,7 @@ class ActionModule(ActionBase):
args_data += '%s="%s" ' % (k, pipes.quote(to_unicode(v)))
argsfile = self._transfer_data(self._connection._shell.join_path(tmp, 'arguments'), args_data)
remote_paths = tmp, remote_module_path, async_module_path
remote_paths = tmp, remote_module_path, remote_async_module_path
# argsfile doesn't need to be executable, but this saves an extra call to the remote host
if argsfile:
@ -86,25 +90,33 @@ class ActionModule(ActionBase):
async_limit = self._task.async
async_jid = str(random.randint(0, 999999999999))
async_cmd = [env_string, async_module_path, async_jid, async_limit, remote_module_path]
async_cmd = [env_string, remote_async_module_path, async_jid, async_limit, remote_module_path]
if argsfile:
async_cmd.append(argsfile)
else:
# maintain a fixed number of positional parameters for async_wrapper
async_cmd.append('_')
if not self._should_remove_tmp_path(tmp):
async_cmd.append("-preserve_tmp")
async_cmd = " ".join([to_unicode(x) for x in async_cmd])
result.update(self._low_level_execute_command(cmd=async_cmd))
# clean up after
self._remove_tmp_path(tmp)
result['changed'] = True
# the async_wrapper module returns dumped JSON via its stdout
# response, so we (attempt to) parse it here
parsed_result = self._parse_returned_data(result)
# Delete tmpdir from controller unless async_wrapper says something else will do it.
# Windows cannot request deletion of files/directories that are in use, so the async
# supervisory process has to be responsible for it.
if parsed_result.get("_suppress_tmpdir_delete", False) != True:
self._remove_tmp_path(tmp)
# just return the original result
if 'skipped' in result and result['skipped'] or 'failed' in result and result['failed']:
return result
# the async_wrapper module returns dumped JSON via its stdout
# response, so we parse it here and replace the result
result = self._parse_returned_data(result)
return result
return parsed_result