summaryrefslogtreecommitdiffstats
path: root/src/software/test/test_software_installed_package.py
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-02-04 12:37:58 +0100
committerMichal Minar <miminar@redhat.com>2013-02-04 14:51:03 +0100
commit775290a2c13b801c84fefdc4538fe110c4df6c24 (patch)
tree04427c4859b874ed4346a042f3d097ba51fa50d7 /src/software/test/test_software_installed_package.py
parent861a85d3b8e7ed6eaa68edc6d03f1192d46272e1 (diff)
downloadopenlmi-providers-775290a2c13b801c84fefdc4538fe110c4df6c24.tar.gz
openlmi-providers-775290a2c13b801c84fefdc4538fe110c4df6c24.tar.xz
openlmi-providers-775290a2c13b801c84fefdc4538fe110c4df6c24.zip
rewritten for safe execution of transactions
Made separate process openlmi.software.yumdb.process.YumWorker for calls to yum API. Its client openlmi.software.yumdb.YumDB communicates with it via synchronnous queues - uplink and downlink. Resolves: #63 in openlmi trac -- yum API not useable, while changing thread_id) Resolves: #33 in openlmi trac -- Install/remove package Common functionality of providers moved under openlmi.software.core subpackage to make them easily accessible from other providers without cyclic dependencies. Improved logging with cmpi_logging module. openlmi.software.cimom_entry module now is the only module loadable by cmpi-bindings. It sets up providers and maps them by their name. New subpackages: openlmi.software.core openlmi.software.yumdb
Diffstat (limited to 'src/software/test/test_software_installed_package.py')
-rwxr-xr-xsrc/software/test/test_software_installed_package.py71
1 files changed, 45 insertions, 26 deletions
diff --git a/src/software/test/test_software_installed_package.py b/src/software/test/test_software_installed_package.py
index 9de627a..93669f9 100755
--- a/src/software/test/test_software_installed_package.py
+++ b/src/software/test/test_software_installed_package.py
@@ -24,13 +24,15 @@ Unit tests for LMI_SoftwareInstalledPackage provider.
import os
import pywbem
-import shutil
import socket
import stat
import unittest
import common
-import rpmcache
+
+def make_path_tuple(objpath):
+ return tuple(objpath[a] for a in ("SoftwareElementID", "Name", "Version",
+ "SoftwareElementState"))
class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
"""
@@ -71,7 +73,7 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
"""
for pkg in self.pkgdb:
if not common.is_installed(pkg):
- common.install_pkg(pkg)
+ self.install_pkg(pkg)
objpath = self.make_op(pkg)
inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
self.assertIsSubclass(inst.path.classname, self.CLASS_NAME)
@@ -93,32 +95,46 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
"Package %s should not be installed"%pkg)
@common.mark_dangerous
- def test_enum_instances(self):
+ def test_enum_instance_names(self):
"""
Tests EnumInstances call.
TODO: test this in non-dangerous way
"""
- pkg = self.pkgdb[0]
- if common.is_installed(pkg.name):
+ pkg = self.pkgdb[0] if len(self.pkgdb) > 0 else None
+ if pkg and common.is_installed(pkg.name):
common.remove_pkg(pkg.name)
insts1 = self.conn.EnumerateInstanceNames(ClassName=self.CLASS_NAME)
- common.install_pkg(pkg)
- insts2 = self.conn.EnumerateInstanceNames(ClassName=self.CLASS_NAME)
- self.assertEqual(len(insts1) + 1, len(insts2))
+ if pkg:
+ self.install_pkg(pkg)
+ insts2 = self.conn.EnumerateInstanceNames(ClassName=self.CLASS_NAME)
+ self.assertEqual(len(insts1) + 1, len(insts2))
- objpath = self.make_op(pkg)
- self.assertIn(objpath['Software'],
- (inst['Software'] for inst in insts2))
+ if pkg:
+ objpath = self.make_op(pkg)
+ self.assertIn(make_path_tuple(objpath['Software']),
+ set(make_path_tuple(inst['Software']) for inst in insts2))
self.assertTrue(all(isinstance(inst, pywbem.CIMInstanceName)
for inst in insts1))
+ @common.mark_dangerous
+ def test_enum_instances(self):
+ """
+ Tests EnumInstances call.
+ """
+ pkg = self.pkgdb[0] if len(self.pkgdb) > 0 else None
+ if pkg and not common.is_installed(pkg.name):
+ self.install_pkg(pkg.name)
insts1 = self.conn.EnumerateInstances(ClassName=self.CLASS_NAME)
- common.remove_pkg(pkg.name)
- insts2 = self.conn.EnumerateInstances(ClassName=self.CLASS_NAME)
+ if pkg:
+ common.remove_pkg(pkg.name)
+ insts2 = self.conn.EnumerateInstances(ClassName=self.CLASS_NAME)
+ objpath = self.make_op(pkg)
+ self.assertEqual(len(insts2) + 1, len(insts1))
+ path_values = set(make_path_tuple(p["Software"]) for p in insts1)
+ self.assertIn(make_path_tuple(objpath['Software']), path_values)
+ path_values = set(make_path_tuple(p["Software"]) for p in insts2)
+ self.assertNotIn(make_path_tuple(objpath['Software']), path_values)
- self.assertEqual(len(insts2) + 1, len(insts1))
- self.assertIn(objpath['Software'],
- (inst['Software'] for inst in insts1))
self.assertTrue(all(inst['Software'] == inst.path['Software']
for inst in insts1))
self.assertTrue(all(inst['System'] == inst.path['System']
@@ -164,7 +180,7 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
"""
for pkg in self.pkgdb:
if not common.is_installed(pkg.name):
- common.install_pkg(pkg)
+ self.install_pkg(pkg)
self.assertTrue(common.is_installed(pkg.name),
"Package %s must be installed"%pkg)
objpath = self.make_op(pkg)
@@ -173,7 +189,8 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
"Package %s must be uninstalled"%pkg)
with self.assertRaises(pywbem.CIMError) as cmngr:
self.conn.DeleteInstance(objpath)
- self.assertEqual(pywbem.CIM_ERR_NOT_FOUND, cmngr.exception.args[0],
+ self.assertIn(cmngr.exception.args[0],
+ [pywbem.CIM_ERR_FAILED, pywbem.CIM_ERR_NOT_FOUND],
"Package %s can not be uninstalled again"%pkg)
@common.mark_dangerous
@@ -190,7 +207,7 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
and not common.is_installed(pkg))) :
common.remove_pkg(pkg.name)
if not common.is_installed(pkg.name):
- common.install_pkg(pkg)
+ self.install_pkg(pkg)
self.assertTrue(common.is_installed(pkg),
"Package %s must be installed"%pkg)
@@ -244,8 +261,8 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
self.assertEqual(1, len(oparms))
self.assertIn("Failed", oparms)
self.assertEqual(len(oparms["Failed"]), cnt_bad,
- "Number of errors should match number of elements in"
- " Failed for %s:%s"%(pkg.name, file_path))
+ "Number of errors not correct. Failed for %s:%s" % (
+ pkg.name, file_path))
self.assertIn(file_path, (p["Name"] for p in oparms["Failed"]),
"File %s:%s should also be in failed"%(pkg.name, file_path))
@@ -259,7 +276,7 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
and not common.is_installed(pkg, False)):
common.remove_pkg(pkg.name)
if not common.is_installed(pkg.name):
- common.install_pkg(pkg, False)
+ self.install_pkg(pkg, False)
self.assertTrue(common.is_installed(pkg, False),
"Package %s must be installed"%pkg.get_nevra(False))
@@ -288,17 +305,19 @@ class TestSoftwareInstalledPackage(common.SoftwareBaseTestCase):
self.assertTrue(common.is_installed(pkg.name),
"Package %s must be installed"%pkg)
self.assertFalse(common.is_installed(pkg, False),
- "Older package %s must not be installed"%pkg.get_nevra(False))
+ "Older package %s must not be installed" %
+ pkg.get_nevra(False))
with self.assertRaises(pywbem.CIMError) as cmngr:
self.conn.InvokeMethod(
MethodName="Update",
ObjectName=objpath)
self.assertEqual(pywbem.CIM_ERR_NOT_FOUND, cmngr.exception.args[0],
- "Older package %s should not be installed"%pkg.get_nevra(False))
+ "Older package %s should not be installed" %
+ pkg.get_nevra(False))
common.remove_pkg(pkg.name)
- common.install_pkg(pkg, False)
+ self.install_pkg(pkg, False)
self.assertTrue(common.is_installed(pkg, False))
(rval, oparms) = self.conn.InvokeMethod(