From 40a66a25016cd9705772a4bd2f814f176d9bd290 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 1 Feb 2016 16:15:46 -0700 Subject: [PATCH] Logic for handling version: latest --- salt/modules/win_pkg.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index 66d84fdc8a..b794e2f211 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -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