[PATCH] [TEST]updating 01_forward.py to use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file()

# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1208960938 -19800 # Node ID 25d9015078055a6f6f3a6975fd3c48c4c0efef24 # Parent 413ef6a636d51ab12f16588268c8debe4d952f05 [TEST]updating 01_forward.py to use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file() Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r 413ef6a636d5 -r 25d901507805 suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py --- a/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py Wed Apr 23 19:56:59 2008 +0530 +++ b/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py Wed Apr 23 19:58:58 2008 +0530 @@ -55,135 +55,124 @@ 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 -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) -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 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) +def print_error(fieldname, ret_value, exp_value): + logger.error("%s Mismatch", fieldname) + logger.error("Returned %s instead of %s", ret_value, exp_value) -@do_main(sup_types) +def verify_rasd_fields(loop, assoc_info, cllist, rtype, rangelist): + for inst in assoc_info: + if inst.classname != cllist[loop]: + print_error("Classname", inst.classname, cllist[loop]) + return FAIL + if inst['ResourceType'] != rtype[cllist[loop]]: + print_error("ResourceType", inst['ResourceType'], + rtype[cllist[loop]]) + return FAIL + ppolicy = inst['PropertyPolicy'] + if ppolicy != 0 and ppolicy != 1: + print_error("PropertyPolicy", inst['PropertyPolicy'], ppolicy) + return FAIL + vrole = inst['ValueRole'] + if vrole < 0 or vrole > 4: + print_error("ValueRole", inst['ValueRole'], vrole) + return FAIL + insid = inst['InstanceID'] + vrange = rangelist[insid] + if vrange != inst['ValueRange']: + print_error("ValueRange", inst['ValueRange'], vrange) + return FAIL + return PASS + + +@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 +181,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__":

Deepti B. Kalakeri wrote:
# HG changeset patch # User Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> # Date 1208960938 -19800 # Node ID 25d9015078055a6f6f3a6975fd3c48c4c0efef24 # Parent 413ef6a636d51ab12f16588268c8debe4d952f05 [TEST]updating 01_forward.py to use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file()
Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com>
diff -r 413ef6a636d5 -r 25d901507805 suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py
Can you split this into two patches? The commit log says that it's modifying the diskpool conf files, but the patch also converts this to a KVM test. This fails for me on KVM with updated sources and libvirt-0.4.2. In order for it to work with such environment, we'll need to have storage pool support in place.
-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) +def print_error(fieldname, ret_value, exp_value): + logger.error("%s Mismatch", fieldname) + logger.error("Returned %s instead of %s", ret_value, exp_value)
You can use the library function instead. There's also some strange indenting in this patch. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B. Kalakeri
-
Kaitlin Rupert