diff options
author | Michal Minar <miminar@redhat.com> | 2013-12-19 16:29:45 +0100 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2014-01-06 13:40:42 +0100 |
commit | 41f4ea0290be9393cd0a5560c47e1c22b1fd1800 (patch) | |
tree | 95d5f1b086ddd3febc1b905e3e0f60020d83f8fa /src/software | |
parent | 4cb462a1530d52ec18955cddd0761c2d0e4c6823 (diff) | |
download | openlmi-providers-41f4ea0290be9393cd0a5560c47e1c22b1fd1800.tar.gz openlmi-providers-41f4ea0290be9393cd0a5560c47e1c22b1fd1800.tar.xz openlmi-providers-41f4ea0290be9393cd0a5560c47e1c22b1fd1800.zip |
software: test improvements
* Suppress warnings when removing testing packages that may have been
modified by finished test. Whe some installed file were missing, rpm
produced ugly warnings and errors.
* Set LC_ALL=C when running yum and parsing its output. Otherwise
numbers get localized, which confuses the parser.
* Allow to run tests from another directory.
* Minor cleanups and docstrings corrections.
Diffstat (limited to 'src/software')
-rw-r--r-- | src/software/test/README | 2 | ||||
-rw-r--r-- | src/software/test/package.py | 16 | ||||
-rw-r--r-- | src/software/test/repository.py | 12 | ||||
-rw-r--r-- | src/software/test/swbase.py | 4 | ||||
-rw-r--r-- | src/software/test/test_resource_for_software_identity.py | 6 | ||||
-rw-r--r-- | src/software/test/test_software_identity_checks.py | 2 | ||||
-rw-r--r-- | src/software/test/test_software_identity_file_check.py | 2 | ||||
-rw-r--r-- | src/software/test/test_software_identity_resource.py | 18 | ||||
-rw-r--r-- | src/software/test/test_software_installation_service.py | 7 |
9 files changed, 45 insertions, 24 deletions
diff --git a/src/software/test/README b/src/software/test/README index 4a059bd..f34a81c 100644 --- a/src/software/test/README +++ b/src/software/test/README @@ -23,7 +23,7 @@ There are number of environment variables, that affect test running: Dependencies ------------ - * @development-tools (rpmbuild, createrepo, etc.) + * @development-tools (rpmbuild, createrepo, yum-utils, etc.) Preparation ----------- diff --git a/src/software/test/package.py b/src/software/test/package.py index c4b7dfa..59f3837 100644 --- a/src/software/test/package.py +++ b/src/software/test/package.py @@ -236,15 +236,18 @@ def filter_installed_packages(pkgs, installed=True): result = {pkg_map.get(pstr, pstr) for pstr in result} return result -def remove_pkgs(pkgs, *args): +def remove_pkgs(pkgs, *args, **kwargs): """ Remove package with rpm command. - :param pkg: Either an instance of :py:class:`Package` or package name. + :param pkgs: Either an instance of :py:class:`Package` or package name. If it's a name, any version will be removed. Otherwise the exact version must be installed for command to be successful. :param list args: List of parameters for rpm command. + :param boolean suppress_stderr: Whether the standard error output of ``rpm`` + command shall be suppressed. Defaults to ``False``. """ + suppress_stderr = kwargs.pop('suppress_stderr', False) cmd = ["rpm", "--quiet"] + list(args) + ['-e'] if isinstance(pkgs, (basestring, Package)): pkgs = [pkgs] @@ -256,14 +259,17 @@ def remove_pkgs(pkgs, *args): pkg_strings.append(pkg) if len(pkg_strings) > 0: cmd.extend(pkg_strings) - subprocess.call(cmd) + kwargs = {} + if suppress_stderr: + kwargs['stderr'] = util.DEV_NULL + subprocess.call(cmd, **kwargs) def install_pkgs(pkgs, *args): """ Install a specific package. - :param pkg: Package object. - :type pkg: :py:class:`Package` + :param pkgs: Package object. + :type pkgs: :py:class:`Package` """ cmd = ["rpm", "--quiet"] + list(args) + ["-i"] if isinstance(pkgs, Package): diff --git a/src/software/test/repository.py b/src/software/test/repository.py index fce1707..bc5b44a 100644 --- a/src/software/test/repository.py +++ b/src/software/test/repository.py @@ -21,11 +21,9 @@ Abstraction of YUM repository for test purposes. """ -from collections import defaultdict, namedtuple +from collections import defaultdict from datetime import datetime -import functools import inspect -import json import os import re from subprocess import call, check_output @@ -346,10 +344,12 @@ def get_repo_list(kind='all'): if kind.lower() not in ('all', 'enabled', 'disabled'): raise ValueError('kind must be on of {"all", "enabled", "disabled"}') cmd = ["yum", "-q", "repoinfo", "all"] + env = os.environ.copy() + env['LC_ALL'] = 'C' return list( RE_REPO_TAG.search(m.group(1)).group('value').split('/')[0] for m in RE_REPO_INFOS.finditer( - check_output(cmd).decode('utf-8'))) + check_output(cmd, env=env).decode('utf-8'))) def get_repo_database(): """ @@ -358,7 +358,9 @@ def get_repo_database(): """ result = [] cmd = ["yum", "-q", "repoinfo", "all"] - repo_infos = check_output(cmd).decode('utf-8') + env = os.environ.copy() + env['LC_ALL'] = 'C' + repo_infos = check_output(cmd, env=env).decode('utf-8') for match in RE_REPO_INFOS.finditer(repo_infos): result.append(make_repo(match.group(1))) return result diff --git a/src/software/test/swbase.py b/src/software/test/swbase.py index a7d8e3c..7c2de1e 100644 --- a/src/software/test/swbase.py +++ b/src/software/test/swbase.py @@ -154,7 +154,7 @@ def test_with_packages(*install_pkgs, **enable_dict): % repopkg) to_remove = package.filter_installed_packages( to_remove.union(set(p.name for p in to_install))) - package.remove_pkgs(to_remove) + package.remove_pkgs(to_remove, suppress_stderr=True) to_install = package.filter_installed_packages( to_install, installed=False) package.install_pkgs(to_install) @@ -272,7 +272,7 @@ class SwTestCase(LmiTestCase): repository.set_repos_enabled(SwTestCase.repodb.keys(), False) to_uninstall = package.filter_installed_packages(to_uninstall) if to_uninstall: - package.remove_pkgs(to_uninstall) + package.remove_pkgs(to_uninstall, suppress_stderr=True) repository.set_repos_enabled(cls._restore_repos, True) if SwTestCase._cleanup_db: shutil.rmtree(cls.repos_dir) diff --git a/src/software/test/test_resource_for_software_identity.py b/src/software/test/test_resource_for_software_identity.py index 05814f3..e22038e 100644 --- a/src/software/test/test_resource_for_software_identity.py +++ b/src/software/test/test_resource_for_software_identity.py @@ -213,7 +213,7 @@ class TestResourceForSoftwareIdentity(swbase.SwTestCase): @swbase.test_with_repos('stable') def test_get_pkg_repository_name(self): """ - Test ``AssociatorNames()`` call on ``LMI_SoftwareIdentity``. + Try to get software identities associated with repository. """ repo = self.get_repo('stable') self.assertTrue(repo.status) @@ -248,9 +248,7 @@ class TestResourceForSoftwareIdentity(swbase.SwTestCase): }) def test_get_pkg_repository(self): """ - Test ``AssociatorNames()`` call on ``LMI_SoftwareIdentity``. - - Try to get repository for installed and not installed repository. + Try to get repository for installed and not installed package. """ repo = self.get_repo('updates') self.assertTrue(repo.status) diff --git a/src/software/test/test_software_identity_checks.py b/src/software/test/test_software_identity_checks.py index 8a8761d..6298d2d 100644 --- a/src/software/test/test_software_identity_checks.py +++ b/src/software/test/test_software_identity_checks.py @@ -67,7 +67,7 @@ class TestSoftwareIdentityChecks(swbase.SwTestCase): for pkg in repo.packages: to_uninstall.add(pkg.name) to_uninstall = list(package.filter_installed_packages(to_uninstall)) - package.remove_pkgs(to_uninstall) + package.remove_pkgs(to_uninstall, suppress_stderr=True) @swbase.test_with_packages('stable#pkg1') def test_get_instance(self): diff --git a/src/software/test/test_software_identity_file_check.py b/src/software/test/test_software_identity_file_check.py index c1fb77b..6c6b571 100644 --- a/src/software/test/test_software_identity_file_check.py +++ b/src/software/test/test_software_identity_file_check.py @@ -126,7 +126,7 @@ class TestSoftwareIdentityFileCheck(swbase.SwTestCase): for pkg in repo.packages: to_uninstall.add(pkg.name) to_uninstall = list(package.filter_installed_packages(to_uninstall)) - package.remove_pkgs(to_uninstall) + package.remove_pkgs(to_uninstall, suppress_stderr=True) def do_check_symlink(self, pkg, filepath, inst): """ diff --git a/src/software/test/test_software_identity_resource.py b/src/software/test/test_software_identity_resource.py index a53b361..cf76ed9 100644 --- a/src/software/test/test_software_identity_resource.py +++ b/src/software/test/test_software_identity_resource.py @@ -85,7 +85,11 @@ class TestSoftwareIdentityResource(swbase.SwTestCase): objpath = self.make_op(repo) self.assertCIMNameEqual(objpath, inst.path) for key in self.KEYS: - self.assertEqual(getattr(inst, key), getattr(inst.path, key)) + if key == 'SystemName': + self.assertIn(inst.SystemName, (self.SYSTEM_NAME, 'localhost')) + self.assertIn(inst.path.SystemName, (self.SYSTEM_NAME, 'localhost')) + else: + self.assertEqual(getattr(inst, key), getattr(inst.path, key)) self.assertEqual(inst.Name, repo.repoid) self.assertIsInstance(inst.AccessContext, pywbem.Uint16) @@ -410,7 +414,11 @@ class TestSoftwareIdentityResource(swbase.SwTestCase): """ repo_file_path = os.path.join(self.yum_repos_dir, DUMMY_TEST_REPO + ".repo") - shutil.copy2("%s.repo" % DUMMY_TEST_REPO, repo_file_path) + shutil.copy2( + "%s/%s.repo" % ( + os.path.dirname(swbase.__file__), + DUMMY_TEST_REPO), + repo_file_path) try: repository.set_repos_enabled(DUMMY_TEST_REPO, True) subprocess.call(["/usr/bin/yum-config-manager", @@ -441,7 +449,11 @@ class TestSoftwareIdentityResource(swbase.SwTestCase): """ repo_file_path = os.path.join(self.yum_repos_dir, DUMMY_TEST_REPO + ".repo") - shutil.copy2("%s.repo" % DUMMY_TEST_REPO, repo_file_path) + shutil.copy2( + "%s/%s.repo" % ( + os.path.dirname(swbase.__file__), + DUMMY_TEST_REPO), + repo_file_path) try: repo = self.cim_class.first_instance_name( diff --git a/src/software/test/test_software_installation_service.py b/src/software/test/test_software_installation_service.py index 1b95c21..543302b 100644 --- a/src/software/test/test_software_installation_service.py +++ b/src/software/test/test_software_installation_service.py @@ -90,8 +90,11 @@ class TestSoftwareInstallationService(swbase.SwTestCase): self.assertNotEqual(inst, None) self.assertCIMNameEqual(inst.path, objpath) for key_property in objpath.key_properties(): - self.assertEqual(getattr(inst, key_property), - getattr(objpath, key_property)) + if key_property == 'SystemName': + self.assertIn(inst.SystemName, (self.SYSTEM_NAME, 'localhost')) + else: + self.assertEqual(getattr(inst, key_property), + getattr(objpath, key_property)) self.assertGreater(len(inst.Caption), 0) self.assertEqual(inst.CommunicationStatus, COMMUNICATION_STATUS_NOT_AVAILABLE) |