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

[Xen-changelog] Improve error handling, in particular fixing the ProtocolError that is thrown



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID da24df1ea484cf72dc9d367d52e828777e0e20cd
# Parent  c1bb4eb565296bdb00aed84fcc877befbcebd8e9
Improve error handling, in particular fixing the ProtocolError that is thrown
when a domain is specified by the user that does not exist.  Added a few
error codes -- many more to come, I expect.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r c1bb4eb56529 -r da24df1ea484 tools/python/xen/xend/XendClient.py
--- a/tools/python/xen/xend/XendClient.py       Thu Mar 23 10:58:19 2006
+++ b/tools/python/xen/xend/XendClient.py       Thu Mar 23 11:59:43 2006
@@ -21,4 +21,8 @@
 
 XML_RPC_SOCKET = "/var/run/xend-xmlrpc.sock"
 
+ERROR_INTERNAL = 1
+ERROR_GENERIC = 2
+ERROR_INVALID_DOMAIN = 3
+
 server = ServerProxy('httpu:///var/run/xend-xmlrpc.sock')
diff -r c1bb4eb56529 -r da24df1ea484 tools/python/xen/xend/XendError.py
--- a/tools/python/xen/xend/XendError.py        Thu Mar 23 10:58:19 2006
+++ b/tools/python/xen/xend/XendError.py        Thu Mar 23 11:59:43 2006
@@ -17,10 +17,12 @@
 
 from xmlrpclib import Fault
 
+import XendClient
+
 class XendError(Fault):
     
     def __init__(self, value):
-        Fault.__init__(self, 2, value)
+        Fault.__init__(self, XendClient.ERROR_GENERIC, value)
         self.value = value
 
     def __str__(self):
diff -r c1bb4eb56529 -r da24df1ea484 
tools/python/xen/xend/server/XMLRPCServer.py
--- a/tools/python/xen/xend/server/XMLRPCServer.py      Thu Mar 23 10:58:19 2006
+++ b/tools/python/xen/xend/server/XMLRPCServer.py      Thu Mar 23 11:59:43 2006
@@ -13,25 +13,45 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2006 Anthony Liguori <aliguori@xxxxxxxxxx>
-# Copyright (C) 2006 XenSource Ltd
+# Copyright (C) 2006 XenSource Ltd.
 #============================================================================
+
+import xmlrpclib
 
 from xen.xend import XendDomain, XendDomainInfo, XendNode, \
                      XendLogging, XendDmesg
 from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
 
-from xen.xend.XendClient import XML_RPC_SOCKET
+from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
 
 def lookup(domid):
-    return XendDomain.instance().domain_lookup_by_name_or_id(domid)
+    try:
+        return XendDomain.instance().domain_lookup_by_name_or_id(domid)
+    except exn:
+        log.exception(exn)
+        raise exn
 
 def dispatch(domid, fn, args):
     info = lookup(domid)
-    return getattr(info, fn)(*args)
+    if info:
+        try:
+            return getattr(info, fn)(*args)
+        except exn:
+            log.exception(exn)
+            raise exn
+    else:
+        raise xmlrpclib.Fault(ERROR_INVALID_DOMAIN, domid)
 
 def domain(domid):
     info = lookup(domid)
-    return info.sxpr()
+    if info:
+        try:
+            return info.sxpr()
+        except exn:
+            log.exception(exn)
+            raise exn
+    else:
+        raise xmlrpclib.Fault(ERROR_INVALID_DOMAIN, domid)
 
 def domains(detail=1):
     if detail < 1:
diff -r c1bb4eb56529 -r da24df1ea484 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Thu Mar 23 10:58:19 2006
+++ b/tools/python/xen/xm/main.py       Thu Mar 23 11:59:43 2006
@@ -1,6 +1,6 @@
 # (C) Copyright IBM Corp. 2005
 # Copyright (C) 2004 Mike Wray
-# Copyright (c) 2005 XenSource Ltd
+# Copyright (c) 2005-2006 XenSource Ltd.
 #
 # Authors:
 #     Sean Dague <sean at dague dot net>
@@ -38,7 +38,7 @@
 from xen.xm.opts import *
 
 import console
-
+import xen.xend.XendClient
 from xen.xend.XendClient import server
 
 # getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use
@@ -1111,7 +1111,10 @@
         except SystemExit:
             sys.exit(1)
         except xmlrpclib.Fault, ex:
-            print "Error: %s" % ex.faultString
+            if ex.faultCode == xen.xend.XendClient.ERROR_INVALID_DOMAIN:
+                print "Error: the domain '%s' does not exist." % ex.faultString
+            else:
+                print "Error: %s" % ex.faultString
             sys.exit(1)
         except:
             print "Unexpected error:", sys.exc_info()[0]

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.