clear available pkgs cache when pkgrepo state has changes

This clears __context__['pkg._avail'] when a pkgrepo state makes
changes, as this changes the available packages.
This commit is contained in:
Erik Johnson 2014-03-06 19:30:51 -06:00
parent 4b4fb3fb52
commit 2461e94d0d

View File

@ -265,12 +265,12 @@ def managed(name, **kwargs):
return ret
try:
__salt__['pkg.mod_repo'](**kwargs)
except Exception as e:
except Exception as exc:
# This is another way to pass information back from the mod_repo
# function.
ret['result'] = False
ret['comment'] = ('Failed to configure repo {0!r}: {1}'
.format(name, str(e)))
ret['comment'] = \
'Failed to configure repo {0!r}: {1}'.format(name, exc)
return ret
else:
# Repo was modified, refresh the pkg db if on an apt-based OS. Other
@ -279,9 +279,9 @@ def managed(name, **kwargs):
__salt__['pkg.refresh_db']()
try:
repodict = __salt__['pkg.get_repo'](kwargs['repo'],
ppa_auth=kwargs.get('ppa_auth',
None))
repodict = __salt__['pkg.get_repo'](
kwargs['repo'], ppa_auth=kwargs.get('ppa_auth', None)
)
if repo:
for kwarg in sanitizedkwargs:
if repodict.get(kwarg) != repo.get(kwarg):
@ -293,10 +293,16 @@ def managed(name, **kwargs):
ret['result'] = True
ret['comment'] = 'Configured package repo {0!r}'.format(name)
except Exception as e:
except Exception as exc:
ret['result'] = False
ret['comment'] = 'Failed to confirm config of repo {0!r}: {1}'.format(
name, str(e))
ret['comment'] = \
'Failed to confirm config of repo {0!r}: {1}'.format(name, exc)
# Clear cache of available packages, if present, since changes to the
# repositories may change the packages that are available.
if ret['changes']:
sys.modules[
__salt__['test.ping'].__module__
].__context__.pop('pkg._avail', None)
return ret
@ -342,8 +348,9 @@ def absent(name, **kwargs):
kwargs['name'] = kwargs.pop('ppa')
try:
repo = __salt__['pkg.get_repo'](name,
ppa_auth=kwargs.get('ppa_auth', None))
repo = __salt__['pkg.get_repo'](
name, ppa_auth=kwargs.get('ppa_auth', None)
)
except Exception:
pass
if not repo:
@ -360,10 +367,16 @@ def absent(name, **kwargs):
__salt__['pkg.del_repo'](repo=name, **kwargs)
repos = __salt__['pkg.list_repos']()
if name not in repos.keys():
ret['changes'] = {'repo': name}
ret['result'] = True
ret['changes'] = {'repo': name}
ret['comment'] = 'Removed package repo {0}'.format(name)
return ret
ret['result'] = False
ret['comment'] = 'Failed to remove repo {0}'.format(name)
else:
ret['result'] = False
ret['comment'] = 'Failed to remove repo {0}'.format(name)
# Clear cache of available packages, if present, since changes to the
# repositories may change the packages that are available.
if ret['changes']:
sys.modules[
__salt__['test.ping'].__module__
].__context__.pop('pkg._avail', None)
return ret