# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1208411620 25200
# Node ID e12d888a9502d9089f982c87305994ec17c28cc4
# Parent 2977c29bb772fb764004aad004e4ff7c43264f38
[TEST].3# add ElementAllocatedFromPool.01 for KVM & XenFV support
Signed-off-by: Guolian Yun <yunguol(a)cn.ibm.com>
diff -r 2977c29bb772 -r e12d888a9502
suites/libvirt-cim/cimtest/ElementAllocatedFromPool/01_forward.py
--- a/suites/libvirt-cim/cimtest/ElementAllocatedFromPool/01_forward.py Wed Apr 16
10:49:55 2008 +0800
+++ b/suites/libvirt-cim/cimtest/ElementAllocatedFromPool/01_forward.py Wed Apr 16
22:53:40 2008 -0700
@@ -21,56 +21,89 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# This tc is used to verify the classname, InstanceID are
-# appropriately set for a given of the domains when verified using the
+# This tc is used to verify the classname, InstanceID are
+# appropriately set for a given of the domains when verified using the
# Xen_ElementAllocatedFromPool asscoiation.
#
# Example command for LogicalDisk w.r.t to Xen_ElementAllocatedFromPool \
# asscoiation :
#
-# wbemcli ain -ac Xen_ElementAllocatedFromPool
+# wbemcli ain -ac Xen_ElementAllocatedFromPool
# 'http://localhost:5988/root/virt:
# Xen_LogicalDisk.CreationClassName="Xen_LogicalDisk",\
#
DeviceID="hd_domain/xvda",SystemCreationClassName="",SystemName="hd_domain"'
-#
+#
# Output:
# localhost:5988/root/virt:Xen_DiskPool.InstanceID="DiskPool/foo"
-#
+#
# Similarly we check for Memory,Network,Processor.
#
# Date : 26-11-2007
import sys
import pywbem
+import os
+from distutils.file_util import move_file
from XenKvmLib.test_xml import testxml, testxml_bridge
from VirtLib import utils
from XenKvmLib import assoc
-from XenKvmLib.test_doms import test_domain_function, destroy_and_undefine_all
+from XenKvmLib.test_doms import test_domain_function, destroy_and_undefine_all
from XenKvmLib import devices
+from XenKvmLib import vxml
+from XenKvmLib.classes import get_typed_class
from CimTest import Globals
from CimTest.Globals import do_main
from VirtLib.live import network_by_bridge
from CimTest.ReturnCodes import PASS, FAIL, SKIP
-sup_types = ['Xen']
+sup_types = ['Xen', 'XenFV', 'KVM']
test_dom = "hd_domain"
test_mac = "00:11:22:33:44:aa"
-test_vcpus = 1
-test_disk = 'xvda'
-
+test_vcpus = 1
+test_dpath = "foo"
+disk_file = '/tmp/diskpool.conf'
+back_disk_file = disk_file + "." + "01_forward"
+
+def conf_file():
+ """
+ Creating diskpool.conf file.
+ """
+ try:
+ f = open(disk_file, 'w')
+ f.write('%s %s' % (test_dpath, '/'))
+ f.close()
+ except Exception,detail:
+ Globals.logger.error("Exception: %s", detail)
+ status = SKIP
+ sys.exit(status)
+
+def clean_up_restore():
+ """
+ Restoring back the original diskpool.conf
+ file.
+ """
+ try:
+ if os.path.exists(back_disk_file):
+ os.remove(disk_file)
+ move_file(back_disk_file, disk_file)
+ except Exception, detail:
+ Globals.logger.error("Exception: %s", detail)
+ status = SKIP
+ sys.exit(status)
def print_error(cn, detail):
Globals.logger.error(Globals.CIM_ERROR_GETINSTANCE, cn)
Globals.logger.error("Exception: %s", detail)
-def get_keys(cn, device_id):
+def get_keys(cn, device_id, virt='Xen'):
id = "%s/%s" % (test_dom, device_id)
+ cs = get_typed_class(virt, "ComputerSystem")
key_list = { 'DeviceID' : id,
'CreationClassName' : cn,
'SystemName' : test_dom,
- 'SystemCreationClassName' : "Xen_ComputerSystem"
+ 'SystemCreationClassName' : cs
}
return key_list
@@ -85,93 +118,104 @@ def main():
destroy_and_undefine_all(options.ip)
Globals.log_param()
- test_xml, bridge = testxml_bridge(test_dom, vcpus = test_vcpus, \
- mac = test_mac, disk = test_disk, \
- server = options.ip)
+ os.system("rm -f %s" % back_disk_file )
+ if not (os.path.exists(disk_file)):
+ conf_file()
+ else:
+ move_file(disk_file, back_disk_file)
+ conf_file()
+
+ if options.virt == 'Xen':
+ test_disk = 'xvda'
+ else:
+ test_disk = 'hda'
+
+ virt_xml = vxml.get_class(options.virt)
+ cxml = virt_xml(test_dom, vcpus = test_vcpus, mac = test_mac, disk = test_disk)
+ bridge = cxml.set_vbridge(options.ip)
+
if bridge == None:
Globals.logger.error("Unable to find virtual bridge")
- return SKIP
-
- if test_xml == None:
- Globals.logger.error("Guest xml not created properly")
- return FAIL
-
- virt_network = network_by_bridge(bridge, options.ip)
+ return SKIP
+
+ virt_network = network_by_bridge(bridge, options.ip, options.virt)
if virt_network == None:
Globals.logger.error("No virtual network found for bridge %s", bridge)
- return SKIP
-
- ret = test_domain_function(test_xml, options.ip, cmd = "create")
+ return SKIP
+
+ ret = cxml.define(options.ip)
if not ret:
- Globals.logger.error("Failed to Create the dom: %s", test_dom)
- return FAIL
-
- try:
- cn = "Xen_LogicalDisk"
- key_list = get_keys(cn, test_disk)
- disk = devices.Xen_LogicalDisk(options.ip, key_list)
- except Exception,detail:
- print_error(cn, detail)
- return FAIL
-
- try:
- cn = "Xen_Memory"
- key_list = get_keys(cn, "mem")
- mem = devices.Xen_Memory(options.ip, key_list)
- except Exception,detail:
- print_error(cn, detail)
- return FAIL
-
- try:
- cn = "Xen_NetworkPort"
- key_list = get_keys(cn, test_mac)
- net = devices.Xen_NetworkPort(options.ip, key_list)
- except Exception,detail:
- print_error(cn, detail)
- return FAIL
-
- try:
- cn = "Xen_Processor"
- key_list = get_keys(cn, "0")
- proc = devices.Xen_Processor(options.ip, key_list)
+ Globals.logger.error('Unable to create domain %s' % test_dom)
+ return FAIL
+
+ disk_cn = get_typed_class(options.virt, "LogicalDisk")
+ mem_cn = get_typed_class(options.virt, "Memory")
+ net_cn = get_typed_class(options.virt, "NetworkPort")
+ proc_cn = get_typed_class(options.virt, "Processor")
+
+ try:
+ key_list = get_keys(disk_cn, test_disk, options.virt)
+ disk = eval('devices.' + disk_cn)(options.ip, key_list)
+ except Exception,detail:
+ print_error(cn, detail)
+ return FAIL
+
+ try:
+ key_list = get_keys(mem_cn, "mem", options.virt)
+ mem = eval('devices.' + mem_cn)(options.ip, key_list)
+ except Exception,detail:
+ print_error(cn, detail)
+ return FAIL
+
+ try:
+ key_list = get_keys(net_cn, test_mac, options.virt)
+ net = eval('devices.' + net_cn)(options.ip, key_list)
+ except Exception,detail:
+ print_error(cn, detail)
+ return FAIL
+
+ try:
+ key_list = get_keys(proc_cn, "0", options.virt)
+ proc = eval('devices.' + proc_cn)(options.ip, key_list)
except Exception,detail:
print_error(cn, detail)
return FAIL
netpool_id = "NetworkPool/%s" % virt_network
-
+ diskpool_id = "DiskPool/%s" % test_dpath
lelist = {
- "Xen_LogicalDisk" : disk.DeviceID, \
- "Xen_Memory" : mem.DeviceID, \
- "Xen_NetworkPort" : net.DeviceID, \
- "Xen_Processor" : proc.DeviceID
+ disk_cn : disk.DeviceID, \
+ mem_cn : mem.DeviceID, \
+ net_cn : net.DeviceID, \
+ proc_cn : proc.DeviceID
}
- poollist = [
- "Xen_DiskPool", \
- "Xen_MemoryPool", \
- "Xen_NetworkPool", \
- "Xen_ProcessorPool"
+ poollist = [
+ get_typed_class(options.virt, "DiskPool"), \
+ get_typed_class(options.virt, "MemoryPool"), \
+ get_typed_class(options.virt, "NetworkPool"), \
+ get_typed_class(options.virt, "ProcessorPool")
]
- poolval = [
- "DiskPool/foo", \
+ poolval = [
+ diskpool_id, \
"MemoryPool/0", \
netpool_id, \
"ProcessorPool/0"
]
- sccn = "Xen_ComputerSystem"
+ sccn = get_typed_class(options.virt, "ComputerSystem")
for cn, devid in sorted(lelist.items()):
try:
assoc_info = assoc.Associators(options.ip, \
- "Xen_ElementAllocatedFromPool",
+ "ElementAllocatedFromPool",
cn,
+ options.virt,
DeviceID = devid,
CreationClassName = cn,
SystemName = test_dom,
SystemCreationClassName = sccn)
if len(assoc_info) != 1:
- Globals.logger.error("Xen_ElementAllocatedFromPool returned %i\
- ResourcePool objects for domain '%s'", len(assoc_info), test_dom)
+ Globals.logger.error("ElementAllocatedFromPool returned %i
ResourcePool \
+ objects for domain '%s'",
len(assoc_info), test_dom)
status = FAIL
break
@@ -181,8 +225,8 @@ def main():
assoc_info[0].classname, \
poollist[idx])
status = FAIL
-
- if assoc_info[0]['InstanceID'] != poolval[idx]:
+
+ if assoc_info[0]['InstanceID'] != poolval[idx]:
Globals.logger.error("InstanceID Mismatch")
Globals.logger.error("Returned %s instead of %s", \
assoc_info[0]['InstanceID'], \
@@ -196,13 +240,15 @@ def main():
except Exception, detail:
Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, \
- 'Xen_ElementAllocatedFromPool')
+ 'ElementAllocatedFromPool')
Globals.logger.error("Exception: %s", detail)
status = FAIL
- ret = test_domain_function(test_dom, options.ip, \
- cmd = "destroy")
+ cxml.destroy(options.ip)
+ cxml.undefine(options.ip)
+ clean_up_restore()
+
return status
-
+
if __name__ == "__main__":
sys.exit(main())