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

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Fri Apr 24 07:08:45 UTC 2009



Deepti B Kalakeri wrote:
>
>
> yunguol at cn.ibm.com wrote:
>> # HG changeset patch
>> # User Guolian Yun <yunguol at cn.ibm.com>
>> # Date 1240466305 25200
>> # Node ID 6789fc642c76198f983ed771f4a00237ed6daeff
>> # Parent e8dc06eefada41252ba8d27b08fcef8ef6604251
>> [TEST] #3Update RPCS/04 to validate that the Network child pool can 
>> be created through the providers
>>
>>
>> Updates from 2 to 3:
>> 1) Use CIM_NS from const.py instead of hardcoding
>> 2) Check if the IP is already used on the system before setting
>> 3) Rewrite try, except... blocks
>>
>> 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 e8dc06eefada -r 6789fc642c76 
>> suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py 
>>
>> --- 
>> a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py 
>> Tue Apr 21 17:08:06 2009 -0700
>> +++ 
>> b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/04_CreateChildResourcePool.py 
>> Wed Apr 22 22:58:25 2009 -0700
>> @@ -39,45 +39,123 @@
>> # OUT -- Error -- String -- Encoded error instance if the operation # 
>> failed and did not return a job
>> #
>> -# REVISIT : -# --------
>> -# As of now the CreateChildResourcePool() simply throws an Exception.
>> -# We must improve this tc once the service is implemented. -# -# 
>> -Date: 20.02.2008
>> -
>> +# Exception details before Revision 837
>> +# -----
>> +# Error code: CIM_ERR_NOT_SUPPORTED +#
>> +# After revision 837, the service is implemented
>> +#
>> +# -Date: 20.02.2008
>>
>> import sys
>> import pywbem 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 CimTest.Globals import CIM_NS
Can you move the CIM_NS import stmt above and to import it along with 
the logger
>> +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, undefine_netpool
>> +from XenKvmLib.xm_virt_util import net_list
>> +from VirtLib.utils import run_remote
>>
>> 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")
> When I did dumpxml for the different netpool types. I did not see any 
> specific information for nat type : for ex: the dump did not show 
> <forward mode='nat'/>.
> Also for routed pool I did not see the <forward mode="route" 
> dev="eth1"/>. Are we not setting these kind of information via 
> Libvirt-cim ?
>> +
>> + 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')
>> + addr = "192.168.0.30"
>> + 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.31",
>> + "IPRangeEnd" : "192.168.0.57",
>> + } + for i in range(0, len(test_pool)):
>> + np_id = 'NetworkPool/%s' % test_pool[i]
>> + iname = CIMInstanceName(nprasd,
>> + namespace = CIM_NS,
>> + keybindings = {'InstanceID':np_id})
>> + if test_pool[i] == "routedpool":
>> + np_prop["ForwardMode"] = "route eth1"
>> + elif test_pool[i] == "natpool":
>> + np_prop["ForwardMode"] = "nat"
>> +
>> + nrasd = CIMInstance(nprasd, path = iname, properties = np_prop)
>> + try:
>> + rpcs_conn.CreateChildResourcePool(ElementName=test_pool[i], + 
>> Settings=[nrasd.tomof()])
>> + 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")
>> + status = destroy_netpool(options.ip, options.virt, test_pool[i])
>> + if status != PASS:
>> + raise Exception("Unable to destroy networkpool %s"
>> + % test_pool[i])
>> + status = undefine_netpool(options.ip, options.virt, test_pool[i])
>> + if status != PASS:
>> + raise Exception("Unable to undefine networkpool %s"
>> + % test_pool[i])
>> + except Exception, details:
>> + logger.error("Invoke CreateChildResourcePool() error when "
>> + "create %s", np_id)
>> + logger.error(details)
> since we raise exceptions when failing to destroy and undefine the 
> network pool can you make it more generic ?
> logger.error("Exception details: %s", details)
>> + return FAIL
>> + + return status
>> +
>> if __name__ == "__main__":
>> sys.exit(main())
>> - diff -r e8dc06eefada -r 6789fc642c76 
>> suites/libvirt-cim/lib/XenKvmLib/common_util.py
>> --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Apr 21 
>> 17:08:06 2009 -0700
>> +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed Apr 22 
>> 22:58:25 2009 -0700
>> @@ -36,7 +36,8 @@
>> CIM_ERROR_GETINSTANCE
>> from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
>> from XenKvmLib.xm_virt_util import diskpool_list, virsh_version, 
>> net_list,\
>> - domain_list, virt2uri, net_destroy
>> + domain_list, virt2uri, net_destroy,\
>> + net_undefine
>> from XenKvmLib.vxml import PoolXML, NetXML
>> from VirtLib import utils from XenKvmLib.const import 
>> default_pool_name, default_network_name
>> @@ -387,6 +388,17 @@
>>
>> return PASS
>> +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 +
>> def libvirt_cached_data_poll(ip, virt, dom_name):
>> cs = None
>>
>> diff -r e8dc06eefada -r 6789fc642c76 
>> suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
>> --- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Tue Apr 21 
>> 17:08:06 2009 -0700
>> +++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Wed Apr 22 
>> 22:58:25 2009 -0700
>> @@ -191,6 +191,15 @@
>> ret, out = utils.run_remote(server, cmd)
>>
>> return ret + +def net_undefine(network, server, virt="Xen"):
>> + """Function undefine a given virtual network"""
>> +
>> + cmd = "virsh -c %s net-undefine %s" % (virt2uri(virt), network)
>> + print cmd
>> + ret, out = utils.run_remote(server, cmd)
>> + + return ret
> Any specific reason for calling net_undefine() from common_util.py and 
> for making to 2 levels?
> Why dont we move it all to xml_virt_util.py ?
>> def network_by_bridge(bridge, server, virt="Xen"):
>> """Function returns virtual network for a given bridge"""
>>
>> _______________________________________________
>> 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