From: David-Sarah Hopwood Date: Thu, 21 Feb 2013 22:17:06 +0000 (+0000) Subject: OpenStack: if we get a 401 Unauthorized response, reauthenticate immediately. X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/frontends?a=commitdiff_plain;h=81b396767e60d69bdbfedca81ac7862ec7fd1ce5;p=tahoe-lafs%2Ftahoe-lafs.git OpenStack: if we get a 401 Unauthorized response, reauthenticate immediately. Signed-off-by: David-Sarah Hopwood --- diff --git a/src/allmydata/storage/backends/cloud/openstack/openstack_container.py b/src/allmydata/storage/backends/cloud/openstack/openstack_container.py index 4e52dc07..7aedf175 100644 --- a/src/allmydata/storage/backends/cloud/openstack/openstack_container.py +++ b/src/allmydata/storage/backends/cloud/openstack/openstack_container.py @@ -9,6 +9,7 @@ from allmydata.util.deferredutil import eventually_callback, eventually_errback from twisted.internet.protocol import Protocol from twisted.web.client import Agent, FileBodyProducer, ResponseDone from twisted.web.http_headers import Headers +from twisted.web.http import UNAUTHORIZED from zope.interface import implements, Interface @@ -230,6 +231,10 @@ class AuthenticationClient(object): d.addCallback(lambda ign: self._auth_info) return d + def invalidate(self): + self._auth_info = None + self._reauthenticate() + def _authenticate(self): (method, url, request_headers, body, need_response_body) = self._authenticator.make_auth_request() @@ -311,6 +316,14 @@ class OpenStackContainer(ContainerRetryMixin): return "%s/%s/%s" % (auth_info.public_storage_url, urllib.quote(self._container_name, safe=''), urllib.quote(object_name)) + def _react_to_error(self, response_code): + if response_code == UNAUTHORIZED: + # Invalidate auth_info and retry. + self._auth_client.invalidate() + return True + else: + return ContainerRetryMixin._react_to_error(self, response_code) + def _create(self): """ Create this container.