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

Chip Vincent cvincent at linux.vnet.ibm.com
Wed Jun 8 15:12:16 UTC 2011


Worked like a charm, thanks. +1.

Pushed.

On 05/27/2011 03:01 PM, Eduardo Lima (Etrunko) wrote:
> # HG changeset patch
> # User Eduardo Lima (Etrunko)<eblima at br.ibm.com>
> # Date 1306522145 10800
> # Node ID c8670eeacbb02db390825e4dda776a2a4cf67ff8
> # 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.
>
> Changes from #1:
>   * Avoid NameError (ret) if another exception other than
>     KeyboardInterrupt occurs
>
> 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())
> +    ret = -1
> +    try:
> +        options, args = parser.parse_args()
> +        ret = main(options, args)
> +    except (KeyboardInterrupt, SystemExit):
> +        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)
>
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim

-- 
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list