# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1210765549 25200
# Node ID 6671b339cc8fd7c2cc7cada2ac15bc93635fbe4b
# Parent 63c2d5e576bd750c0ba0975424a72ac24105c6f7
[TEST] Adding create_diskpool() function.
Modified vxml to get the poolname and networkname .
To create the storage pool on machine with libvirt >= 0.4.1
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 63c2d5e576bd -r 6671b339cc8f suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed May 14 04:36:40 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed May 14 04:45:49 2008 -0700
@@ -1,3 +1,4 @@
+#!/usr/bin/python
#
# Copyright 2008 IBM Corp.
#
@@ -33,6 +34,8 @@ from CimTest.Globals import logger, log_
from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE
from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
from XenKvmLib.const import CIM_REV
+from VirtLib.live import diskpool_list, virsh_version, net_list
+from XenKvmLib.vxml import PoolXML, NetXML
test_dpath = "foo"
diskpoolconf_rev = 558
@@ -294,3 +297,53 @@ def create_diskpool_file():
return conf_file()
+def create_diskpool(server, virt='KVM'):
+ status = PASS
+ try:
+ dpool_list = diskpool_list(server, virt='KVM')
+ if len(dpool_list) > 0:
+ dpoolname=dpool_list[0]
+ else:
+ diskxml = PoolXML(server, virt=virt)
+ ret = diskxml.create_vpool()
+ if not ret:
+ logger.error('Failed to create the disk pool "%s"',
+ dpoolname)
+ status = FAIL
+ dpoolname=diskxml.xml_get_diskpool_name()
+ except Exception, detail:
+ logger.error("Exception: In fn create_diskpool(): %s", detail)
+ status=FAIL
+ return status, dpoolname
+
+def create_diskpool_conf(server, virt):
+ libvirt_version = virsh_version(server, virt)
+ if virt == 'KVM' and libvirt_version >= '0.4.1' and \
+ CIM_REV > diskpoolconf_rev:
+ status, dpoolname = create_diskpool(server, virt=virt)
+ diskid = "%s/%s" % ("DiskPool", dpoolname)
+ else:
+ status = create_diskpool_file()
+ diskid = "%s/%s" % ("DiskPool", test_dpath)
+
+ return status, diskid
+
+
+def create_netpool_conf(server, virt):
+ status = PASS
+ try:
+ vir_network = net_list(server, virt)
+ if len(vir_network) > 0:
+ test_network = vir_network[0]
+ else:
+ netxml = NetXML(server, virt=virt)
+ ret = netxml.create_vnet()
+ if not ret:
+ logger.error("Failed to create Virtual Network '%s'",
+ test_network)
+ status = FAIL
+ test_network = netxml.xml_get_netpool_name()
+ except Exception, detail:
+ logger.error("Exception: In fn create_netpool_conf(): %s", detail)
+ status=FAIL
+ return status, test_network
diff -r 63c2d5e576bd -r 6671b339cc8f suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed May 14 04:36:40 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Wed May 14 04:45:49 2008 -0700
@@ -121,7 +121,6 @@ class XMLClass:
except Exception:
logger.info('Zero or multiple node found')
return None
-
if node.nodeType == Node.ATTRIBUTE_NODE:
return node.value
if node.nodeType == Node.TEXT_NODE:
@@ -213,10 +212,14 @@ class NetXML(Virsh, XMLClass):
def create_vnet(self):
return self.run(self.server, 'net-create', self.xml_string)
+ def xml_get_netpool_name(self):
+ npoolname = self.get_value_xpath('/network/name')
+ return npoolname
+
class PoolXML(Virsh, XMLClass):
def __init__(self, server, poolname=const.default_pool_name,
- virt='xen'):
+ virt='xen'):
XMLClass.__init__(self)
if virt == 'XenFV':
@@ -235,6 +238,10 @@ class PoolXML(Virsh, XMLClass):
def destroy_vpool(self):
return self.run(self.server, 'pool-destroy', self.pool_name)
+
+ def xml_get_diskpool_name(self):
+ dpoolname = self.get_value_xpath('/pool/name')
+ return dpoolname
class VirtXML(Virsh, XMLClass):
"""Base class for all XML generation &
operation"""
@@ -293,7 +300,7 @@ class VirtXML(Virsh, XMLClass):
def set_diskdev(self, diskdev):
self.set_attributes('/domain/devices/disk/target', dev=diskdev)
-
+
def define(self, ip):
return self.run(ip, 'define', self.xml_string)
@@ -374,7 +381,8 @@ class VirtXML(Virsh, XMLClass):
bridgeStr = self.get_value_xpath(
'/domain/devices/interface/source/@bridge')
return bridgeStr
-
+
+
def dumpxml(self, ip):
cmd = 'virsh -c %s dumpxml %s' % (self.vuri, self.dname)
s, o = utils.run_remote(ip, cmd)