summaryrefslogtreecommitdiffstats
path: root/src/software/test/test_hosted_software_collection.py
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-02-12 15:54:14 +0100
committerMichal Minar <miminar@redhat.com>2013-02-13 20:02:50 +0100
commit46aacac8e2aabed5582f5c7da70a5acb5b679569 (patch)
tree8190c55b05f02108620732232ef5c080d5529f35 /src/software/test/test_hosted_software_collection.py
parent1d60a267af3eb94f8f158b4cf8abf3cc254611a1 (diff)
downloadopenlmi-providers-46aacac8e2aabed5582f5c7da70a5acb5b679569.tar.gz
openlmi-providers-46aacac8e2aabed5582f5c7da70a5acb5b679569.tar.xz
openlmi-providers-46aacac8e2aabed5582f5c7da70a5acb5b679569.zip
initial phase of rewrite for SMASH profile
currently only a subset of Software Inventory profile is supported * listing available packages
Diffstat (limited to 'src/software/test/test_hosted_software_collection.py')
-rwxr-xr-xsrc/software/test/test_hosted_software_collection.py155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/software/test/test_hosted_software_collection.py b/src/software/test/test_hosted_software_collection.py
new file mode 100755
index 0000000..dc798d8
--- /dev/null
+++ b/src/software/test/test_hosted_software_collection.py
@@ -0,0 +1,155 @@
+#!/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_MemberOfSoftwareCollection provider.
+"""
+
+import pywbem
+import socket
+import unittest
+
+import base
+
+class TestHostedSoftwareCollection(base.SoftwareBaseTestCase):
+ """
+ Basic cim operations test.
+ """
+
+ CLASS_NAME = "LMI_HostedSoftwareCollection"
+ KEYS = ("Antecedent", "Dependent")
+
+ def make_op(self):
+ """
+ @param ses SoftwareElementState property value
+ @return object path of SoftwareIdentity
+ """
+ objpath = self.objpath.copy()
+ objpath["Antecedent"] = pywbem.CIMInstanceName(
+ classname="Linux_ComputerSystem",
+ namespace="root/cimv2",
+ keybindings=pywbem.NocaseDict({
+ "CreationClassName" : "Linux_ComputerSystem",
+ "Name" : socket.gethostname()
+ }))
+ objpath["Dependent"] = pywbem.CIMInstanceName(
+ classname="LMI_SystemSoftwareCollection",
+ namespace="root/cimv2",
+ keybindings=pywbem.NocaseDict({
+ "InstanceID" : "LMI:SystemSoftwareCollection"
+ }))
+ return objpath
+
+ def test_get_instance(self):
+ """
+ Tests GetInstance call on packages from our rpm cache.
+ """
+ objpath = self.make_op()
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertIsInstance(inst, pywbem.CIMInstance)
+ self.assertEqual(inst.path, objpath)
+ self.assertEqual(sorted(inst.properties.keys()), sorted(self.KEYS))
+ self.assertEqual(objpath, inst.path)
+ for key in self.KEYS:
+ self.assertEqual(inst[key], inst.path[key])
+
+ # try with CIM_ prefix
+ antecedent = objpath["Antecedent"].copy()
+ objpath["Antecedent"].classname = "CIM_ComputerSystem"
+
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertIsInstance(inst, pywbem.CIMInstance)
+ objpath["Antecedent"] = antecedent.copy()
+ self.assertEqual(objpath, inst.path)
+ self.assertEqual(sorted(inst.properties.keys()), sorted(self.KEYS))
+ for key in self.KEYS:
+ self.assertEqual(inst[key], inst.path[key])
+
+ # try with CIM_ prefix also for CreationClassName
+ objpath["Antecedent"]["CreationClassName"] = "CIM_ComputerSystem"
+
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertIsInstance(inst, pywbem.CIMInstance)
+ objpath["Antecedent"] = antecedent.copy()
+ self.assertEqual(objpath, inst.path)
+ self.assertEqual(sorted(inst.properties.keys()), sorted(self.KEYS))
+ for key in self.KEYS:
+ self.assertEqual(inst[key], inst.path[key])
+
+ def test_enum_instances(self):
+ """
+ Tests EnumInstances call on installed packages.
+ """
+ objpath = self.make_op()
+ insts = self.conn.EnumerateInstances(ClassName=self.CLASS_NAME)
+ self.assertEqual(1, len(insts))
+ self.assertEqual(objpath, insts[0].path)
+ self.assertEqual(sorted(insts[0].properties.keys()), sorted(self.KEYS))
+ self.assertEqual(objpath, insts[0].path)
+ for key in self.KEYS:
+ self.assertEqual(insts[0][key], insts[0].path[key])
+
+ def test_enum_instance_names(self):
+ """
+ Tests EnumInstanceNames call on installed packages.
+ """
+ objpath = self.make_op()
+ inames = self.conn.EnumerateInstanceNames(ClassName=self.CLASS_NAME)
+ self.assertEqual(1, len(inames))
+ self.assertEqual(objpath, inames[0])
+
+ def test_get_antecedent_referents(self):
+ """
+ Test ReferenceNames for ComputerSystem.
+ """
+ objpath = self.make_op()
+ refs = self.conn.ReferenceNames(
+ Role="Antecedent",
+ ObjectName=objpath["Antecedent"])
+ self.assertGreater(len(refs), 0)
+ refs = [ r for r in refs if "Dependent" in r
+ and r["Dependent"].classname == \
+ "LMI_SystemSoftwareCollection" ]
+ self.assertEqual(1, len(refs))
+ ref = refs[0]
+ self.assertEqual(ref, objpath)
+
+ @base.mark_dangerous
+ def test_get_dependent_referents(self):
+ """
+ Test ReferenceNames for SystemSoftwareCollection.
+ """
+ objpath = self.make_op()
+ refs = self.conn.AssociatorNames(
+ ObjectName=objpath["Dependent"],
+ Role="Dependent",
+ ResultRole="Antecedent",
+ ResultClass="Linux_ComputerSystem")
+ self.assertEqual(1, len(refs))
+ ref = refs[0]
+ self.assertEqual(objpath["Antecedent"], ref)
+
+def suite():
+ """For unittest loaders."""
+ return unittest.TestLoader().loadTestsFromTestCase(
+ TestHostedSoftwareCollection)
+
+if __name__ == '__main__':
+ unittest.main()