diff --git a/salt/states/archive.py b/salt/states/archive.py index 025ccf43bf..ba8c94031c 100644 --- a/salt/states/archive.py +++ b/salt/states/archive.py @@ -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', diff --git a/salt/states/file.py b/salt/states/file.py index ac94d77502..da982a13d7 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -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 ` - 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 `: - - .. 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. diff --git a/tests/integration/files/file/prod/issue45893/custom.tar.gz b/tests/integration/files/file/prod/issue45893/custom.tar.gz new file mode 100644 index 0000000000..584852716c Binary files /dev/null and b/tests/integration/files/file/prod/issue45893/custom.tar.gz differ diff --git a/tests/integration/files/file/prod/issue45893/init.sls b/tests/integration/files/file/prod/issue45893/init.sls new file mode 100644 index 0000000000..28e4ff0fe2 --- /dev/null +++ b/tests/integration/files/file/prod/issue45893/init.sls @@ -0,0 +1,5 @@ +test_non_base_env: + archive.extracted: + - name: {{ pillar['issue45893.name'] }} + - source: salt://issue45893/custom.tar.gz + - keep: False diff --git a/tests/integration/states/test_archive.py b/tests/integration/states/test_archive.py index 3722c948fb..c1b9ca8f5b 100644 --- a/tests/integration/states/test_archive.py +++ b/tests/integration/states/test_archive.py @@ -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))