[PATCH 0 of 5] [TEST] Rework negative tc to not use try_getinstance()

try_getinstance() really isn't needed anymore as the same functionality can be achieved using the functions in enumclass.py. Removing try_getinstance() requires essentially a re-write of these tests - they're old, so updates are needed anyway. More test re-writes will follow in the next set. As these are re-writest, it's easier to review the test case with the patch applied.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229469289 28800 # Node ID def2cef30362e74b98844dea72c4e86c99850932 # Parent d7e3d5782e205b31d831f2a2d3e0cd2a62f99326 [TEST] Remove try_getinstance() from RP - 02_rp_gi_errors.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 d7e3d5782e20 -r def2cef30362 suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py --- a/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py Mon Dec 15 09:45:28 2008 -0800 +++ b/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py Tue Dec 16 15:14:49 2008 -0800 @@ -22,118 +22,82 @@ # This tc is used to verify if appropriate exceptions are # returned by ResourcePool providers on giving invalid inputs. # +# Input: +# ------ +# wbemcli gi 'http://localhost:5988/root/virt:KVM_DiskPool.InstanceID="Wrong"' # -# Date : 19-02-2008 +# Output: +# ------- +# error code : CIM_ERR_NOT_FOUND +# error desc : "No such instance (Invalid_Keyvalue)" +# -import os import sys -import pywbem -from XenKvmLib.xm_virt_util import net_list -from XenKvmLib import assoc -from XenKvmLib import vxml -from XenKvmLib.common_util import 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.classes import get_typed_class -from distutils.file_util import move_file -from CimTest.ReturnCodes import PASS, SKIP -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from XenKvmLib.const import do_main, default_pool_name +from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass +from XenKvmLib.pool import enum_pools sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_keyname" : { 'rc' : pywbem.CIM_ERR_FAILED, - 'desc' : 'Missing InstanceID' }, - "invalid_keyvalue" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, - 'desc' : 'No such instance (Invalid_Keyvalue)'} - } +def init_pool_list(virt, ip): + pool_insts = {} -def err_invalid_instid_keyname(conn, classname, instid): - # Input: - # ------ - # wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:<ClassName>. - # Invalid_Keyname="<InstanceID>"' - # - # Output: - # ------- - # error code : CIM_ERR_FAILED - # error desc : "Missing InstanceID" - # - key = {'Invalid_Keyname' : instid} - return try_getinstance(conn, classname, key, - field_name='INVALID_InstID_KeyName', - expr_values=expr_values['invalid_keyname'], - bug_no="") + pools, status = enum_pools(virt, ip) + if status != PASS: + return pool_insts, status + for pool_cn, pool_list in pools.iteritems(): + if len(pool_list) < 1: + logger.error("Got %d %s, exp at least 1", len(pool_list), pool_cn) + return pool_insts, FAIL -def err_invalid_instid_keyvalue(conn, classname): - # Input: - # ------ - # wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:<ClassName>. - # InstanceID="Invalid_Keyvalue" - # - # Output: - # ------- - # error code : CIM_ERR_NOT_FOUND - # error desc : "No such instance (Invalid_Keyvalue)" - # - key = {'InstanceID' : 'Invalid_Keyvalue'} - return try_getinstance(conn, classname, key, - field_name='INVALID_InstID_KeyValue', - expr_values=expr_values['invalid_keyvalue'], - bug_no="") - + return pool_insts, PASS @do_main(sup_types) def main(): - ip = main.options.ip - if main.options.virt == "XenFV": - virt = "Xen" - else: - virt = main.options.virt - conn = assoc.myWBEMConnection('http://%s' % ip, (CIM_USER, CIM_PASS), - CIM_NS) + options = main.options - # Verify the Virtual Network on the machine. - vir_network = net_list(ip, virt) - if len(vir_network) > 0: - test_network = vir_network[0] - else: - bridgename = 'testbridge' - test_network = 'default-net' - netxml = vxml.NetXML(ip, bridgename, test_network, virt) - ret = netxml.create_vnet() - if not ret: - logger.error("Failed to create the Virtual Network '%s'", - test_network) - return SKIP - netid = "%s/%s" % ("NetworkPool", test_network) + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance (Invalid_Keyvalue)' + } - if virt == 'LXC': - cn_instid_list = { - get_typed_class(virt, "MemoryPool") : "MemoryPool/0", - get_typed_class(virt, "NetworkPool") : netid, - get_typed_class(virt, "ProcessorPool") : "ProcessorPool/0" - } - else: - cn_instid_list = { - get_typed_class(virt, "DiskPool") : "DiskPool/foo", - get_typed_class(virt, "MemoryPool") : "MemoryPool/0", - get_typed_class(virt, "NetworkPool") : netid, - get_typed_class(virt, "ProcessorPool") : "ProcessorPool/0" - } + pools, status = init_pool_list(options.virt, options.ip) + if status != PASS: + logger.error("Unable to build pool instance list") + return status + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } - for cn, instid in cn_instid_list.items(): - ret_value = err_invalid_instid_keyname(conn, cn, instid) - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Name.------") - return ret_value + for cn, pool_list in pools.iteritems(): + status = FAIL - ret_value = err_invalid_instid_keyvalue(conn, cn) - if ret_value != PASS: - logger.error("------ FAILED: Invalid InstanceID Key Value.------") - return ret_value + ref = CIMInstanceName(cn, 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 %s ------", cn, tc) + break + + return status if __name__ == "__main__": sys.exit(main())

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229469302 28800 # Node ID 4cc1d2d7cb55e5df87cdc158c3a45f43ad87fb87 # Parent def2cef30362e74b98844dea72c4e86c99850932 [TEST] Remove try_getinstance() from RASD - 03_rasd_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 def2cef30362 -r 4cc1d2d7cb55 suites/libvirt-cim/cimtest/RASD/03_rasd_errs.py --- a/suites/libvirt-cim/cimtest/RASD/03_rasd_errs.py Tue Dec 16 15:14:49 2008 -0800 +++ b/suites/libvirt-cim/cimtest/RASD/03_rasd_errs.py Tue Dec 16 15:15:02 2008 -0800 @@ -24,109 +24,62 @@ # This test case is used to verify the ResourceAllocationSettingData # returns appropriate exceptions when invalid values are passed. # -# 1) Test by passing Invalid InstanceID Key Name +# 1) Test by giving invalid Invalid InstanceID Key Value # Input: # ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_MemResourceAllocationSettingData.\ -# Wrong="virt1/mem"' - -# -# Output: -# ------- -# error code : CIM_ERR_FAILED -# error desc : "Missing InstanceID" -# -# 2) Test by giving invalid Invalid InstanceID Key Value -# Input: -# ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_MemResourceAllocationSettingData.\ -# InstanceID="Wrong"' +# wbemcli gi 'http://localhost:5988/root/virt:Xen_MemResourceAllocationSetting\ +# Data.InstanceID="Wrong"' # # Output: # ------- # error code : CIM_ERR_NOT_FOUND # error desc : "No such instance" # -# -# -# Date : 26-03-2008 -# - import sys -import pywbem -from XenKvmLib import assoc -from XenKvmLib.common_util import try_getinstance +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.const import do_main -from XenKvmLib.test_doms import destroy_and_undefine_all from XenKvmLib.vxml import get_class from XenKvmLib.classes import get_typed_class -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS, CIM_ERROR_GETINSTANCE -from CimTest.ReturnCodes import PASS, FAIL from XenKvmLib.const import default_network_name +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass +from XenKvmLib.rasd import enum_rasds +from XenKvmLib.common_util import parse_instance_id sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] test_dom = "VSSDC_dom" -test_vcpus = 1 -test_mem = 128 -test_mac = "00:11:22:33:44:aa" -expr_values = { - 'INVALID_Instid_KeyName' : { - 'rc' : pywbem.CIM_ERR_FAILED, \ - 'desc' : 'Missing InstanceID' - }, \ - 'INVALID_Instid_KeyValue' : { - 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance' - } - } +def init_rasd_list(virt, ip, guest_name): + rasd_insts = {} -def init_list(virt="Xen"): - disk = { - 'cn' : get_typed_class(virt, "DiskResourceAllocationSettingData"), \ - 'instid' : '%s/%s' %(test_dom, test_disk) - } - mem = { - 'cn' : get_typed_class(virt, "MemResourceAllocationSettingData"), \ - 'instid' : '%s/%s' %(test_dom, "mem"), - } - proc = { - 'cn' : get_typed_class(virt, "ProcResourceAllocationSettingData"), \ - 'instid' : '%s/%s' %(test_dom,0) - } - - net = { - 'cn' : get_typed_class(virt, "NetResourceAllocationSettingData"), \ - 'instid' : '%s/%s' %(test_dom,test_mac) - } - - if virt == 'LXC': - rasd_values_list =[ mem ] - else: - rasd_values_list =[ disk, mem, proc, net ] - return rasd_values_list + rasds, status = enum_rasds(virt, ip) + if status != PASS: + logger.error("Enum RASDs failed") + return rasd_insts, status -def verify_rasd_err(field, keys, rasd_type): - status = PASS - try: - ret_value = try_getinstance(conn, rasd_type['cn'], keys, field_name=field, \ - expr_values=expr_values[field], bug_no="") - if ret_value != PASS: - logger.error("------ FAILED: to verify %s.------", field) - status = ret_value - except Exception, detail: - logger.error(CIM_ERROR_GETINSTANCE, rasd_type['cn']) - logger.error("Exception: %s", detail) - status = FAIL - return status + for rasd_cn, rasd_list in rasds.iteritems(): + for rasd in rasd_list: + guest, dev, status = parse_instance_id(rasd.InstanceID) + if status != PASS: + logger.error("Unable to parse InstanceID: %s" % rasd.InstanceID) + return rasd_insts, FAIL + + if guest == guest_name: + rasd_insts[rasd.Classname] = rasd + + if len(rasds) != len(rasd_insts): + logger.error("Expected %d RASDs, got %d", len(rasds), len(rasd_insts)) + return rasd_insts, FAIL + + return rasd_insts, PASS @do_main(sup_types) def main(): options = main.options - global test_disk, vsxml - global virt, server, conn - destroy_and_undefine_all(options.ip) server = options.ip virt = options.virt @@ -137,12 +90,8 @@ if options.virt == 'LXC': vsxml = get_class(virt)(test_dom) else: - vsxml = get_class(virt)(test_dom, \ - mem=test_mem, \ - vcpus = test_vcpus, \ - mac = test_mac, \ - disk = test_disk) - bridge = vsxml.set_vbridge(server, default_network_name) + vsxml = get_class(virt)(test_dom, disk = test_disk) + try: ret = vsxml.cim_define(options.ip) if not ret: @@ -152,30 +101,42 @@ logger.error("Exception : %s", details) return FAIL - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) + rasds, status = init_rasd_list(virt, options.ip, test_dom) + if status != PASS: + logger.error("Unable to build rasd instance list") + return status - rasd_list = init_list() - - # Each Loop checks one of the RASD types [ Disk, Mem, Net, Proc ] - for rasd_type in sorted(rasd_list): - # Test RASD by passing Invalid InstanceID Key Name - field = 'INVALID_Instid_KeyName' - keys = { field : rasd_type['instid'] } - status = verify_rasd_err(field, keys, rasd_type) + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance' + } + + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } + + for cn, rasd_list in rasds.iteritems(): + status = FAIL + + 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 %s ------", cn, tc) break - # Test RASD by passing Invalid InstanceID Key Value - field = 'INVALID_Instid_KeyValue' - keys = { 'InstanceID' : field } - status = verify_rasd_err(field, keys, rasd_type) - if status != PASS: - break - try: - vsxml.undefine(server) - except Exception, detail: - logger.error("Failed to undefine domain %s", test_dom) - logger.error("Exception: %s", detail) + vsxml.undefine(server) return status if __name__ == "__main__":

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229469323 28800 # Node ID 158b28f7b8a481723a9fafd7e27d018a56c04245 # Parent 4cc1d2d7cb55e5df87cdc158c3a45f43ad87fb87 [TEST] Remove try_getinstance() from Profile - 03_rprofile_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 4cc1d2d7cb55 -r 158b28f7b8a4 suites/libvirt-cim/cimtest/Profile/03_rprofile_gi_errs.py --- a/suites/libvirt-cim/cimtest/Profile/03_rprofile_gi_errs.py Tue Dec 16 15:15:02 2008 -0800 +++ b/suites/libvirt-cim/cimtest/Profile/03_rprofile_gi_errs.py Tue Dec 16 15:15:23 2008 -0800 @@ -25,18 +25,7 @@ # This tc is used to verify if appropriate exceptions are # returned by Xen_RegisteredProfile on giving invalid inputs. # -# 1) Test by passing Invalid InstanceID Key Value -# Input: -# ------ -# wbemcli gi http://localhost:5988/root/interop:\ -# Xen_RegisteredProfile.InstanceID="Wrong" -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "Profile instance not found" -# -# 2) Test by giving Invalid InstanceID Key Name +# 1) Test by giving Invalid InstanceID Key Name # Input: # ------ # wbemcli gi http://localhost:5988/root/interop:\ @@ -46,59 +35,54 @@ # ------- # error code : CIM_ERR_FAILED # error desc : "No InstanceID specified" -# -Date 25.02.2008 import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc -from XenKvmLib.common_util import try_getinstance +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 CimTest import Globals from XenKvmLib.const import do_main +from XenKvmLib.classes import get_typed_class +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -expr_values = { - "invalid_instid_keyvalue" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : "No such instance" }, - "invalid_instid_keyname" : { 'rc' : pywbem.CIM_ERR_FAILED, \ - 'desc' : "No InstanceID specified" } \ - } - - @do_main(sup_types) def main(): options = main.options prev_namespace = Globals.CIM_NS Globals.CIM_NS = 'root/interop' - classname = 'Xen_RegisteredProfile' - status = PASS - conn = assoc.myWBEMConnection('http://%s' % options.ip, ( \ - Globals.CIM_USER, Globals.CIM_PASS), Globals.CIM_NS) + cn = get_typed_class(options.virt, 'RegisteredProfile') - inst_id = ["CIM:DSP1042-SystemVirtualization-1.0.0", "CIM:DSP1057-VirtualSystem-1.0.0a"] + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance" + } - # 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: - Globals.logger.error("------ FAILED: Invalid InstanceID Key Value.------") - status = ret_value + keys = { 'InstanceID' : 'INVALID_Instid_KeyValue' } - # 2) Test by giving Invalid InstanceID Key Name - for i in range(len(inst_id)): - field = 'INVALID_Instid_KeyName' - keys = { field : inst_id[i] } - ret_value = try_getinstance(conn, classname, keys, field_name=field, \ - expr_values=expr_values['invalid_instid_keyname'], bug_no="") - if ret_value != PASS: - Globals.logger.error("------ FAILED: Invalid InstanceID Key Name.------") - status = ret_value + 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, desc %s", err_no, err_desc) + logger.error("Expected %s %s", exp_desc, exp_rc) + + if status != PASS: + logger.error("------ FAILED: %s %s ------", cn, tc) Globals.CIM_NS = prev_namespace return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229037067 28800 # Node ID 091cf0f15d48977a19cac7465043e70637d6c526 # Parent 158b28f7b8a481723a9fafd7e27d018a56c04245 [TEST] Remove try_getinstance() from Processor - 03_proc_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 158b28f7b8a4 -r 091cf0f15d48 suites/libvirt-cim/cimtest/Processor/03_proc_gi_errs.py --- a/suites/libvirt-cim/cimtest/Processor/03_proc_gi_errs.py Tue Dec 16 15:15:23 2008 -0800 +++ b/suites/libvirt-cim/cimtest/Processor/03_proc_gi_errs.py Thu Dec 11 15:11:07 2008 -0800 @@ -26,20 +26,15 @@ # This tc is used to verify if appropriate exceptions are # returned by Xen_Processor on giving invalid inputs. # -# 1) Test by passing Invalid CCName Keyname +# Test by passing Invalid Keyvalue for following keys: # Input: # ------ -# wbemcli gi 'http://localhost:5988/root/virt:Xen_Processor.\ -# wrong="Xen_Processor",DeviceID="Domain-0/0",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -nl -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" +# CreationClassName +# DeviceID +# SystemCreationClassName +# SystemName -# 2) Test by passing Invalid CCName Keyvalue -# Input: +# Format: # ------ # wbemcli gi 'http://localhost:5988/root/virt:Xen_Processor.\ # CreationClassName="wrong",DeviceID="Domain-0/0",SystemCreationClassName=\ @@ -48,180 +43,126 @@ # 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_Processor.\ -# CreationClassName="Xen_Processor",wrong="Domain-0/0",SystemCreationClassName=\ -# "Xen_ComputerSystem",SystemName="Domain-0"' -nl +# error desc : "No such instance (CreationClassName)" (varies by key name) # -# 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_Processor.\ -# CreationClassName="Xen_Processor",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_Processor.\ -# CreationClassName="Xen_Processor",DeviceID="Domain-0/0",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_Processor.\ -# CreationClassName="Xen_Processor",DeviceID="Domain-0/0",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_Processor.\ -# CreationClassName="Xen_Processor",DeviceID="Domain-0/0",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_Processor.\ -# CreationClassName="Xen_Processor",DeviceID="Domain-0/0",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 XenKvmLib import assoc -from XenKvmLib.common_util import try_getinstance +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.classes import get_typed_class from XenKvmLib.vxml import get_class from XenKvmLib.test_doms import destroy_and_undefine_all -from CimTest.ReturnCodes import PASS, FAIL -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS from XenKvmLib.const import do_main, get_provider_version +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances 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_sysname" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (SystemName)" }, + "invalid_ccname" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (CreationClassName)" }, + "invalid_sccname" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (SystemCreationClassName)" }, + "invalid_devid" : {'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance " } } test_dom = "proc_domain" test_vcpus = 1 +err_msg_changeset = 682 -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] +def get_proc_inst(virt, ip, cn, guest_name): + try: + enum_list = EnumInstances(ip, cn) - 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 + 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) + + return None, FAIL @do_main(sup_types) def main(): options = main.options - devid = "%s/%s" % (test_dom, "0") - status = PASS + vsxml = get_class(options.virt)(test_dom, vcpus=test_vcpus) + ret = vsxml.cim_define(options.ip) + if not ret: + logger.error("Failed to define the guest: %s", test_dom) + return FAIL - # 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, vcpus=test_vcpus) - vsxml.cim_define(options.ip) - ret = vsxml.start(options.ip) - if not ret: - logger.error("Failed to Create the dom: %s", test_dom) + status = vsxml.cim_start(options.ip, options.virt, test_dom) + if status != PASS: + logger.error("Failed to start the guest: %s", test_dom) + vsxml.undefine(options.ip) return FAIL - global conn - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - global name_val - global classname - classname = get_typed_class(options.virt, 'Processor') - name_val = [ - 'CreationClassName', classname, - 'DeviceID', devid, - 'SystemCreationClassName', get_typed_class(options.virt, 'ComputerSystem'), - 'SystemName', test_dom - ] + rev, changeset = get_provider_version(options.virt, options.ip) + if rev < err_msg_changeset: + old_ret = { 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : "No such instance (invalid_devid)" + } + expected_values["invalid_devid"] = old_ret - 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' + ccn = get_typed_class(options.virt, "Processor") + + proc, status = get_proc_inst(options.virt, options.ip, ccn, test_dom) + if status != PASS: + vsxml.undefine(options.ip) + return status + + key_vals = { 'SystemName' : proc.SystemName, + 'CreationClassName' : proc.CreationClassName, + 'SystemCreationClassName' : proc.SystemCreationClassName, + 'DeviceID' : proc.DeviceID + } + + tc_scen = { + 'invalid_sysname' : 'SystemName', + 'invalid_ccname' : 'CreationClassName', + 'invalid_sccname' : 'SystemCreationClassName', + 'invalid_devid' : 'DeviceID', } - 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)" - } - expr_values["invalid_devid_keyvalue"] = old_ret + for tc, field in tc_scen.iteritems(): + status = FAIL - 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 + keys = key_vals.copy() + keys[field] = tc + expr_values = expected_values[tc] - vsxml.destroy(options.ip) + ref = CIMInstanceName(ccn, 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.cim_destroy(options.ip) vsxml.undefine(options.ip) return status

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1229469375 28800 # Node ID 3361699367632045d82be89f43f09adb499a3d73 # Parent 091cf0f15d48977a19cac7465043e70637d6c526 [TEST] Remove try_getinstance() from NetworkPort - 02_np_gi_errors.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 091cf0f15d48 -r 336169936763 suites/libvirt-cim/cimtest/NetworkPort/02_np_gi_errors.py --- a/suites/libvirt-cim/cimtest/NetworkPort/02_np_gi_errors.py Thu Dec 11 15:11:07 2008 -0800 +++ b/suites/libvirt-cim/cimtest/NetworkPort/02_np_gi_errors.py Tue Dec 16 15:16:15 2008 -0800 @@ -23,223 +23,57 @@ # returned by Xen_NetworkPort on giving invalid inputs. # # -# Date : 18-02-2008 - -import sys -import pywbem -from VirtLib import utils -from XenKvmLib import assoc -from XenKvmLib.common_util import try_getinstance -from XenKvmLib.classes import get_typed_class -from XenKvmLib.vxml import XenXML, KVMXML, LXCXML, get_class -from CimTest.ReturnCodes import PASS, SKIP -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS -from XenKvmLib.const import do_main - -sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] - - -expr_values = { - "invalid_sysname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance'}, \ - "invalid_sccname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance'}, \ - "invalid_devid" : { 'rc' : pywbem.CIM_ERR_FAILED, \ - 'desc' : 'No DeviceID specified'}, \ - "invalid_ccname" : { 'rc' : pywbem.CIM_ERR_NOT_FOUND, \ - 'desc' : 'No such instance'} - } - -def err_invalid_ccname_keyname(): # Input: # ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# DeviceID="<deviceid>", -# SystemCreationClassName="Xen_ComputerSystem", -# SystemName="<sys name>"' +# 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)" +# error desc : "No such instance (DeviceID)" (this varies by key) # - keys = { - 'DeviceID' : devid, \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_CCName_KeyName', \ - expr_values=expr_values['invalid_ccname'], bug_no="") +import sys +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.classes import get_typed_class +from XenKvmLib.vxml import get_class +from XenKvmLib.const import do_main +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass, EnumInstances -def err_invalid_ccname_keyvalue(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="", -# DeviceID="<deviceid>", -# SystemCreationClassName="Xen_ComputerSystem", -# SystemName="<sys name>"' -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (CreationClassName)" -# - keys = { - 'CreationClassName' : '', \ - 'DeviceID' : devid, \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_CCName_KeyValue', \ - expr_values=expr_values['invalid_ccname'], bug_no="") +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] -def err_invalid_devid_keyname(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# SystemCreationClassName="Xen_ComputerSystem", -# SystemName="<sys name>"' -# -# Output: -# ------- -# error code : CIM_ERR_FAILED -# error desc : "No DeviceID specified" -# - keys = { - 'CreationClassName' : classname, \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_DevID_KeyName', \ - expr_values=expr_values['invalid_devid'], bug_no="") +def get_net_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 -def err_invalid_devid_keyvalue(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# DeviceID="", -# SystemCreationClassName="Xen_ComputerSystem", -# SystemName="<sys name>"' -# -# Output: -# ------- -# error code : CIM_ERR_FAILED -# error desc : "No DeviceID specified" -# - keys = { - 'CreationClassName' : classname, \ - 'DeviceID' : '', \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_DevID_KeyValue', \ - expr_values=expr_values['invalid_devid'], bug_no="") + for inst in enum_list: + if inst.SystemName == guest_name: + return inst, PASS + except Exception, details: + logger.error(details) -def err_invalid_sccname_keyname(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# DeviceID="<deviceid>", -# SystemName="<sys name>"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemCreationClassName)" -# - keys = { - 'CreationClassName' : classname, \ - 'DeviceID' : devid, \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_Sys_CCName_KeyName', \ - expr_values=expr_values['invalid_sccname'], bug_no="") - -def err_invalid_sccname_keyvalue(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# DeviceID="<deviceid>", -# SystemCreationClassName="", -# SystemName="<sys name>"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemCreationClassName)" -# - keys = { - 'CreationClassName' : classname, \ - 'DeviceID' : devid, \ - 'SystemCreationClassName' : '', \ - 'SystemName' : guestname - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_Sys_CCName_KeyValue', \ - expr_values=expr_values['invalid_sccname'], bug_no="") - -def err_invalid_sysname_keyname(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# DeviceID="<deviceid>", -# SystemCreationClassName="Xen_ComputerSystem"' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemName)" -# - keys = { - 'CreationClassName' : classname, \ - 'DeviceID' : devid, \ - 'SystemCreationClassName' : sccname, \ - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_SysName_KeyName', \ - expr_values=expr_values['invalid_sysname'], bug_no="") - -def err_invalid_sysname_keyvalue(): -# Input: -# ------ -# wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:Xen_NetworkPort. -# CreationClassName="Xen_NetworkPort", -# DeviceID="<deviceid>", -# SystemCreationClassName="Xen_ComputerSystem", -# SystemName=""' -# -# Output: -# ------- -# error code : CIM_ERR_NOT_FOUND -# error desc : "No such instance (SystemName)" -# - keys = { - 'CreationClassName' : classname, \ - 'DeviceID' : devid, \ - 'SystemCreationClassName' : sccname, \ - 'SystemName' : '' - } - return try_getinstance(conn, classname, keys, - field_name='INVALID_SysName_KeyValue', \ - expr_values=expr_values['invalid_sysname'], bug_no="") + return None, FAIL @do_main(sup_types) def main(): options = main.options - status = PASS test_dom = "nettest_domain" test_mac = "00:11:22:33:44:55" @@ -248,59 +82,58 @@ ret = vsxml.cim_define(options.ip) if ret != 1: logger.error("Define domain failed!") - return SKIP - - global conn - global classname - global guestname - global sccname - global devid - - conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS) - classname = get_typed_class(options.virt, 'NetworkPort') - guestname = test_dom - sccname = get_typed_class(options.virt, 'ComputerSystem') - devid = "%s/%s" % (test_dom, test_mac) + return FAIL - ret_value = err_invalid_ccname_keyname() - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Name.------") - status = ret_value + expr_values = { + 'rc' : CIM_ERR_NOT_FOUND, + 'desc' : 'No such instance' + } - ret_value = err_invalid_ccname_keyvalue() - if ret_value != PASS: - logger.error("------ FAILED: Invalid CCName Key Value.------") - status = ret_value + cn = get_typed_class(options.virt, 'NetworkPort') - ret_value = err_invalid_devid_keyname() - if ret_value != PASS: - logger.error("------ FAILED: Invalid DeviceID Key Name.------") - status = ret_value + net, status = get_net_inst(options.virt, options.ip, cn, test_dom) + if status != PASS: + vsxml.undefine(options.ip) + return status - ret_value = err_invalid_devid_keyvalue() - if ret_value != PASS: - logger.error("------ FAILED: Invalid DeviceID Key Value.------") - status = ret_value + key_vals = { 'SystemName' : net.SystemName, + 'CreationClassName' : net.CreationClassName, + 'SystemCreationClassName' : net.SystemCreationClassName, + 'DeviceID' : net.DeviceID + } - ret_value = err_invalid_sccname_keyname() - if ret_value != PASS: - logger.error("---FAILED: Invalid System CreationClassName Key Name.---") - status = ret_value + tc_scen = { + 'invalid_sysval' : 'SystemName', + 'invalid_ccname' : 'CreationClassName', + 'invalid_sccname' : 'SystemCreationClassName', + 'invalid_devid' : 'DeviceID', + } - ret_value = err_invalid_sccname_keyvalue() - if ret_value != PASS: - logger.error("--FAILED: Invalid System CreationClassName Key Value.--") - status = ret_value + for tc, field in tc_scen.iteritems(): + status = FAIL - ret_value = err_invalid_sysname_keyname() - if ret_value != PASS: - logger.error("------ FAILED: Invalid SystemName Key Name.------") - status = ret_value + keys = key_vals.copy() + keys[field] = tc - ret_value = err_invalid_sysname_keyvalue() - if ret_value != PASS: - logger.error("------ FAILED: Invalid SystemName Key Value.------") - status = ret_value + 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

try_getinstance() really isn't needed anymore as the same functionality can be achieved using the functions in enumclass.py.
Removing try_getinstance() requires essentially a re-write of these tests - they're old, so updates are needed anyway.
More test re-writes will follow in the next set.
As these are re-writest, it's easier to review the test case with the
+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 libvirt-cim-bounces@redhat.com wrote on 2008-12-17 07:17:08: patch
applied.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (2)
-
Guo Lian Yun
-
Kaitlin Rupert