[Libvirt-cim] [PATCH] [TEST] Verify creation of a guest with a floppy device

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Thu Jan 28 07:43:34 UTC 2010



Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1264633475 28800
> # Node ID f89fab2298c8f47552437b6d75b5ac57b6ba1cf1
> # Parent  b863f339b41bab9569c8306b804377a99bd3b199
> [TEST] Verify creation of a guest with a floppy device
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r b863f339b41b -r f89fab2298c8 suites/libvirt-cim/cimtest/VirtualSystemManagementService/25_definesystem_floppy.py
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/25_definesystem_floppy.py	Wed Jan 27 15:04:35 2010 -0800
> @@ -0,0 +1,153 @@
> +#!/usr/bin/python
> +#
> +# Copyright 2010 IBM Corp.
> +#
> +# Authors:
> +#    Kaitlin Rupert <karupert at us.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
> +#    
> +# Purpose:
> +#   Verify providers support floppy devices 
> +#
> +# Steps:
> +#  1) Create a with a regular disk device and a floppy device
>   
Very small typo .. guest is missing.. :-)
> +#  2) Build RASD parameters, making sure to specify floppy device 
> +#  3) Verify guest is defined properly
> +#
> +
> +import sys
> +from CimTest.Globals import logger
> +from CimTest.ReturnCodes import FAIL, PASS, SKIP
> +from XenKvmLib.classes import get_typed_class, inst_to_mof
> +from XenKvmLib.rasd import get_rasd_templates 
> +from XenKvmLib.const import do_main, get_provider_version, \
> +                            KVM_secondary_disk_path, default_pool_name
> +from XenKvmLib.vxml import get_class
> +from XenKvmLib.vsms import VIRT_DISK_TYPE_FLOPPY
> +from XenKvmLib.common_util import parse_instance_id
> +from XenKvmLib.enumclass import EnumInstances
> +
> +sup_types = ['Xen', 'XenFV', 'KVM']
> +test_dom = 'rstest_floppy'
> +
> +floppy_rev = 1023 
> +
> +def get_rasd_list(ip, virt, addr):
> +    drasd_cn = get_typed_class(virt, "DiskResourceAllocationSettingData")
> +    pool_id = "DiskPool/%s" % default_pool_name
> +
> +    rasds = get_rasd_templates(ip, virt, pool_id)
> +    if len(rasds) < 1:
> +        logger.info("No RASD templates returned for %s", pool_id)
> +        return [] 
> +
> +    rasd_list = {} 
> +
> +    for rasd in rasds:
> +        if rasd.classname != drasd_cn:
> +            continue
> +
> +        if rasd['EmulatedType'] == VIRT_DISK_TYPE_FLOPPY and \
> +           rasd['InstanceID'].find("Default") >= 0:
>   
You could use "Default" in rasd['InstanceID']. That looks much simpler 
to understand.
> +
> +            rasd['Address'] = addr
> +            rasd_list[rasd.classname] = inst_to_mof(rasd)
> +
> +    return rasd_list 
> +
> +def verify_floppy_disk(ip, virt, addr, guest_name):
> +    inst = None
> +
> +    try:
> +        drasd_cn = get_typed_class(virt, 'DiskResourceAllocationSettingData')
> +        enum_list = EnumInstances(ip, drasd_cn)
> +
> +        if enum_list < 1:
> +            raise Exception("No %s instances returned" % drasd_cn)
> +
> +        for rasd in enum_list:
> +            guest, dev, status = parse_instance_id(rasd.InstanceID)
> +            if status != PASS:
> +                raise Exception("Unable to parse InstanceID: %s" % \
> +                                rasd.InstanceID)
> +
> +            if guest == guest_name:
> +                inst = rasd 
> +                break
> +
> +        if inst is None:
> +            raise Exception("%s instance for %s not found" % (drasd_cn, 
> +                            guest_name))
> +
> +        if inst.Address != addr:
> +            raise Exception("%s instance for %s not found" % (drasd_cn, 
> +                            guest_name))
>   
You can combine both the if statements into one as the log message 
remains same.
Or if you want you can make the log messages specific to the error type.
> +
> +        if inst.EmulatedType != VIRT_DISK_TYPE_FLOPPY:
> +            raise Exception("Expected device to be of %d type" % \
> +                            (VIRT_DISK_TYPE_FLOPPY))
> +
> +    except Exception, details:
> +        logger.error(details)
> +        return FAIL
> +
> +    return PASS 
> +
> + at do_main(sup_types)
> +def main():
> +    options = main.options
> +
> +    status = FAIL
> +
> +    curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
> +    if curr_cim_rev < floppy_rev:
> +        logger.error("Floppy support is available in rev >= %s", floppy_rev)
> +        return SKIP
> +
> +    cxml = get_class(options.virt)(test_dom)
> +
> +    addr = KVM_secondary_disk_path
> +
> +    guest_defined = False
> +
> +    try:
> +        rasd_list = get_rasd_list(options.ip, options.virt, addr)
> +        if len(rasd_list) < 1:
> +            raise Exception("Unable to get template RASDs for %s" % test_dom)
> +
> +        cxml.set_res_settings(rasd_list)
> +        ret = cxml.cim_define(options.ip)
> +        if not ret:
> +            raise Exception("Unable to define %s" % test_dom)
> +
> +        guest_defined = True 
> +
> +        status = verify_floppy_disk(options.ip, options.virt, addr, test_dom)
> +        if status != PASS:
> +            raise Exception("Failed to verify disk path for %s" % test_dom)
> +
> +    except Exception, details:
> +        logger.error(details)
> +        status = FAIL
> +
> +    if guest_defined == True: 
> +        cxml.undefine(options.ip)
> +
> +    return status 
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> +    
> diff -r b863f339b41b -r f89fab2298c8 suites/libvirt-cim/lib/XenKvmLib/vsms.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Fri Dec 11 16:12:01 2009 -0800
> +++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Wed Jan 27 15:04:35 2010 -0800
> @@ -37,6 +37,10 @@
>  RASD_TYPE_INPUT = 13
>  RASD_TYPE_STOREVOL = 32768
>
> +VIRT_DISK_TYPE_DISK = 0
> +VIRT_DISK_TYPE_CDROM = 1
> +VIRT_DISK_TYPE_FLOPPY = 2
> +
>  VSSD_RECOVERY_NONE     = 2
>  VSSD_RECOVERY_RESTART  = 3
>  VSSD_RECOVERY_PRESERVE = 123
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>   

-- 
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list