
# HG changeset patch # User Guolian Yun <yunguol@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@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" @do_main(platform_sup) def main(): + status = FAIL options = main.options rpcs_conn = eval("rpcs_service." + get_typed_class(options.virt, \ "ResourcePoolConfigurationService"))(options.ip) - 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) - 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.DeleteResourcePool() + 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') + 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") + + 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 + elif ret_pool != np_id and i == len(netpool) -1: + status = PASS + except Exception, details: + logger.error(details) + return status + + return status if __name__ == "__main__": sys.exit(main()) -