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
(cherry picked from commit b8a881f5ea)
This commit is contained in:
Flavio Percoco 2015-09-16 10:56:31 +02:00
parent 6764b8bf1a
commit e82d9df74c
2 changed files with 6 additions and 7 deletions

View File

@ -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,

View File

@ -314,11 +314,11 @@ def do_image_upload(gc, args):
@utils.arg('id', metavar='<IMAGE_ID>', 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='<IMAGE_ID>',