# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1208329893 25200
# Node ID 2309180af71056a15fd1f14914586b29593a99c7
# Parent ac6d65d178a0deec57611e6b0175deac7a7a28cc
[TEST] add ElementAllocatedFromPool.02 for KVM & XenFV support
Signed-off-by: Guolian Yun <yunguol(a)cn.ibm.com>
diff -r ac6d65d178a0 -r 2309180af710
suites/libvirt-cim/cimtest/ElementAllocatedFromPool/02_reverse.py
--- a/suites/libvirt-cim/cimtest/ElementAllocatedFromPool/02_reverse.py Wed Apr 16
00:08:32 2008 -0700
+++ b/suites/libvirt-cim/cimtest/ElementAllocatedFromPool/02_reverse.py Wed Apr 16
00:11:33 2008 -0700
@@ -4,6 +4,7 @@
#
# Authors:
# Deepti B. Kalakeri <dkalaker(a)in.ibm.com>
+# Guolian Yun <yunguol(a)cn.ibm.com>
# Kaitlin Rupert <karupert(a)us.ibm.com>
#
# This library is free software; you can redistribute it and/or
@@ -53,6 +54,8 @@ from VirtLib import live
from VirtLib import live
from XenKvmLib import assoc
from XenKvmLib import enumclass
+from XenKvmLib import vxml
+from XenKvmLib.classes import get_typed_class
from CimTest import Globals
from CimTest.Globals import do_main
from CimTest.ReturnCodes import PASS, FAIL, SKIP
@@ -60,14 +63,13 @@ from XenKvmLib.test_doms import test_dom
from XenKvmLib.test_doms import test_domain_function, destroy_and_undefine_all
from VirtLib.live import network_by_bridge
-sup_types = ['Xen']
+sup_types = ['Xen', 'XenFV', 'KVM']
status = PASS
test_dom = "hd_domain"
test_mac = "00:11:22:33:44:aa"
test_mem = 128
test_vcpus = 4
-test_disk = "xvdb"
test_dpath = "foo"
disk_file = '/tmp/diskpool.conf'
back_disk_file = disk_file + "." + "02_reverse"
@@ -105,14 +107,14 @@ def clean_up_restore(ip):
sys.exit(status)
-def get_or_bail(ip, id, pool_class):
+def get_or_bail(ip, id, pool_class, virt="Xen"):
"""
Getinstance for the CLass and return instance on success, otherwise
exit after cleanup_restore and destroying the guest.
"""
key_list = { 'InstanceID' : id }
try:
- instance = enumclass.getInstance(ip, pool_class, key_list)
+ instance = enumclass.getInstance(ip, pool_class, key_list, virt)
except Exception, detail:
Globals.logger.error(Globals.CIM_ERROR_GETINSTANCE, '%s', pool_class)
Globals.logger.error("Exception: %s", detail)
@@ -127,22 +129,22 @@ def print_error(field, ret_val, req_val)
Globals.logger.error("%s Mismatch", field)
Globals.logger.error("Returned %s instead of %s", ret_val, req_val)
-def init_list(ip, disk, mem, net, proc):
+def init_list(ip, disk, mem, net, proc, virt="Xen"):
"""
Creating the lists that will be used for comparisons.
"""
pllist = {
- "Xen_DiskPool" : disk.InstanceID, \
- "Xen_MemoryPool" : mem.InstanceID, \
- "Xen_NetworkPool" : net.InstanceID, \
- "Xen_ProcessorPool": proc.InstanceID
+ get_typed_class(virt, "DiskPool") : disk.InstanceID, \
+ get_typed_class(virt, "MemoryPool") : mem.InstanceID, \
+ get_typed_class(virt, "NetworkPool") : net.InstanceID, \
+ get_typed_class(virt, "ProcessorPool"): proc.InstanceID
}
cllist = [
- "Xen_LogicalDisk", \
- "Xen_Memory", \
- "Xen_NetworkPort", \
- "Xen_Processor"
+ get_typed_class(virt, "LogicalDisk"), \
+ get_typed_class(virt, "Memory"), \
+ get_typed_class(virt, "NetworkPort"), \
+ get_typed_class(virt, "Processor")
]
prop_list = ["%s/%s" % (test_dom, test_disk), test_disk, \
"%s/%s" % (test_dom, "mem"), test_mem, \
@@ -162,7 +164,7 @@ def get_inst_for_dom(assoc_val):
return list
-def get_spec_fields_list(inst_list, field_name):
+def get_spec_fields_list(inst_list, field_name, virt="Xen"):
global status
specific_fields = { }
if (len(inst_list)) != 1:
@@ -172,7 +174,7 @@ 1", len(inst_list))
return
# verifying the Name field for LogicalDisk
try:
- if inst_list[0]['CreationClassName'] != 'Xen_Memory':
+ if inst_list[0]['CreationClassName'] != get_typed_class(virt,
'Memory'):
field_value = inst_list[0][field_name]
if field_name == 'NetworkAddresses':
# For network we NetworkAddresses is a list of addresses, since we
@@ -190,7 +192,7 @@ 1", len(inst_list))
return specific_fields
-def assoc_values(assoc_list, field , list, index, specific_fields_list=""):
+def assoc_values(assoc_list, field , list, index, specific_fields_list="",
virt="Xen"):
"""
Verifying the records retruned by the associations.
"""
@@ -203,7 +205,7 @@ def assoc_values(assoc_list, field , li
if status != PASS:
break
elif field == "DeviceID":
- if assoc_list[0]['CreationClassName'] == 'Xen_Processor':
+ if assoc_list[0]['CreationClassName'] == get_typed_class(virt,
'Processor'):
# Verifying the list of DeviceId returned by the association
# against the list created intially .
for i in range(len(list)):
@@ -218,7 +220,7 @@ def assoc_values(assoc_list, field , li
status = FAIL
else:
# other specific fields verification
- if assoc_list[0]['CreationClassName'] != 'Xen_Processor':
+ if assoc_list[0]['CreationClassName'] != get_typed_class(virt,
'Processor'):
spec_field_name = specific_fields_list['field_name']
spec_field_value = specific_fields_list['field_value']
if spec_field_value != list[index]:
@@ -235,24 +237,28 @@ def main():
server = options.ip
destroy_and_undefine_all(options.ip)
Globals.log_param()
- test_xml, bridge = testxml_bridge(test_dom, mem = test_mem, vcpus = test_vcpus, \
- mac = test_mac, disk = test_disk, server = options.ip)
+ global test_disk
+ 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 was not created properly")
- return FAIL
-
- virt_network = network_by_bridge(bridge, server)
+ 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, server, cmd = "create")
+ ret = cxml.create(options.ip)
if not ret:
- Globals.logger.error("Failed to Create the dom: %s", test_dom)
+ logger.error('Unable to create domain %s' % test_dom)
return FAIL
# Taking care of already existing diskconf file
@@ -264,16 +270,17 @@ def main():
else:
move_file(disk_file, back_disk_file)
conf_file()
+
+ diskpool = eval('enumclass.' + get_typed_class(options.virt,
"DiskPool"))
+ mempool = eval('enumclass.' + get_typed_class(options.virt,
"MemoryPool"))
+ netpool = eval('enumclass.' + get_typed_class(options.virt,
"NetworkPool"))
+ procpool = eval('enumclass.' + get_typed_class(options.virt,
"ProcessorPool"))
try :
- disk = get_or_bail(server, id=diskid, \
- pool_class=enumclass.Xen_DiskPool)
- mem = get_or_bail(server, id = memid, \
- pool_class=enumclass.Xen_MemoryPool)
+ disk = get_or_bail(server, id = diskid, pool_class = diskpool,
virt=options.virt)
+ mem = get_or_bail(server, id = memid, pool_class = mempool, virt=options.virt)
netid = "%s/%s" % ("NetworkPool", virt_network)
- net = get_or_bail(server, id = netid, \
- pool_class=enumclass.Xen_NetworkPool)
- proc = get_or_bail(server, id = procid, \
- pool_class=enumclass.Xen_ProcessorPool)
+ net = get_or_bail(server, id = netid, pool_class = netpool, virt=options.virt)
+ proc = get_or_bail(server, id = procid, pool_class = procpool, virt=options.virt)
except Exception, detail:
Globals.logger.error("Exception: %s", detail)
@@ -283,15 +290,16 @@ def main():
cmd = "destroy")
return status
- pllist, cllist, prop_list, proc_prop = init_list(server, disk, mem, net, proc)
+ pllist, cllist, prop_list, proc_prop = init_list(server, disk, mem, net, proc,
options.virt)
# Looping through the pllist to get association for various pools.
for cn, instid in sorted(pllist.items()):
try:
- assoc_info = assoc.Associators(server, \
- "Xen_ElementAllocatedFromPool",
\
- cn, \
- InstanceID = instid)
+ assoc_info = assoc.Associators(server,
+ "ElementAllocatedFromPool",
+ cn,
+ options.virt,
+ InstanceID = instid)
# Verifying the Creation Class name for all the records returned for each
# pool class queried
inst_list = get_inst_for_dom(assoc_info)
@@ -301,43 +309,47 @@ the specified domain: %s", test_dom)
status = FAIL
break
- assoc_values(assoc_list=inst_list, field="CreationClassName", \
- list=cllist, \
- index=loop)
+ assoc_values(assoc_list=inst_list, field="CreationClassName", list=cllist,
\
+ index=loop, virt=options.virt)
# verifying the DeviceID
- if inst_list[0]['CreationClassName'] == 'Xen_Processor':
+ if inst_list[0]['CreationClassName'] == get_typed_class(options.virt,
'Processor'):
# The DeviceID for the processor varies from 0 to (vcpu - 1 )
list_index = 0
assoc_values(assoc_list=inst_list, field="DeviceID", \
list=proc_prop, \
- index=list_index)
+ index=list_index, \
+ virt=options.virt)
else:
# For LogicalDisk, Memory and NetworkPort
- if inst_list[0]['CreationClassName'] ==
'Xen_LogicalDisk':
+ if inst_list[0]['CreationClassName'] ==
get_typed_class(options.virt, 'LogicalDisk'):
list_index = 0
- elif inst_list[0]['CreationClassName'] == 'Xen_Memory':
+ elif inst_list[0]['CreationClassName'] ==
get_typed_class(options.virt, 'Memory'):
list_index = 2
else:
list_index = 4 # NetworkPort
assoc_values(assoc_list=inst_list, field="DeviceID", \
list=prop_list, \
- index=list_index)
- if inst_list[0]['CreationClassName'] ==
'Xen_LogicalDisk':
+ index=list_index, \
+ virt=options.virt)
+ if inst_list[0]['CreationClassName'] ==
get_typed_class(options.virt, 'LogicalDisk'):
# verifying the Name field for LogicalDisk
- specific_fields =
get_spec_fields_list(inst_list,field_name="Name")
+ specific_fields =
get_spec_fields_list(inst_list,field_name="Name", virt=options.virt)
list_index = 1
- elif inst_list[0]['CreationClassName'] == 'Xen_Memory':
+ elif inst_list[0]['CreationClassName'] ==
get_typed_class(options.virt, 'Memory'):
# verifying the NumberOfBlocks allocated for Memory
- specific_fields =
get_spec_fields_list(inst_list,field_name="NumberOfBlocks")
+ specific_fields =
get_spec_fields_list(inst_list,field_name="NumberOfBlocks", \
+ virt=options.virt)
list_index = 3
else:
# verifying the NetworkAddresses for the NetworkPort
- specific_fields =
get_spec_fields_list(inst_list,field_name="NetworkAddresses")
+ specific_fields =
get_spec_fields_list(inst_list,field_name="NetworkAddresses", \
+ virt=options.virt)
list_index = 5 # NetworkPort
assoc_values(assoc_list=inst_list, field="Other", \
list=prop_list, \
index=list_index, \
- specific_fields_list=specific_fields)
+ specific_fields_list=specific_fields, \
+ virt=options.virt)
if status != PASS:
break
else:
@@ -350,8 +362,9 @@ the specified domain: %s", test_dom)
clean_up_restore(server)
status = FAIL
- ret = test_domain_function(test_dom, server, \
- cmd = "destroy")
+ cxml.destroy(options.ip)
+ cxml.undefine(options.ip)
+
clean_up_restore(server)
return status
if __name__ == "__main__":