summaryrefslogtreecommitdiffstats
path: root/src/software/test/test_software_identity.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/test/test_software_identity.py')
-rwxr-xr-xsrc/software/test/test_software_identity.py154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/software/test/test_software_identity.py b/src/software/test/test_software_identity.py
new file mode 100755
index 0000000..934d4c9
--- /dev/null
+++ b/src/software/test/test_software_identity.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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: Michal Minar <miminar@redhat.com>
+#
+"""
+Unit tests for LMI_SoftwareIdentity provider.
+"""
+
+from datetime import datetime, timedelta
+import itertools
+import pywbem
+import unittest
+
+import base
+import rpmcache
+import util
+
+class TestSoftwareIdentity(base.SoftwareBaseTestCase): #pylint: disable=R0904
+ """
+ Basic cim operations test.
+ """
+
+ CLASS_NAME = "LMI_SoftwareIdentity"
+ KEYS = ("InstanceID", )
+
+ def make_op(self, pkg, newer=True):
+ """
+ @param ses SoftwareElementState property value
+ @return object path of SoftwareIdentity
+ """
+ objpath = self.objpath.copy()
+ objpath["InstanceID"] = 'LMI:PKG:'+pkg.get_nevra(newer, "ALWAYS")
+ return objpath
+
+ @base.mark_dangerous
+ def test_get_instance(self):
+ """
+ Dangerous test, making sure, that properties are set correctly
+ for installed and removed packages.
+ """
+ for pkg in self.dangerous_pkgs:
+ if rpmcache.is_pkg_installed(pkg.name):
+ rpmcache.remove_pkg(pkg.name)
+ objpath = self.make_op(pkg)
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertIsNone(inst["InstallDate"])
+ time_stamp = datetime.now(pywbem.cim_types.MinutesFromUTC(0)) \
+ - timedelta(seconds=0.01)
+ rpmcache.install_pkg(pkg)
+ inst2 = self.conn.GetInstance(
+ InstanceName=objpath, LocalOnly=False)
+ self.assertIsNotNone(inst2["InstallDate"])
+ self.assertGreater(inst2["InstallDate"].datetime, time_stamp)
+
+ def test_get_instance_safe(self):
+ """
+ Tests GetInstance call on packages from our rpm cache.
+ """
+ for pkg in self.safe_pkgs:
+ objpath = self.make_op(pkg)
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertEqual(inst.path, objpath,
+ "Object paths should match for package %s"%pkg)
+ for key in self.KEYS:
+ self.assertTrue(inst.properties.has_key(key),
+ "OP is missing \"%s\" key for package %s"%(key, pkg))
+ self.assertIsInstance(inst["Caption"], basestring)
+ self.assertIsInstance(inst["Description"], basestring)
+ self.assertEqual(pkg.up_evra, inst["VersionString"],
+ "VersionString does not match evra for pkg %s" % pkg)
+ self.assertTrue(inst['IsEntity'])
+ self.assertEqual(pkg.name, inst["Name"],
+ "Name does not match for pkg %s" % pkg)
+ self.assertIsInstance(inst["Epoch"], pywbem.Uint32,
+ "Epoch does not match for pkg %s" % pkg)
+ self.assertEqual(int(pkg.epoch), inst["Epoch"])
+ self.assertEqual(pkg.ver, inst["Version"],
+ "Version does not match for pkg %s" % pkg)
+ self.assertEqual(pkg.rel, inst["Release"],
+ "Release does not match for pkg %s" % pkg)
+ self.assertEqual(pkg.arch, inst["Architecture"],
+ "Architecture does not match for pkg %s" % pkg)
+
+ # try to leave out epoch part
+ if pkg.epoch == "0":
+ op_no_epoch = objpath.copy()
+ op_no_epoch["SoftwareElementID"] = util.make_nevra(pkg.name,
+ pkg.up_epoch, pkg.up_ver, pkg.up_rel, pkg.arch, "NEVER")
+ self.assertNotIn(":", op_no_epoch["SoftwareElementID"])
+ inst = self.conn.GetInstance(
+ InstanceName=op_no_epoch, LocalOnly=False)
+ self.assertIn(inst.path, (objpath, op_no_epoch))
+
+ @base.mark_tedious
+ def test_enum_instance_names_safe(self):
+ """
+ Tests EnumInstanceNames call on installed packages.
+ """
+ inames = self.conn.EnumerateInstanceNames(ClassName=self.CLASS_NAME)
+ self.assertGreater(len(inames), 0)
+ for iname in inames:
+ self.assertIsInstance(iname, pywbem.CIMInstanceName)
+ self.assertEqual(iname.namespace, 'root/cimv2')
+ self.assertEqual(sorted(iname.keys()), sorted(self.KEYS))
+ nevra_set = set(i["InstanceID"] for i in inames)
+ for pkg in self.safe_pkgs:
+ self.assertIn('LMI:PKG:'+pkg.get_nevra(with_epoch="ALWAYS"),
+ nevra_set)
+
+# @base.mark_tedious
+# def test_enum_instances(self):
+# """
+# Tests EnumInstances call on installed packages.
+# """
+# insts = self.conn.EnumerateInstances(ClassName=self.CLASS_NAME)
+# self.assertGreater(len(insts), 0)
+# for inst in insts:
+# self.assertIsInstance(inst, pywbem.CIMInstance)
+# self.assertEqual(inst.namespace, 'root/cimv2')
+# self.assertEqual(sorted(inst.keys()), sorted(self.KEYS))
+# self.assertEqual(inst["InstanceID"], inst.path["InstanceID"])
+# nevra_set = set()
+# name_set = set()
+# for inst in insts:
+# nevra_set.add(inst["InstanceID"])
+# name_set.add(inst["Name"])
+# for pkg in self.safe_pkgs:
+# self.assertIn("LMI:PKG:"+pkg.get_nevra(with_epoch="ALWAYS"),
+# nevra_set)
+# self.assertIn(pkg.name, name_set)
+
+def suite():
+ """For unittest loaders."""
+ return unittest.TestLoader().loadTestsFromTestCase(
+ TestSoftwareIdentity)
+
+if __name__ == '__main__':
+ unittest.main()