# HG changeset patch
# User Kaitlin Rupert <karupert(a)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(a)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__":