Merge "Swift store add should not use wildcard raise"

This commit is contained in:
Jenkins 2013-10-07 18:48:52 +00:00 committed by Gerrit Code Review
commit 4c64bf1f0f
2 changed files with 34 additions and 6 deletions

View File

@ -29,6 +29,7 @@ from oslo.config import cfg
from glance.common import auth
from glance.common import exception
from glance.openstack.common import excutils
import glance.openstack.common.log as logging
import glance.store
import glance.store.base
@ -385,12 +386,12 @@ class BaseStore(glance.store.base.Store):
written_chunks.append(chunk_name)
except Exception:
# Delete orphaned segments from swift backend
LOG.exception(_("Error during chunked upload to "
"backend, deleting stale chunks"))
self._delete_stale_chunks(connection,
location.container,
written_chunks)
raise
with excutils.save_and_reraise_exception():
LOG.exception(_("Error during chunked upload to "
"backend, deleting stale chunks"))
self._delete_stale_chunks(connection,
location.container,
written_chunks)
bytes_read = reader.bytes_read
msg = _("Wrote chunk %(chunk_name)s (%(chunk_id)d/"

View File

@ -19,6 +19,7 @@
import hashlib
import httplib
import mock
import StringIO
import tempfile
import urllib
@ -545,6 +546,32 @@ class SwiftTests(object):
self.store.add,
FAKE_UUID, image_swift, 0)
def test_add_saves_and_reraises_and_not_uses_wildcard_raise(self):
image_id = uuidutils.generate_uuid()
swift_size = self.store.large_object_size = 1024
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
swift_contents = "*" * swift_size
connection = mock.Mock()
def fake_delete_chunk(connection,
container,
chunks):
try:
raise Exception()
except Exception:
pass
image_swift = StringIO.StringIO(swift_contents)
connection.put_object.side_effect = exception.ClientConnectionError
self.store._delete_stale_chunks = fake_delete_chunk
self.assertRaises(exception.ClientConnectionError,
self.store.add,
image_id,
image_swift,
swift_size,
connection)
def _option_required(self, key):
conf = self.getConfig()
conf[key] = None