[Libvirt-cim] [PATCH] Cimtest: Handle keyboard interrupt

Eduardo Lima (Etrunko) eblima at linux.vnet.ibm.com
Fri May 27 19:04:31 UTC 2011


On 05/27/2011 03:49 PM, Eduardo Lima (Etrunko) wrote:
> # HG changeset patch
> # User Eduardo Lima (Etrunko)<eblima at br.ibm.com>
> # Date 1306522145 10800
> # Node ID c7ff1c6e7cb60b37ce6d2ce4fbf58535b3b3fc9e
> # Parent  01aa645a1e1269eb31d1fdd9de8d7e9120f5fa74
> Cimtest: Handle keyboard interrupt
>
> During my tests I have noticed that if the user interrupts the program
> execution, by pressing Ctrl+C, the next time cimtest runs, it will fail
> due to leftovers of previous execution, especially, a disk pool called
> cimtest-diskpool and a network called cimtest-netpool.
>
> With this patch, if a KeyboardInterrupt exception occurs, the
> cleanup_env() function will be called before the program exit.
>
> Signed-off-by: Eduardo Lima (Etrunko)<eblima at br.ibm.com>
>
> diff --git a/suites/libvirt-cim/main.py b/suites/libvirt-cim/main.py
> --- a/suites/libvirt-cim/main.py
> +++ b/suites/libvirt-cim/main.py
> @@ -176,8 +176,7 @@
>       testsuite.debug("%s %sh | %smin | %ssec | %smsec" %
>                       (prefix, h, m, s, msec))
>
> -def main():
> -    (options, args) = parser.parse_args()
> +def main(options, args):
>       to_addr = None
>       from_addr = None
>       relay = None
> @@ -302,7 +301,21 @@
>                 (from_addr, to_addr, relay)
>           send_report(to_addr, from_addr, relay, msg_body, heading)
>
> +    return 0
> +# main()
> +
>   if __name__ == '__main__':
> -    sys.exit(main())
> +    try:
> +        options, args = parser.parse_args()
> +        ret = main(options, args)
> +    except (KeyboardInterrupt, SystemExit):
> +        ret = -1
> +        print "\nKeyboardInterrupt. Cleaning up..."
> +        status = cleanup_env(options.ip, options.virt)
> +        if status != PASS:
> +            print "Unable to clean up. Please check your environment."
> +        else:
> +            print "Clean up successful"
>
> +    sys.exit(ret)

-1.

If other exception than KeyboardInterrupt, SystemExit occurs, we will 
have a NameError exception:

Traceback (most recent call last):
   File "main.py", line 316, in <module>
     sys.exit(ret)
NameError: name 'ret' is not defined

A new patch fixing this is on the way.

-- 
Eduardo de Barros Lima
Software Engineer, Open Virtualization
Linux Technology Center - IBM/Brazil
eblima at br.ibm.com




More information about the Libvirt-cim mailing list