mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #45934 from rallytime/bp-45902
Back-port #45902 to 2017.7.3
This commit is contained in:
commit
fb378cebb0
@ -975,7 +975,7 @@ def extracted(name,
|
||||
|
||||
if result['result']:
|
||||
# Get the path of the file in the minion cache
|
||||
cached = __salt__['cp.is_cached'](source_match)
|
||||
cached = __salt__['cp.is_cached'](source_match, saltenv=__env__)
|
||||
else:
|
||||
log.debug(
|
||||
'failed to download %s',
|
||||
|
@ -6533,37 +6533,7 @@ def cached(name,
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
cached = __salt__['cp.is_cached'](source_match)
|
||||
|
||||
This function will return the cached path of the file, or an empty string
|
||||
if the file is not present in the minion cache.
|
||||
|
||||
This state will in most cases not be useful in SLS files, but it is useful
|
||||
when writing a state or remote-execution module that needs to make sure
|
||||
that a file at a given URL has been downloaded to the cachedir. One example
|
||||
of this is in the :py:func:`archive.extracted <salt.states.file.extracted>`
|
||||
state:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
result = __states__['file.cached'](source_match,
|
||||
source_hash=source_hash,
|
||||
source_hash_name=source_hash_name,
|
||||
skip_verify=skip_verify,
|
||||
saltenv=__env__)
|
||||
|
||||
This will return a dictionary containing the state's return data, including
|
||||
a ``result`` key which will state whether or not the state was successful.
|
||||
Note that this will not catch exceptions, so it is best used within a
|
||||
try/except.
|
||||
|
||||
Once this state has been run from within another state or remote-execution
|
||||
module, the actual location of the cached file can be obtained using
|
||||
:py:func:`cp.is_cached <salt.modules.cp.is_cached>`:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
cached = __salt__['cp.is_cached'](source_match)
|
||||
cached = __salt__['cp.is_cached'](source_match, saltenv=__env__)
|
||||
|
||||
This function will return the cached path of the file, or an empty string
|
||||
if the file is not present in the minion cache.
|
||||
|
BIN
tests/integration/files/file/prod/issue45893/custom.tar.gz
Normal file
BIN
tests/integration/files/file/prod/issue45893/custom.tar.gz
Normal file
Binary file not shown.
5
tests/integration/files/file/prod/issue45893/init.sls
Normal file
5
tests/integration/files/file/prod/issue45893/init.sls
Normal file
@ -0,0 +1,5 @@
|
||||
test_non_base_env:
|
||||
archive.extracted:
|
||||
- name: {{ pillar['issue45893.name'] }}
|
||||
- source: salt://issue45893/custom.tar.gz
|
||||
- keep: False
|
@ -68,6 +68,16 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
log.debug('Checking for extracted file: %s', path)
|
||||
self.assertTrue(os.path.isfile(path))
|
||||
|
||||
def run_function(self, *args, **kwargs):
|
||||
ret = super(ArchiveTest, self).run_function(*args, **kwargs)
|
||||
log.debug('ret = %s', ret)
|
||||
return ret
|
||||
|
||||
def run_state(self, *args, **kwargs):
|
||||
ret = super(ArchiveTest, self).run_state(*args, **kwargs)
|
||||
log.debug('ret = %s', ret)
|
||||
return ret
|
||||
|
||||
def test_archive_extracted_skip_verify(self):
|
||||
'''
|
||||
test archive.extracted with skip_verify
|
||||
@ -75,7 +85,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=self.archive_tar_source, archive_format='tar',
|
||||
skip_verify=True)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
@ -91,7 +100,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=self.archive_tar_source, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
@ -111,7 +119,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
source=self.archive_tar_source, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
user='root', group=r_group)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
@ -128,7 +135,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
options='--strip=1',
|
||||
enforce_toplevel=False)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
@ -145,7 +151,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
options='--strip-components=1',
|
||||
enforce_toplevel=False)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
|
||||
@ -160,7 +165,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=self.archive_tar_source,
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
@ -177,7 +181,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
source_hash=ARCHIVE_TAR_HASH,
|
||||
use_cmd_unzip=False,
|
||||
archive_format='tar')
|
||||
log.debug('ret = %s', ret)
|
||||
if 'Timeout' in ret:
|
||||
self.skipTest('Timeout talking to local tornado server.')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
@ -190,7 +193,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
'''
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar')
|
||||
log.debug('ret = %s', ret)
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
@ -203,7 +205,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_BAD_HASH, skip_verify=True)
|
||||
log.debug('ret = %s', ret)
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
@ -216,7 +217,6 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
@ -229,6 +229,17 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
|
||||
ret = self.run_state('archive.extracted', name=ARCHIVE_DIR,
|
||||
source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar',
|
||||
source_hash=ARCHIVE_TAR_BAD_HASH)
|
||||
log.debug('ret = %s', ret)
|
||||
|
||||
self.assertSaltFalseReturn(ret)
|
||||
|
||||
def test_archive_extracted_with_non_base_saltenv(self):
|
||||
'''
|
||||
test archive.extracted with a saltenv other than `base`
|
||||
'''
|
||||
ret = self.run_function(
|
||||
'state.sls',
|
||||
['issue45893'],
|
||||
pillar={'issue45893.name': ARCHIVE_DIR},
|
||||
saltenv='prod')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self._check_extracted(os.path.join(ARCHIVE_DIR, UNTAR_FILE))
|
||||
|
Loading…
Reference in New Issue
Block a user