Delete image from specific store
Add support to delete image from specific store. bp: delete-from-store Change-Id: Ie57d7de5822264a5ea8a5f4587ab8cfb4afb79de
This commit is contained in:
parent
6d506c3a36
commit
d91bcae8a5
@ -2165,6 +2165,29 @@ class ShellV2Test(testtools.TestCase):
|
||||
self.assertEqual(2, mocked_print_err.call_count)
|
||||
mocked_utils_exit.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(utils, 'exit')
|
||||
def test_do_image_delete_from_store_not_found(self, mocked_utils_exit):
|
||||
args = argparse.Namespace(id='image1', store='store1')
|
||||
with mock.patch.object(self.gc.images,
|
||||
'delete_from_store') as mocked_delete:
|
||||
mocked_delete.side_effect = exc.HTTPNotFound
|
||||
|
||||
test_shell.do_stores_delete(self.gc, args)
|
||||
|
||||
self.assertEqual(1, mocked_delete.call_count)
|
||||
mocked_utils_exit.assert_called_once_with('Multi Backend support '
|
||||
'is not enabled or '
|
||||
'Image/store not found.')
|
||||
|
||||
def test_do_image_delete_from_store(self):
|
||||
args = argparse.Namespace(id='image1', store='store1')
|
||||
with mock.patch.object(self.gc.images,
|
||||
'delete_from_store') as mocked_delete:
|
||||
test_shell.do_stores_delete(self.gc, args)
|
||||
|
||||
mocked_delete.assert_called_once_with('store1',
|
||||
'image1')
|
||||
|
||||
@mock.patch.object(utils, 'exit')
|
||||
@mock.patch.object(utils, 'print_err')
|
||||
def test_do_image_delete_with_forbidden_ids(self, mocked_print_err,
|
||||
|
@ -302,6 +302,14 @@ class Controller(object):
|
||||
resp, body = self.http_client.get(url)
|
||||
return body, resp
|
||||
|
||||
@utils.add_req_id_to_object()
|
||||
def delete_from_store(self, store_id, image_id):
|
||||
"""Delete image data from specific store."""
|
||||
url = ('/v2/stores/%(store)s/%(image)s' % {'store': store_id,
|
||||
'image': image_id})
|
||||
resp, body = self.http_client.delete(url)
|
||||
return body, resp
|
||||
|
||||
@utils.add_req_id_to_object()
|
||||
def stage(self, image_id, image_data, image_size=None):
|
||||
"""Upload the data to image staging.
|
||||
|
@ -556,6 +556,24 @@ def do_stores_info(gc, args):
|
||||
utils.print_dict(stores_info)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<IMAGE_ID>', help=_('ID of image to update.'))
|
||||
@utils.arg('--store', metavar='<STORE_ID>', required=True,
|
||||
help=_('Store to delete image from.'))
|
||||
def do_stores_delete(gc, args):
|
||||
"""Delete image from specific store."""
|
||||
try:
|
||||
gc.images.delete_from_store(args.store, args.id)
|
||||
except exc.HTTPNotFound:
|
||||
utils.exit('Multi Backend support is not enabled or Image/store not '
|
||||
'found.')
|
||||
except (exc.HTTPForbidden, exc.HTTPException) as e:
|
||||
msg = ("Unable to delete image '%s' from store '%s'. (%s)" % (
|
||||
args.id,
|
||||
args.store,
|
||||
e))
|
||||
utils.exit(msg)
|
||||
|
||||
|
||||
@utils.arg('--allow-md5-fallback', action='store_true',
|
||||
default=utils.env('OS_IMAGE_ALLOW_MD5_FALLBACK', default=False),
|
||||
help=_('If os_hash_algo and os_hash_value properties are available '
|
||||
|
4
releasenotes/notes/del_from_store-2d807c3038283907.yaml
Normal file
4
releasenotes/notes/del_from_store-2d807c3038283907.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Support for deleting the image data from single store.
|
Loading…
Reference in New Issue
Block a user