From b8a881f5ea89514d715e61b632bc3081a0dde2c6 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Wed, 16 Sep 2015 10:56:31 +0200 Subject: [PATCH] Don't get the image before deleting it The client currently downloads the image metadata to check if it's deleted or not. This logic belongs to the server and it's already implemented there. Instead of getting the image, send the delete request and catch the 404 error, which is already raised by the server. Change-Id: I1e6ef42340f8e380ff99b9d6ca7ea416e0eebfbc Closes-bug: #1496305 --- glanceclient/tests/unit/v2/test_shell_v2.py | 5 ++--- glanceclient/v2/shell.py | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index e2678af6..39699ced 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -582,9 +582,8 @@ class ShellV2Test(testtools.TestCase): def test_do_image_delete_deleted(self): image_id = 'deleted-img' args = self._make_args({'id': image_id}) - with mock.patch.object(self.gc.images, 'get') as mocked_get: - mocked_get.return_value = self._make_args({'id': image_id, - 'status': 'deleted'}) + with mock.patch.object(self.gc.images, 'delete') as mocked_get: + mocked_get.side_effect = exc.HTTPNotFound msg = "No image with an ID of '%s' exists." % image_id self.assert_exits_with_msg(func=test_shell.do_image_delete, diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 3ae5d41e..08271e01 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -314,11 +314,11 @@ def do_image_upload(gc, args): @utils.arg('id', metavar='', help='ID of image to delete.') def do_image_delete(gc, args): """Delete specified image.""" - image = gc.images.get(args.id) - if image and image.status == "deleted": - msg = "No image with an ID of '%s' exists." % image.id + try: + gc.images.delete(args.id) + except exc.HTTPNotFound: + msg = "No image with an ID of '%s' exists." % args.id utils.exit(msg) - gc.images.delete(args.id) @utils.arg('image_id', metavar='',