libvirt-cim-bounces@redhat.com wrote on 2008-12-12 08:20:49:

> # HG changeset patch
> # User Kaitlin Rupert <karupert@us.ibm.com>
> # Date 1229040425 28800
> # Node ID 3bb307b122797cae2b3d3bb7c37f81fb8a50e0f9
> # Parent  5657d8fc247e73e143e7ce82ee2de5aecd7e6d6d
> [TEST] Remove try_getinstance() from VSMSD - 02_vsmsd_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 thefunction,
> 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 5657d8fc247e -r 3bb307b12279 suites/libvirt-
> cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py  
> Thu Dec 11 16:06:29 2008 -0800
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemMigrationSettingData/02_vsmsd_gi_errs.py  
> Thu Dec 11 16:07:05 2008 -0800
> @@ -23,69 +23,63 @@
>  # --------------
>  # This tc is used to verify if appropriate exceptions are
>  # returned by Xen_VSMSD on giving invalid inputs.
> -# 1) Test by giving invalid Invalid InstanceID Key Name
> -# Input:
> -# ------
> -# wbemcli gi http://localhost:5988/root/virt:\
> -# Xen_VirtualSystemMigrationSettingData.Wrong="MigrationSettingData" -nl
>  #
> -# 2) Test by passing Invalid InstanceID Key Value
> +# 1) Test by passing Invalid InstanceID Key Value
>  # Input:
>  # ------
>  # wbemcli gi http://localhost:5988/root/virt:\
>  # Xen_VirtualSystemMigrationSettingData.InstanceID="Wrong" -nl
> -#
> -# Inboth the cases the following exception is verified.
>  #
>  # Output:
>  # -------
>  # error code  : CIM_ERR_NOT_FOUND
>  # error desc  : "No such instance (InstanceID)"
>  #
> -#                                                         Date: 06-03-2008
> +
>  import sys
> -import pywbem
> -from XenKvmLib import assoc
> -from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
> -from CimTest.ReturnCodes import PASS
> -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.classes import get_typed_class
> +from XenKvmLib.enumclass import GetInstance, CIM_CimtestClass
>  
>  platform_sup = ['Xen', 'XenFV', 'KVM', 'LXC']
>  
> -expr_values = {
> -                "invalid_instid" :  { 'rc'   : pywbem.CIM_ERR_NOT_FOUND, \
> -                                      'desc' : 'No such instance
> (InstanceID)' }
> -              }
> -def verify_fields():
> -    classname = get_typed_class(options.virt,
> "VirtualSystemMigrationSettingData")
> -    return try_getinstance(conn, classname, keys, field_name=field, \
> -                          
> expr_values=expr_values['invalid_instid'], bug_no="")
> -    
> -
>  @do_main(platform_sup)
>  def main():
> -    global options
>      options = main.options
> -    global conn
> -    global keys
> -    global field
> -    conn = assoc.myWBEMConnection('http://%s' % options.ip,
> (CIM_USER, CIM_PASS), CIM_NS)
>  
> -    field = 'INVALID_Instid_KeyName'
> -    keys = { field : "MigrationSettingData" }
> -    status = verify_fields()
> +    expr_values = {
> +                   'rc'   : CIM_ERR_NOT_FOUND,
> +                   'desc' : 'No such instance (InstanceID)'
> +                  }
> +
> +    cn = get_typed_class(options.virt, 'VirtualSystemMigrationSettingData')
> +
> +    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("Got %s %s", err_desc, err_no)
> +            status = FAIL
> +
>      if status != PASS:
> -        logger.error("------ FAILED: to check INVALID_Instid_KeyName.------")
> -        return status
> -
> -    field = 'INVALID_Instid_KeyValue'
> -    keys = { 'InstanceID' : field }
> -    status = verify_fields()
> -    if status != PASS:
> -        logger.error("------ FAILED: to check
> INVALID_Instid_KeyValue.------")
> -        return status
> +        logger.error("------ FAILED: Invalid InstanceID Key Value.------")

       
> It's better to return FAIL after logger.error above, otherwise, we have to return

  status instead of PASS below.
  Others looks fine for me.

>      return PASS
>  if __name__ == "__main__":
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim