Merge lp:~pwlars/adt-image-mapper/keystone-token-refresh into lp:adt-image-mapper

Proposed by Paul Larson
Status: Merged
Approved by: Paul Larson
Approved revision: 7
Merged at revision: 8
Proposed branch: lp:~pwlars/adt-image-mapper/keystone-token-refresh
Merge into: lp:adt-image-mapper
Diff against target: 43 lines (+18/-5)
1 file modified
adt_image_mapper/cloud.py (+18/-5)
To merge this branch: bzr merge lp:~pwlars/adt-image-mapper/keystone-token-refresh
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+253456@code.launchpad.net

Commit message

Handle a common situation where the token needs to be refreshed

Description of the change

Handle a common situation where the token needs to be refreshed

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

hacky, but it should work.

review: Approve
Revision history for this message
Paul Larson (pwlars) wrote :

Yeah, I normally don't like catching blanket exceptions like that, but the one we really need to catch I think would need to be caught deeper in the client itself. On the plus side, if anything else goes wrong here it'll log the exception and give it one more chance to right itself before failing the request.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'adt_image_mapper/cloud.py'
2--- adt_image_mapper/cloud.py 2015-03-13 01:08:05 +0000
3+++ adt_image_mapper/cloud.py 2015-03-19 02:58:11 +0000
4@@ -30,9 +30,7 @@
5 self._config = config
6 self._glance_client = None
7
8- def get_image_for_series(self, series_name, architecture):
9- logger.info("Searching for image with series=%r, arch=%r", series_name, architecture)
10- glance_client = self.get_glance_client()
11+ def _get_candidate_image(self, glance_client, series_name, architecture):
12 candidate_image = None
13 for image in glance_client.images.list():
14 logger.debug("Testing image %r", image.name)
15@@ -51,11 +49,26 @@
16 candidate_image = image
17 else:
18 logger.debug("Rejected because version is less")
19+ return candidate_image
20+
21+ def get_image_for_series(self, series_name, architecture):
22+ logger.info("Searching for image with series=%r, arch=%r", series_name, architecture)
23+ glance_client = self.get_glance_client()
24+ try:
25+ candidate_image = self._get_candidate_image(
26+ glance_client, series_name, architecture)
27+ except Exception as e:
28+ logger.debug("The following exception is probably just the "
29+ "token needing to be refreshed")
30+ logger.exception("Exception caught:")
31+ glance_client = self.get_glance_client(refresh=True)
32+ candidate_image = self._get_candidate_image(
33+ glance_client, series_name, architecture)
34 logger.info("Search finished, found %r", candidate_image)
35 return candidate_image.name if candidate_image else None
36
37- def get_glance_client(self):
38- if self._glance_client is None:
39+ def get_glance_client(self, refresh=False):
40+ if self._glance_client is None or refresh is True:
41 keystone = keystoneclient.v2_0.client.Client(
42 username=self._config.get('nova', 'os_username'),
43 password=self._config.get('nova', 'os_password'),

Subscribers

People subscribed via source and target branches