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