<br><tt><font size=2>libvirt-cim-bounces@redhat.com wrote on 2008-10-06
21:29:45:<br>
<br>
> <br>
> <br>
> yunguol@cn.ibm.com wrote: </font></tt>
<br><tt><font size=2>> # HG changeset patch<br>
> # User Guolian Yun <yunguol@cn.ibm.com><br>
> # Date 1223272339 25200<br>
> # Node ID bdb5911993d5e56c6398a447b3e5eabc5d41f83d<br>
> # Parent b710ecb26adf500caa6b801fdf10e4efbed3877e<br>
> [TEST] #4 Fix HostedService - 03_forward_errs.py to work with sblim
<br>
> base provider installed<br>
> <br>
> Updates from 3 to 4:<br>
> <br>
> 1) Update the tc to verify the case when we pass Invalid CreationClassName<br>
> 2) Verify the complete exception instead of just verifying part of
it<br>
> <br>
> Signed-off-by: Guolian Yun <yunguol@cn.ibm.com><br>
> <br>
> diff -r b710ecb26adf -r bdb5911993d5 suites/libvirt-<br>
> cim/cimtest/HostedService/03_forward_errs.py<br>
> --- a/suites/libvirt-cim/cimtest/HostedService/03_forward_errs.py
<br>
> Fri Oct 03 06:34:29 2008 -0700<br>
> +++ b/suites/libvirt-cim/cimtest/HostedService/03_forward_errs.py
<br>
> Sun Oct 05 22:52:19 2008 -0700<br>
> @@ -25,6 +25,7 @@ from pywbem.cim_obj import CIMInstanceNa<br>
> from pywbem.cim_obj import CIMInstanceName<br>
> from XenKvmLib import assoc<br>
> from XenKvmLib import enumclass<br>
> +from XenKvmLib.common_util import get_host_info<br>
> from XenKvmLib.classes import get_typed_class<br>
> from CimTest.Globals import logger, CIM_ERROR_ENUMERATE, CIM_USER,
\<br>
>
CIM_PASS, CIM_NS<br>
> @@ -33,7 +34,8 @@ from CimTest.ReturnCodes import PASS, FA<br>
> <br>
> sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']<br>
> exp_rc = 6 #CIM_ERR_NOT_FOUND<br>
> -exp_desc = "No such instance"<br>
> +exp_desc = ["No such instance (Name)",<br>
> + "No such instance
(CreationClassName)"]<br>
> <br>
> @do_main(sup_types)<br>
> def main():<br>
> @@ -41,37 +43,41 @@ def main():<br>
> rc = -1<br>
> status = FAIL<br>
> keys = ['Name', 'CreationClassName']<br>
> - try:<br>
> - host_sys = enumclass.enumerate(options.ip,
'HostSystem', <br>
> keys, options.virt)[0]<br>
> - except Exception:<br>
> - logger.error(CIM_ERROR_ENUMERATE % host_sys.name)<br>
> + status, host_name, host_ccn = get_host_info(options.ip,
options.virt)<br>
> + if status != PASS:<br>
> + logger.error("Error in calling get_host_info
function")<br>
> return FAIL<br>
> -<br>
> <br>
> conn = assoc.myWBEMConnection('http://%s' % options.ip,
<br>
>
(CIM_USER, CIM_PASS),<br>
>
CIM_NS)<br>
> - instanceref = CIMInstanceName(get_typed_class(options.virt,
<br>
> "HostSystem"), <br>
> -
keybindings = {"Wrong"
: "wrong",<br>
> "CreationClassName" : host_sys.CreationClassName})<br>
> -<br>
> + hostsystem = get_typed_class(options.virt, "HostSystem")<br>
> + instanceref = [CIMInstanceName(hostsystem, <br>
> +
keybindings = {"Wrong"
: "wrong",<br>
> "CreationClassName" : host_ccn}),<br>
> + CIMInstanceName(hostsystem,<br>
> +
keybindings = {"Name"
: <br>
> host_name, "Wrong" : "wrong"})]<br>
> +
<br>
> </font></tt>
<br><tt><font size=2>> The instanceref[0] will produce unexpected result
as below and not <br>
> the required exception <br>
> <br>
> DEBUG instanceref is Xen_HostSystem.<br>
> CreationClassName="Linux_ComputerSystem",Wrong="wrong"<br>
> Unexpected rc code 6 and description CIM_ERR_NOT_FOUND: No such
<br>
> instance (CreationClassName)<br>
> <br>
> <br>
> Replace CIMInstanceName(hostsystem, of instanceref[0] with <br>
> CIMInstanceName(host_ccn, otherwise it the instanceref will give <br>
> unexpected exception as above when sblim-base-provider is installed.</font></tt>
<br><tt><font size=2>> names = []<br>
> <br>
> - try:<br>
> - names = conn.AssociatorNames(instanceref,
AssocClass = <br>
> get_typed_class(options.virt, "HostedService"))<br>
> - rc = 0<br>
> - except pywbem.CIMError, (rc, desc):<br>
> - if rc == exp_rc and desc.find(exp_desc)
>= 0:<br>
> - logger.info("Got excepted
rc code and error string")<br>
> - status = PASS<br>
> - else:<br>
> - logger.error("Unexpected
rc code %s and description %<br>
> s\n" %(rc, desc))<br>
> - except Exception, details:<br>
> - logger.error("Unknown exception
happened")<br>
> - logger.error(details)<br>
> + hostedservice = get_typed_class(options.virt, "HostedService")<br>
> + for i in range(0, len(instanceref)):<br>
> + try:<br>
> + names = conn.AssociatorNames(instanceref[i],
AssocClass<br>
> = hostedservice)<br>
> + rc = 0<br>
> + except pywbem.CIMError, (rc, desc):<br>
> + if rc == exp_rc and desc.find(exp_desc[i])
>= 0:<br>
> + logger.info("Got
excepted rc code and error string")<br>
> + status =
PASS<br>
> + else:<br>
> + logger.error("Unexpected
rc code %s and description<br>
> %s\n" %(rc, desc))<br>
> + except Exception, details:<br>
> + logger.error("Unknown
exception happened")<br>
> + logger.error(details)<br>
> <br>
> - if rc == 0:<br>
> - logger.error("HostedService associator
should NOT return <br>
> excepted result with a wrong key name and value of HostSystem input")<br>
> - status = FAIL<br>
> + if rc == 0:<br>
> + logger.error("HostedService
associator should NOT <br>
> return excepted result\<br>
> +
with a wrong key name and value of <br>
> HostSystem input")<br>
> + status = FAIL<br>
> </font></tt>
<br><tt><font size=2>> This does not exit the test case even when it
fails. <br>
> Return appropriate return value here directly, for sblim-base-<br>
> provider we need to return XFAIL.</font></tt>
<br><tt><font size=2>> <br>
> return status <br>
> <br>
> </font></tt>
<br><tt><font size=2>> You can replace calling Associators() and verifications,
with the <br>
> library function try_assoc() of common_util.py to verify the <br>
> exceptions for the associtations.</font></tt>
<br>
<br><tt><font size=2> #5 patch on the way. </font></tt>
<br><tt><font size=2> Thanks for your good point.</font></tt>
<br><tt><font size=2><br>
> <br>
> This is not related to your changes, but can you change the following
log msg <br>
> logger.error("Unknown exception happened")<br>
> to <br>
> logger.error("Unknown exception") </font></tt>
<br><tt><font size=2>> <br>
> _______________________________________________<br>
> Libvirt-cim mailing list<br>
> Libvirt-cim@redhat.com<br>
> https://www.redhat.com/mailman/listinfo/libvirt-cim<br>
> _______________________________________________<br>
> Libvirt-cim mailing list<br>
> Libvirt-cim@redhat.com<br>
> https://www.redhat.com/mailman/listinfo/libvirt-cim</font></tt>