mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-20 11:48:28 -06:00
* python/Makefile.am python/generator.py python/libvir.c python/libvir.py: improved python binding, raise exception when an instance creation or lookup fails, and add support for the global error handler, per conn handler still needed * python/tests/error.py python/tests/Makefile.am: adding a regression test Daniel
42 lines
780 B
Python
Executable File
42 lines
780 B
Python
Executable File
#!/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)
|