# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1210085515 25200
# Node ID 23459a6df1bcf447f9903a0f49d5c782d6169bb9
# Parent 618967ffe41001ad705b2babfd972a0ab1aedaf8
[TEST] Updating 01_forward.py of SDC to support XenFV, KVM.
1) To make use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file().
2) To use the lib fn print_field_error.
3) To retain the PropertyPolicy, ValueRole, ValueRange depending on the revision no.
4) Tested on rpm based libvirt-cim KVM machine, latest libvirt-cim for KVM and Xen,
XenFV.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 618967ffe410 -r 23459a6df1bc
suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py
--- a/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py Tue May 06
07:41:45 2008 -0700
+++ b/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py Tue May 06
07:51:55 2008 -0700
@@ -55,135 +55,125 @@ import sys
import sys
import os
from distutils.file_util import move_file
-from VirtLib import utils
from XenKvmLib import assoc
from XenKvmLib import enumclass
-from CimTest import Globals
-from CimTest.Globals import do_main
from XenKvmLib.test_xml import netxml
from XenKvmLib.test_doms import create_vnet
from VirtLib.live import net_list
from CimTest.ReturnCodes import PASS, FAIL, SKIP
+from CimTest.Globals import do_main, platform_sup, logger, \
+CIM_ERROR_GETINSTANCE, CIM_ERROR_ASSOCIATORS
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.common_util import cleanup_restore, test_dpath, \
+create_diskpool_file
+from XenKvmLib.common_util import print_field_error
+from XenKvmLib.const import CIM_REV
-sup_types = ['Xen']
-
-status = PASS
-test_dpath = "foo"
-disk_file = '/tmp/diskpool.conf'
-back_disk_file = disk_file + "." + "SSDC_01_forward"
diskid = "%s/%s" % ("DiskPool", test_dpath)
memid = "%s/%s" % ("MemoryPool", 0)
procid = "%s/%s" % ("ProcessorPool", 0)
+libvirtcim_rev = 571
-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 get_or_bail(ip, id, pool_class):
+def get_or_bail(virt, ip, id, pool_class):
"""
Getinstance for the CLass and return instance on success, otherwise
exit after cleanup_restore .
"""
key_list = { 'InstanceID' : id }
-
+ status = PASS
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)
- clean_up_restore()
+ logger.error(CIM_ERROR_GETINSTANCE, '%s' % pool_class)
+ logger.error("Exception: %s", detail)
+ cleanup_restore()
status = FAIL
sys.exit(status)
return instance
-def init_list(disk, mem, net, proc):
+def init_list(virt, disk, mem, net, proc):
"""
Creating the lists that will be used for comparisons.
"""
instlist = [
- disk.InstanceID, \
- mem.InstanceID, \
- net.InstanceID, \
- proc.InstanceID
- ]
+ disk.InstanceID,
+ mem.InstanceID,
+ net.InstanceID,
+ proc.InstanceID
+ ]
cllist = [
- "Xen_DiskResourceAllocationSettingData", \
- "Xen_MemResourceAllocationSettingData", \
- "Xen_NetResourceAllocationSettingData", \
- "Xen_ProcResourceAllocationSettingData"
+ get_typed_class(virt, "DiskResourceAllocationSettingData"),
+ get_typed_class(virt, "MemResourceAllocationSettingData"),
+ get_typed_class(virt, "NetResourceAllocationSettingData"),
+ get_typed_class(virt, "ProcResourceAllocationSettingData")
]
rtype = {
- "Xen_DiskResourceAllocationSettingData" : 17, \
- "Xen_MemResourceAllocationSettingData" : 4, \
- "Xen_NetResourceAllocationSettingData" : 10, \
- "Xen_ProcResourceAllocationSettingData" : 3
+ get_typed_class(virt, "DiskResourceAllocationSettingData") : 17,
+ get_typed_class(virt, "MemResourceAllocationSettingData") : 4,
+ get_typed_class(virt, "NetResourceAllocationSettingData") : 10,
+ get_typed_class(virt, "ProcResourceAllocationSettingData") : 3
}
rangelist = {
- "Default" : 0, \
- "Minimum" : 1, \
- "Maximum" : 2, \
+ "Default" : 0,
+ "Minimum" : 1,
+ "Maximum" : 2,
"Increment" : 3
}
return instlist, cllist, rtype, rangelist
+def verify_rasd_fields(loop, assoc_info, cllist, rtype, rangelist):
+ for inst in assoc_info:
+ if inst.classname != cllist[loop]:
+ print_field_error("Classname", inst.classname, cllist[loop])
+ return FAIL
+ if inst['ResourceType'] != rtype[cllist[loop]]:
+ print_field_error("ResourceType", inst['ResourceType'],
+ rtype[cllist[loop]])
+ return FAIL
-def print_error(index, fieldname, assoc_info, exp_value):
- ret_value = assoc_info[index][fieldname]
- Globals.logger.error("%s Mismatch", fieldname)
- Globals.logger.error("Returned %s instead of %s", ret_value, exp_value)
+ # The following properties have been removed in the patchset 571
+ # but is present in the rpm libvirt-cim and hence retained it.
+ if CIM_REV < libvirtcim_rev:
+ ppolicy = inst['PropertyPolicy']
+ if ppolicy != 0 and ppolicy != 1:
+ print_field_error("PropertyPolicy",
inst['PropertyPolicy'], ppolicy)
+ return FAIL
+ vrole = inst['ValueRole']
+ if vrole < 0 or vrole > 4:
+ print_field_error("ValueRole", inst['ValueRole'],
vrole)
+ return FAIL
+ insid = inst['InstanceID']
+ vrange = rangelist[insid]
+ if vrange != inst['ValueRange']:
+ print_field_error("ValueRange", inst['ValueRange'],
vrange)
+ return FAIL
+ return PASS
-@do_main(sup_types)
+@do_main(platform_sup)
def main():
options = main.options
- global status
-
- cn = 'Xen_AllocationCapabilities'
+
+ cn = get_typed_class(options.virt, "AllocationCapabilities")
loop = 0
server = options.ip
+ virt = options.virt
- # Taking care of already existing diskconf file
- # Creating diskpool.conf if it does not exist
- # Otherwise backing up the prev file and create new one.
- 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()
+ # Verify DiskPool on machine
+ status = create_diskpool_file()
+ if status != PASS:
+ return status
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)
- vir_network = net_list(server)
+ disk_cn = eval("enumclass." + get_typed_class(options.virt,
+ "DiskPool"))
+ disk = get_or_bail(virt, server, id=diskid, pool_class=disk_cn)
+ mem_cn = eval("enumclass." + get_typed_class(options.virt,
+ "MemoryPool"))
+ mem = get_or_bail(virt, server, id = memid, pool_class=mem_cn)
+ vir_network = net_list(server, virt)
if len(vir_network) > 0:
test_network = vir_network[0]
else:
@@ -192,68 +182,46 @@ def main():
net_xml, bridge = netxml(server, bridgename, test_network)
ret = create_vnet(server, net_xml)
if not ret:
- Globals.logger.error("Failed to create the Virtual Network
'%s'", \
- test_network)
+ logger.error("Failed to create Virtual Network '%s'",
+ test_network)
return SKIP
netid = "%s/%s" % ("NetworkPool", test_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_cn = eval("enumclass." + get_typed_class(options.virt,
+ "NetworkPool"))
+ net = get_or_bail(virt, server, id = netid, pool_class=net_cn)
+ proc_cn = eval("enumclass." + get_typed_class(options.virt,
+ "ProcessorPool"))
+ proc = get_or_bail(virt, server, id = procid, pool_class=proc_cn)
except Exception, detail:
- Globals.logger.error("Exception: %s", detail)
- clean_up_restore()
+ logger.error("Exception: %s", detail)
+ cleanup_restore()
status = FAIL
return status
- instlist, cllist, rtype, rangelist = init_list(disk, mem, net, proc )
-
+ instlist, cllist, rtype, rangelist = init_list(virt, disk, mem, net, proc )
+ assoc_cname = get_typed_class(virt, "SettingsDefineCapabilities")
for instid in sorted(instlist):
try:
- assoc_info = assoc.Associators(options.ip, \
-
"Xen_SettingsDefineCapabilities",
- cn,
- InstanceID = instid)
+ assoc_info = assoc.Associators(options.ip, assoc_cname, cn,
+ InstanceID = instid, virt=virt)
if len(assoc_info) != 4:
- Globals.logger.error("Xen_SettingsDefineCapabilities returned \
-%i ResourcePool objects instead 4", len(assoc_info))
+ logger.error("%s returned %i ResourcePool objects"
+"instead 4", assoc_cname, len(assoc_info))
status = FAIL
break
- for i in range(len(assoc_info)):
- if assoc_info[i].classname != cllist[loop]:
- print_error(i, "Classname", assoc_info, cllist[loop])
- status = FAIL
- if assoc_info[i]['ResourceType'] != rtype[cllist[loop]]:
- print_error(i, "ResourceType", assoc_info,
rtype[cllist[loop]])
- status = FAIL
- ppolicy = assoc_info[i]['PropertyPolicy']
- if ppolicy != 0 and ppolicy != 1:
- print_error(i, "PropertyPolicy", assoc_info, ppolicy)
- status = FAIL
- vrole = assoc_info[i]['ValueRole']
- if vrole < 0 or vrole > 4:
- print_error(i, "ValueRole", assoc_info, vrole)
- status = FAIL
- insid = assoc_info[i]['InstanceID']
- vrange = rangelist[insid]
- if vrange != assoc_info[i]['ValueRange']:
- print_error(i, "ValueRange", assoc_info, vrange)
- status = FAIL
- if status != 0:
- break
- if status != 0:
+ status = verify_rasd_fields(loop, assoc_info, cllist, rtype, rangelist)
+ if status != PASS:
break
else:
loop = loop + 1
except Exception, detail:
- Globals.logger.error(Globals.CIM_ERROR_ASSOCIATORS, \
- 'Xen_SettingsDefineCapabilities')
- Globals.logger.error("Exception: %s", detail)
- clean_up_restore()
+ logger.error(CIM_ERROR_ASSOCIATORS, assoc_cname)
+ logger.error("Exception: %s", detail)
+ cleanup_restore()
status = FAIL
- clean_up_restore()
+ cleanup_restore()
return status
if __name__ == "__main__":