Anthony Liguori
2006-Mar-23 20:11 UTC
[Xen-devel] Re: [Xen-changelog] Improve error handling, in particular fixing the ProtocolError that is thrown
Xen patchbot -unstable wrote:> # HG changeset patch > # User emellor@leeni.uk.xensource.com > # 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@xensource.com> > > 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@us.ibm.com> > -# 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) >log doesn''t appear to be defined in this scope. Also, there appears to be a problem with the except syntax. Don''t you mean: except Exception, exn: Regards, Anthony Liguori> + 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@lists.xensource.com > http://lists.xensource.com/xen-changelog >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel