diff --git a/tests/integration/states/pkg.py b/tests/integration/states/pkg.py index a106f74c12a0..204ac7c91e16 100644 --- a/tests/integration/states/pkg.py +++ b/tests/integration/states/pkg.py @@ -566,16 +566,23 @@ def test_pkg_012_latest_only_upgrade(self, grains=None): # Now look for updates and try to run the state on a package which is # already up-to-date. + installed_pkgs = self.run_function('pkg.list_pkgs') updates = self.run_function('pkg.list_upgrades', refresh=False) - try: - target = next(iter(updates)) - except StopIteration: + + for pkgname in updates: + if pkgname in installed_pkgs: + target = pkgname + break + else: + target = '' log.warning( - 'No available upgrades, skipping only_upgrade=True test with ' - 'already-installed package. For best results run this test ' - 'on a machine with upgrades available.' + 'No available upgrades to installed packages, skipping ' + 'only_upgrade=True test with already-installed package. For ' + 'best results run this test on a machine with upgrades ' + 'available.' ) - else: + + if target: ret = self.run_state('pkg.latest', name=target, refresh=False, only_upgrade=True) self.assertSaltTrueReturn(ret)