Merge pull request #24088 from jfindlay/pkg_tests

pkg module integration tests
This commit is contained in:
Thomas S Hatch 2015-05-25 13:39:02 -06:00
commit 9cec5d3dc9
2 changed files with 184 additions and 13 deletions

View file

@ -718,7 +718,7 @@ def check_db(*names, **kwargs):
return ret
def refresh_db(branch_arg, repo_arg, exclude_arg):
def refresh_db(branch_arg=None, repo_arg=None, exclude_arg=None, branch=None, repo=None, exclude=None):
'''
Check the yum repos for updated packages
@ -734,25 +734,53 @@ def refresh_db(branch_arg, repo_arg, exclude_arg):
salt '*' pkg.refresh_db
'''
def warn(old, new):
'''
warn about old arguments
'''
salt.utils.warn_until(
'Carbon',
'"{0}" is being deprecated in favor of "{1}"'.format(old, new)
)
if branch_arg:
warn(branch_arg, branch)
branch = branch_arg
if repo_arg:
warn(repo_arg, repo)
repo = repo_arg
if exclude_arg:
warn(exclude_arg, exclude)
exclude = exclude_arg
retcodes = {
100: True,
0: None,
1: False,
}
clean_cmd = 'yum -q clean expire-cache {repo} {exclude} {branch}'.format(
repo=repo_arg,
exclude=exclude_arg,
branch=branch_arg
)
__salt__['cmd.run'](clean_cmd)
update_cmd = 'yum -q check-update {repo} {exclude} {branch}'.format(
repo=repo_arg,
exclude=exclude_arg,
branch=branch_arg
)
clean_cmd = ['yum', '-q', 'clean', 'expire-cache']
update_cmd = ['yum', '-q', 'check-update']
if repo:
clean_cmd.append(repo)
update_cmd.append(repo)
if exclude:
clean_cmd.append(exclude)
update_cmd.append(exclude)
if branch:
clean_cmd.append(branch)
update_cmd.append(branch)
__salt__['cmd.run'](clean_cmd, python_shell=False)
ret = __salt__['cmd.retcode'](update_cmd,
python_shell=False,
ignore_retcode=True)
ret = __salt__['cmd.retcode'](update_cmd, ignore_retcode=True)
return retcodes.get(ret, False)

View file

@ -0,0 +1,143 @@
# -*- coding: utf-8 -*-
# Import Salt Testing libs
from salttesting.helpers import (
destructiveTest,
requires_network,
ensure_in_syspath
)
ensure_in_syspath('../../')
# Import salt libs
import integration
class PkgModuleTest(integration.ModuleCase,
integration.SaltReturnAssertsMixIn):
'''
Validate the pkg module
'''
def test_list(self):
'''
verify that packages are installed
'''
ret = self.run_function('pkg.list_pkgs')
self.assertNotEqual(len(ret.keys()), 0)
def test_version_cmp(self):
'''
test package version comparison on supported platforms
'''
func = 'pkg.version_cmp'
os_family = self.run_function('grains.item', ['os_family'])['os_family']
if os_family == 'Debian':
lt = ['0.2.4-0ubuntu1', '0.2.4.1-0ubuntu1']
eq = ['0.2.4-0ubuntu1', '0.2.4-0ubuntu1']
gt = ['0.2.4.1-0ubuntu1', '0.2.4-0ubuntu1']
self.assertEqual(self.run_function(func, lt), -1)
self.assertEqual(self.run_function(func, eq), 0)
self.assertEqual(self.run_function(func, gt), 1)
else:
self.skipTest('{0} is unavailable on {1}'.format(func, os_family))
@requires_network()
@destructiveTest
def test_mod_del_repo(self):
'''
test modifying a software repository
'''
func = 'pkg.mod_repo'
os_grain = self.run_function('grains.item', ['os'])['os']
if os_grain == 'Ubuntu':
repo = 'ppa:saltstack/salt'
uri = 'http://ppa.launchpad.net/saltstack/salt/ubuntu'
ret = self.run_function(func, [repo, 'comps=main'])
self.assertNotEqual(ret, {})
self.assertIn(uri, ret.keys()[0])
self.run_function('pkg.del_repo', [repo])
else:
self.skipTest('{0} is unavailable on {1}'.format(func, os_grain))
def test_owner(self):
'''
test finding the package owning a file
'''
func = 'pkg.owner'
available = self.run_function('sys.doc', [func])
if available:
ret = self.run_function(func, ['/bin/ls'])
self.assertNotEqual(len(ret), 0)
else:
os_grain = self.run_function('grains.item', ['os'])['os']
self.skipTest('{0} is unavailable on {1}'.format(func, os_grain))
@requires_network()
@destructiveTest
def test_install_remove(self):
'''
successfully install and uninstall a package
'''
pkg = 'htop'
version = self.run_function('pkg.version', [pkg])
def test_install():
install_ret = self.run_function('pkg.install', [pkg])
self.assertIn(pkg, install_ret)
def test_remove():
remove_ret = self.run_function('pkg.remove', [pkg])
self.assertIn(pkg, remove_ret)
if version:
test_remove()
test_install()
else:
test_install()
test_remove()
@requires_network()
@destructiveTest
def test_hold_unhold(self):
'''
test holding and unholding a package
'''
func = 'pkg.hold'
pkg = 'htop'
os_family = self.run_function('grains.item', ['os_family'])['os_family']
if os_family == 'RedHat':
self.run_function('pkg.install', ['yum-plugin-versionlock'])
ret = self.run_function(func, [pkg])
else:
os_grain = self.run_function('grains.item', ['os'])['os']
self.skipTest('{0} is unavailable on {1}'.format(func, os_grain))
@requires_network()
@destructiveTest
def test_refresh_db(self):
'''
test refreshing the package database
'''
func = 'pkg.refresh_db'
os_family = self.run_function('grains.item', ['os_family'])['os_family']
if os_family == 'RedHat':
ret = self.run_function(func)
self.assertIn(ret, (True, None))
elif os_family == 'Debian':
ret = self.run_function(func)
self.assertNotEqual(ret, {})
for source, state in ret.items():
self.assertIn(state, (True, False, None))
else:
os_grain = self.run_function('grains.item', ['os'])['os']
self.skipTest('{0} is unavailable on {1}'.format(func, os_grain))
if __name__ == '__main__':
from integration import run_tests
run_tests(PkgModuleTest)