summaryrefslogtreecommitdiffstats
path: root/tests/error.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/error.py')
-rwxr-xr-xtests/error.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/error.py b/tests/error.py
new file mode 100755
index 0000000..9979ed1
--- /dev/null
+++ b/tests/error.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python -u
+#
+# Tests global error handlers at the python level.
+#
+import libvirt
+import sys
+import os
+
+errno = None
+
+def handler(ctxt, err):
+ global errno
+
+ #print "handler(%s, %s)" % (ctxt, err)
+ errno = err
+
+libvirt.registerErrorHandler(handler, 'context')
+
+conn = libvirt.openReadOnly(None)
+if conn == None:
+ print 'Failed to open connection to the hypervisor'
+ sys.exit(1)
+
+try:
+ dom0 = conn.lookupByName("Does_not_exist")
+ print 'strange found a Does_not_exist domain'
+ sys.exit(1)
+except:
+ pass
+
+del conn
+
+if errno == None:
+ print 'failed to get an error'
+elif errno[0] == libvirt.VIR_ERR_NO_CONNECT or \
+ errno[0] == libvirt.VIR_ERR_INVALID_DOMAIN:
+ print "OK"
+else:
+ print 'got unexpected error %s' % (errno)
+
+sys.exit(0)