Browse Source

Delete data if image is deleted after staging call

Trying to delete image after staging call image gets deleted
from the database, but image data remains in the
staging area.

Deleted image data from the staging area if image_import is
enabled and image is in uploading state while deleting.

Closes-Bug: #1733289
Change-Id: I6ef1c05760a27a0b3620024003b49328c55f19a6
tags/16.0.0.0rc1
Abhishek Kekane 2 years ago
parent
commit
7eb2fcc865
3 changed files with 28 additions and 0 deletions
  1. +7
    -0
      glance/api/v2/images.py
  2. +3
    -0
      glance/tests/unit/utils.py
  3. +18
    -0
      glance/tests/unit/v2/test_images_resource.py

+ 7
- 0
glance/api/v2/images.py View File

@@ -265,6 +265,13 @@ class ImagesController(object):
image_repo = self.gateway.get_repo(req.context)
try:
image = image_repo.get(image_id)

# NOTE(abhishekk): If 'image-import' is supported and image status
# is uploading then delete image data from the staging area.
if CONF.enable_image_import and image.status == 'uploading':
file_path = str(CONF.node_staging_uri + '/' + image.image_id)
self.store_api.delete_from_backend(file_path)

image.delete()
image_repo.remove(image)
except (glance_store.Forbidden, exception.Forbidden) as e:


+ 3
- 0
glance/tests/unit/utils.py View File

@@ -224,6 +224,9 @@ class FakeStoreAPI(object):
def check_location_metadata(self, val, key=''):
store.check_location_metadata(val)

def delete_from_backend(self, uri, context=None):
pass


class FakePolicyEnforcer(object):
def __init__(self, *_args, **kwargs):


+ 18
- 0
glance/tests/unit/v2/test_images_resource.py View File

@@ -2175,6 +2175,24 @@ class TestImagesController(base.IsolatedUnitTest):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
request, UUID1)

def test_delete_uploading_status_image(self):
"""Ensure status of uploading image is updated (LP bug #1733289)"""
self.config(enable_image_import=True)
request = unit_test_utils.get_fake_request(is_admin=True)
image = self.db.image_create(request.context, {'status': 'uploading'})
image_id = image['id']
with mock.patch.object(self.store,
'delete_from_backend') as mock_store:
self.controller.delete(request, image_id)

# Ensure delete_from_backend is called
self.assertEqual(1, mock_store.call_count)

image = self.db.image_get(request.context, image_id,
force_show_deleted=True)
self.assertTrue(image['deleted'])
self.assertEqual('deleted', image['status'])

def test_index_with_invalid_marker(self):
fake_uuid = str(uuid.uuid4())
request = unit_test_utils.get_fake_request()


Loading…
Cancel
Save