[Libvirt-cim] [PATCH] [TEST] #2 Add tc to verify VSMS.RemoveResourceSettings() with correct resource

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Mar 16 20:50:27 UTC 2009


yunguol at cn.ibm.com wrote:
> # HG changeset patch
> # User Guolian Yun <yunguol at cn.ibm.com>
> # Date 1237196093 25200
> # Node ID dd3b676d57e5e719213e4587743c0b0c06194160
> # Parent  b1e05c9de638909c5c6a7ba86aa2b3551802d013
> [TEST] #2 Add tc to verify VSMS.RemoveResourceSettings() with correct resource
> 
> 
> Updates from 1 to 2:
> Get RASD instances by SystemDevice and SettingsDefineState associaton
> 
> Tested for KVM with current sources and rpm
> Signed-off-by: Guolian Yun<yunguol at cn.ibm.com>
> 
> diff -r b1e05c9de638 -r dd3b676d57e5 suites/libvirt-cim/cimtest/VirtualSystemManagementService/16_removeresource.py
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/16_removeresource.py	Mon Mar 16 02:34:53 2009 -0700
> @@ -0,0 +1,108 @@
> +#!/usr/bin/python
> +#
> +# Copyright 2009 IBM Corp.
> +#
> +# Authors:
> +#    Guolian Yun <yunguol at 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
> +from XenKvmLib.vsms import get_vsms_class
> +from XenKvmLib.vxml import get_class
> +from XenKvmLib.classes import get_typed_class
> +from XenKvmLib.assoc import AssociatorNames
> +from CimTest.Globals import logger
> +from XenKvmLib.const import do_main, get_provider_version
> +from CimTest.ReturnCodes import FAIL, PASS, SKIP
> +
> +sup_types = ['Xen', 'KVM', 'XenFV']
> +default_dom = 'domain'
> +rem_res_err_rev_start = 779
> +rem_res_err_rev_end = 828
> +nmac = '00:11:22:33:44:55'
> +
> + at do_main(sup_types)
> +def main():
> +    options = main.options
> +
> +    if options.virt == 'KVM':
> +        nddev = 'hdb'
> +    else:
> +        nddev = 'xvdb'
> +
> +    cxml = get_class(options.virt)(default_dom, disk=nddev, mac=nmac)
> +    ret = cxml.cim_define(options.ip)
> +    if not ret:
> +        logger.error("Failed to define the dom: %s", default_dom)
> +        return FAIL
> +   
> +    try:
> +        # Get system devices through SystemDevice assocation
> +        sd_classname = get_typed_class(options.virt, 'SystemDevice')
> +        cs_classname = get_typed_class(options.virt, 'ComputerSystem')
> +
> +        devs = AssociatorNames(options.ip, sd_classname, cs_classname,
> +                               Name=default_dom, CreationClassName=cs_classname)
> +        
> +        if len(devs) == 0:
> +            raise Exception("No devices returned")
> +
> +        # Get RASD instances through SettingsDefineState
> +        sds_classname = get_typed_class(options.virt, 'SettingsDefineState')
> +        mem = get_typed_class(options.virt, 'Memory')
> +        proc = get_typed_class(options.virt, 'Processor')
> +        input = get_typed_class(options.virt, 'PointingDevice')
> +        dev_not_rem = [mem, proc, input] 
> +                
> +        for dev in devs:
> +            if dev['CreationClassName'] not in dev_not_rem:

A cleaner way would be:

if dev['CreationClassName'] in dev_not_rem:
     continue

That way, the bulk of the for loop doesn't have to be underneath the if 
block.

> +                ccn = dev['CreationClassName']
> +                sccn = dev['SystemCreationClassName']
> +                rasd = AssociatorNames(options.ip, sds_classname, ccn,
> +                                       DeviceID = dev['DeviceID'],
> +                                       CreationClassName = ccn,
> +                                       SystemName = dev['SystemName'],
> +                                       SystemCreationClassName = sccn)
> +                if len(rasd) != 1:
> +                    raise Exception("%i RASD insts for %s", len(rasd), dev.DeviceID)
> +
> +             # Invoke RemoveResourceSettings() to remove resource
> +                service = get_vsms_class(options.virt)(options.ip)
> +                service.RemoveResourceSettings(ResourceSettings=[rasd[0]])

Capture the return of RemoveResourceSettings() and check for an error.

-- 
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list