[Libvirt-cim] [PATCH] [TEST] #2 Update RPCS/07_DeleteResourcePool.py validate that the Network pool can be deleted through the providers

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Apr 27 21:32:03 UTC 2009


yunguol at cn.ibm.com wrote:
> # HG changeset patch
> # User Guolian Yun <yunguol at cn.ibm.com>
> # Date 1240826363 25200
> # Node ID bf6c03f3c0518a6db28f1fc0313b29ed36726a5c
> # Parent  e8dc06eefada41252ba8d27b08fcef8ef6604251
> [TEST] #2 Update RPCS/07_DeleteResourcePool.py validate that the Network pool can be deleted through the providers
> 
> 
> Updates from 1 to 2:
> 1) Merge CIM_NS and logger
> 2) Remove the netpool length check
> 3) Check the use of the ip address before using
> 
> Tested for KVM with current sources
> Signed-off-by: Guolian Yun<yunguol at cn.ibm.com>
> 
> diff -r e8dc06eefada -r bf6c03f3c051 suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py
> --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py	Tue Apr 21 17:08:06 2009 -0700
> +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/07_DeleteResourcePool.py	Mon Apr 27 02:59:23 2009 -0700
> @@ -33,10 +33,12 @@
>  # OUT -- Job -- CIM_ConcreteJob REF -- Returned job if started
>  # OUT -- Error-- String -- Encoded error instance if the operation 
>  #                          failed and did not return a job.
> -# REVISIT : 
> -# --------
> -# As of now the DeleteResourcePool() simply throws an Exception.
> -# We must improve this tc once the service is implemented. 
> +#
> +# Exception details before Revision 841
> +# -----
> +# Error code: CIM_ERR_NOT_SUPPORTED 
> +#
> +# After revision 841, the service is implemented
>  # 
>  #                                                  -Date: 20.02.2008
> 
> @@ -44,34 +46,90 @@
>  import sys
>  import pywbem 
>  from XenKvmLib import rpcs_service
> -from CimTest.Globals import logger
> +from CimTest.Globals import logger, CIM_NS
>  from CimTest.ReturnCodes import FAIL, PASS
> -from XenKvmLib.const import do_main, platform_sup
> +from XenKvmLib.const import do_main, platform_sup, get_provider_version
> +from pywbem.cim_obj import CIMInstanceName, CIMInstance
> +from XenKvmLib.enumclass import EnumInstances
> +from XenKvmLib.xm_virt_util import net_list
>  from XenKvmLib.classes import get_typed_class
> +from VirtLib.utils import run_remote
> 
>  cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
>  cim_mname  = "DeleteResourcePool"
> +libvirt_cim_child_pool_rev = 841
> +test_pool = "nat_pool"

The name here is confusing.. the type of pool you create isn't a NAT'ed 
pool.

> 
>  @do_main(platform_sup)
>  def main():
> +    status = FAIL
>      options = main.options
>      rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \
>                        "ResourcePoolConfigurationService"))(options.ip)

Place get_typed_class() on its own line.


> +    curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
> +    if curr_cim_rev < libvirt_cim_child_pool_rev:
> +        try:
> +            rpcs_conn.DeleteResourcePool()
> +        except pywbem.CIMError, (err_no, desc):
> +            if err_no == cim_errno :
> +                logger.info("Got expected exception for '%s' service", cim_mname)

The line above is longer than 80 characters.


> +    elif curr_cim_rev >= libvirt_cim_child_pool_rev:
> +        nprasd = get_typed_class(options.virt,
> +                                 'NetPoolResourceAllocationSettingData')
> +        np = get_typed_class(options.virt, 'NetworkPool')                          
> +        np_id = 'NetworkPool/%s' % test_pool
> +        iname = CIMInstanceName(nprasd,
> +                                namespace = CIM_NS,
> +                                keybindings = {'InstanceID':np_id})
> +        addr = "192.168.0.20"
> +        n_list = net_list(options.ip, options.virt)
> +        for _net_name in n_list:
> +            cmd = "virsh net-dumpxml %s | awk '/ip address/ {print}' | \
> +                   cut -d ' ' -f 4 | sed 's/address=//'" % _net_name
> +            s, in_use_addr = run_remote(options.ip, cmd)
> +            in_use_addr = in_use_addr.strip("'")
> +            if in_use_addr == addr:
> +                logger.error("IP address is in use by a different network")
> +                return FAIL
> +        np_prop = {
> +                   "Address" : addr,
> +                   "Netmask" : "255.255.255.0",
> +                   "IPRangeStart" : "192.168.0.21",
> +                   "IPRangeEnd"   : "192.168.0.30"
> +                  }                       
> +        nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)     
> +        try:
> +            rpcs_conn.CreateChildResourcePool(ElementName=test_pool,
> +                                              Settings=[nrasd.tomof()])
> +            netpool = EnumInstances(options.ip, np)
> +            for i in range(0, len(netpool)):
> +                ret_pool = netpool[i].InstanceID
> +                if ret_pool == np_id:
> +                    break
> +                elif ret_pool != np_id and i == len(netpool) - 1:
> +                    raise Exception("Can not find expected pool")

Since you need the almost identical code in RPCS/04, make a function 
that creates network pool using the providers.

> +
> +            pool = CIMInstanceName(np, keybindings = {'InstanceID':np_id})
> +            rpcs_conn.DeleteResourcePool(Pool = pool)
> +            netpool = EnumInstances(options.ip, np)
> +            for i in range(0, len(netpool)):
> +                ret_pool = netpool[i].InstanceID
> +                if ret_pool == np_id:
> +                    raise Exception("Failed to delete %s" % test_pool)
> +                    break

In this case, status is not set.  So in the except block below, you 
can't guarantee what value the test will return.

Also, no need for the break here, because the exception will case the 
test to jump the the exception block.

> +                elif ret_pool != np_id and i == len(netpool) -1:
> +                    status = PASS

No need for this elif statement. If the test case doesn't hit the 
exception condition above, then the pool wasn't found.  That means the 
test passes.  So, outside of the for loop, set status = PASS.

> +        except Exception, details:
> +            logger.error(details)
> +            return status

Just return fail here.

> +                 
> +        return status

You don't have a specific return statement in the case where neither one 
of the if statements is matched.  The test should return a failure in 
that case.

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




More information about the Libvirt-cim mailing list