From: <mik...@us...> - 2008-08-22 21:19:02
|
Revision: 880 http://omc.svn.sourceforge.net/omc/?rev=880&view=rev Author: mike-brasher Date: 2008-08-22 21:19:11 +0000 (Fri, 22 Aug 2008) Log Message: ----------- Added new provider-specific tests for cardinality of instances and associations. Modified Paths: -------------- cmpiprofiles/test/trunk/Makefile Added Paths: ----------- cmpiprofiles/test/trunk/ProviderTests.py Modified: cmpiprofiles/test/trunk/Makefile =================================================================== --- cmpiprofiles/test/trunk/Makefile 2008-08-21 14:19:49 UTC (rev 879) +++ cmpiprofiles/test/trunk/Makefile 2008-08-22 21:19:11 UTC (rev 880) @@ -1,8 +1,8 @@ help: - @ echo "targets: all sanity profiles" + @ echo "targets: all sanity profiles providers" -all: sanity profiles +all: sanity profiles providers sanity: ./AllSanityTest.py --url=http://localhost @@ -15,3 +15,6 @@ @ ./ProfileTest.py --url $(URL) Linux_SSHProtocolService Linux_SSHRegisteredProfile @ ./ProfileTest.py --url $(URL) Linux_Fan Linux_FanRegisteredProfile @ ./ProfileTest.py --url $(URL) Linux_PowerSupply Linux_PowerSupplyRegisteredProfile + +providers: + ./ProviderTests.py --url=http://localhost Added: cmpiprofiles/test/trunk/ProviderTests.py =================================================================== --- cmpiprofiles/test/trunk/ProviderTests.py (rev 0) +++ cmpiprofiles/test/trunk/ProviderTests.py 2008-08-22 21:19:11 UTC (rev 880) @@ -0,0 +1,226 @@ +#!/usr/bin/env python +# Author: Mike Brasher +# Date: Wed Aug 13 2008 + +import pywbem +import optparse +import sys +sys.path.append("./lib") +import wbem_connection + +################################################################################ +## +## class TestConnection +## +################################################################################ + +def err(msg): + print "\n**** ERROR: %s\n" %(msg) + sys.exit(1) + +################################################################################ +## +## class TestConnection +## +################################################################################ + +class TestConnection(pywbem.WBEMConnection): + + def __init__(self, parser = None): + + if parser == None: + parser = optparse.OptionParser() + + wbem_connection.getWBEMConnParserOptions(parser) + opts, args = parser.parse_args(); + + url = opts.url + user = opts.user + password = opts.password + + if user and not password: + password = getpass('\nEnter password for %s: ' % user) + + pywbem.WBEMConnection.__init__(self, url, ((user, password))) + + # Expect exactly n instances of the given class. + def expect_n(self, n, classname, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_n(%u, %s, %s)" %(n, classname, namespace) + + r = self.EnumerateInstances(classname, namespace) + m = len(r) + + if (m != n): + err("expected %d instances but found %d" %(n, m)) + + return m + + # Expect zero instances of the given class. + def expect_0(self, classname, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_0(%s, %s)" %(classname, namespace) + + r = self.EnumerateInstances(classname, namespace) + n = len(r) + + if (n != 0): + err("expected 0 instances but found %d" %(n)) + + return n + + # Expect one instance of the given class. + def expect_1(self, classname, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_1(%s, %s)" %(classname, namespace) + + r = self.EnumerateInstances(classname, namespace) + n = len(r) + + if (n != 1): + err("expected 1 instance but found %d" %(n)) + + return n + + # Expect one or more instances of the given class. + def expect_1_plus(self, classname, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_1_plus(%s, %s)" %(classname, namespace) + + r = self.EnumerateInstances(classname, namespace) + n = len(r) + + if (n < 1): + err("expected 1+ instances but found %d" %(n)) + + return n + + # Expect 1-to-1 cardinality between class1 and class2 through the assoc. + def expect_1_to_1(self, class1, assoc, class2, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_1_to_1(%s, %s, %s, %s)" \ + %(class1, assoc, class2, namespace) + + r = self.EnumerateInstanceNames(class1, namespace) + + for i in r: + + a1 = self.AssociatorNames(i, AssocClass=assoc) + + if len(a1) != 1: + err("expected 1 associator but found %d" %(len(a1))) + + try: + inst = c.GetInstance(a1[0]) + except: + err("GetInstance() failed") + + # Expect 1-to-n cardinality between class1 and class2 through the assoc. + def expect_1_to_n(self, n, class1, assoc, class2, namespace = None): + + if namespace is None: + namespace = self.default_namespace + + print ">>>> expect_1_to_n(%d, %s, %s, %s, %s)" \ + %(n, class1, assoc, class2, namespace) + + r = self.EnumerateInstanceNames(class1, namespace) + + for i in r: + + a1 = self.AssociatorNames(i, AssocClass=assoc) + + if len(a1) != n: + err("expected %d associators but found %d" %(n, len(a1))) + +################################################################################ +## +## __main__ +## +################################################################################ + +if __name__ == "__main__": + + c = TestConnection() + + ## + ## General tests + ## + + c.expect_0("CIM_RegisteredProfile") + c.expect_0("CIM_ReferencedProfile") + c.expect_1_plus("CIM_RegisteredProfile", "root/interop") + c.expect_1_plus("CIM_ReferencedProfile", "root/interop") + c.expect_1_plus("CIM_ElementConformsToProfile", "root/interop") + c.expect_1_plus("CIM_ElementConformsToProfile") + + ## + ## Ethernet Port Profile + ## + + n = c.expect_1_plus("Linux_EthernetPort") + c.expect_n(n, "Linux_LANEndpoint") + c.expect_n(n, "Linux_EthernetPortDeviceSAPImplementation") + c.expect_n(n, "Linux_EthernetPortElementConformsToProfile") + c.expect_n(n, "Linux_EthernetPortElementCapabilities") + c.expect_n(n, "Linux_EthernetPortHostedAccessPoint") + c.expect_n(n, "Linux_EthernetPortSystemDevice") + c.expect_n(n, "Linux_EthernetPortElementConformsToProfile", "root/interop") + c.expect_1("Linux_EthernetPortRegisteredProfile", "root/interop") + c.expect_1("Linux_EthernetPortReferencedProfile", "root/interop") + c.expect_1("Linux_EthernetPortEnabledLogicalElementCapabilities"); + # Linux_EthernetPortDeviceSAPImplementation associations: + c.expect_1_to_1( \ + "Linux_EthernetPort", \ + "Linux_EthernetPortDeviceSAPImplementation", \ + "Linux_LANEndpoint") + c.expect_1_to_1( \ + "Linux_LANEndpoint", \ + "Linux_EthernetPortDeviceSAPImplementation", \ + "Linux_EthernetPort") + # Linux_EthernetPortElementCapabilities associations: + c.expect_1_to_n( \ + n, + "Linux_EthernetPortEnabledLogicalElementCapabilities", \ + "Linux_EthernetPortElementCapabilities", \ + "Linux_EthernetPort") + c.expect_1_to_1( \ + "Linux_EthernetPort", \ + "Linux_EthernetPortElementCapabilities", \ + "Linux_EthernetPortEnabledLogicalElementCapabilities") + # Linux_EthernetPortElementCapabilities associations: + c.expect_1_to_1( \ + "Linux_EthernetPort", \ + "Linux_EthernetPortElementConformsToProfile", \ + "Linux_EthernetPortRegisteredProfile") + c.expect_1_to_n( \ + n, + "Linux_EthernetPortRegisteredProfile", \ + "Linux_EthernetPortElementConformsToProfile", \ + "Linux_EthernetPort", \ + "root/interop") + # LANEndpointElementCapabilitiesProvider associations: + c.expect_1_to_n( \ + n, + "Linux_LANEndpointEnabledLogicalElementCapabilities", \ + "Linux_LANEndpointElementCapabilities", \ + "Linux_LANEndpoint") + + print "OKAY" + sys.exit(0) + Property changes on: cmpiprofiles/test/trunk/ProviderTests.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |