Skip to content

Commit

Permalink
Merge pull request #55707 from Akm0d/requires_salt_state_modules
Browse files Browse the repository at this point in the history
Create a wrapper that checks for the presence of state modules for tests
  • Loading branch information
dwoz authored Jan 9, 2020
2 parents 224278d + c6c2eb8 commit eeaba82
Show file tree
Hide file tree
Showing 5 changed files with 343 additions and 261 deletions.
7 changes: 5 additions & 2 deletions salt/modules/mac_brew_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,13 @@ def _fix_cask_namespace(name=None, pkgs=None):
if pkgs:
pkgs_ = []
for pkg in pkgs:
if pkg.startswith('caskroom/cask/'):
if isinstance(pkg, str) and pkg.startswith('caskroom/cask/'):
show_warning = True
pkg = pkg.replace("caskroom/cask/", "homebrew/cask/")
pkgs_.append(pkg)
pkgs_.append(pkg)
else:
pkgs_.append(pkg)
continue
pkgs = pkgs_

if show_warning:
Expand Down
53 changes: 32 additions & 21 deletions tests/integration/modules/test_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
destructiveTest,
requires_network,
requires_salt_modules,
requires_salt_states,
requires_system_grains,
skip_if_not_root)
from tests.support.unit import skipIf

# Import Salt libs
from salt.ext import six
import salt.utils.path
import salt.utils.pkg
import salt.utils.platform
Expand Down Expand Up @@ -181,37 +181,47 @@ def test_remove():
test_remove()

@destructiveTest
@requires_salt_modules('pkg.hold', 'pkg.unhold', 'pkg.install', 'pkg.version', 'pkg.remove')
@requires_salt_modules('pkg.hold', 'pkg.unhold', 'pkg.install', 'pkg.version', 'pkg.remove', 'pkg.list_pkgs')
@requires_salt_states('pkg.installed')
@requires_network()
@requires_system_grains
def test_hold_unhold(self, grains):
'''
test holding and unholding a package
'''
ret = None
versionlock_pkg = None
if grains['os_family'] == 'RedHat':
# get correct plugin for dnf packages following the logic in `salt.modules.yumpkg._yum`
lock_pkg = 'yum-versionlock' if grains['osmajorrelease'] == '5' else 'yum-plugin-versionlock'
if 'fedora' in grains['os'].lower() and int(grains['osrelease']) >= 22:
if int(grains['osmajorrelease']) >= 26:
lock_pkg = 'python{py}-dnf-plugin-versionlock'.format(py=3 if six.PY3 else 2)
else:
lock_pkg = 'python{py}-dnf-plugins-extras-versionlock'.format(py=3 if six.PY3 else '')
ret = self.run_state('pkg.installed', name=lock_pkg)
pkgs = {p for p in self.run_function('pkg.list_pkgs') if '-versionlock' in p}
if not pkgs:
self.skipTest('No versionlock package found in repositories')
for versionlock_pkg in pkgs:
ret = self.run_state('pkg.installed', name=versionlock_pkg, refresh=False)
# Exit loop if a versionlock package installed correctly
try:
self.assertSaltTrueReturn(ret)
break
except AssertionError:
pass
else:
self.fail('Could not install versionlock package from {}'.format(pkgs))

self.run_function('pkg.install', [self.pkg])

hold_ret = self.run_function('pkg.hold', [self.pkg])
if 'versionlock is not installed' in hold_ret:
try:
hold_ret = self.run_function('pkg.hold', [self.pkg])
if versionlock_pkg and '-versionlock is not installed' in str(hold_ret):
self.skipTest('{} `{}` is installed'.format(hold_ret, versionlock_pkg))
self.assertIn(self.pkg, hold_ret)
self.assertTrue(hold_ret[self.pkg]['result'])

unhold_ret = self.run_function('pkg.unhold', [self.pkg])
self.assertIn(self.pkg, unhold_ret)
self.assertTrue(unhold_ret[self.pkg]['result'])
self.run_function('pkg.remove', [self.pkg])
self.skipTest('Versionlock could not be installed on this system: {}'.format(ret))
self.assertIn(self.pkg, hold_ret)
self.assertTrue(hold_ret[self.pkg]['result'])

unhold_ret = self.run_function('pkg.unhold', [self.pkg])
self.assertIn(self.pkg, unhold_ret)
self.assertTrue(unhold_ret[self.pkg]['result'])
self.run_function('pkg.remove', [self.pkg])
finally:
if versionlock_pkg:
ret = self.run_state('pkg.removed', name=versionlock_pkg)
self.assertSaltTrueReturn(ret)

@destructiveTest
@requires_salt_modules('pkg.refresh_db')
Expand Down Expand Up @@ -345,6 +355,7 @@ def test_pkg_upgrade_has_pending_upgrades(self, grains):
@destructiveTest
@skipIf(salt.utils.platform.is_darwin(), 'The jenkins user is equivalent to root on mac, causing the test to be unrunnable')
@requires_salt_modules('pkg.remove', 'pkg.latest_version')
@requires_salt_states('pkg.removed')
@requires_system_grains
def test_pkg_latest_version(self, grains):
'''
Expand Down
Loading

0 comments on commit eeaba82

Please sign in to comment.