diff options
author | Michal Minar <miminar@redhat.com> | 2013-03-04 15:15:36 +0100 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2013-03-04 15:15:36 +0100 |
commit | 19ab3372fe708be3e937df5d1ed6945ac813b51c (patch) | |
tree | 7e2cc6c06c2234498d1ac37633333a4c2eb13ff3 /src/software/test/test_resource_for_software_identity.py | |
parent | 282aa360c1ab3c58622d9e284bb0b3600e8997b4 (diff) | |
download | openlmi-providers-19ab3372fe708be3e937df5d1ed6945ac813b51c.tar.gz openlmi-providers-19ab3372fe708be3e937df5d1ed6945ac813b51c.tar.xz openlmi-providers-19ab3372fe708be3e937df5d1ed6945ac813b51c.zip |
added association providers for SoftwareIdentityResource
simplified writing references() method of any association provider
Diffstat (limited to 'src/software/test/test_resource_for_software_identity.py')
-rwxr-xr-x | src/software/test/test_resource_for_software_identity.py | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/src/software/test/test_resource_for_software_identity.py b/src/software/test/test_resource_for_software_identity.py new file mode 100755 index 0000000..15fc047 --- /dev/null +++ b/src/software/test/test_resource_for_software_identity.py @@ -0,0 +1,176 @@ +#!/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_ResourceForSoftwareIdentity provider. +""" + +import pywbem +import socket +import unittest + +import base + +class TestResourceForSoftwareIdentity(base.SoftwareBaseTestCase): + """ + Basic cim operations test. + """ + + CLASS_NAME = "LMI_ResourceForSoftwareIdentity" + KEYS = ("ManagedElement", "AvailableSAP") + + @classmethod + def needs_repodb(cls): + return True + + def make_op(self, pkg=None, newer=True, repo=None): + """ + @return object path of ResourceForSoftwareIdentity association + """ + objpath = self.objpath.copy() + objpath["AvailableSAP"] = pywbem.CIMInstanceName( + classname="LMI_SoftwareIdentityResource", + namespace="root/cimv2", + keybindings=pywbem.NocaseDict({ + "CreationClassName" : "LMI_SoftwareIdentityResource", + "SystemCreationClassName" : "Linux_ComputerSystem", + "SystemName" : socket.gethostname() + })) + if repo is not None: + objpath["AvailableSAP"]["Name"] = repo.repoid + elif pkg is not None: + objpath["AvailableSAP"]["Name"] = getattr(pkg, + 'up_repo' if newer else 'repo') + objpath["ManagedElement"] = pywbem.CIMInstanceName( + classname="LMI_SoftwareIdentity", + namespace="root/cimv2") + if pkg is not None: + objpath["ManagedElement"]["InstanceID"] = \ + 'LMI:PKG:' + pkg.get_nevra(newer=newer, with_epoch="ALWAYS") + return objpath + + def test_get_instance(self): + """ + Tests GetInstance call on packages from our rpm cache. + """ + for pkg in self.dangerous_pkgs: + objpath = self.make_op(pkg) + inst = self.conn.GetInstance(InstanceName=objpath) + self.assertEqual(objpath, inst.path, + "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.assertEqual(inst[key], inst.path[key], + 'Key property "%s" does not match for package "%s"!' % + (key, pkg)) + + @base.mark_tedious + def test_get_resource_referents(self): + """ + Test ReferenceNames for AvailableSAP. + """ + for repo in self.repodb: + objpath = self.make_op(repo=repo) + if not repo.pkg_count or repo.pkg_count > 10000: + # do not test too big repositories + continue + refs = self.conn.AssociatorNames( + Role="AvailableSAP", + ObjectName=objpath["AvailableSAP"], + ResultRole="ManagedElement", + ResultClass="LMI_SoftwareIdentity") + # there may be empty repositories + #self.assertGreater(len(refs), 0) + for ref in refs: + self.assertIsInstance(ref, pywbem.CIMInstanceName) + self.assertEqual(ref.namespace, 'root/cimv2') + self.assertEqual(ref.classname, "LMI_SoftwareIdentity") + self.assertEqual(sorted(ref.keys()), ["InstanceID"]) + self.assertTrue(ref["InstanceID"].startswith("LMI:PKG:")) + + nevra_set = set(i["InstanceID"] for i in refs) + # NOTE: installed packages might not be available + for pkg, up in ((pkg, up) for pkg in self.dangerous_pkgs + for up in (True, False)): + nevra = 'LMI:PKG:'+pkg.get_nevra( + newer=up, with_epoch="ALWAYS") + reponame = getattr(pkg, 'up_repo' if up else 'repo') + if reponame == repo.repoid: + self.assertTrue(nevra in nevra_set, + 'Missing nevra "%s" for repo "%s".' % (nevra, + reponame)) + + @base.mark_tedious + def test_get_resource_referents_for_disabled_repo(self): + """ + Test ReferenceNames for AvailableSAP, which is disabled. + """ + for repo in self.repodb: + if repo.status: + continue # test only disabled repositories + objpath = self.make_op(repo=repo) + refs = self.conn.AssociatorNames( + Role="AvailableSAP", + ObjectName=objpath["AvailableSAP"], + ResultRole="ManagedElement", + ResultClass="LMI_SoftwareIdentity") + self.assertGreater(len(refs), 0) + for ref in refs: + self.assertIsInstance(ref, pywbem.CIMInstanceName) + self.assertEqual(ref.namespace, 'root/cimv2') + self.assertEqual(ref.classname, "LMI_SoftwareIdentity") + self.assertEqual(sorted(ref.keys()), ["InstanceID"]) + self.assertTrue(ref["InstanceID"].startswith("LMI:PKG:")) + + def test_get_managed_element_referents(self): + """ + Test ReferenceNames for SoftwareIdentity. + """ + for pkg, up in ((pkg, up) for pkg in self.dangerous_pkgs + for up in (True, False)): + objpath = self.make_op(pkg, newer=up) + refs = self.conn.AssociatorNames( + ObjectName=objpath["ManagedElement"], + Role="ManagedElement", + ResultRole="AvailableSAP", + ResultClass="LMI_SoftwareIdentityResource") + self.assertEqual(1, len(refs), + 'No repo found for pkg "%s".' % pkg.get_nevra(newer=up, + with_epoch="ALWAYS")) + ref = refs[0] + self.assertIsInstance(ref, pywbem.CIMInstanceName) + self.assertEqual(ref.namespace, 'root/cimv2') + self.assertEqual(ref.classname, "LMI_SoftwareIdentityResource") + self.assertEqual(sorted(ref.keys()), + sorted(["SystemCreationClassName", "SystemName", + "Name", "CreationClassName"])) + self.assertEqual( + getattr(pkg, 'up_repo' if up else 'repo'), + ref["Name"], 'Repository name does not match for pkg "%s"'% + pkg.get_nevra(newer=up, with_epoch="ALWAYS")) + +def suite(): + """For unittest loaders.""" + return unittest.TestLoader().loadTestsFromTestCase( + TestResourceForSoftwareIdentity) + +if __name__ == '__main__': + unittest.main() |