diff --git a/.mailmap b/.mailmap index f081ccf1bb61..2bbc329fceab 100644 --- a/.mailmap +++ b/.mailmap @@ -1,6 +1,7 @@ # Format is: # # + diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 660824d2e60a..76a8ab7f60a9 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -409,14 +409,9 @@ class ComputeManager(manager.SchedulerDependentManager): if network_info is not None: _deallocate_network() - @contextlib.contextmanager - def _logging_error(instance_id, message): - try: - yield - except Exception as error: - with utils.save_and_reraise_exception(): - LOG.exception(_("Instance '%(instance_id)s' " - "failed %(message)s.") % locals()) + def _error_message(instance_id, message): + return _("Instance '%(instance_id)s' " + "failed %(message)s.") % locals() context = context.elevated() instance = self.db.instance_get(context, instance_id) @@ -444,14 +439,16 @@ class ComputeManager(manager.SchedulerDependentManager): is_vpn = instance['image_ref'] == str(FLAGS.vpn_image_id) try: network_info = None - with _logging_error(instance_id, "network setup"): + with utils.logging_error(_error_message(instance_id, + "network setup")): network_info = _make_network_info() self._instance_update(context, instance_id, vm_state=vm_states.BUILDING, task_state=task_states.BLOCK_DEVICE_MAPPING) - with _logging_error(instance_id, "block device setup"): + with utils.logging_error(_error_message(instance_id, + "block device setup")): block_device_info = _make_block_device_info() self._instance_update(context, @@ -460,7 +457,8 @@ class ComputeManager(manager.SchedulerDependentManager): task_state=task_states.SPAWNING) # TODO(vish) check to make sure the availability zone matches - with _logging_error(instance_id, "failed to spawn"): + with utils.logging_error(_error_message(instance_id, + "failed to spawn")): self.driver.spawn(context, instance, image_meta, network_info, block_device_info) diff --git a/nova/utils.py b/nova/utils.py index 655be744d9d2..0023442b1b1b 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1002,6 +1002,19 @@ def save_and_reraise_exception(): raise type_, value, traceback +@contextlib.contextmanager +def logging_error(message): + """Catches exception, write message to the log, re-raise. + This is a common refinement of save_and_reraise that writes a specific + message to the log. + """ + try: + yield + except Exception as error: + with save_and_reraise_exception(): + LOG.exception(message) + + def make_dev_path(dev, partition=None, base='/dev'): """Return a path to a particular device.