[Libvirt-cim] [PATCH] [Test](#2)Testcase to check for duplicate UUID

Deepti B Kalakeri deeptik at linux.vnet.ibm.com
Mon Aug 17 08:18:04 UTC 2009



Yogananth Subramanian wrote:
> # HG changeset patch
> # User anantyog at in.ibm.com
> # Date 1250252541 25200
> # Node ID 9169e2a0e51a841e35ab75ad7072c3924ed2cf91
> # Parent  85a07c7dadb889ffeb0e38ba7de31cd42dcfcc79
> [Test](#2)Testcase to check for duplicate UUID
>
> ModifySystemSetting does thrw an error for duplicate UUID, as  Deepti Kalakeri,
> had indicated. I have updated my providers and redesigned the test accourdingly.
> Have also removed bug 00016 from 'know provider issues' wiki page.
>
> Signed-off-by: Yogananth Subramanian <anantyog at linux.vnet.ibm.com>
>
> diff -r 85a07c7dadb8 -r 9169e2a0e51a suites/libvirt-cim/cimtest/VSSD/06_dupicate_uuid.py
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/suites/libvirt-cim/cimtest/VSSD/06_dupicate_uuid.py	Fri Aug 14 05:22:21 2009 -0700
> @@ -0,0 +1,115 @@
> +#!/usr/bin/python
> +#
> +# Copyright 2009 IBM Corp.
> +#
> +# Authors:
> +#    Yogananth Subramanian <anantyog at linux.vnet.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
> +#
> +#Steps:
> +#1) Define 2 domains,'default' and 'test', both with random UUID
> +#2) Reset the uuid of the second domain, 'test', to the uuid of the
> +#   first domain, using ModifySystemSettings
> +#
> +
> +import sys
> +import time
> +from XenKvmLib import vsms
> +from XenKvmLib import vxml
> +from CimTest.Globals import logger
> +from CimTest.ReturnCodes import PASS, FAIL
> +from XenKvmLib.const import do_main
> +from XenKvmLib.classes import get_typed_class, inst_to_mof
> +from XenKvmLib.enumclass import GetInstance 
> +
> +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
> +default_dom = 'uuid_domain'
> +test_dom = 'test_domain'
> +nmac = '99:aa:bb:cc:ee:ff'
> +
> +def get_vssd(ip, virt, get_cim_inst, default_dom):
>   
Since you expect get_cim_inst to be True no need to pass the parameter here.
Instead use get_cim_inst = True in the GetInstance() call.
> +    cn = get_typed_class(virt, "VirtualSystemSettingData") 
> +    inst = None
> +
> +    try:
> +        if virt == "XenFV": 
> +            virt = "Xen"
> +
> +        key_list = {"InstanceID" : "%s:%s" % (virt, default_dom) }
> +        inst = GetInstance(ip, cn, key_list, get_cim_inst)
>   
For the reasons mentioned above, this could be changed to:

inst = GetInstance(ip, cn, key_list, get_cim_inst=True)

> +
> +    except Exception, details:
> +        logger.error(details)
> +        return FAIL, inst
> +
> +    if inst is None:
> +        return FAIL, inst
> +
> +    return PASS, inst
> +
> + at do_main(sup_types)
> +def main():
> +    options = main.options 
> +
> +    service = vsms.get_vsms_class(options.virt)(options.ip)
> +
> +    cxml = vxml.get_class(options.virt)(default_dom)
> +    ret = cxml.cim_define(options.ip)
> +    if not ret:
> +        logger.error("Failed to define the dom: %s", default_dom)
> +        return FAIL
> +
> +    try:
> +        status, inst = get_vssd(options.ip, options.virt, True,default_dom)
> +        if status != PASS:
> +            raise Exception("Failed to get the VSSD instance for %s"% 
> +                             default_dom)
>   

Need space before %
> +
> +        uuid = inst['UUID']
> +
> +        sxml = vxml.get_class(options.virt)(test_dom, uuid, mac=nmac)
>   
Don't pass uuid here, let the libvirt-cim assing one.
FYI...Also, its always better to pass the arguments in the Key=Value format.
This will be helpful in case the get_class() adds one more param as the 
second argument in which case it would make uuid would be third argument 
of the function get_class().
> +        ret = sxml.cim_define(options.ip)
> +        if not ret:
> +            raise Exception("Failed to define the dom: %s"% test_dom)
> +
> +        status, inst = get_vssd(options.ip, options.virt, True,test_dom)
> +        if status != PASS:
> +            raise Exception("Failed to get the VSSD instance for %s"%
>   
Need space before %

> +                             test_dom)
> +
> +        inst['UUID'] = uuid
>   
I am little selfish here.
Move the call for the get_vssd() for the first domain here, or change 
the name uuid of the first domain to uuid_defaultdomain.
otherwise the tracking of the uuid information becomes little difficult.
> +        vssd = inst_to_mof(inst)
> +        ret = service.ModifySystemSettings(SystemSettings=vssd)
> +        if ret[0] == 0:
> +            raise Exception("Was able to define domains with duplicate UUID") 
>   
The log message could be changed to "Was able to Modify the domain with 
duplicate UUID"
> +
> +    except Exception, details:
> +        err_no   = details[0]
> +        err_desc = details[1]
> +        if err_desc.find("domain 'uuid_domain' is already defined"):
> +            logger.info('Got expected error desc')
> +            status = PASS
> +        else:
> +            logger.error(details)
> +            status = FAIL
> +
> +    sxml.undefine(options.ip)
> +    cxml.undefine(options.ip)
> +    return status
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> + 
>
>   
Also, can you change the name of the test case from 06_dupicate_uuid.py 
to 06_duplicate_uuid.py.
> _______________________________________________
> 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