libvirt-cim-bounces@redhat.com wrote on 2009-03-09 14:24:42:

>
>
> yunguol@cn.ibm.com wrote:
> > # HG changeset patch
> > # User Guolian Yun <yunguol@cn.ibm.com>
> > # Date 1236567513 25200
> > # Node ID e601bc0ba234dae371ec38b8289b5827d12f2910
> > # Parent  087aaba2658940bbc8718aa55cbcd6150f7cac23
> > [TEST] #3 Fix ElementCapabilities/03_forward_errs.py with
> provider's updated err message
> >
> >
> > Updates from 2 to 3:
> > Get correct CS Name instead of hard code of "Xen_ComputerSystem"
> >
> > Updates from 1 to 2:
> > Use a variable to assign revision value to be calculated for comparison
> >
> > Also fix the line to meet 80 length
> >
> > Tested for KVM/LXC with current sources and rpm
> >
> > Signed-off-by: Guolian Yun<yunguol@cn.ibm.com>
> >
> > diff -r 087aaba26589 -r e601bc0ba234 suites/libvirt-
> cim/cimtest/ElementCapabilities/03_forward_errs.py
> > --- a/suites/libvirt-
> cim/cimtest/ElementCapabilities/03_forward_errs.py   Thu Mar 05 22:
> 04:39 2009 -0800
> > +++ b/suites/libvirt-
> cim/cimtest/ElementCapabilities/03_forward_errs.py   Sun Mar 08 19:
> 58:33 2009 -0700
> > @@ -27,10 +27,11 @@
> >  from XenKvmLib import enumclass
> >  from XenKvmLib.classes import get_typed_class
> >  from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
> > -from XenKvmLib.const import do_main
> > +from XenKvmLib.const import do_main, get_provider_version
> >  from CimTest.ReturnCodes import PASS, FAIL
> >
> >  sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
> > +libvirt_ec_changes = 815
> >
> >  exp_rc = 6 #CIM_ERR_NOT_FOUND
> >  exp_desc = "No such instance"
> > @@ -42,23 +43,24 @@
> >      status = FAIL
> >      rc = -1
> >      names = []
> > -
> > +    ec = get_typed_class(options.virt, "ElementCapabilities")
> >      try:
> > -        names = conn.AssociatorNames(ref, AssocClass =
> get_typed_class(options.virt, "ElementCapabilities"))
> > +        names = conn.AssociatorNames(ref, AssocClass = ec)
> >          rc = 0
> >      except pywbem.CIMError, (rc, desc):
> >          if rc == exp_rc and desc.find(exp_desc) >= 0:
> >              logger.info("Got expected rc code and error string")
> >              status = PASS
> >          else:
> > -            logger.error("Unexpected rc code %s and description %
> s\n", rc, desc)
> > +            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("ElementCapabilities associator should NOT
> return excepted \
> > -                      result with a wrong key name and value of %
> s input", ref_class)
> > +        logger.error("ElementCapabilities associator should NOT" + \
> > +                     " return records with a wrong key name and value")
> >  
> Remove the + sign here, using slash is enough to continue the string.
> >          status = FAIL
> >      
> >      return status
> > @@ -73,7 +75,8 @@
> >      cs = get_typed_class(options.virt, "ComputerSystem")
> >
> >      instanceref = CIMInstanceName(hs,
> > -                                  keybindings = {"Name" :
> "wrong", "CreationClassName" : "wrong"})
> > +                                  keybindings = {"Name" : "wrong",
> > +                                  "CreationClassName" : "wrong"})
> >      rc = try_assoc(instanceref, hs, exp_rc, exp_desc, options)
> >      
> >      if rc != PASS:
> > @@ -81,8 +84,16 @@
> >          return status
> >
> >      instance_cs = CIMInstanceName(cs,
> > -                                  keybindings = {"Name" :
> "wrong", "CreationClassName" : "Xen_ComputerSystem"})
> > -    rc = try_assoc(instance_cs, cs, exp_rc, exp_desc, options)
> > +                                  keybindings = {"Name" : "wrong",
> > +                                  "CreationClassName" : cs})
> > +
> > +    curr_cim_rev, changeset = get_provider_version(options.virt,
> options.ip)
> > +    if curr_cim_rev >= libvirt_ec_changes:
> > +        cs_exp_desc = "Referenced domain `wrong' does not exist:" + \
> > +                      " Domain not found"
> >  
> Remove the "+" sign here. Only slash is enough.
> Also, instead of calling try_assoc twice you can do the following:
>
> if curr_cim_rev >= libvirt_ec_changes:
>         exp_desc = "Referenced domain `wrong' does not exist:"  \
>                      " Domain not found"
>
> I tried to do this in the first patch, but it reports error as follows:


  ERROR   - UnboundLocalError : local variable 'exp_desc' referenced before assignment
  Traceback (most recent call last):
  File "./lib/XenKvmLib/const.py", line 141, in do_try
  File "03_forward_errs.py", line 80, in main
    rc = try_assoc(instanceref, hs, exp_rc, exp_desc, options)
UnboundLocalError: local variable 'exp_desc' referenced before assignment
ERROR   - None
 
  So I define a new variable of cs_exp_desc to cover this and call try_assco twice.

> try_assoc(instance_cs, cs, exp_rc, exp_desc, options)
> Since exp_desc will be changed only when curr_cim_rev >= libvirt_ec_changes.
>
> > +        try_assoc(instance_cs, cs, exp_rc, cs_exp_desc, options)
> > +    else:
> > +        rc = try_assoc(instance_cs, cs, exp_rc, exp_desc, options)
> >      if rc != PASS:
> >          status = FAIL        
> >          return status
> >
> > _______________________________________________
> > Libvirt-cim mailing list
> > Libvirt-cim@redhat.com
> > https://www.redhat.com/mailman/listinfo/libvirt-cim
> >  
>
> --
> Thanks and Regards,
> Deepti B. Kalakeri
> IBM Linux Technology Center
> deeptik@linux.vnet.ibm.com
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim