First bit of fixing temporary to have one source of truth (#35747)

* First bit of fixing temporary to have one source of truth

* Fix pep8

* Remove explicit make_tmp_path() in copy

The copy action plugin sets TRANSFER_FILES=True so it does not need to
set the temporary directory explicitly; the base class's run() method
will do that for us.

* Fix for calling a module's run when a shell has already created a temp path.

* Remember to inform the rest of the world when tempdir is removed

* New strategy for how to warn on passing tmp

Now we just warn when calling the parent class run() early.  If the
module does a late call to the parent run() and doesn't make use of the
temporary directory, then we don't check for the possibility that the
user mistakenly is sending tmp in.  If we truly deprecate this (rather
than ignoring it forever) then we might want to switch back to checking
for someone passing a value in as tmp.

* Remove tmp parameter from _execute_module as well

* Port all action plugins to not send tmp explicitly

This is now handled inside of _execute_module via the
_connection._shell.tempdir attribute.

Also update warnings and docs to tell people to set the attribute
instead of using _execute_module's tmp parameter.

* Always set local tempdir variable
This commit is contained in:
Toshio Kuratomi 2018-02-07 15:11:36 -08:00 committed by Matt Davis
parent 7225839bef
commit 71f46d69d6
82 changed files with 210 additions and 117 deletions

View file

@ -192,7 +192,7 @@ class ActionModule(ActionBase):
# remove action plugin only keys
return dict((k, v) for k, v in module_args.items() if k not in ('content', 'decrypt'))
def _copy_file(self, source_full, source_rel, content, content_tempfile, dest, task_vars, tmp):
def _copy_file(self, source_full, source_rel, content, content_tempfile, dest, task_vars):
decrypt = boolean(self._task.args.get('decrypt', True), strict=False)
follow = boolean(self._task.args.get('follow', False), strict=False)
force = boolean(self._task.args.get('force', 'yes'), strict=False)
@ -224,7 +224,7 @@ class ActionModule(ActionBase):
dest_file = dest
# Attempt to get remote file info
dest_status = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=follow, tmp=tmp, checksum=force)
dest_status = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=follow, checksum=force)
if dest_status['exists'] and dest_status['isdir']:
# The dest is a directory.
@ -237,7 +237,7 @@ class ActionModule(ActionBase):
else:
# Append the relative source location to the destination and get remote stats again
dest_file = self._connection._shell.join_path(dest, source_rel)
dest_status = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=follow, tmp=tmp, checksum=force)
dest_status = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=follow, checksum=force)
if dest_status['exists'] and not force:
# remote_file exists so continue to next iteration.
@ -258,7 +258,7 @@ class ActionModule(ActionBase):
return result
# Define a remote directory that we will copy the file to.
tmp_src = self._connection._shell.join_path(tmp, 'source')
tmp_src = self._connection._shell.join_path(self._connection._shell.tempdir, 'source')
remote_path = None
@ -273,7 +273,7 @@ class ActionModule(ActionBase):
# fix file permissions when the copy is done as a different user
if remote_path:
self._fixup_perms2((tmp, remote_path))
self._fixup_perms2((self._connection._shell.tempdir, remote_path))
if raw:
# Continue to next iteration if raw is defined.
@ -297,7 +297,7 @@ class ActionModule(ActionBase):
if lmode:
new_module_args['mode'] = lmode
module_return = self._execute_module(module_name='copy', module_args=new_module_args, task_vars=task_vars, tmp=tmp)
module_return = self._execute_module(module_name='copy', module_args=new_module_args, task_vars=task_vars)
else:
# no need to transfer the file, already correct hash, but still need to call
@ -312,7 +312,7 @@ class ActionModule(ActionBase):
# If checksums match, and follow = True, find out if 'dest' is a link. If so,
# change it to point to the source of the link.
if follow:
dest_status_nofollow = self._execute_remote_stat(dest_file, all_vars=task_vars, tmp=tmp, follow=False)
dest_status_nofollow = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=False)
if dest_status_nofollow['islnk'] and 'lnk_source' in dest_status_nofollow.keys():
dest = dest_status_nofollow['lnk_source']
@ -331,7 +331,7 @@ class ActionModule(ActionBase):
new_module_args['mode'] = lmode
# Execute the file module.
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars, tmp=tmp)
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars)
if not module_return.get('checksum'):
module_return['checksum'] = local_checksum
@ -391,8 +391,7 @@ class ActionModule(ActionBase):
task_vars = dict()
result = super(ActionModule, self).run(tmp, task_vars)
tmp = self._connection._shell.tempdir
del tmp # tmp no longer has any effect
source = self._task.args.get('src', None)
content = self._task.args.get('content', None)
@ -492,7 +491,7 @@ class ActionModule(ActionBase):
for source_full, source_rel in source_files['files']:
# copy files over. This happens first as directories that have
# a file do not need to be created later
module_return = self._copy_file(source_full, source_rel, content, content_tempfile, dest, task_vars, tmp)
module_return = self._copy_file(source_full, source_rel, content, content_tempfile, dest, task_vars)
if module_return is None:
continue
@ -518,7 +517,7 @@ class ActionModule(ActionBase):
new_module_args['state'] = 'directory'
new_module_args['mode'] = self._task.args.get('directory_mode', None)
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars, tmp=tmp)
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars)
module_executed = True
changed = changed or module_return.get('changed', False)
@ -530,7 +529,7 @@ class ActionModule(ActionBase):
new_module_args['state'] = 'link'
new_module_args['force'] = True
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars, tmp=tmp)
module_return = self._execute_module(module_name='file', module_args=new_module_args, task_vars=task_vars)
module_executed = True
if module_return.get('failed'):
@ -550,6 +549,6 @@ class ActionModule(ActionBase):
result.update(dict(dest=dest, src=source, changed=changed))
# Delete tmp path
self._remove_tmp_path(tmp)
self._remove_tmp_path(self._connection._shell.tempdir)
return result