WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Added retry behaviour when receiving SESS

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added retry behaviour when receiving SESSION_INVALID. This means that xm shell
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 23 Dec 2006 15:10:12 -0800
Delivery-date: Sat, 23 Dec 2006 15:10:48 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Added retry behaviour when receiving SESSION_INVALID. This means that xm shell, Xen patchbot-unstable <=