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

Eduardo Lima (Etrunko) eblima at linux.vnet.ibm.com
Fri May 27 18:49:24 UTC 2011


# 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)
 




More information about the Libvirt-cim mailing list