[PATCH] [TEST] Add new test to verify enum of DiskRASD to have EmulatedType=0 for Disk

# HG changeset patch # User Guolian Yun <yunguol@cn.ibm.com> # Date 1229504556 28800 # Node ID 8e1a1e349f21351c38f42d315adabc441cad366f # Parent 3bef4df8290571505d2c9028b6c82e0abc8b2e74 [TEST] Add new test to verify enum of DiskRASD to have EmulatedType=0 for Disk Signed-off-by: Guolian Yun <yunguol@cn.ibm.com> diff -r 3bef4df82905 -r 8e1a1e349f21 suites/libvirt-cim/cimtest/RASD/05_disk_rasd_emu_type.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/RASD/05_disk_rasd_emu_type.py Wed Dec 17 01:02:36 2008 -0800 @@ -0,0 +1,76 @@ +#!/usr/bin/python +# +# Copyright 2008 IBM Corp. +# +# Authors: +# Guolian Yun <yunguol@cn.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import sys +import pywbem +from VirtLib import utils +from XenKvmLib import enumclass +from XenKvmLib.classes import get_typed_class +from XenKvmLib.test_doms import undefine_test_domain +from XenKvmLib.common_util import create_using_definesystem +from XenKvmLib.const import do_main +from CimTest.ReturnCodes import PASS, FAIL +from CimTest.Globals import logger, CIM_ERROR_ENUMERATE +from XenKvmLib.const import get_provider_version + +SUPPORTED_TYPES = ['Xen', 'KVM', 'LXC'] +default_dom = 'test_domain' +libvirt_em_type_changeset = 737 + +@do_main(SUPPORTED_TYPES) +def main(): + options = main.options + curr_cim_rev, changeset = get_provider_version(options.virt, options.ip) + if curr_cim_rev >= libvirt_em_type_changeset: + status = create_using_definesystem(default_dom, options.ip, emu_type=0, + virt=options.virt) + + if status != PASS: + logger.error("Failed to call DefineSystem()") + return FAIL + + drasd= get_typed_class(options.virt, 'DiskResourceAllocationSettingData') + + try: + drasd_list = enumclass.EnumInstances(options.ip, drasd, ret_cim_inst=True) + if len(drasd_list) < 1: + logger.error("%s returned %i instances, excepted at least 1.", + drasd, len(drasd_list)) + return FAIL + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, drasd) + logger.error("Exception: %s", detail) + return FAIL + + if drasd_list[0]['EmulatedType'] != 0: + logger.error("%s Mismatch", 'EmulatedType') + return FAIL + + + undefine_test_domain(default_dom, options.ip, + virt=options.virt) + + return status + +if __name__ == "__main__": + sys.exit(main()) + diff -r 3bef4df82905 -r 8e1a1e349f21 suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Mon Dec 15 09:45:28 2008 -0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Wed Dec 17 01:02:36 2008 -0800 @@ -72,7 +72,7 @@ return (0, cs) def create_using_definesystem(domain_name, ip, params=None, ref_config=' ', - exp_err=None, virt='Xen'): + exp_err=None, emu_type=None, virt='Xen'): bug = "85673" try: class_vsms = eval('vsms.' + \ diff -r 3bef4df82905 -r 8e1a1e349f21 suites/libvirt-cim/lib/XenKvmLib/vsms.py --- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py Mon Dec 15 09:45:28 2008 -0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py Wed Dec 17 01:02:36 2008 -0800 @@ -126,8 +126,10 @@ # classes to define RASD parameters class CIM_DiskResourceAllocationSettingData(CIMClassMOF): - def __init__(self, dev, source, name): + def __init__(self, dev, source, name, emu_type=None): self.ResourceType = RASD_TYPE_DISK + if emu_type != None: + self.EmulatedType = emu_type if dev != None: self.VirtualDevice = dev self.InstanceID = '%s/%s' % (name, dev) @@ -141,10 +143,11 @@ pass class LXC_DiskResourceAllocationSettingData(CIMClassMOF): - def __init__(self, mountpoint, source, name): + def __init__(self, mountpoint, source, name, emu_type=None): self.MountPoint = mountpoint self.Address = source self.InstanceID = '%s/%s' % (name, mountpoint) + self.EmulatedType = emu_type @eval_cls('DiskResourceAllocationSettingData') def get_dasd_class(virt): @@ -239,6 +242,7 @@ proc_vcpu=1, mem_mb=512, malloc_units="MegaBytes", + emu_type = None, virt='Xen'): vssd = get_vssd_mof(virt, dom_name) @@ -252,7 +256,7 @@ elif virt == 'LXC': disk_dev = const.LXC_default_mp disk_source = const.LXC_default_source - d = class_dasd(disk_dev, disk_source, dom_name) + d = class_dasd(disk_dev, disk_source, dom_name, emu_type) class_masd = get_masd_class(virt) m = class_masd(

+SUPPORTED_TYPES = ['Xen', 'KVM', 'LXC'] +default_dom = 'test_domain' +libvirt_em_type_changeset = 737 + +@do_main(SUPPORTED_TYPES) +def main(): + options = main.options + curr_cim_rev, changeset = get_provider_version(options.virt, options.ip) + if curr_cim_rev >= libvirt_em_type_changeset:
Instead, you can do: if curr_cim_rev < libvirt_em_type_changeset: return SKIP This way, you don't have to indent the whole body of the test. Also, right now, the test returns a PASS if the rev is less than 737. It should return a SKIP since the test body isn't executed.
+ status = create_using_definesystem(default_dom, options.ip, emu_type=0, + virt=options.virt)
Instead of using create_using_definesystem(), use cim_define() - create_using_definesystem() really should be removed at some point as cim_define() is a better interface.
+ + if status != PASS: + logger.error("Failed to call DefineSystem()") + return FAIL + + drasd= get_typed_class(options.virt, 'DiskResourceAllocationSettingData') + + try: + drasd_list = enumclass.EnumInstances(options.ip, drasd, ret_cim_inst=True) + if len(drasd_list) < 1: + logger.error("%s returned %i instances, excepted at least 1.", + drasd, len(drasd_list))
If you do an enum here, you can't be sure the first RASD in the list is the RASD that corresponds to the guest (because there might be more than one guest defined on the system). You'll need to loop through the RASD list and find the corresponding RASD. You can use the parse_instance_id() to extract the guest name for the RASD InstanceID.. If you don't find the corresponding RASD, return an error
+ return FAIL + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, drasd) + logger.error("Exception: %s", detail) + return FAIL +
You could use exp_emu_type = 0
+ if drasd_list[0]['EmulatedType'] != 0: + logger.error("%s Mismatch", 'EmulatedType')
Instead, you can format this as "EmulatedType Mismatch" since its a static string. However, the following would be more descriptive: logger.error("EmulatedType Mismatch: got %d, expected %d",drasd_list[0]['EmulatedType'], exp_emu_type)
+ return FAIL + + + undefine_test_domain(default_dom, options.ip, + virt=options.virt) + + return status +
You can test both EmulationType = 0 and EmulationType = 1 in the same test. Have the main body of the test be a loop, something like the following: emu_types = [0, 1] for exp_emu_type in emu_types: #Define guest with exp_emu_type set #Enum DiskRASDs and find the instance that corresponds to the guest #Verify the EmulationType equals the exp_emu_type #Undefine the guest -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
yunguol@cn.ibm.com