[Libvirt-cim] [PATCH 2 of 6] [TEST] Remove try_getinstance() from LogicalDisk - 03_ld_gi_errs.py

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu Dec 18 22:59:27 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1229639711 28800
# Node ID 1add9163d3135bb46a0648669de97ba04796181b
# Parent  a77720f03c87b82c2357f621f962bebc7c00327d
[TEST] Remove try_getinstance() from LogicalDisk - 03_ld_gi_errs.py

try_getinstance() is no longer needed - this function can be implemented using
functions from enumclass.py.  Plus, a conn needs to be passed to the function,
which is poor function design.

Removed the "invalid_instid_keyname" case - passing an invalid keyname only
tests the CIMOM, it does not test the providers.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r a77720f03c87 -r 1add9163d313 suites/libvirt-cim/cimtest/LogicalDisk/03_ld_gi_errs.py
--- a/suites/libvirt-cim/cimtest/LogicalDisk/03_ld_gi_errs.py	Thu Dec 18 14:35:10 2008 -0800
+++ b/suites/libvirt-cim/cimtest/LogicalDisk/03_ld_gi_errs.py	Thu Dec 18 14:35:11 2008 -0800
@@ -20,166 +20,72 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 #
-# Test Case Info:
-# --------------
-# This tc is used to verify if appropriate exceptions are
-# returned by Xen_LogicalDisk on giving invalid inputs.
 #
-# 1) Test by passing Invalid CCName Keyname
 # Input:
 # ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# wrong="Xen_LogicalDisk",DeviceID="virt1/xvda",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="virt1"' -nl
+#  DeviceID
+#  SystemCreationClassName
+#  SystemName
+#  CreationClassName
+#
+# Format:
+# ------
+# wbemcli gi 'http://localhost:5988/root/virt:KVM_NetworkPort.DeviceID="wrong",
+# SystemCreationClassName="KVM_ComputerSystem", SystemName="guest",
+# CreationClassName="KVM_NetworkPort"'
 #
 # Output:
 # -------
 # error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (CreationClassName)"
-
-# 2) Test by passing Invalid CCName Keyvalue
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="wrong",DeviceID="virt1/xvda",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="virt1"' -nl
+# error desc  : "No such instance (DeviceID)" (this varies by key)
 #
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (CreationClassName)"
-
-# 3) Test by passing Invalid DevId Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",wrong="virt1/xvda",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="virt1"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_FAILED
-# error desc  : "No DeviceID specified"
-
-# 4) Test by passing Invalid DevId Keyvalue
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",DeviceID="wrong",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="virt1"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (wrong)"
-
-# 5) Test by passing Invalid SCCName Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",DeviceID="virt1/xvda",wrong=\
-# "Xen_ComputerSystem",SystemName="virt1"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (SystemCreationClassName)"
-
-# 6) Test by passing Invalid SCCName Keyvalue
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",DeviceID="virt1/xvda",SystemCreationClassName=\
-# "wrong",SystemName="virt1"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (SystemCreationClassName)"
-
-# 7) Test by passing Invalid SysName Keyname
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",DeviceID="virt1/xvda",SystemCreationClassName=\
-# "Xen_ComputerSystem",wrong="virt1"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (SystemName)"
-
-# 8) Test by passing Invalid SysName Keyvalue# Input:
-# Input:
-# ------
-# wbemcli gi 'http://localhost:5988/root/virt:Xen_LogicalDisk.\
-# CreationClassName="Xen_LogicalDisk",DeviceID="virt1/xvda",SystemCreationClassName=\
-# "Xen_ComputerSystem",SystemName="wrong"' -nl
-#
-# Output:
-# -------
-# error code  : CIM_ERR_NOT_FOUND
-# error desc  : "No such instance (SystemName)"
-#                                                   -Date 26.02.2008
 
 import sys
