From 99e4a923bc09ecbab7abbc885b6b32765fed0ab3 Mon Sep 17 00:00:00 2001 From: Anand Shanmugam Date: Wed, 7 Sep 2016 12:00:15 -0700 Subject: [PATCH] Fix glance api to return appropriate exception Change-Id: Ib21d0dec6b6c3a3d0a4009f53a84160176911dbc --- cloudpulse/openstack/api/glance_api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cloudpulse/openstack/api/glance_api.py b/cloudpulse/openstack/api/glance_api.py index f2e949e..9ec3bd4 100644 --- a/cloudpulse/openstack/api/glance_api.py +++ b/cloudpulse/openstack/api/glance_api.py @@ -15,18 +15,25 @@ from glanceclient.v2 import client as glance_client class GlanceHealth(object): + def __init__(self, keystone_instance): authtoken = keystone_instance.keystone_return_authtoken() glance_endpoint = (keystone_instance - .keystone_endpoint_find(service_type='image')) + .keystone_endpoint_find(service_type='image', + endpoint_type='internalURL') + ) self.glanceclient = glance_client.Client(glance_endpoint, token=authtoken) def glance_image_list(self): try: image_list = self.glanceclient.images.list() + # The above api doens't generate appropriate exception + # so we are walking through the generator to raise exception + for image in image_list: + pass except (ClientException, Exception) as e: - return (404, e.message, []) + return (404, "ClientException:" + str(e), []) return (200, "success", image_list) def glance_image_create(self, image_url,