Skip to content

Commit

Permalink
Swallow exception on unsupported image deletion.
Browse files Browse the repository at this point in the history
Fixes LP #912897

When the remote store does not support deletion of images (e.g. HTTP)
the StoreDeleteNotSupported exception is now swallowed and logged as
opposed to it being propagated back to the glance CLI.

Also after a failed delete, we avoid falling through to the delayed
delete logic.

Change-Id: I6cc529f029750fc66a4d32e2076f29198b3d2093
  • Loading branch information
Eoghan Glynn committed Jan 19, 2012
1 parent b712949 commit 41b981c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
12 changes: 10 additions & 2 deletions glance/store/__init__.py
Expand Up @@ -18,6 +18,7 @@
import logging
import optparse
import os
import sys
import time
import urlparse

Expand Down Expand Up @@ -188,9 +189,16 @@ def schedule_delete_from_backend(uri, conf, context, image_id, **kwargs):
{'status': 'deleted'})
try:
return delete_from_backend(uri, **kwargs)
except (UnsupportedBackend, exception.NotFound):
msg = _("Failed to delete image from store (%(uri)s).") % locals()
except (UnsupportedBackend,
exception.StoreDeleteNotSupported,
exception.NotFound):
exc_type = sys.exc_info()[0].__name__
msg = _("Failed to delete image at %s from store (%s)") % \
(uri, exc_type)
logger.error(msg)
finally:
# avoid falling through to the delayed deletion logic
return

datadir = get_scrubber_datadir(conf)
delete_time = time.time() + conf.scrub_time
Expand Down
35 changes: 32 additions & 3 deletions glance/tests/unit/test_http_store.py
Expand Up @@ -20,11 +20,14 @@

import stubout

from glance.common import exception
from glance.store import create_stores, delete_from_backend
from glance.common import exception, context
from glance.registry.db import api as db_api
from glance.store import (create_stores,
delete_from_backend,
schedule_delete_from_backend)
from glance.store.http import Store
from glance.store.location import get_location_from_uri
from glance.tests import utils
from glance.tests import utils, stubs as test_stubs


def stub_out_http_backend(stubs):
Expand Down Expand Up @@ -70,6 +73,20 @@ def fake_get_conn_class(self, *args, **kwargs):
stubs.Set(Store, '_get_conn_class', fake_get_conn_class)


def stub_out_registry_image_update(stubs):
"""
Stubs an image update on the registry.
:param stubs: Set of stubout stubs
"""
test_stubs.stub_out_registry_server(stubs)

def fake_image_update(ctx, image_id, values, purge_props=False):
return {'properties': {}}

stubs.Set(db_api, 'image_update', fake_image_update)


class TestHttpStore(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -108,3 +125,15 @@ def test_http_delete_raise_error(self):
create_stores(utils.TestConfigOpts({}))
self.assertRaises(exception.StoreDeleteNotSupported,
delete_from_backend, uri)

def test_http_schedule_delete_swallows_error(self):
stub_out_registry_image_update(self.stubs)
uri = "https://netloc/path/to/file.tar.gz"
ctx = context.RequestContext()
conf = utils.TestConfigOpts({})
create_stores(conf)

try:
schedule_delete_from_backend(uri, conf, ctx, 'image_id')
except exception.StoreDeleteNotSupported:
self.fail('StoreDeleteNotSupported should be swallowed')

0 comments on commit 41b981c

Please sign in to comment.