From 24385adb7a8829885f0172e0cd3607e5dba9a594 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 26 May 2015 16:05:10 -0700 Subject: [PATCH] Always refresh glanceclient for tokens validity Glanceclient doesn't refresh tokens on its own. Work around this by always making a new glanceclient with a potentialy new token if the existing token is near expiration. This adds some overhead to our use of glance but that is preferable to having glanceclient break because its token has expired. Change-Id: If57531a72eb90ee7bc6e67905ddfd5bda9bb6f1b --- shade/__init__.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/shade/__init__.py b/shade/__init__.py index 5a8089838..64095ef75 100644 --- a/shade/__init__.py +++ b/shade/__init__.py @@ -556,25 +556,29 @@ class OpenStackCloud(object): @property def glance_client(self): - if self._glance_client is None: - token = self.auth_token - endpoint = self.get_session_endpoint('image') - glance_api_version = self._get_glance_api_version() - kwargs = dict() - if self.api_timeout is not None: - kwargs['timeout'] = self.api_timeout - try: - self._glance_client = glanceclient.Client( - glance_api_version, endpoint, token=token, - session=self.keystone_session, - **kwargs) - except Exception as e: - self.log.debug("glance unknown issue", exc_info=True) - raise OpenStackCloudException( - "Error in connecting to glance: %s" % str(e)) + # Note that glanceclient doesn't use keystoneclient sessions + # which means that it won't make a new token if the old one has + # expired. Work around that by always making a new glanceclient here + # which may create a new token if the current one is close to + # expiration. + token = self.auth_token + endpoint = self.get_session_endpoint('image') + glance_api_version = self._get_glance_api_version() + kwargs = dict() + if self.api_timeout is not None: + kwargs['timeout'] = self.api_timeout + try: + self._glance_client = glanceclient.Client( + glance_api_version, endpoint, token=token, + session=self.keystone_session, + **kwargs) + except Exception as e: + self.log.debug("glance unknown issue", exc_info=True) + raise OpenStackCloudException( + "Error in connecting to glance: %s" % str(e)) - if not self._glance_client: - raise OpenStackCloudException("Error connecting to glance") + if not self._glance_client: + raise OpenStackCloudException("Error connecting to glance") return self._glance_client @property