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

[Xen-changelog] [xen-unstable] Added retry behaviour when receiving SESSION_INVALID. This means that xm shell



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1166905234 0
# Node ID 26f3c7f5de9d00e2d8d765bebe5c412c04c9e65d
# Parent  967426f60378716aa60279a6f18eadc85dd4d9c4
Added retry behaviour when receiving SESSION_INVALID.  This means that xm shell
and XenAPI.Session will reauthenticate across a Xend restart.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/python/xen/xm/XenAPI.py |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff -r 967426f60378 -r 26f3c7f5de9d tools/python/xen/xm/XenAPI.py
--- a/tools/python/xen/xm/XenAPI.py     Sat Dec 23 19:06:31 2006 +0000
+++ b/tools/python/xen/xm/XenAPI.py     Sat Dec 23 20:20:34 2006 +0000
@@ -72,6 +72,9 @@ class Failure(Exception):
                      for i in range(len(self.details))])
 
 
+_RECONNECT_AND_RETRY = (lambda _ : ())
+
+
 class Session(xen.util.xmlrpclib2.ServerProxy):
     """A server proxy and session manager for communicating with Xend using
     the Xen-API.
@@ -102,13 +105,27 @@ class Session(xen.util.xmlrpclib2.Server
             self._login(methodname, params)
             return None
         else:
-            full_params = (self._session,) + params
-            return _parse_result(getattr(self, methodname)(*full_params))
+            retry_count = 0
+            while retry_count < 3:
+                full_params = (self._session,) + params
+                result = _parse_result(getattr(self, methodname)(*full_params))
+                if result == _RECONNECT_AND_RETRY:
+                    retry_count += 1
+                    self._login(self.last_login_method, self.last_login_params)
+                else:
+                    return result
+            raise xmlrpclib.Fault(
+                500, 'Tried 3 times to get a valid session, but failed')
 
 
     def _login(self, method, params):
-        self._session = _parse_result(
-            getattr(self, 'session.%s' % method)(*params))
+        result = _parse_result(getattr(self, 'session.%s' % method)(*params))
+        if result == _RECONNECT_AND_RETRY:
+            raise xmlrpclib.Fault(
+                500, 'Received SESSION_INVALID when logging in')
+        self._session = result
+        self.last_login_method = method
+        self.last_login_params = params
 
 
     def __getattr__(self, name):
@@ -131,7 +148,10 @@ def _parse_result(result):
                                   'Missing Value in response from server')
     else:
         if 'ErrorDescription' in result:
-            raise Failure(result['ErrorDescription'])
+            if result['ErrorDescription'][0] == 'SESSION_INVALID':
+                return _RECONNECT_AND_RETRY
+            else:
+                raise Failure(result['ErrorDescription'])
         else:
             raise xmlrpclib.Fault(
                 500, 'Missing ErrorDescription in response from server')

_______________________________________________
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®.