mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Add test interface to pkg state
This commit is contained in:
parent
7a8a0fb76c
commit
2fccc17537
@ -26,7 +26,13 @@ def __gen_rtag():
|
|||||||
return os.path.join(__opts__['cachedir'], 'pkg_refresh')
|
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
|
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
|
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,
|
return {'name': name,
|
||||||
'changes': {},
|
'changes': {},
|
||||||
'result': True,
|
'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:
|
elif cver:
|
||||||
# The package is installed
|
# The package is installed
|
||||||
return {'name': name,
|
return {'name': name,
|
||||||
'changes': {},
|
'changes': {},
|
||||||
'result': True,
|
'result': True,
|
||||||
'comment': 'Package {0} is already installed'.format(name)}
|
'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):
|
if refresh or os.path.isfile(rtag):
|
||||||
changes = __salt__['pkg.install'](name,
|
changes = __salt__['pkg.install'](name,
|
||||||
True,
|
True,
|
||||||
@ -121,12 +134,19 @@ def latest(name, refresh=False, repo='', skip_verify=False, **kwargs):
|
|||||||
try:
|
try:
|
||||||
has_newer = LooseVersion(avail) > LooseVersion(version)
|
has_newer = LooseVersion(avail) > LooseVersion(version)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logger.debug("Error comparing versions for '%s' (%s > %s)",
|
logger.debug(
|
||||||
|
'Error comparing versions for "{0}" ({1} > {2})'.format(
|
||||||
name, avail, version)
|
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
|
return ret
|
||||||
|
|
||||||
if has_newer:
|
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):
|
if refresh or os.path.isfile(rtag):
|
||||||
ret['changes'] = __salt__['pkg.install'](name,
|
ret['changes'] = __salt__['pkg.install'](name,
|
||||||
True,
|
True,
|
||||||
@ -171,6 +191,10 @@ def removed(name):
|
|||||||
'result': True,
|
'result': True,
|
||||||
'comment': 'Package {0} is not installed'.format(name)}
|
'comment': 'Package {0} is not installed'.format(name)}
|
||||||
else:
|
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)
|
changes['removed'] = __salt__['pkg.remove'](name)
|
||||||
if not changes:
|
if not changes:
|
||||||
return {'name': name,
|
return {'name': name,
|
||||||
@ -198,6 +222,10 @@ def purged(name):
|
|||||||
'result': True,
|
'result': True,
|
||||||
'comment': 'Package {0} is not installed'.format(name)}
|
'comment': 'Package {0} is not installed'.format(name)}
|
||||||
else:
|
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)
|
changes['removed'] = __salt__['pkg.purge'](name)
|
||||||
|
|
||||||
if not changes:
|
if not changes:
|
||||||
|
Loading…
Reference in New Issue
Block a user