Add test interface to pkg state

This commit is contained in:
Thomas S Hatch 2012-04-10 18:45:02 -06:00
parent 7a8a0fb76c
commit 2fccc17537

View File

@ -26,7 +26,13 @@ def __gen_rtag():
return os.path.join(__opts__['cachedir'], 'pkg_refresh')
def installed(name, version=None, refresh=False, repo='', skip_verify=False, **kwargs):
def installed(
name,
version=None,
refresh=False,
repo='',
skip_verify=False,
**kwargs):
'''
Verify that the package is installed, and only that it is installed. This
state will not upgrade an existing package and only verify that it is
@ -57,13 +63,20 @@ def installed(name, version=None, refresh=False, repo='', skip_verify=False, **k
return {'name': name,
'changes': {},
'result': True,
'comment': 'Package {0} is already installed and is the correct version'.format(name)}
'comment': ('Package {0} is already installed and is the '
'correct version').format(name)}
elif cver:
# The package is installed
return {'name': name,
'changes': {},
'result': True,
'comment': 'Package {0} is already installed'.format(name)}
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Package {0} is set to be installed'.format(name)
return ret
if refresh or os.path.isfile(rtag):
changes = __salt__['pkg.install'](name,
True,
@ -121,12 +134,19 @@ def latest(name, refresh=False, repo='', skip_verify=False, **kwargs):
try:
has_newer = LooseVersion(avail) > LooseVersion(version)
except AttributeError:
logger.debug("Error comparing versions for '%s' (%s > %s)",
logger.debug(
'Error comparing versions for "{0}" ({1} > {2})'.format(
name, avail, version)
ret['comment'] = "No version could be retrieved for '{0}'".format(name)
)
ret['comment'] = 'No version could be retrieved for "{0}"'.format(
name)
return ret
if has_newer:
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Package {0} is set to be upgraded'.format(name)
return ret
if refresh or os.path.isfile(rtag):
ret['changes'] = __salt__['pkg.install'](name,
True,
@ -171,6 +191,10 @@ def removed(name):
'result': True,
'comment': 'Package {0} is not installed'.format(name)}
else:
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Package {0} is set to be removed'.format(name)
return ret
changes['removed'] = __salt__['pkg.remove'](name)
if not changes:
return {'name': name,
@ -198,6 +222,10 @@ def purged(name):
'result': True,
'comment': 'Package {0} is not installed'.format(name)}
else:
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Package {0} is set to be purged'.format(name)
return ret
changes['removed'] = __salt__['pkg.purge'](name)
if not changes: