[Libvirt-cim] [PATCH] [TEST] Add new functions to pool.py for poolverificaiton through providers

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Thu May 7 11:21:08 UTC 2009



yunguol at cn.ibm.com wrote:
> # HG changeset patch
> # User Guolian Yun <yunguol at cn.ibm.com>
> # Date 1241686602 25200
> # Node ID 0456e939b4326d1fa1110f4be8281fbb54af2dc9
> # Parent  92caf252c2fa8c8a7a9b70548d12b03c52f3935c
> [TEST] Add new functions to pool.py for pool verificaiton through providers
>
>
> Tested for KVM with current sources
> Signed-off-by: Guolian Yun<yunguol at cn.ibm.com>
>
> diff -r 92caf252c2fa -r 0456e939b432 suites/libvirt-cim/lib/XenKvmLib/pool.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/pool.py	Mon May 04 03:49:32 2009 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py	Thu May 07 01:56:42 2009 -0700
> @@ -21,15 +21,21 @@
>  #
>
>  import sys
> -from CimTest.Globals import logger
> +from CimTest.Globals import logger, CIM_NS
>  from CimTest.ReturnCodes import PASS, FAIL
>  from XenKvmLib.classes import get_typed_class
>  from XenKvmLib.const import get_provider_version, default_pool_name 
>  from XenKvmLib.enumclass import EnumInstances
>  from VirtLib.utils import run_remote
> -from XenKvmLib.xm_virt_util import virt2uri
> +from XenKvmLib.xm_virt_util import virt2uri, net_list
> +from XenKvmLib import rpcs_service
> +import pywbem
> +from CimTest.CimExt import CIMClassMOF
>
> +cim_errno  = pywbem.CIM_ERR_NOT_SUPPORTED
> +cim_mname  = "CreateChildResourcePool"
>  input_graphics_pool_rev = 757
> +libvirt_cim_child_pool_rev = 837
>
>  def pool_cn_to_rasd_cn(pool_cn, virt):
>      if pool_cn.find('ProcessorPool') >= 0:
> @@ -97,3 +103,119 @@
>
>      return volume
>
> +def net_undefine(network, server, virt="Xen"):
> +    """Function undefine a given virtual network"""
> +
> +    cmd = "virsh -c %s net-undefine %s" % (virt2uri(virt), network)
> +    ret, out = run_remote(server, cmd)
> +        
> +    return ret
> +
> +def undefine_netpool(server, virt, net_name):
> +    if net_name == None:
> +       return FAIL
> +
> +    ret = net_undefine(net_name, server, virt)
> +    if ret != 0:
> +        logger.error("Failed to undefine Virtual Network '%s'", net_name)
> +        return FAIL
> +
> +    return PASS    
> +
> +class CIM_NetPoolResourceAllocationSettingData(CIMClassMOF):
> +    def __init__(self, addr, netmask, ipstart, ipend, mode):
> +        if addr != None:
> +            self.Address = addr
> +        if netmask != None:
> +            self.NetMask = netmask
> +        if ipstart != None:
> +            self.IPRangeStart = ipstart
> +        if ipend != None:
> +            self.IPRangeEnd = ipend
> +        if mode != None:
> +            self.ForwardMode = mode
> +
> +class Xen_NetPoolResourceAllocationSettingData(CIM_NetPoolResourceAllocationSettingData):
> +    pass
> +
> +class KVM_NetPoolResourceAllocationSettingData(CIM_NetPoolResourceAllocationSettingData):
> +    pass
> +
> +class LXC_NetPoolResourceAllocationSettingData(CIM_NetPoolResourceAllocationSettingData):
> +    pass
> +
> +def dump_netxml(server, netname):
> +    cmd = "virsh net-dumpxml %s | awk '/ip address/ {print}' | \
> +           cut -d ' ' -f 4 | sed 's/address=//'" % netname
> +    s, addr = run_remote(server, cmd)
> +    addr = addr.strip("'")
> +    
> +    return addr
> +
> +def create_netpool(server, virt, test_pool, address, mode):
> +    status = PASS
>   
status = PASS value is used only in one place, hence you can remove this 
variable definition and use return PASS instead.
> +    rpcs = get_typed_class(virt, "ResourcePoolConfigurationService")
> +    rpcs_conn = eval("rpcs_service." + rpcs)(server)
> +    curr_cim_rev, changeset = get_provider_version(virt, server)
> +    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(virt, 
> +                                 'NetPoolResourceAllocationSettingData')
> +        n_list = net_list(server, virt)
> +        for _net_name in n_list:
> +            in_use_addr = dump_netxml(server, _net_name)
> +            if in_use_addr == address:
> +                logger.error("IP address is in use by a different network")
> +                return FAIL
> +        
> +        class_nprasd = eval(nprasd)
> +        nprasd = class_nprasd(addr = address,
> +                              netmask = "255.255.255.0",
> +                              ipstart = "192.168.0.31",
> +                              ipend = "192.168.0.57",
> +                              mode = mode)
>   
Do you think using the following here will avoid the harcoding of the 
NetPoolRASD setting here ?
wbemcli ain -ac KVM_SettingsDefineCapabilities 
'http://root:password@localhost/root/virt:KVM_AllocationCapabilities.InstanceID="NetworkPool/0"' 
-nl

localhost/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" 

localhost/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" 

localhost/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" 

localhost/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" 


You could use the default o/p from the above query.

> +        try:
> +            rpcs_conn.CreateChildResourcePool(ElementName=test_pool, 
> +                                              Settings=[nprasd.mof()])
> +        except Exception, details:
> +            logger.error("Error in childpool creation")
> +            logger.error(details)
> +            return FAIL
> +
> +        return status
> +    
> +def verify_pool(server, pooltype, poolid, address):
> +    status = FAIL
> +    pool_list = EnumInstances(server, pooltype)
> +    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
> +        ret_pool_name = ret_pool.split("/")[1]
> +        if ret_pool == poolid:
> +            ret_addr = dump_netxml(server, ret_pool_name)
> +            if ret_addr == address: 
> +                status = PASS
> +                break
> +            else:
> +                logger.error('Return address is %s, but expect is %s',
> +                             ret_addr, address)
> +        elif ret_pool != poolid and i == len(pool_list)-1:
> +            logger.error("The created pool can not be found")
> +
> +    return status
>
> _______________________________________________
> 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