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='',