mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #49164 from terminalmage/issue49154
Fix bug in keep_source for non-templated salt:// file sources
This commit is contained in:
commit
0157eacffc
2 changed files with 65 additions and 7 deletions
|
@ -2596,8 +2596,15 @@ def managed(name,
|
|||
ret['changes'] = {}
|
||||
log.debug(traceback.format_exc())
|
||||
salt.utils.files.remove(tmp_filename)
|
||||
if not keep_source and sfn:
|
||||
salt.utils.files.remove(sfn)
|
||||
if not keep_source:
|
||||
if not sfn \
|
||||
and source \
|
||||
and _urlparse(source).scheme == 'salt':
|
||||
# The file would not have been cached until manage_file was
|
||||
# run, so check again here for a cached copy.
|
||||
sfn = __salt__['cp.is_cached'](source, __env__)
|
||||
if sfn:
|
||||
salt.utils.files.remove(sfn)
|
||||
return _error(ret, 'Unable to check_cmd file: {0}'.format(exc))
|
||||
|
||||
# file being updated to verify using check_cmd
|
||||
|
@ -2667,8 +2674,15 @@ def managed(name,
|
|||
finally:
|
||||
if tmp_filename:
|
||||
salt.utils.files.remove(tmp_filename)
|
||||
if not keep_source and sfn:
|
||||
salt.utils.files.remove(sfn)
|
||||
if not keep_source:
|
||||
if not sfn \
|
||||
and source \
|
||||
and _urlparse(source).scheme == 'salt':
|
||||
# The file would not have been cached until manage_file was
|
||||
# run, so check again here for a cached copy.
|
||||
sfn = __salt__['cp.is_cached'](source, __env__)
|
||||
if sfn:
|
||||
salt.utils.files.remove(sfn)
|
||||
|
||||
|
||||
_RECURSE_TYPES = ['user', 'group', 'mode', 'ignore_files', 'ignore_dirs']
|
||||
|
|
|
@ -723,6 +723,29 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
if os.path.exists(name):
|
||||
os.remove(name)
|
||||
|
||||
@with_tempfile
|
||||
def test_managed_keep_source_false_salt(self, name):
|
||||
'''
|
||||
This test ensures that we properly clean the cached file if keep_source
|
||||
is set to False, for source files using a salt:// URL
|
||||
'''
|
||||
source = 'salt://grail/scene33'
|
||||
saltenv = 'base'
|
||||
|
||||
# Run the state
|
||||
ret = self.run_state(
|
||||
'file.managed',
|
||||
name=name,
|
||||
source=source,
|
||||
saltenv=saltenv,
|
||||
keep_source=False)
|
||||
ret = ret[next(iter(ret))]
|
||||
assert ret['result'] is True
|
||||
|
||||
# Now make sure that the file is not cached
|
||||
result = self.run_function('cp.is_cached', [source, saltenv])
|
||||
assert result == '', 'File is still cached at {0}'.format(result)
|
||||
|
||||
def test_directory(self):
|
||||
'''
|
||||
file.directory
|
||||
|
@ -3860,6 +3883,11 @@ class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
if exc.errno != errno.ENOENT:
|
||||
raise exc
|
||||
|
||||
def run_state(self, *args, **kwargs):
|
||||
ret = super(RemoteFileTest, self).run_state(*args, **kwargs)
|
||||
log.debug('ret = %s', ret)
|
||||
return ret
|
||||
|
||||
def test_file_managed_http_source_no_hash(self):
|
||||
'''
|
||||
Test a remote file with no hash
|
||||
|
@ -3868,7 +3896,6 @@ class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
name=self.name,
|
||||
source=self.source,
|
||||
skip_verify=False)
|
||||
log.debug('ret = %s', ret)
|
||||
# This should fail because no hash was provided
|
||||
self.assertSaltFalseReturn(ret)
|
||||
|
||||
|
@ -3881,7 +3908,6 @@ class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
source=self.source,
|
||||
source_hash=self.source_hash,
|
||||
skip_verify=False)
|
||||
log.debug('ret = %s', ret)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
def test_file_managed_http_source_skip_verify(self):
|
||||
|
@ -3892,9 +3918,27 @@ class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
name=self.name,
|
||||
source=self.source,
|
||||
skip_verify=True)
|
||||
log.debug('ret = %s', ret)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
def test_file_managed_keep_source_false_http(self):
|
||||
'''
|
||||
This test ensures that we properly clean the cached file if keep_source
|
||||
is set to False, for source files using an http:// URL
|
||||
'''
|
||||
# Run the state
|
||||
ret = self.run_state('file.managed',
|
||||
name=self.name,
|
||||
source=self.source,
|
||||
source_hash=self.source_hash,
|
||||
keep_source=False)
|
||||
ret = ret[next(iter(ret))]
|
||||
assert ret['result'] is True
|
||||
|
||||
# Now make sure that the file is not cached
|
||||
result = self.run_function('cp.is_cached', [self.source])
|
||||
assert result == '', 'File is still cached at {0}'.format(result)
|
||||
|
||||
|
||||
WIN_TEST_FILE = 'c:/testfile'
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue