mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #39852 from rallytime/bp-39651
Back-port #39651 to 2016.11
This commit is contained in:
commit
8ecc719f90
5 changed files with 15 additions and 7 deletions
4
salt/cache/__init__.py
vendored
4
salt/cache/__init__.py
vendored
|
@ -143,8 +143,8 @@ class Cache(object):
|
|||
added by the driver itself.
|
||||
|
||||
:return:
|
||||
Return a python object fetched from the cache or None if the given
|
||||
path or key not found.
|
||||
Return a python object fetched from the cache or an empty dict if
|
||||
the given path or key not found.
|
||||
|
||||
:raises SaltCacheError:
|
||||
Raises an exception if cache driver detected an error accessing data
|
||||
|
|
2
salt/cache/consul.py
vendored
2
salt/cache/consul.py
vendored
|
@ -104,7 +104,7 @@ def fetch(bank, key):
|
|||
try:
|
||||
_, value = api.kv.get(c_key)
|
||||
if value is None:
|
||||
return value
|
||||
return {}
|
||||
return __context__['serial'].loads(value['Value'])
|
||||
except Exception as exc:
|
||||
raise SaltCacheError(
|
||||
|
|
2
salt/cache/localfs.py
vendored
2
salt/cache/localfs.py
vendored
|
@ -61,7 +61,7 @@ def fetch(bank, key, cachedir):
|
|||
key_file = os.path.join(cachedir, os.path.normpath(bank), '{0}.p'.format(key))
|
||||
if not os.path.isfile(key_file):
|
||||
log.debug('Cache file "%s" does not exist', key_file)
|
||||
return None
|
||||
return {}
|
||||
try:
|
||||
with salt.utils.fopen(key_file, 'rb') as fh_:
|
||||
return __context__['serial'].load(fh_)
|
||||
|
|
|
@ -134,6 +134,14 @@ class MasterPillarUtil(object):
|
|||
if not salt.utils.verify.valid_id(self.opts, minion_id):
|
||||
continue
|
||||
mdata = self.cache.fetch('minions/{0}'.format(minion_id), 'data')
|
||||
if not isinstance(mdata, dict):
|
||||
log.warning(
|
||||
'cache.fetch should always return a dict. ReturnedType: {0}, MinionId: {1}'.format(
|
||||
type(mdata).__name__,
|
||||
minion_id
|
||||
)
|
||||
)
|
||||
continue
|
||||
if 'grains' in mdata:
|
||||
grains[minion_id] = mdata['grains']
|
||||
if 'pillar' in mdata:
|
||||
|
|
6
tests/unit/cache/localfs_test.py
vendored
6
tests/unit/cache/localfs_test.py
vendored
|
@ -100,10 +100,10 @@ class LocalFSTest(TestCase):
|
|||
@patch('os.path.isfile', MagicMock(return_value=False))
|
||||
def test_fetch_return_when_cache_file_does_not_exist(self):
|
||||
'''
|
||||
Tests that the fetch function returns None when the cache key file doesn't
|
||||
exist.
|
||||
Tests that the fetch function returns an empty dic when the cache key file
|
||||
doesn't exist.
|
||||
'''
|
||||
self.assertIsNone(localfs.fetch(bank='', key='', cachedir=''))
|
||||
self.assertEqual(localfs.fetch(bank='', key='', cachedir=''), {})
|
||||
|
||||
@patch('os.path.isfile', MagicMock(return_value=True))
|
||||
@patch('salt.utils.fopen', MagicMock(side_effect=IOError))
|
||||
|
|
Loading…
Add table
Reference in a new issue