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

View File

@ -296,11 +296,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>',

View File

@ -20,6 +20,7 @@ import tempfile
import testtools
from glanceclient.common import utils
from glanceclient import exc
from glanceclient.v2 import shell as test_shell
@ -454,9 +455,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,