Logic for handling version: latest

This commit is contained in:
twangboy 2016-02-01 16:15:46 -07:00
parent b7dadd3b9b
commit 40a66a2501

View File

@ -546,6 +546,7 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
# Loop through each package
changed = []
latest = []
for pkg_name, options in six.iteritems(pkg_params):
# Load package information for the package
@ -579,6 +580,9 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
ret[pkg_name] = {'not found': version_num}
continue
if 'latest' in pkginfo:
latest.append(pkg_name)
# Get the installer
installer = pkginfo[version_num].get('installer')
@ -694,6 +698,21 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
# Get a new list of installed software
new = list_pkgs()
# For installers that have no specific version (ie: chrome)
# The software definition file will have a version of 'latest'
# In that case there's no way to know which version has been installed
# Just return the current installed version
# This has to be done before the loop below, otherwise the installation
# will not be detected
if latest:
for pkg_name in latest:
ret[pkg_name] = {'current': new[pkg_name],
'comment': 'Version of "latest" found in the\n'
'software definition file.'}
# Sometimes the installer takes awhile to update the registry
# This checks 10 times, 3 seconds between each for a registry change
tries = 0
difference = salt.utils.compare_dicts(old, new)
while not all(name in difference for name in changed) and tries < 10:
@ -704,11 +723,13 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
tries += 1
log.debug("Try {0}".format(tries))
if tries == 10:
ret['_comment'] = 'Software not found in the registry.\n' \
'Could be a problem with the Software\n' \
'definition file. Verify the full_name\n' \
'and the version match the registry exactly.\n' \
'Failed after {0} tries.'.format(tries)
if not latest:
ret['_comment'] = 'Software not found in the registry.\n' \
'Could be a problem with the Software\n' \
'definition file. Verify the full_name\n' \
'and the version match the registry ' \
'exactly.\n' \
'Failed after {0} tries.'.format(tries)
# Compare the software list before and after
# Add the difference to ret