-import pywbem
-from VirtLib import utils
-from XenKvmLib import assoc
-from XenKvmLib.enumclass import GetInstance
-from XenKvmLib.common_util import try_getinstance
-from XenKvmLib.test_doms import destroy_and_undefine_all
+from pywbem import CIM_ERR_NOT_FOUND, CIMError
+from pywbem.cim_obj import CIMInstanceName
+from CimTest.ReturnCodes import PASS, FAIL
+from CimTest.Globals import logger
+from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances
 from XenKvmLib.classes import get_typed_class
-from XenKvmLib.vxml import XenXML, KVMXML, get_class
-from CimTest.ReturnCodes import PASS, FAIL
-from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS, \
-                            CIM_ERROR_GETINSTANCE
+from XenKvmLib.vxml import get_class
 from XenKvmLib.const import do_main, get_provider_version
 
 sup_types = ['Xen', 'KVM', 'XenFV']
 
-expr_values = {
-    "invalid_ccname"         : {'rc'   : pywbem.CIM_ERR_NOT_FOUND, 
-                                'desc' : "No such instance (CreationClassName)" }, 
-    "invalid_devid_keyname"  : {'rc'   : pywbem.CIM_ERR_FAILED, 
-                                'desc' : "No DeviceID specified" }, 
-    "invalid_devid_keyvalue" : {'rc'   : pywbem.CIM_ERR_NOT_FOUND, 
-                                'desc' : "No such instance "\
-                                         "(bad id INVALID_DevID_Keyvalue)" },
-    "invalid_sccname"        : {'rc'   : pywbem.CIM_ERR_NOT_FOUND, 
-                                'desc' : "No such instance (SystemCreationClassName)" },
-    "invalid_sysname"        : {'rc'   : pywbem.CIM_ERR_NOT_FOUND, 
-                                'desc' : "No such instance (SystemName)" }
-              }
+expected_values = {
+   "invalid_ccname"  : {'rc'   : CIM_ERR_NOT_FOUND, 
+                        'desc' : "No such instance (CreationClassName)" }, 
+   "invalid_devid"   : {'rc'   : CIM_ERR_NOT_FOUND, 
+                        'desc' : "No such instance (bad id invalid_devid)" }, 
+   "invalid_sccname" : {'rc'   : CIM_ERR_NOT_FOUND, 
+                        'desc' : "No such instance (SystemCreationClassName)" },
+   "invalid_sysname" : {'rc'   : CIM_ERR_NOT_FOUND, 
+                        'desc' : "No such instance (SystemName)" }
+                  }
 
-test_dom = "hd_domain"
+def get_disk_inst(virt, ip, cn, guest_name):
+    try:
+        enum_list = EnumInstances(ip, cn)
+        
+        if enum_list < 1:
+            logger.error("No %s instances returned", cn)
+            return None, FAIL
+                    
+        for inst in enum_list:
+            if inst.SystemName == guest_name:
+                return inst, PASS
+        
+    except Exception, details:
+        logger.error(details)
 
-
-def try_invalid_gi(i, field1, field2):
-    temp = name_val[i]
-    name_val[i] = field1
-    keys = {
-                name_val[0] : name_val[1], 
-                name_val[2] : name_val[3], 
-                name_val[4] : name_val[5], 
-                name_val[6] : name_val[7]
-            }
-    ret_value = try_getinstance(conn, classname, keys, field_name=field1, 
-                                expr_values=expr_values[field2], bug_no="")
-    if ret_value != PASS:
-        logger.error("------ FAILED: %s------" % field1)
-    name_val[i] = temp
-    return ret_value
+    return None, FAIL
 
 @do_main(sup_types)
 def main():
     options = main.options
+    test_dom = "hd_domain"
+    err_msg_changeset = 682
 
-    global classname
-    classname = get_typed_class(options.virt, 'LogicalDisk')
-    status = PASS
-
-    # Getting the VS list and deleting the test_dom if it already exists.
-    destroy_and_undefine_all(options.ip)
     if options.virt == 'Xen':
         test_disk = 'xvda'
     else:
@@ -191,53 +97,59 @@
         logger.error("Failed to Define the dom: %s", test_dom)
         return FAIL
 
