File: error.py

package info (click to toggle)
libvirt 0.9.12.3-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 115,024 kB
  • sloc: ansic: 324,394; xml: 44,112; sh: 15,676; python: 6,198; makefile: 2,916; perl: 2,003; ml: 472; sed: 16
file content (42 lines) | stat: -rwxr-xr-x 824 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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 or \
     errno[0] == libvirt.VIR_ERR_GET_FAILED:
    print "OK"
else:
    print 'got unexpected error:', errno

sys.exit(0)