Merge "When re-raising exceptions, use save_and_reraise"
This commit is contained in:
commit
17974cef1c
|
@ -16,6 +16,7 @@
|
|||
from oslo.config import cfg
|
||||
|
||||
from glance.common import exception
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -41,11 +42,11 @@ def size_checked_iter(response, image_meta, expected_size, image_iter,
|
|||
yield chunk
|
||||
bytes_written += len(chunk)
|
||||
except Exception as err:
|
||||
msg = (_("An error occurred reading from backend storage "
|
||||
"for image %(image_id)s: %(err)s") % {'image_id': image_id,
|
||||
with excutils.save_and_reraise_exception():
|
||||
msg = (_("An error occurred reading from backend storage for "
|
||||
"image %(image_id)s: %(err)s") % {'image_id': image_id,
|
||||
'err': err})
|
||||
LOG.error(msg)
|
||||
raise
|
||||
LOG.error(msg)
|
||||
|
||||
if expected_size != bytes_written:
|
||||
msg = (_("Backend storage for image %(image_id)s "
|
||||
|
|
|
@ -40,6 +40,7 @@ from glance.common import property_utils
|
|||
from glance.common import utils
|
||||
from glance.common import wsgi
|
||||
from glance import notifier
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import strutils
|
||||
import glance.registry.client.v1.api as registry
|
||||
|
@ -631,15 +632,14 @@ class Controller(controller.BaseController):
|
|||
self.notifier.info("image.update", redact_loc(image_meta_data))
|
||||
return image_meta_data
|
||||
except exception.Duplicate:
|
||||
# Delete image data since it has been supersceded by another
|
||||
# upload.
|
||||
LOG.debug(_("duplicate operation - deleting image data for %(id)s "
|
||||
"(location:%(location)s)") %
|
||||
{'id': image_id, 'location': image_meta['location']})
|
||||
upload_utils.initiate_deletion(req, image_meta['location'],
|
||||
image_id, CONF.delayed_delete)
|
||||
# Then propagate the exception.
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
# Delete image data since it has been supersceded by another
|
||||
# upload and re-raise.
|
||||
LOG.debug(_("duplicate operation - deleting image data for "
|
||||
" %(id)s (location:%(location)s)") %
|
||||
{'id': image_id, 'location': image_meta['location']})
|
||||
upload_utils.initiate_deletion(req, image_meta['location'],
|
||||
image_id, CONF.delayed_delete)
|
||||
except exception.Invalid as e:
|
||||
msg = _("Failed to activate image. Got error: %(e)s") % {'e': e}
|
||||
LOG.debug(msg)
|
||||
|
|
|
@ -104,10 +104,11 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
|
|||
glance.api.common.check_quota(
|
||||
req.context, size, db_api, image_id=image_id)
|
||||
except exception.StorageQuotaFull:
|
||||
LOG.info(_('Cleaning up %s after exceeding the quota') % image_id)
|
||||
glance.store.safe_delete_from_backend(
|
||||
location, req.context, image_meta['id'])
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.info(_('Cleaning up %s after exceeding '
|
||||
'the quota') % image_id)
|
||||
glance.store.safe_delete_from_backend(
|
||||
location, req.context, image_meta['id'])
|
||||
|
||||
def _kill_mismatched(image_meta, attr, actual):
|
||||
supplied = image_meta.get(attr)
|
||||
|
|
|
@ -22,6 +22,7 @@ from glance.common import wsgi
|
|||
import glance.db
|
||||
import glance.gateway
|
||||
import glance.notifier
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
import glance.store
|
||||
|
||||
|
@ -132,15 +133,15 @@ class ImageDataController(object):
|
|||
request=req)
|
||||
|
||||
except webob.exc.HTTPError as e:
|
||||
LOG.error(_("Failed to upload image data due to HTTP error"))
|
||||
self._restore(image_repo, image)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(_("Failed to upload image data due to HTTP error"))
|
||||
self._restore(image_repo, image)
|
||||
|
||||
except Exception as e:
|
||||
LOG.exception(_("Failed to upload image data due to "
|
||||
"internal error"))
|
||||
self._restore(image_repo, image)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_("Failed to upload image data due to "
|
||||
"internal error"))
|
||||
self._restore(image_repo, image)
|
||||
|
||||
def download(self, req, image_id):
|
||||
image_repo = self.gateway.get_repo(req.context)
|
||||
|
|
|
@ -38,6 +38,7 @@ from oslo.config import cfg
|
|||
from webob import exc
|
||||
|
||||
from glance.common import exception
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import strutils
|
||||
|
||||
|
@ -100,9 +101,9 @@ def cooperative_iter(iter):
|
|||
sleep(0)
|
||||
yield chunk
|
||||
except Exception as err:
|
||||
msg = _("Error: cooperative_iter exception %s") % err
|
||||
LOG.error(msg)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
msg = _("Error: cooperative_iter exception %s") % err
|
||||
LOG.error(msg)
|
||||
|
||||
|
||||
def cooperative_read(fd):
|
||||
|
@ -455,8 +456,8 @@ def setup_remote_pydev_debug(host, port):
|
|||
stderrToServer=True)
|
||||
return True
|
||||
except Exception:
|
||||
LOG.exception(error_msg)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(error_msg)
|
||||
|
||||
|
||||
class LazyPluggable(object):
|
||||
|
|
|
@ -23,6 +23,7 @@ from oslo.config import cfg
|
|||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import importutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import units
|
||||
|
@ -255,10 +256,10 @@ class ImageCache(object):
|
|||
raise exception.GlanceException(msg)
|
||||
|
||||
except exception.GlanceException as e:
|
||||
# image_iter has given us bad, (size_checked_iter has found a
|
||||
# bad length), or corrupt data (checksum is wrong).
|
||||
LOG.exception(e)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
# image_iter has given us bad, (size_checked_iter has found a
|
||||
# bad length), or corrupt data (checksum is wrong).
|
||||
LOG.exception(e)
|
||||
except Exception as e:
|
||||
LOG.exception(_("Exception encountered while tee'ing "
|
||||
"image '%(image_id)s' into cache: %(error)s. "
|
||||
|
|
|
@ -30,6 +30,7 @@ import sqlite3
|
|||
|
||||
from glance.common import exception
|
||||
from glance.image_cache.drivers import base
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -340,8 +341,8 @@ class Driver(base.Driver):
|
|||
with open(incomplete_path, 'wb') as cache_file:
|
||||
yield cache_file
|
||||
except Exception as e:
|
||||
rollback(e)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
rollback(e)
|
||||
else:
|
||||
commit()
|
||||
finally:
|
||||
|
|
|
@ -64,6 +64,7 @@ import xattr
|
|||
|
||||
from glance.common import exception
|
||||
from glance.image_cache.drivers import base
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -297,8 +298,8 @@ class Driver(base.Driver):
|
|||
with open(incomplete_path, 'wb') as cache_file:
|
||||
yield cache_file
|
||||
except Exception as e:
|
||||
rollback(e)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
rollback(e)
|
||||
else:
|
||||
commit()
|
||||
finally:
|
||||
|
|
|
@ -20,6 +20,7 @@ import webob
|
|||
|
||||
from glance.common import exception
|
||||
import glance.domain.proxy
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import timeutils
|
||||
|
||||
|
@ -271,19 +272,19 @@ class ImageProxy(glance.domain.proxy.Image):
|
|||
self.notifier.error('image.upload', msg)
|
||||
raise webob.exc.HTTPNotFound(explanation=unicode(e))
|
||||
except webob.exc.HTTPError as e:
|
||||
msg = (_("Failed to upload image data for image %(image_id)s"
|
||||
" due to HTTP error: %(error)s") %
|
||||
{'image_id': self.image.image_id,
|
||||
'error': e})
|
||||
self.notifier.error('image.upload', msg)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
msg = (_("Failed to upload image data for image %(image_id)s"
|
||||
" due to HTTP error: %(error)s") %
|
||||
{'image_id': self.image.image_id,
|
||||
'error': e})
|
||||
self.notifier.error('image.upload', msg)
|
||||
except Exception as e:
|
||||
msg = (_("Failed to upload image data for image %(image_id)s "
|
||||
"due to internal error: %(error)s") %
|
||||
{'image_id': self.image.image_id,
|
||||
'error': e})
|
||||
self.notifier.error('image.upload', msg)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
msg = (_("Failed to upload image data for image %(image_id)s "
|
||||
"due to internal error: %(error)s") %
|
||||
{'image_id': self.image.image_id,
|
||||
'error': e})
|
||||
self.notifier.error('image.upload', msg)
|
||||
else:
|
||||
payload = format_image_notification(self.image)
|
||||
self.notifier.info('image.upload', payload)
|
||||
|
|
|
@ -21,6 +21,7 @@ import glance.common.exception as exception
|
|||
from glance.common import utils
|
||||
import glance.domain
|
||||
import glance.domain.proxy
|
||||
from glance.openstack.common import excutils
|
||||
import glance.openstack.common.log as logging
|
||||
|
||||
|
||||
|
@ -313,12 +314,12 @@ class ImageProxy(glance.domain.proxy.Image):
|
|||
self.context, self.image.size, self.db_api,
|
||||
image_id=self.image.image_id)
|
||||
except exception.StorageQuotaFull:
|
||||
LOG.info(_('Cleaning up %s after exceeding the quota.')
|
||||
% self.image.image_id)
|
||||
location = self.image.locations[0]['url']
|
||||
glance.store.safe_delete_from_backend(
|
||||
self.context, location, self.image.image_id)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.info(_('Cleaning up %s after exceeding the quota.')
|
||||
% self.image.image_id)
|
||||
location = self.image.locations[0]['url']
|
||||
glance.store.safe_delete_from_backend(
|
||||
self.context, location, self.image.image_id)
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
|
|
|
@ -20,6 +20,7 @@ the Glance Registry API
|
|||
|
||||
from glance.common.client import BaseClient
|
||||
from glance.common import crypt
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import jsonutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.registry.api.v1 import images
|
||||
|
@ -114,12 +115,12 @@ class RegistryClient(BaseClient):
|
|||
LOG.debug(msg)
|
||||
|
||||
except Exception as exc:
|
||||
exc_name = exc.__class__.__name__
|
||||
LOG.info(_("Registry client request %(method)s %(action)s "
|
||||
"raised %(exc_name)s"),
|
||||
{'method': method, 'action': action,
|
||||
'exc_name': exc_name})
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
exc_name = exc.__class__.__name__
|
||||
LOG.info(_("Registry client request %(method)s %(action)s "
|
||||
"raised %(exc_name)s"),
|
||||
{'method': method, 'action': action,
|
||||
'exc_name': exc_name})
|
||||
return res
|
||||
|
||||
def get_images_detailed(self, **kwargs):
|
||||
|
|
|
@ -24,6 +24,7 @@ from glance.common import exception
|
|||
from glance.common import utils
|
||||
import glance.context
|
||||
import glance.domain.proxy
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import importutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance import scrubber
|
||||
|
@ -556,8 +557,8 @@ class StoreLocations(collections.MutableSequence):
|
|||
self.image_proxy.image.image_id,
|
||||
location['url'])
|
||||
except Exception:
|
||||
self.value.insert(i, location)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.value.insert(i, location)
|
||||
return location
|
||||
|
||||
def count(self, location):
|
||||
|
|
|
@ -27,6 +27,7 @@ import six.moves.urllib.parse as urlparse
|
|||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import jsonutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import processutils
|
||||
|
@ -441,8 +442,8 @@ class Store(glance.store.base.Store):
|
|||
errno.EACCES: exception.StorageWriteDenied()}
|
||||
raise exceptions.get(e.errno, e)
|
||||
except Exception:
|
||||
self._delete_partial(filepath, image_id)
|
||||
raise
|
||||
with excutils.save_and_reraise_exception():
|
||||
self._delete_partial(filepath, image_id)
|
||||
|
||||
checksum_hex = checksum.hexdigest()
|
||||
metadata = self._get_metadata()
|
||||
|
|
Loading…
Reference in New Issue