[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] for testing the python binding API



From: ShaoHe Feng <shaohef linux vnet ibm com>

there will come an  "RESUME" events when qemu domains are started.
this python test can catch the "RESUME" event

Signed-off-by: ShaoHe Feng <shaohef linux vnet ibm com>
---
 qemu-event-test.py |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)
 create mode 100755 qemu-event-test.py

diff --git a/qemu-event-test.py b/qemu-event-test.py
new file mode 100755
index 0000000..cf33d04
--- /dev/null
+++ b/qemu-event-test.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import libvirt
+import libvirt_qemu
+import threading
+import time
+import signal
+import os
+import sys
+
+eventLoopThread = None
+
+def eventLoopRun():
+    while True:
+        libvirt.virEventRunDefaultImpl()
+
+def eventLoopStart():
+    global eventLoopThread
+
+    libvirt.virEventRegisterDefaultImpl()
+    eventLoopThread = threading.Thread(target=eventLoopRun, name="libvirtEventLoop")
+    eventLoopThread.setDaemon(True)
+    eventLoopThread.start()
+
+
+def reportDefault(conn, dom, eventName,eventArgs,opaque):
+    print "DEFAULT EVENT: Domain %s(%s), pass the unknown event:%s, arguments is: %s" % (dom.name(), dom.ID(), eventName, eventArgs)
+
+eventStrings = (
+                "RESUME",
+                "VNC_CONNECTED",
+                "VNC_DISCONNECTED",
+                "VNC_INITIALIZED",
+                "RESET",
+                "SHUTDOWN",
+                "HELLO" );
+eventID = {};
+
+def signal_handler(signal, frame):
+    print "deregister event: %d" %(eventID[0])
+    #libvirt_qemu.domainQemuEventDeregister(conn, eventID[0])
+    print "test safely exit"
+    sys.exit(0)
+
+def main():
+    eventLoopStart()
+    signal.signal(signal.SIGINT, signal_handler)
+    conn = libvirt.openReadOnly('qemu:///system')
+    eventID[0] = libvirt_qemu.domainQemuEventRegister(conn, None, eventStrings[0], reportDefault, None)
+
+    while 1:
+        time.sleep(1)
+ 
+if __name__ == "__main__":
+    main()
+
+
-- 
1.7.5.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]