# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1242287001 25200
# Node ID fe5b8e3ff97aa7892c050b2642838ca2d0840a5e
# Parent 9391439d65e7ec6b88f34923d97f969c6114a237
[TEST] #2 Add general functions for pool verification
Tested for KVM with current sources
Signed-off-by: Guolian Yun<yunguol(a)cn.ibm.com>
diff -r 9391439d65e7 -r fe5b8e3ff97a suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py Wed May 13 07:28:33 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py Thu May 14 00:43:21 2009 -0700
@@ -21,15 +21,23 @@
#
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.classes import get_typed_class, inst_to_mof
from XenKvmLib.const import get_provider_version, default_pool_name
-from XenKvmLib.enumclass import EnumInstances
+from XenKvmLib.enumclass import EnumInstances, GetInstance
+from XenKvmLib.assoc import Associators
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
+from XenKvmLib.vxml import NetXML
+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 +105,118 @@
return volume
+def get_pool_rasds(server, virt):
+ net_pool_rasds = []
+
+ ac_cn = get_typed_class(virt, "AllocationCapabilities")
+ an_cn = get_typed_class(virt, "SettingsDefineCapabilities")
+ key_list = {"InstanceID" : "NetworkPool/0" }
+
+ try:
+ inst = GetInstance(server, ac_cn, key_list)
+ rasd = Associators(server, an_cn, ac_cn, InstanceID=inst.InstanceID)
+ except Exception, detail:
+ logger.error("Exception: %s", detail)
+ return None
+
+ for item in rasd:
+ if item['InstanceID'] == "Default":
+ net_pool_rasds.append(item)
+
+ return net_pool_rasds
+
+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
+
+def create_netpool(server, virt, test_pool, pool_attr_list):
+ 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:
+ n_list = net_list(server, virt)
+ for _net_name in n_list:
+ net_xml = NetXML(server=server, networkname=_net_name,
+ virt=virt, is_new_net=False)
+ pool_use_attr = net_xml.xml_get_netpool_attr_list()
+ if pool_attr_list['Address'] in pool_use_attr:
+ logger.error("IP address is in use by a different network")
+ return FAIL
+
+ net_pool_rasds = get_pool_rasds(server, virt)
+ if len(net_pool_rasds) == 0:
+ logger.error("We can not get NetPoolRASDs")
+ return FAIL
+ else:
+ net_pool_rasds[0]['PoolID'] = "NetworkPool/%s" % test_pool
+ for attr, val in pool_attr_list.iteritems():
+ net_pool_rasds[0][attr] = val
+
+ pool_settings = inst_to_mof(net_pool_rasds[0])
+
+ try:
+ rpcs_conn.CreateChildResourcePool(ElementName=test_pool,
+ Settings=[pool_settings])
+ except Exception, details:
+ logger.error("Error in childpool creation")
+ logger.error(details)
+ return FAIL
+
+ return status
+
+
+def verify_pool(server, virt, pooltype, poolname, pool_attr_list):
+ 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
+
+ poolid = "NetworkPool/%s" % poolname
+ for i in range(0, len(pool_list)):
+ ret_pool = pool_list[i].InstanceID
+ if ret_pool != poolid:
+ continue
+
+ net_xml = NetXML(server, virt=virt, networkname=poolname,
+ is_new_net=False)
+ ret_pool_attr_list = net_xml.xml_get_netpool_attr_list()
+
+ for i in range(0, len(ret_pool_attr_list)):
+ if ret_pool_attr_list[i] not in pool_attr_list.itervalues():
+ logger.error("Got error when parsing %s",
ret_pool_attr_list[i])
+ return FAIL
+
+ status = PASS
+
+ return status
diff -r 9391439d65e7 -r fe5b8e3ff97a suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed May 13 07:28:33 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu May 14 00:43:21 2009 -0700
@@ -197,7 +197,8 @@
def __init__(self, server, bridgename=const.default_bridge_name,
networkname=const.default_network_name,
- virt='xen'):
+ virt='xen',
+ is_new_net=True):
def get_valid_bridge_name(server):
bridge_list = live.available_bridges(server)
@@ -222,6 +223,17 @@
self.net_name = networkname
self.server = server
+ if is_new_net is False:
+ cmd = "virsh net-dumpxml %s" % self.net_name
+ s, net_xml = utils.run_remote(server, cmd)
+ if s != 0:
+ logger.error("Encounter error dump netxml")
+ return None
+ else:
+ self.xml_string = net_xml
+ self.xdoc = minidom.parseString(self.xml_string)
+ return
+
network = self.add_sub_node(self.xdoc, 'network')
self.add_sub_node(network, 'name', self.net_name)
self.add_sub_node(network, 'uuid', set_uuid())
@@ -259,6 +271,22 @@
npoolname = self.get_value_xpath('/network/name')
return npoolname
+ def xml_get_netpool_attr_list(self):
+ pool_attr_list = []
+
+ npoolmode = self.get_value_xpath('/network/forward/@mode')
+ npooladdr = self.get_value_xpath('/network/ip/@address')
+ npoolmask = self.get_value_xpath('/network/ip/@netmask')
+ npoolstart = self.get_value_xpath('/network/ip/dhcp/range/@start')
+ npoolend = self.get_value_xpath('/network/ip/dhcp/range/@end')
+
+ pool_attr_list.append(npoolmode)
+ pool_attr_list.append(npooladdr)
+ pool_attr_list.append(npoolmask)
+ pool_attr_list.append(npoolstart)
+ pool_attr_list.append(npoolend)
+
+ return pool_attr_list
class PoolXML(Virsh, XMLClass):