summaryrefslogtreecommitdiffstats
path: root/src/software
diff options
context:
space:
mode:
authorRobin Hack <rhack@redhat.com>2013-12-10 10:41:09 +0100
committerRobin Hack <rhack@redhat.com>2013-12-10 10:41:09 +0100
commitae2ebe7f2c145b3553a42e016f67edb950ed87b9 (patch)
tree6f945ed131bcbde99cde3b8aeaa56b61c8879dcf /src/software
parenteee7c40c1f91e5b19eafb7b1135c57d659ec8345 (diff)
downloadopenlmi-providers-ae2ebe7f2c145b3553a42e016f67edb950ed87b9.tar.gz
openlmi-providers-ae2ebe7f2c145b3553a42e016f67edb950ed87b9.tar.xz
openlmi-providers-ae2ebe7f2c145b3553a42e016f67edb950ed87b9.zip
Software: Tests reorganization and fixes.
Diffstat (limited to 'src/software')
-rw-r--r--src/software/test/test_installed_software_identity.py60
-rw-r--r--src/software/test/test_software_identity_resource.py69
-rw-r--r--src/software/test/util.py17
3 files changed, 145 insertions, 1 deletions
diff --git a/src/software/test/test_installed_software_identity.py b/src/software/test/test_installed_software_identity.py
index 12aa2e8..a415733 100644
--- a/src/software/test/test_installed_software_identity.py
+++ b/src/software/test/test_installed_software_identity.py
@@ -16,6 +16,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
+# Authors: Jan Grec <jgrec@redhat.com>
# Authors: Michal Minar <miminar@redhat.com>
#
"""
@@ -30,6 +31,7 @@ from lmi.test.lmibase import enable_lmi_exceptions
from lmi.test.util import mark_tedious
import package
import swbase
+import util
class TestInstalledSoftwareIdentity(swbase.SwTestCase):
"""
@@ -179,6 +181,29 @@ class TestInstalledSoftwareIdentity(swbase.SwTestCase):
# of requested packages
self.assertEqual(db_installed, 4)
+ @mark_tedious
+ def test_list_installed_packages(self):
+ """
+ Test list of all installed packages.
+
+ Use LMI_InstalledSoftwareIdentity instances to get installed packages.
+ Compare all package names with:
+ rpm -qa
+ Cases:
+ OpenLMI package list matches yum package list.
+ """
+ package_list = []
+ for iname in self.cim_class.instance_names():
+ path = iname.InstalledSoftware.InstanceID
+ name = path[len("LMI:LMI_SoftwareIdentity:"):]
+ package_list.append(name)
+
+ self.assertNotEqual(len(package_list), 0,
+ "OpenLMI returned empty list of installed packages")
+
+ rpm_packages = util.get_installed_packages()
+ self.assertEqual(sorted(package_list), sorted(rpm_packages))
+
@swbase.test_with_repos('stable',
**{'updates' : False, 'updates-testing' : False, 'misc' : False })
@swbase.test_with_packages(**{'stable#pkg1' : False})
@@ -201,6 +226,26 @@ class TestInstalledSoftwareIdentity(swbase.SwTestCase):
self.assertCIMNameEqual(inst.path, objpath,
'Object path does not match for %s.' % pkg)
+ @swbase.test_with_repos('stable', 'misc',
+ **{ 'updates' : False, 'updates-testing' : False })
+ @swbase.test_with_packages(**{'pkg2' : False})
+ def test_install_package_same_arch(self):
+ """
+ Test package installation with ``LMI_InstalledSoftwareIdentity`` of
+ package with specific architecture.
+ """
+ pkg_arch = self.get_repo('misc')['pkg2']
+ op_arch = self.make_op(pkg_arch)
+ properties = {
+ "InstalledSoftware" : op_arch.InstalledSoftware,
+ "System" : op_arch.System
+ }
+
+ inst = self.cim_class.create_instance(properties)
+ self.assertTrue(package.is_pkg_installed(pkg_arch))
+ self.assertCIMNameEqual(inst.path, op_arch,
+ 'Object path does not match for %s.' % pkg_arch)
+
@enable_lmi_exceptions
@swbase.test_with_repos('stable',
**{'updates' : False, 'updates-testing' : False, 'misc' : False })
@@ -222,6 +267,21 @@ class TestInstalledSoftwareIdentity(swbase.SwTestCase):
self.assertRaisesCIM(pywbem.CIM_ERR_ALREADY_EXISTS,
self.cim_class.create_instance, properties)
+ @swbase.test_with_repos(**{'stable' : False})
+ @swbase.test_with_packages(**{'stable#pkg1' : False})
+ def test_install_from_disabled_repo(self):
+ pkg = self.get_repo('stable')['pkg1']
+ self.assertFalse(package.is_pkg_installed(pkg))
+ objpath = self.make_op(pkg)
+
+ properties = {
+ "InstalledSoftware" : objpath.InstalledSoftware,
+ "System" : objpath.System
+ }
+ # try to install it
+ inst = self.cim_class.create_instance(properties)
+ self.assertEqual(inst, None)
+
@enable_lmi_exceptions
@swbase.test_with_packages('stable#pkg2')
def test_remove_installed(self):
diff --git a/src/software/test/test_software_identity_resource.py b/src/software/test/test_software_identity_resource.py
index 8c18f62..2e6fa86 100644
--- a/src/software/test/test_software_identity_resource.py
+++ b/src/software/test/test_software_identity_resource.py
@@ -16,18 +16,24 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
+# Authors: Jan Grec <jgrec@redhat.com>
# Authors: Michal Minar <miminar@redhat.com>
#
"""
Unit tests for ``LMI_SoftwareIdentityResource`` provider.
"""
+import os
import pywbem
import time
+import shutil
+import subprocess
import unittest
-import swbase
+from lmi.test.lmibase import enable_lmi_exceptions
import repository
+import swbase
+import util
ENABLED_DEFAULT_NOT_APPLICABLE = 5
ENABLED_STATE_DISABLED = 3
@@ -41,11 +47,14 @@ OPERATIONAL_STATUS_OK = 2
REQUESTED_STATE_ENABLED = 2
REQUESTED_STATE_DISABLED = 3
REQUEST_STATE_CHANGE_SUCCESSFUL = 0
+REQUEST_STATE_CHANGE_ERROR = 2
RESOURCE_TYPE_OTHER = 1
PRIMARY_STATUS_ERROR = 3
PRIMARY_STATUS_OK = 1
TRANSITIONING_TO_STATE_NOT_APPLICABLE = 12
+DUMMY_TEST_REPO = 'lmi-test'
+
class TestSoftwareIdentityResource(swbase.SwTestCase):
"""
Basic cim operations test on ``LMI_SoftwareIdentityResource``.
@@ -383,6 +392,64 @@ class TestSoftwareIdentityResource(swbase.SwTestCase):
self.assertEqual(inst.OperationalStatus, [OPERATIONAL_STATUS_OK])
self.assertEqual(inst.PrimaryStatus, PRIMARY_STATUS_OK)
+ @enable_lmi_exceptions
+ def test_disable_unexisting_repository(self):
+ """
+ Test disable unexisting repository.
+
+ Enable DUMMY_TEST_REPO repository, get its instance, delete it
+ from /etc/yum.repos.d and try to disable it by OpenLMI.
+ Cases:
+ OpenLMI won't disable repository - returns error in LMIReturnValue
+ """
+ repo_file_path = os.path.join(self.yum_repos_dir,
+ DUMMY_TEST_REPO + ".repo")
+ shutil.copy2("%s.repo" % DUMMY_TEST_REPO, repo_file_path)
+ try:
+ repository.set_repo_enabled(DUMMY_TEST_REPO, True)
+ subprocess.call(["/usr/bin/yum-config-manager",
+ "--enable", DUMMY_TEST_REPO],
+ stdout=util.DEV_NULL, stderr=util.DEV_NULL)
+ repo = self.cim_class.first_instance_name(
+ {"Name": DUMMY_TEST_REPO}).to_instance()
+ self.assertNotEqual(repo, None, "dummy repository exists")
+
+ os.remove(repo_file_path)
+
+ self.assertRaisesCIM(pywbem.CIM_ERR_NOT_FOUND,
+ repo.RequestStateChange,
+ RequestedState=REQUESTED_STATE_DISABLED)
+ finally:
+ if os.path.exists(repo_file_path):
+ os.remove(repo_file_path)
+
+ @enable_lmi_exceptions
+ def test_enable_unexisting_repository(self):
+ """
+ Test enable deleted repository.
+
+ Get DUMMY_TEST_REPO's instance, delete it from /etc/yum.repos.d
+ and try to enable it by OpenLMI.
+ Cases:
+ OpenLMI won't enable repository - returns error in LMIReturnValue
+ """
+ repo_file_path = os.path.join(self.yum_repos_dir,
+ DUMMY_TEST_REPO + ".repo")
+ shutil.copy2("%s.repo" % DUMMY_TEST_REPO, repo_file_path)
+ try:
+
+ repo = self.cim_class.first_instance_name(
+ {"Name": DUMMY_TEST_REPO}).to_instance()
+
+ os.remove(repo_file_path)
+
+ self.assertRaisesCIM(pywbem.CIM_ERR_NOT_FOUND,
+ repo.RequestStateChange,
+ RequestedState=REQUESTED_STATE_ENABLED)
+ finally:
+ if os.path.exists(repo_file_path):
+ os.remove(repo_file_path)
+
def suite():
""" For unittest loaders. """
return unittest.TestLoader().loadTestsFromTestCase(
diff --git a/src/software/test/util.py b/src/software/test/util.py
index be82c6e..3999a09 100644
--- a/src/software/test/util.py
+++ b/src/software/test/util.py
@@ -18,6 +18,7 @@
#
# Authors: Radek Novacek <rnovacek@redhat.com>
# Authors: Michal Minar <miminar@redhat.com>
+# Authors: Jan Grec <jgrec@redhat.com>
"""
Common test utilities.
@@ -141,3 +142,19 @@ def get_target_operating_system():
if platform.uname()[4].lower() == 'x86_64':
target_operating_system = 80 # RHEL 64bit
return pywbem.Uint16(target_operating_system)
+
+def get_installed_packages():
+ """
+ :returns: list of packages in format: ``NAME-EPOCH:VERSION-RELEASE.ARCH``
+ """
+ output = check_output(
+ [ "/usr/bin/rpm", "-qa", "--qf"
+ , "%{NAME}-%{EPOCH}:%{VERSION}-%{RELEASE}.%{ARCH}\n"],
+ stderr=DEV_NULL).split()
+ package_list = []
+ for package in output:
+ # Skip all gpg public keys returned by rpm -qa
+ if "gpg-pubkey" not in package:
+ package_list.append(package.replace("(none)", "0"))
+ return package_list
+