[Libvirt-cim] [PATCH] [TEST] Some VirtualSystemManagementService -t 02_destroysystem.py cleanup

Guo Lian Yun yunguol at cn.ibm.com
Tue Jul 1 02:49:40 UTC 2008


libvirt-cim-bounces at redhat.com wrote on 2008-07-01 03:04:41:

> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1214852675 25200
> # Node ID 7d3d5dcffad210d1da9f208ce1881f391a21ba9e
> # Parent  692121d37b3aefafce0d6856d81468add629514d
> [TEST] Some VirtualSystemManagementService -t 02_destroysystem.py 
cleanup.
> 
> Add checks to see if the define() / start() calls pass.
> Added cleanup_env() function to destroy()/undefine() guest in case of 
error.
> Ensure status is set to PASS only if the guest is not found in the 
> domain list after the DestroySystem() call is made.
> 
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
> 
> diff -r 692121d37b3a -r 7d3d5dcffad2 suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Mon
> Jun 30 09:58:36 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Mon
> Jun 30 12:04:35 2008 -0700
> @@ -35,47 +35,53 @@
>  sup_types = ['Xen', 'KVM', 'XenFV', 'LXC']
>  default_dom = 'test_domain'
> 
> +def cleanup_env(ip, cxml):
> +    cxml.destroy(ip)
> +    cxml.undefine(ip)
> +
>  @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)
> -    cxml.define(options.ip)
> -    cxml.start(options.ip)
> +    ret = cxml.define(options.ip)
> +    if not ret:
> +        logger.error("Failed to define the dom: %s", default_dom)
> +        return FAIL
> +    ret = cxml.start(options.ip)
> +    if not ret:
> +        logger.error("Failed to define the dom: %s", default_dom)

   It's better to log the error as "logger.error("Failed to create(or 
start) the dom: %s", default_dom)",
   which more reflect the actual failure.

> +        cleanup_env(options.ip, cxml)
> +        return FAIL
> 
>      classname = get_typed_class(options.virt, 'ComputerSystem')
>      cs_ref = CIMInstanceName(classname, keybindings = {
>                                          'Name':default_dom,
>                                          'CreationClassName':classname})
>      list_before = domain_list(options.ip, options.virt)
> -    status = PASS
> -    rc = -1
> +    if default_dom not in list_before:
> +        logger.error("Domain not in domain list")
> +        cleanup_env(options.ip, cxml)
> +        return FAIL
> 
>      try:
>          service.DestroySystem(AffectedSystem=cs_ref)
> -        rc = 0
>      except Exception, details:
>          logger.error('Unknow exception happened')
>          logger.error(details)
> -        status = FAIL
> +        cleanup_env(options.ip, cxml)
> +        return FAIL
> 
>      list_after = domain_list(options.ip, options.virt)
> 
> -    status = PASS
> -    if default_dom not in list_before:
> -        logger.error("Domain not started, check config")
> +    if default_dom in list_after:
> +        logger.error("Domain %s not destroyed: provider didn't 
> return error" % \
> +                     default_dom)
> +        cleanup_env(options.ip, cxml)
>          status = FAIL
>      else:
> -        destroyed = set(list_before) - set(list_after)
> -        if len(destroyed) != 1:
> -            logger.error("Destroyed multiple domains")
> -            status = FAIL
> -        elif default_dom not in destroyed:
> -            logger.error("Wrong domain destroyed")
> -            status = FAIL
> -
> -    cxml.undefine(options.ip)
> +        status = PASS
> 
>      return status
> 
> 
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-cim/attachments/20080701/0146e070/attachment.htm>


More information about the Libvirt-cim mailing list