From 9600409e58e3580ccd0e46c1da2c6a019a01ec02 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 28 Feb 2006 12:17:00 +0000 Subject: * TODO: updated * 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 --- tests/Makefile.am | 3 ++- tests/error.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 tests/error.py (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index fd1d5fa..5860190 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,8 @@ EXAMPLE_DIR = $(datadir)/doc/libvirt-python-$(LIBVIRT_VERSION)/examples PYTESTS= \ basic.py \ create.py \ - uuid.py + uuid.py \ + error.py EXTRA_DIST = $(PYTESTS) 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) -- cgit