[Libvirt-cim] [PATCH] [TEST] Fixing 02_reverse.py of RAPF

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Thu May 29 22:29:10 UTC 2008


> diff -r 3ac66cf562f0 -r 9fae4065c845 suites/libvirt-cim/cimtest/ResourceAllocationFromPool/02_reverse.py

This fails for me on latest sources running with KVM:

ResourceAllocationFromPool - 02_reverse.py: FAIL
ERROR   - No associated pool for demo2/hda
CIM_ERR_FAILED: Unable to determine pool of `demo2/hda'

demo2 is a KVM guest that I have defined.

You'll want to make sure that the RASD you're verifying is the RASD that 
matches the guest you've defined.

> +
> +def get_rasd_or_pool_instid(server, virt, cn):
> +    key_list = ["InstanceID"]
> +    inst = []
> +    try:
> +        inst = enumclass.enumerate(server, cn, key_list, virt)
> +    except Exception:
> +        logger.error(Globals.CIM_ERROR_ENUMERATE, cn)
> +        return inst, FAIL
> +    return inst, PASS

Instead of enumerating the RASDs and the pools, you can get the instance 
of the RASD and pool directly (since you should know the InstanceID of 
each).

That way, you verify that the instance RAFP returns is the exact 
instance you're expected it to be.

> +
> +def get_instance(server, virt, vsxml, cn, pool_list, app_val=0):
> +    instances, status = get_rasd_or_pool_instid(server, virt, cn)
> +    if status != PASS:
> +        vsxml.undefine(server)    
> +        return pool_list, status
> +
> +    if app_val == 1:
> +        for inst in instances:
> +            pool_list.append(inst.InstanceID)

I wouldn't create a list of pools, I'd just do a GetInstance to get the 
expected pool instance for each case.

> +    return instances, pool_list, status
> +
> +
> +def verify_pool_from_RAPF(server, virt, instances, pool_instid_list, cn):

This should be RAFP, not RAPF.

> +    pool = []
> +    for inst in instances:
> +        try:
> +            pool = assoc.AssociatorNames(server, "ResourceAllocationFromPool",
> +                                         cn, virt, InstanceID = inst.InstanceID)
> +        except Exception:
> +            logger.error(Globals.CIM_ERROR_ASSOCIATORNAMES, inst.InstanceID)
> +            status = FAIL
> +
> +        if len(pool) < 1:
> +            logger.error("No associated pool for %s", inst.InstanceID)
> +            return FAIL
> +
> +        if not pool[0]['InstanceID'] in pool_instid_list:

I'd do an exact match here. You should be doing a 1 to 1 comparison on 
InstanceIDs.


> +    status = get_inst_verify_pool_from_RAPF(server, virt, vsxml, 'MemoryPool', 
> +                                           'MemResourceAllocationSettingData')
> +    if status != PASS:
> +        return status


If you need to call get_inst_verify_pool_from_RAPF() for each Pool/RASD 
type, you can create a list/dictionary with the argument information. 
You can then create a for loop that walks through the dictionary, that 
way you don't have to repeat the code block above 4 times.

Something like:

arg_list = { 'MemoryPool' : 'MemResourceAllocationSettingData',
               ...
            }

for pool_cn, rasd_cn in arg_list.iteritems():
     status = get_inst_verify_pool_from_RAPF(server, virt, vsxml, 
pool_cn, rasd_cn)
     if status != PASS:
         return status

-- 
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list