[PATCH 0 of 6] [TEST] Another batch of try_getinstance() fixes.

These are also easier to review if you apply the patches and view the source files.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229639710 28800 # Node ID a77720f03c87b82c2357f621f962bebc7c00327d # Parent bac8c62509fa9e94ba8983826ed300b4f946b65f [TEST] Remove try_getinstance() from Memory - 03_mem_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@us.ibm.com> diff -r bac8c62509fa -r a77720f03c87 suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py --- a/suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py Thu Dec 18 00:51:43 2008 -0800 +++ b/suites/libvirt-cim/cimtest/Memory/03_mem_gi_errs.py Thu Dec 18 14:35:10 2008 -0800 @@ -20,196 +20,118 @@ # 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_Memory on giving invalid inputs. # -# 1) Test by passing Invalid CCName Keyname # Input: # ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_Memory.\ -# wrong="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -nl +# DeviceID +# SystemCreationClassName +# SystemName +# CreationClassName +# +# Format: +# ------ +# wbemcli gi 'http://localhost:5988/root/virt:KVM_Memory.DeviceID="wrong", +# SystemCreationClassName="KVM_ComputerSystem", SystemName="guest", +# CreationClassName="KVM_Memory"' # # 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_Memory.\ -# CreationClassName="wrong",DeviceID="Domain-0/mem",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",wrong="Domain-0/mem",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",DeviceID="wrong",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",wrong=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\ -# "wrong",SystemName="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",SystemCreationClassName=\ -# "Xen_ComputerSystem",wrong="Domain-0"' -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_Memory.\ -# CreationClassName="Xen_Memory",DeviceID="Domain-0/mem",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.common_util import try_getinstance -from XenKvmLib.test_doms import destroy_and_undefine_all -from XenKvmLib.vxml import XenXML, KVMXML, get_class -from XenKvmLib.classes import get_typed_class +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, CIM_USER, CIM_PASS, CIM_NS +from XenKvmLib.vxml import get_class +from XenKvmLib.classes import get_typed_class from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_ccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance" }, \ - "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" }, \ - "invalid_sccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance" }, \ - "invalid_sysname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance" } - } +def get_mem_inst(virt, ip, cn, guest_name): + try: + enum_list = EnumInstances(ip, cn) -test_dom = "domU" -test_mem = 256 #MB + if enum_list < 1: + logger.error("No %s instances returned", cn) + return None, FAIL -def try_invalid_gi(i, field1, field2): - j = 0 - keys = {} - temp = name_val[i] - name_val[i] = field1 - for j in range(len(name_val)/2): - k = j * 2 - keys[name_val[k]] = name_val[k+1] + for inst in enum_list: + if inst.SystemName == guest_name: + return inst, PASS - 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 + except Exception, details: + logger.error(details) + + return None, FAIL @do_main(sup_types) def main(): options = main.options - devid = "%s/%s" % (test_dom, test_mem) - status = PASS + test_dom = "domU" + test_mem = 256 #MB - # Getting the VS list and deleting the test_dom if it already exists. - destroy_and_undefine_all(options.ip) vsxml = get_class(options.virt)(test_dom, test_mem) ret = vsxml.cim_define(options.ip) if not ret: logger.error("Failed to Create the dom: %s", test_dom) return FAIL - global conn - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - global classname - global name_val - classname = get_typed_class(options.virt, "Memory") - name_val = [ - 'CreationClassName', classname, \ - 'DeviceID', devid, \ - 'SystemCreationClassName', get_typed_class(options.virt, 'ComputerSystem'), \ - 'SystemName', test_dom - ] + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance' + } - 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' + cn = get_typed_class(options.virt, "Memory") + + mem, status = get_mem_inst(options.virt, options.ip, cn, test_dom) + if status != PASS: + vsxml.undefine(options.ip) + return status + + key_vals = { 'SystemName' : mem.SystemName, + 'CreationClassName' : mem.CreationClassName, + 'SystemCreationClassName' : mem.SystemCreationClassName, + 'DeviceID' : mem.DeviceID + } + + tc_scen = { + 'invalid_sysval' : '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 + + 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

# HG changeset patch # User Kaitlin Rupert <karupert@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@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

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229639712 28800 # Node ID 6422c5ef1c750424ceea505bd8b60deb3134e6c8 # Parent 1add9163d3135bb46a0648669de97ba04796181b [TEST] Remove try_getinstance() from HostSystem - 05_hs_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@us.ibm.com> diff -r 1add9163d313 -r 6422c5ef1c75 suites/libvirt-cim/cimtest/HostSystem/05_hs_gi_errs.py --- a/suites/libvirt-cim/cimtest/HostSystem/05_hs_gi_errs.py Thu Dec 18 14:35:11 2008 -0800 +++ b/suites/libvirt-cim/cimtest/HostSystem/05_hs_gi_errs.py Thu Dec 18 14:35:12 2008 -0800 @@ -23,21 +23,16 @@ # Test Case Info: # -------------- # This tc is used to verify if appropriate exceptions are -# returned by Xen_HostSystem on giving invalid inputs. +# returned by HostSystem on giving invalid inputs. # -# 1) Test by passing Invalid CCName Keyname +# 1) Test by passing invalid values for the following keys: +# # Input: # ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_HostSystem.\ -# Wrong="Xen_HostSystem",Name="x3650"' -nl +# CreationClassName +# Name # -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" -# -# 2) Test by giving Invalid CCName Keyvalue -# Input: +# Format: # ------ # wbemcli gi 'http://localhost:5988/root/virt:Xen_HostSystem.\ # CreationClassName="Wrong",Name="x3650"' -nl @@ -45,53 +40,28 @@ # Output: # ------- # error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" +# error desc : "No such instance (CreationClassName)" (varies by key) # -# 3) Test by passing Invalid Name Keyname -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_HostSystem.\ -# CreationClassName="Xen_HostSystem",Wrong="x3650"' -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (Name)" -# -# 4) Test by giving Invalid CCName Keyvalue -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_HostSystem.\ -# CreationClassName="Xen_HostSystem",Name="Wrong"' -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (Name)" -# -# -Date 26.02.2008 import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc -from XenKvmLib.common_util import get_host_info, try_getinstance +from pywbem import CIM_ERR_NOT_FOUND, CIMError +from pywbem.cim_obj import CIMInstanceName +from CimTest.ReturnCodes import PASS, FAIL, SKIP +from CimTest.Globals import logger +from XenKvmLib.common_util import get_host_info from XenKvmLib.classes import get_typed_class -from optparse import OptionParser -from CimTest.ReturnCodes import PASS, FAIL, SKIP -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_ccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, - 'desc' : "No such instance " - "(CreationClassName)" }, - "invalid_name" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, - 'desc' : "No such instance (Name)" } - } - +expected_values = { + "invalid_name" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (Name)" }, + "invalid_ccname" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance " + "(CreationClassName)" } + } @do_main(sup_types) def main(): @@ -105,57 +75,47 @@ if status != PASS: return status - classname = host_inst.CreationClassName - host_name = host_inst.CreationClassName - #Test calls GetInstance() - no need to test GetInstance() of SBLIM providers - if (classname == "Linux_ComputerSystem"): + if (host_inst.Classname == "Linux_ComputerSystem"): return SKIP - conn = assoc.myWBEMConnection('http://%s' % options.ip, - (CIM_USER, CIM_PASS), CIM_NS) + key_vals = { 'Name' : host_inst.Name, + 'CreationClassName' : host_inst.CreationClassName, + } - # 1) Test by giving Invalid CCName Key Name - field = 'INVALID_CCName_KeyName' - keys = { field : classname, 'Name' : host_name } - ret_value = try_getinstance(conn, classname, keys, field_name=field, - expr_values=expr_values['invalid_ccname'], - bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Name.------") - return ret_value + tc_scen = { + 'invalid_name' : 'Name', + 'invalid_ccname' : 'CreationClassName', + } - # 2) Test by passing Invalid CCName Key Value - field = 'INVALID_CCName_KeyValue' - keys = { 'CreationClassName' : field, 'Name' : host_name } - ret_value = try_getinstance(conn, classname, keys, field_name=field, - expr_values=expr_values['invalid_ccname'], - bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Value.------") - return ret_value + for tc, field in tc_scen.iteritems(): + status = FAIL - # 3) Test by giving Invalid Name Key Name - field = 'INVALID_Name_KeyName' - keys = { 'CreationClassName' : classname, field : host_name} - ret_value = try_getinstance(conn, classname, keys, field_name=field, - expr_values=expr_values['invalid_name'], - bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Name.------") - return ret_value + keys = key_vals.copy() + keys[field] = tc + expr_values = expected_values[tc] - # 4) Test by passing Invalid Name Key Value - field = 'INVALID_Name_KeyValue' - keys = { 'CreationClassName' : classname, 'Name' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, - expr_values=expr_values['invalid_name'], - bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Value.------") - return ret_value + ref = CIMInstanceName(host_inst.Classname, keybindings=keys) - return PASS + 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 + + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229039346 28800 # Node ID 0519b7d3c8b72718e3dbe27f17bf2ad703572fff # Parent 6422c5ef1c750424ceea505bd8b60deb3134e6c8 [TEST] Remove try_getinstance() from ELEC - 02_elecap_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@us.ibm.com> diff -r 6422c5ef1c75 -r 0519b7d3c8b7 suites/libvirt-cim/cimtest/EnabledLogicalElementCapabilities/02_elecap_gi_errs.py --- a/suites/libvirt-cim/cimtest/EnabledLogicalElementCapabilities/02_elecap_gi_errs.py Thu Dec 18 14:35:12 2008 -0800 +++ b/suites/libvirt-cim/cimtest/EnabledLogicalElementCapabilities/02_elecap_gi_errs.py Thu Dec 11 15:49:06 2008 -0800 @@ -23,7 +23,7 @@ # Test Case Info: # -------------- # This tc is used to verify if appropriate exceptions are -# returned by Xen_EnabledLogicalElementCapabilities on giving invalid inputs. +# returned by EnabledLogicalElementCapabilities on giving invalid inputs. # # 1) Test by passing Invalid InstanceID Key Value # Input: @@ -36,83 +36,67 @@ # error code : CIM_ERR_NOT_FOUND # error desc : "The requested object could not be found" # -# 2) Test by giving Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_EnabledLogicalElementCapabilities.Wrong="Domain-0" -nl -# -# Output: -# ------- -# error code : CIM_ERR_FAILED -# error desc : "No InstanceID specified" -# -Date 22.02.2008 import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc -from XenKvmLib.common_util import try_getinstance -from XenKvmLib.vxml import XenXML, KVMXML, get_class +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.vxml import get_class from XenKvmLib.classes import get_typed_class -from CimTest.ReturnCodes import PASS, FAIL -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_instid_keyname" : { 'rc' : pywbem.CIM_ERR_FAILED, \ - 'desc' : "No InstanceID specified" }, \ - "invalid_instid_keyvalue" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance" } - } - @do_main(sup_types) def main(): options = main.options - status = PASS - classname = get_typed_class(options.virt, 'EnabledLogicalElementCapabilities') + test_dom = "qemu" + vsxml = get_class(options.virt)(test_dom) + ret = vsxml.cim_define(options.ip) + if not ret: + logger.error("Failed to Define the dom: %s", test_dom) + return FAIL + status = vsxml.cim_start(options.ip, options.virt, test_dom) + if status != PASS: + logger.error("Failed to Start the dom: %s", test_dom) + vsxml.undefine(options.ip) + return status - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + cn = get_typed_class(options.virt, 'EnabledLogicalElementCapabilities') - # 1) Test by passing Invalid InstanceID Key Value - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid_keyvalue'], bug_no="") - if ret_value != PASS: + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance" + } + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + ref = CIMInstanceName(cn, keybindings=keys) + + status = FAIL + 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 and desc %s", err_no, err_desc) + logger.error("Expected %s %s", exp_desc, exp_rc) + status = FAIL + + if status != PASS: logger.error("------ FAILED: Invalid InstanceID Key Value.------") - status = ret_value - # 2) Test by giving Invalid InstanceID Key Name - if options.virt == "Xen" or options.virt == "XenFV": - inst_id = "Domain-0" - else: - test_dom = "qemu" - vsxml = get_class(options.virt)(test_dom) - ret = vsxml.cim_define(options.ip) - if not ret: - logger.error("Failed to Define the dom: %s", test_dom) - return FAIL - ret = vsxml.start(options.ip) - if not ret: - logger.error("Failed to Start the dom: %s", test_dom) - return FAIL - - inst_id = test_dom - - field = 'INVALID_Instid_KeyName' - keys = { field : inst_id } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid_keyname'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") - status = ret_value - if options.virt == "KVM": - vsxml.destroy(options.ip) - vsxml.undefine(options.ip) + vsxml.cim_destroy(options.ip) + vsxml.undefine(options.ip) return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229639713 28800 # Node ID 1061fa6ad2d5d9dfe72e11b4536823863bdd72bf # Parent 0519b7d3c8b72718e3dbe27f17bf2ad703572fff [TEST] Remove try_getinstance() from CS - 42_cs_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@us.ibm.com> diff -r 0519b7d3c8b7 -r 1061fa6ad2d5 suites/libvirt-cim/cimtest/ComputerSystem/42_cs_gi_errs.py --- a/suites/libvirt-cim/cimtest/ComputerSystem/42_cs_gi_errs.py Thu Dec 11 15:49:06 2008 -0800 +++ b/suites/libvirt-cim/cimtest/ComputerSystem/42_cs_gi_errs.py Thu Dec 18 14:35:13 2008 -0800 @@ -24,127 +24,114 @@ # Test Case Info: # -------------- # This tc is used to verify if appropriate exceptions are -# returned by Xen_ComputerSystem on giving invalid inputs. +# returned by ComputerSystem on giving invalid inputs. # -# 1) Test by passing Invalid Name Key Value +# 1) Test by passing Invalid Key Values for the following # Input: # ------ +# CreationClassName +# Name +# +# Format: +# -------- # wbemcli gi http://localhost:5988/root/virt:Xen_ComputerSystem.\ # CreationClassName="Xen_ComputerSystem",Name="INVALID_Name_KeyValue" -nl # # Output: # ------- # error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (INVALID_Name_KeyValue)" +# error desc : "No such instance (INVALID_Name_KeyValue)" (varies by key) # -# 2) Test by giving Invalid Name Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:Xen_ComputerSystem.\ -# CreationClassName="Xen_ComputerSystem",INVALID_Name_KeyName="Domain-0" -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No domain name specified" -# -# 3) Test by passing Invalid CCName Key Value -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:Xen_ComputerSystem.\ -# CreationClassName="Xen_INVALID_CCName_KeyValue",Name="Domain-0" -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" -# -# 4) Test by giving Invalid CCName Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:Xen_ComputerSystem.\ -# INVALID_CCName_KeyName="Xen_ComputerSystem",Name="Domain-0" -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" -# -Date 22.02.2008 import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc +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 import vxml from XenKvmLib.classes import get_typed_class -from XenKvmLib.common_util import try_getinstance -from CimTest.ReturnCodes import PASS, FAIL -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from XenKvmLib.const import do_main, VIRSH_ERROR_DEFINE - +from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_name_keyvalue" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance (INVALID_Name_KeyValue)" }, \ - "invalid_name_keyname" : {'rc' : pywbem.CIM_ERR_FAILED, \ - 'desc' : "No domain name specified" }, \ - "invalid_ccname" : {'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance (CreationClassName)" } - } +expected_values = { + "invalid_name" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (invalid_name)" }, + "invalid_ccname" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (CreationClassName)" } + } +def get_cs_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 guest in enum_list: + if guest.Name == guest_name: + return guest, PASS + + except Exception, details: + logger.error(details) + + return None, FAIL + @do_main(sup_types) def main(): options = main.options - inst_ccname = classname = get_typed_class(options.virt, 'ComputerSystem') inst_name = 'ETdomain' cxml = vxml.get_class(options.virt)(inst_name) ret = cxml.cim_define(options.ip) if not ret: - logger.error(VIRSH_ERROR_DEFINE % inst_name) + logger.error("Unable to define guest %s", inst_name) return FAIL - status = PASS - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + cn = get_typed_class(options.virt, 'ComputerSystem') - # 1) Test by passing Invalid Name Key Value - field = 'INVALID_Name_KeyValue' - keys = { 'Name' : field, 'CreationClassName' : inst_ccname } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_name_keyvalue'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Value.------") - status = ret_value + cs, status = get_cs_inst(options.virt, options.ip, cn, inst_name) + if status != PASS: + return status - # 2) Test by giving Invalid Name Key Name - field = 'INVALID_Name_KeyName' - keys = { field : inst_name, 'CreationClassName' : inst_ccname } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_name_keyname'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid Name Key Name.------") - status = ret_value + key_vals = { 'Name' : cs.Name, + 'CreationClassName' : cs.CreationClassName, + } - # 3) Test by passing Invalid CCName Key Value - field = 'INVALID_CCName_KeyValue' - keys = { 'Name' : inst_name, 'CreationClassName' : field } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_ccname'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Value.------") - status = ret_value + tc_scen = { + 'invalid_name' : 'Name', + 'invalid_ccname' : 'CreationClassName', + } - # 4) Test by giving Invalid CCName Key Name - field = 'INVALID_CCName_KeyName' - keys = { 'Name' : inst_name, field : inst_ccname } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_ccname'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Name.------") - status = ret_value + 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 cxml.undefine(options.ip) return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229639714 28800 # Node ID e1783c9fa63c5bd2a7d301f9d5dececea01e1411 # Parent 1061fa6ad2d5d9dfe72e11b4536823863bdd72bf [TEST] Remove try_getinstance() from AC - 02_alloccap_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@us.ibm.com> diff -r 1061fa6ad2d5 -r e1783c9fa63c suites/libvirt-cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py --- a/suites/libvirt-cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py Thu Dec 18 14:35:13 2008 -0800 +++ b/suites/libvirt-cim/cimtest/AllocationCapabilities/02_alloccap_gi_errs.py Thu Dec 18 14:35:14 2008 -0800 @@ -23,7 +23,7 @@ # Test Case Info: # -------------- # This tc is used to verify if appropriate exceptions are -# returned by Xen_AllocationCapabilities on giving invalid inputs. +# returned by AllocationCapabilities on giving invalid inputs. # # 1) Test by passing Invalid InstanceID Key Value # Input: @@ -36,38 +36,45 @@ # error code : CIM_ERR_NOT_FOUND # error desc : "Instance not found" # -# 2) Test by giving invalid Invalid InstanceID Key Name -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/virt:\ -# Xen_AllocationCapabilities.Wrong="ProcessorPool/0" -nl -# -# Output: -# ------- -# error code : CIM_ERR_FAILED -# error desc : "No InstanceID specified" -# -Date 21.02.2008 import sys -import os -import pywbem -from distutils.file_util import move_file -from XenKvmLib import assoc -from VirtLib import utils -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS +from pywbem import CIM_ERR_NOT_FOUND, CIMError +from pywbem.cim_obj import CIMInstanceName +from CimTest.Globals import logger from CimTest.ReturnCodes import PASS, SKIP, FAIL -from XenKvmLib.common_util import try_getinstance -from XenKvmLib.xm_virt_util import net_list -from XenKvmLib.test_xml import netxml -from XenKvmLib.test_doms import create_vnet -from XenKvmLib.const import do_main, platform_sup, default_pool_name +from XenKvmLib.const import do_main from XenKvmLib.classes import get_typed_class - -diskid = "%s/%s" % ("DiskPool", default_pool_name) -memid = "%s/%s" % ("MemoryPool", 0) -procid = "%s/%s" % ("ProcessorPool", 0) +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances +from XenKvmLib.common_util import parse_instance_id sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] + +def enum_ac(virt, ip, cn): + ac_ids = [] + + try: + enum_list = EnumInstances(ip, cn) + + if enum_list < 1: + logger.error("No %s instances returned", cn) + return ac_ids, FAIL + + for ac in enum_list: + pool, id, status = parse_instance_id(ac.InstanceID) + if status != PASS: + logger.error("Unable to parse InstanceID: %s" % ac.InstanceID) + return ac_ids, FAIL + + ac_ids.append("%s/invalid_id" % pool) + + ac_ids.append("invalid_id") + + except Exception, details: + logger.error(details) + return ac_ids, FAIL + + return ac_ids, PASS + @do_main(sup_types) def main(): @@ -75,51 +82,41 @@ server = options.ip virt = options.virt - #Verify the virtual Network on the machine - vir_network = net_list(server) - if len(vir_network) > 0: - test_network = vir_network[0] - else: - bridgename = 'testbridge' - test_network = 'default-net' - net_xml, bridge = netxml(server, bridgename, test_network) - ret = create_vnet(server, net_xml) - if not ret: - logger.error("Failed to create the Virtual Network '%s'", - test_network) - return SKIP + cn = get_typed_class(virt, "AllocationCapabilities") - net_instid = 'NetworkPool/%s' %test_network - instid_list = ['ProcessorPool/0', 'MemoryPool/0', - 'DiskPool/foo', net_instid] - conn = assoc.myWBEMConnection('http://%s' % options.ip, - (CIM_USER, CIM_PASS), CIM_NS) - classname = get_typed_class(options.virt, "AllocationCapabilities") + ac_id_list, status = enum_ac(virt, server, cn) + if status != PASS: + logger.error("Unable to enumerate %s instances", cn) + return FAIL + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "Instance not found" + } - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - exp = { - "invalid_keyname" : { 'rc' : pywbem.CIM_ERR_FAILED, - 'desc' : 'No InstanceID specified' }, - "invalid_keyvalue" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, - 'desc' : 'Instance not found' }} + for id in ac_id_list: + status = FAIL + keys = { 'InstanceID' : id } - ret_value = try_getinstance(conn, classname, keys, field_name=field, - expr_values=exp['invalid_keyvalue'], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Value.------") - return ret_value + ref = CIMInstanceName(cn, keybindings=keys) - field = 'INVALID_Instid_KeyName' - status = FAIL - for i in range(len(instid_list)): - keys = { field : instid_list[i] } - status = try_getinstance(conn, classname, keys, field_name=field, - expr_values=exp['invalid_keyname'], - bug_no="") + 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) + status = FAIL + if status != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") + logger.error("------ FAILED: Invalid InstanceID %s ------", id) break return status

+1 for this patch set. Best, Regards Daisy (运国莲) VSM Team, China Systems & Technology Labs (CSTL) E-mail: yunguol@cn.ibm.com TEL: (86)-21-60922403 Building 10, 399 Ke Yuan Rd, Pudong Shanghai, 201203 Kaitlin Rupert <kaitlin@linux.vnet.ibm.com> Sent by: libvirt-cim-bounces@redhat.com 2008-12-19 06:59 Please respond to List for discussion and development of libvirt CIM <libvirt-cim@redhat.com> To libvirt-cim@redhat.com cc Subject [Libvirt-cim] [PATCH 0 of 6] [TEST] Another batch of try_getinstance() fixes. These are also easier to review if you apply the patches and view the source files. _______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (2)
-
Guo Lian Yun
-
Kaitlin Rupert