[PATCH] [TEST] Add new functions to pool.py for pool verificaiton through providers

# HG changeset patch # User Guolian Yun <yunguol@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@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 + 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) + 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

yunguol@cn.ibm.com wrote:
# HG changeset patch # User Guolian Yun <yunguol@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@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@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

+ 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.
Thanks Deepti - this is what I meant by the template NetPoolRASDs. Instead of building the instances of NetPoolRASDs by hand, you can use the instances returned by SDC. You'll probably want a function that does this. You can look at the get_default_rasd_mofs() in rasd.py - this gets the template RASDs for the non-pool related RASDs. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

libvirt-cim-bounces@redhat.com wrote on 2009-05-08 01:13:54:
+ 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.
Thanks Deepti - this is what I meant by the template NetPoolRASDs. Instead of building the instances of NetPoolRASDs by hand, you can use the instances returned by SDC.
I got NetRASDs instead of NetPoolRASDs through this association with latest provider. [root@elm3b197 cimtest]# wbemcli ain -ac KVM_SettingsDefineCapabilities http://root:elm3b197@localhost/root/virt:KVM_AllocationCapabilities.InstanceID="NetworkPool/cimtest-networkpool" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Minimum" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Minimum" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Maximum" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Maximum" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Default" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Default" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Increment" localhost/root/virt:KVM_NetResourceAllocationSettingData.InstanceID="Increment"
You'll probably want a function that does this. You can look at the get_default_rasd_mofs() in rasd.py - this gets the template RASDs for the non-pool related RASDs.
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

Thanks Deepti - this is what I meant by the template NetPoolRASDs. Instead of building the instances of NetPoolRASDs by hand, you can use the instances returned by SDC.
I got NetRASDs instead of NetPoolRASDs through this association with latest provider.
[root@elm3b197 cimtest]# wbemcli ain -ac KVM_SettingsDefineCapabilities http://localhost/root/virt:KVM_AllocationCapabilities.InstanceID="NetworkPool/cimtest-networkpool"
You want to create a child pool from the parent pool. The parent pool is just a placeholder - all network pools that exist on the system will be children of the parent pool. # wbemcli ain -ac KVM_SettingsDefineCapabilities http://localhost/root/virt:KVM_AllocationCapabilities.InstanceID="NetworkPool/0" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Minimum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Maximum" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Default" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" elm3b41/root/virt:KVM_NetPoolResourceAllocationSettingData.InstanceID="Increment" -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

+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
This only checks the IP, it doesn't check the - the netmask, ip start, ip end, etc. I would try to leverage the NetXML class here. You can have a function similar to dumpxml. You can also have functions similar to xml_get_net_mac(), xml_get_vcpus() etc. This will allow you to verify all the values of the XML, not just the IP.
+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]
You can use the parse_instance_id() function for this. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

libvirt-cim-bounces@redhat.com wrote on 2009-05-08 01:28:09:
+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
This only checks the IP, it doesn't check the - the netmask, ip start, ip end, etc.
I would try to leverage the NetXML class here. You can have a function similar to dumpxml. You can also have functions similar to xml_get_net_mac(), xml_get_vcpus() etc. This will allow you to verify all the values of the XML, not just the IP.
I discussed this in detail with Deepti. We'd like to define several functions for parsing net pool values in NetXML class. But on the tc, we can only get NetXML string instead of NetXML class, so we can not call the parsing functions. Do you know how to fix this? Now, the only options is to use dump function outside of NetXML, and then parse the values in the str...
+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]
You can use the parse_instance_id() function for this.
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

I would try to leverage the NetXML class here. You can have a function similar to dumpxml. You can also have functions similar to xml_get_net_mac(), xml_get_vcpus() etc. This will allow you to verify all the values of the XML, not just the IP.
I discussed this in detail with Deepti. We'd like to define several functions for parsing net pool values in NetXML class. But on the tc, we can only get NetXML string instead of NetXML class, so we can not call the parsing functions. Do you know how to fix this? Now, the only options is to use dump function outside of NetXML, and then parse the values in the str...
I would make the init() function of NetXML take a flag that allows you to specify whether the network is a new one or not. If the network isn't a new one, then you can dump the XML directly (instead of building the XML, like what's currently being done in the init() function). Having a flag like this isn't really ideal, but there's not an easy way to tell NetXML whether you want to init a completely new NetXML object or if you want to just get the XML of an existing object. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (4)
-
Deepti B Kalakeri
-
Guo Lian Yun
-
Kaitlin Rupert
-
yunguol@cn.ibm.com