-    try:
-        devid = "%s/%s" % (test_dom, test_disk)
-        key_list = {'DeviceID' : devid,
-                    'CreationClassName' : classname,
-                    'SystemName' : test_dom,
-                    'SystemCreationClassName' : get_typed_class(options.virt, "ComputerSystem")
-                   }
-        disk = GetInstance(options.ip, classname, key_list)
-    except Exception,detail:
-        logger.error(CIM_ERROR_GETINSTANCE, classname)
-        logger.error("Exception: %s", detail)
-        return FAIL
+    cn = get_typed_class(options.virt, 'LogicalDisk')
 
-    global conn
-    conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS)
+    disk, status = get_disk_inst(options.virt, options.ip, cn, test_dom)
+    if status != PASS:
+        vsxml.undefine(options.ip)
+        return status 
 
     rev, changeset = get_provider_version(options.virt, options.ip)
-    if rev < 682:
-        old_ret = { 'rc' : pywbem.CIM_ERR_NOT_FOUND,
-                    'desc' : "No such instance (INVALID_DevID_Keyvalue)"
+    if rev < err_msg_changeset:
+        old_ret = { 'rc' : CIM_ERR_NOT_FOUND,
+                    'desc' : "No such instance (invalid_devid)"
                   }
-        expr_values["invalid_devid_keyvalue"] = old_ret 
+        expected_values["invalid_devid"] = old_ret 
 
-    global name_val
-    name_val = [
-                'CreationClassName',       disk.CreationClassName, 
-                'DeviceID',                disk.DeviceID, 
-                'SystemCreationClassName', disk.SystemCreationClassName, 
-                'SystemName',              disk.SystemName
-              ]
+    key_vals = { 'SystemName'              : disk.SystemName,
+                 'CreationClassName'       : disk.CreationClassName,
+                 'SystemCreationClassName' : disk.SystemCreationClassName,
+                 'DeviceID'                : disk.DeviceID 
+               }
 
-    tc_scen = { 'INVALID_CCName_Keyname'   : 'invalid_ccname', 
-                'INVALID_CCName_Keyvalue'  : 'invalid_ccname', 
-                'INVALID_DevID_Keyname'    : 'invalid_devid_keyname', 
-                'INVALID_DevID_Keyvalue'   : 'invalid_devid_keyvalue', 
-                'INVALID_SCCName_Keyname'  : 'invalid_sccname', 
-                'INVALID_SCCName_Keyvalue' : 'invalid_sccname', 
-                'INVALID_SysName_Keyname'  : 'invalid_sysname', 
-                'INVALID_SysName_Keyvalue' : 'invalid_sysname'
+    tc_scen = {
+                'invalid_sysname'   : 'SystemName',
+                'invalid_ccname'    : 'CreationClassName',
+                'invalid_sccname'   : 'SystemCreationClassName',
+                'invalid_devid'     : 'DeviceID',
               }
 
-    i = 0
-    for field1, field2 in sorted(tc_scen.items()):
-        retval = try_invalid_gi(i, field1, field2)
-        if retval != PASS:
-            status = retval
-        i = i + 1
+    for tc, field in tc_scen.iteritems():
+        status = FAIL
+
+        keys = key_vals.copy()
+        keys[field] = tc 
+        expr_values = expected_values[tc]
+
+        ref = CIMInstanceName(cn, keybindings=keys)
+
+        try:
+            inst = CIM_CimtestClass(options.ip, ref)
+
+        except CIMError, (err_no, err_desc):
+            exp_rc    = expr_values['rc']
+            exp_desc  = expr_values['desc']
+
+            if err_no == exp_rc and err_desc.find(exp_desc) >= 0:
+                logger.info("Got expected exception: %s %s", exp_desc, exp_rc)
+                status = PASS
+            else:
+                logger.error("Unexpected errno %s, desc %s", err_no, err_desc)
+                logger.error("Expected %s %s", exp_desc, exp_rc)
+
+        if status != PASS:
+            logger.error("------ FAILED: %s ------", tc)
+            break
 
     vsxml.undefine(options.ip)
     return status




More information about the Libvirt-cim mailing list