[Libvirt-cim] [PATCH] [TEST] #2 Update RPCS/04 to validate that the Network child pool can be created through the providers

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Mon Apr 20 13:12:07 UTC 2009



yunguol at cn.ibm.com wrote:
> # HG changeset patch
> # User Guolian Yun <yunguol at cn.ibm.com>
> # Date 1240207150 25200
> # Node ID fd53d858ff5fa251862bf36c26eafd79290c2f65
> # Parent  ced161a8198115797a6036f3f22e02d234439a76
> [TEST] #2 Update RPCS/04 to validate that the Network child pool can be created through the providers
>
>
> Updates from 1 to 2:
> Test all types of networkpool including routed network, nat based network and isolated network
>
> Tested for KVM with current sources
> Signed-off-by: Guolian Yun<yunguol at cn.ibm.com>
>
> diff -r ced161a81981 -r fd53d858ff5f suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py
> --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Wed Apr 15 20:19:31 2009 -0700
> +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py	Sun Apr 19 22:59:10 2009 -0700
> @@ -41,8 +41,8 @@
>  #
>  # REVISIT : 
>  # --------
> -# As of now the CreateChildResourcePool() simply throws an Exception.
> -# We must improve this tc once the service is implemented. 
> +# The CreateChildResourcePool() simply throws an Exception before the 
> +# changeset number of 839, and now the service is implemented.
>   
Can you include a heading as "Exception details before Revision 839 " 
for the earlier description and
some heading like "OUTPUT details after revision 839".
>  # 
>  #                                                                            -Date: 20.02.2008
>   
This line crosses beyond 90 columns ,wrap it to 80 columns.
> @@ -52,32 +52,100 @@
>  from XenKvmLib import rpcs_service
>  from CimTest.Globals import logger
>  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 XenKvmLib.classes import get_typed_class
> +from pywbem.cim_obj import CIMInstanceName, CIMInstance
> +from XenKvmLib.enumclass import EnumInstances
> +from XenKvmLib.common_util import destroy_netpool
>
>  cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
>  cim_mname  = "CreateChildResourcePool"
> +libvirt_cim_child_pool_rev = 837
> +test_pool = ["routedpool", "natpool", "isolatedpool"]
> +
> +def verify_pool(pool_list, poolname):
> +    status = FAIL
> +    if len(pool_list) < 1:
> +        logger.error("Return %i instances, expected at least one instance",
> +                     len(pool_list))
> +        return FAIL
> +    
> +    for i in range(0, len(pool_list)):
> +        ret_pool = pool_list[i].InstanceID
> +        if ret_pool == poolname:
> +            status = PASS
> +            break
> +        elif ret_pool != poolname and i == len(pool_list)-1:
> +            logger.error("Can not find expected pool")
> +
> +    return status
>
>  @do_main(platform_sup)
>  def main():
>      options = main.options
>      rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \
>                        "ResourcePoolConfigurationService"))(options.ip)
> -    try:
> -        rpcs_conn.CreateChildResourcePool()
> -    except pywbem.CIMError, (err_no, desc):
> -        if err_no == cim_errno :
> -            logger.info("Got expected exception for '%s' service", cim_mname)
> -            logger.info("Errno is '%s' ", err_no)
> -            logger.info("Error string is '%s'", desc)
> -            return PASS
> -        else:
> -            logger.error("Unexpected rc code %s and description %s\n",
> -                         err_no, desc)
> -            return FAIL
> -     
> -    logger.error("The execution should not have reached here!!")
> -    return FAIL
> +
> +    curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
> +    if curr_cim_rev < libvirt_cim_child_pool_rev:
> +        try:
> +            rpcs_conn.CreateChildResourcePool()
> +        except pywbem.CIMError, (err_no, desc):
> +            if err_no == cim_errno :
> +                logger.info("Got expected exception for '%s'service", cim_mname)
> +                logger.info("Errno is '%s' ", err_no)
> +                logger.info("Error string is '%s'", desc)
> +                return PASS
> +            else:
> +                logger.error("Unexpected rc code %s and description %s\n",
> +                             err_no, desc)
> +                return FAIL
> +    elif curr_cim_rev >= libvirt_cim_child_pool_rev: 
> +        nprasd = get_typed_class(options.virt, 
> +                                 'NetPoolResourceAllocationSettingData')
> +        for i in range(0, len(test_pool)):
> +            np_id = 'NetworkPool/%s' % test_pool[i]
> +            iname = CIMInstanceName(nprasd,
> +                                    namespace = 'root/virt',
>   
You can use CIM_NS from const.py instead of hardcoding.
> +                                    keybindings = {'InstanceID':np_id})
> +            np_prop = {
> +                          "Address" : "192.168.0.30",
> +                          "Netmask" : "255.255.255.0",
> +                          "IPRangeStart" : "192.168.0.31",
> +                          "IPRangeEnd" : "192.168.0.57",
> +                         }
>   
Since these information does not change for through the loop you can 
probably declare it outside the loop.
Also, you probably want to check if the IP is already used on the 
system. You can do something like this:

n_list = net_list(server, 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 = utils.run_remote(server, 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

or something better.

> +            if test_pool == "routedpool":
>   
you should check for test_pool[i] not test_pool or else we endup 
checking the isolated netpool type.
> +                np_prop["ForwardMode"] = "route eth1"
>   
I know using route eth1 works.. but to make it more close to the real 
system, can we use the ifconfig to use one of the eth 's.
> +            elif test_pool == "natpool":
> +                np_prop["ForwardMode"] = "nat"
> +
> +            nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)
> +            try:
> +                rpcs_conn.CreateChildResourcePool(ElementName=test_pool[i], 
> +                                                  Settings=[nrasd.tomof()])
> +            except pywbem.CIMError, details:
> +                logger.error("Invoke CreateChildResourcePool() error when "
> +                              "create %s", np_id)
> +                logger.error(details)
> +                return FAIL
> +             
> +            try:
> +                np = get_typed_class(options.virt, 'NetworkPool')
> +                netpool = EnumInstances(options.ip, np)
> +                status = verify_pool(netpool, np_id)
> +                if status != PASS:
> +                    raise Exception("Error in networkpool verification")
> +                
> +                destroy_netpool(options.ip, options.virt, test_pool[i])
> +                if status != PASS:
> +                    raise Exception("Unable to destroy networkpool %s" 
> +                                    % test_pool[i])
> +            except Exception, details:
> +                logger.error(detatils)
> +                return FAIL
> +       
>   
Since in the exception block you are not checking for anything specific, 
instead of using two try, except... blocks you can open the try block 
immediately after the for loop like the one below:

for i in range(0, len(test_pool)):
try:
np_id = 'NetworkPool/%s' % test_pool[i]
......
except Exception, details:
logger.error("Exception Details: %s", details)
return FAIL
This will reduce the no of return statements as well.
> +        return status
>   
You should undefine the netpools before returning from the tests 
otherwise the test will fail for the next run.
> +
>  if __name__ == "__main__":
>      sys.exit(main())
>      
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>   

-- 
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list