+1 =)

libvirt-cim-bounces@redhat.com wrote on 2008-07-02 04:46:16:

> # HG changeset patch
> # User Kaitlin Rupert <karupert@us.ibm.com>
> # Date 1214945125 25200
> # Node ID ea52dde5ac3e1b10d5aa59b101d91b8ffc5b127e
> # Parent  cb09fbc0900ca656f629057742f19f1771fed4f8
> [TEST] #2 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.
>
> Updated from 1 to 2:
>   -Fix error message - if we are unable to start the guest, error
> message should say "Failed to start the dom: %s"
>
> Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
>
> diff -r cb09fbc0900c -r ea52dde5ac3e suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py
> --- a/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Tue
> Jul 01 13:42:52 2008 -0700
> +++ b/suites/libvirt-
> cim/cimtest/VirtualSystemManagementService/02_destroysystem.py   Tue
> Jul 01 13:45:25 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 start the dom: %s", default_dom)
> +        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@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim