diff --git a/horizon/horizon/api/glance.py b/horizon/horizon/api/glance.py index 7318ceaf549..c5e7e6eef2a 100644 --- a/horizon/horizon/api/glance.py +++ b/horizon/horizon/api/glance.py @@ -68,7 +68,19 @@ def image_delete(request, image_id): def image_get(request, image_id): - return Image(glance_api(request).get_image(image_id)[0]) + """ + Returns the actual image file from Glance for image with + supplied identifier + """ + return glance_api(request).get_image(image_id)[1] + + +def image_get_meta(request, image_id): + """ + Returns an Image object populated with metadata for image + with supplied identifier. + """ + return Image(glance_api(request).get_image_meta(image_id)) def image_list_detailed(request): diff --git a/horizon/horizon/api/nova.py b/horizon/horizon/api/nova.py index d523efd40ca..deaf17ee5a6 100644 --- a/horizon/horizon/api/nova.py +++ b/horizon/horizon/api/nova.py @@ -89,7 +89,7 @@ def image_name(self): from glance.common import exception as glance_exceptions from horizon.api import glance try: - image = glance.image_get(self.request, self.image['id']) + image = glance.image_get_meta(self.request, self.image['id']) return image.name except glance_exceptions.NotFound: return "(not found)" diff --git a/horizon/horizon/dashboards/nova/images/forms.py b/horizon/horizon/dashboards/nova/images/forms.py index 76e087b538b..518fb2165b8 100644 --- a/horizon/horizon/dashboards/nova/images/forms.py +++ b/horizon/horizon/dashboards/nova/images/forms.py @@ -57,7 +57,7 @@ def handle(self, request, data): error_updating = _('Error updating image with id: %s' % image_id) try: - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) except glance_exception.ClientConnectionError, e: LOG.exception(_('Error connecting to glance')) messages.error(request, error_retrieving) @@ -152,7 +152,7 @@ def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] try: - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], @@ -181,7 +181,7 @@ def handle(self, request, data): image_id = data['image_id'] tenant_id = request.user.tenant_id try: - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) if image.owner == request.user.username: api.image_delete(request, image_id) else: diff --git a/horizon/horizon/dashboards/nova/images/tests.py b/horizon/horizon/dashboards/nova/images/tests.py index a938b68abb6..0d2e49f4aec 100644 --- a/horizon/horizon/dashboards/nova/images/tests.py +++ b/horizon/horizon/dashboards/nova/images/tests.py @@ -153,8 +153,8 @@ def test_index_glance_error(self): def test_launch_get(self): IMAGE_ID = '1' - self.mox.StubOutWithMock(api, 'image_get') - api.image_get(IsA(http.HttpRequest), + self.mox.StubOutWithMock(api, 'image_get_meta') + api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') @@ -207,8 +207,8 @@ def test_launch_post(self): 'security_groups': 'default', } - self.mox.StubOutWithMock(api, 'image_get') - api.image_get(IsA(http.HttpRequest), + self.mox.StubOutWithMock(api, 'image_get_meta') + api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') @@ -226,7 +226,7 @@ def test_launch_post(self): self.security_groups) # called again by the form - api.image_get(IsA(http.HttpRequest), + api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') @@ -254,8 +254,8 @@ def test_launch_post(self): def test_launch_flavorlist_error(self): IMAGE_ID = '1' - self.mox.StubOutWithMock(api, 'image_get') - api.image_get(IsA(http.HttpRequest), + self.mox.StubOutWithMock(api, 'image_get_meta') + api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') @@ -288,8 +288,8 @@ def test_launch_flavorlist_error(self): def test_launch_keypairlist_error(self): IMAGE_ID = '2' - self.mox.StubOutWithMock(api, 'image_get') - api.image_get(IsA(http.HttpRequest), + self.mox.StubOutWithMock(api, 'image_get_meta') + api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') @@ -336,8 +336,8 @@ def test_launch_form_apiexception(self): 'security_groups': 'default', } - self.mox.StubOutWithMock(api, 'image_get') - api.image_get(IgnoreArg(), + self.mox.StubOutWithMock(api, 'image_get_meta') + api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') @@ -355,7 +355,7 @@ def test_launch_form_apiexception(self): self.security_groups) # called again by the form - api.image_get(IgnoreArg(), + api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') diff --git a/horizon/horizon/dashboards/nova/images/views.py b/horizon/horizon/dashboards/nova/images/views.py index 865fb16f902..786b727806f 100644 --- a/horizon/horizon/dashboards/nova/images/views.py +++ b/horizon/horizon/dashboards/nova/images/views.py @@ -110,7 +110,7 @@ def securitygrouplist(): tenant_id = request.user.tenant_id # TODO(mgius): Any reason why these can't be after the launchform logic? # If The form is valid, we've just wasted these two api calls - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) quotas = api.tenant_quota_get(request, request.user.tenant_id) try: quotas.ram = int(quotas.ram) @@ -139,7 +139,7 @@ def securitygrouplist(): @login_required def update(request, image_id): try: - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) except glance_exception.ClientConnectionError, e: LOG.exception("Error connecting to glance") messages.error(request, _("Error connecting to glance: %s") diff --git a/horizon/horizon/dashboards/syspanel/images/views.py b/horizon/horizon/dashboards/syspanel/images/views.py index 4a998a5fd92..611f0511363 100644 --- a/horizon/horizon/dashboards/syspanel/images/views.py +++ b/horizon/horizon/dashboards/syspanel/images/views.py @@ -70,7 +70,7 @@ def index(request): @login_required def update(request, image_id): try: - image = api.image_get(request, image_id) + image = api.image_get_meta(request, image_id) except glance_exception.ClientConnectionError, e: LOG.exception("Error connecting to glance") messages.error(request, diff --git a/horizon/horizon/tests/api_tests/glance.py b/horizon/horizon/tests/api_tests/glance.py index be08a2646d1..d1f898879e8 100644 --- a/horizon/horizon/tests/api_tests/glance.py +++ b/horizon/horizon/tests/api_tests/glance.py @@ -79,18 +79,18 @@ def test_image_delete(self): self.assertEqual(ret_val, TEST_RETURN) - def test_image_get(self): + def test_image_get_meta(self): IMAGE_ID = '1' glance_api = self.stub_glance_api() - glance_api.get_image(IMAGE_ID).AndReturn([TEST_RETURN]) + glance_api.get_image_meta(IMAGE_ID).AndReturn([TEST_RETURN]) self.mox.ReplayAll() - ret_val = api.image_get(self.request, IMAGE_ID) + ret_val = api.image_get_meta(self.request, IMAGE_ID) self.assertIsInstance(ret_val, api.Image) - self.assertEqual(ret_val._apidict, TEST_RETURN) + self.assertEqual(ret_val._apidict, [TEST_RETURN]) def test_image_list_detailed(self): images = (TEST_RETURN, TEST_RETURN + '2') diff --git a/horizon/horizon/tests/api_tests/nova.py b/horizon/horizon/tests/api_tests/nova.py index 9163956930f..395b28f90d0 100644 --- a/horizon/horizon/tests/api_tests/nova.py +++ b/horizon/horizon/tests/api_tests/nova.py @@ -99,8 +99,8 @@ def test_get_other_missing(self): def test_image_name(self): image = api.Image({'name': self.IMAGE_NAME}) - self.mox.StubOutWithMock(api.glance, 'image_get') - api.glance.image_get(IsA(http.HttpRequest), + self.mox.StubOutWithMock(api.glance, 'image_get_meta') + api.glance.image_get_meta(IsA(http.HttpRequest), self.IMAGE_OBJ['id']).AndReturn(image) server = api.Server(self.inner_server, self.request)