diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-11-09 19:59:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-11-09 19:59:47 +0000 |
| commit | 2bf0dad68bac912e94854810e3ea3968be7c0e70 (patch) | |
| tree | 02962a76e35d854e1900a708d058355058467885 | |
| parent | 9088c89a54222d187978dd1576651c5959fa98a9 (diff) | |
| parent | 98d30423b31894265342693d618820425382add3 (diff) | |
Merge "Refactor logging_error into utils"
| -rw-r--r-- | .mailmap | 1 | ||||
| -rw-r--r-- | nova/compute/manager.py | 20 | ||||
| -rw-r--r-- | nova/utils.py | 13 |
3 files changed, 23 insertions, 11 deletions
@@ -1,6 +1,7 @@ # Format is: # <preferred e-mail> <other e-mail 1> # <preferred e-mail> <other e-mail 2> +<aaron.lee@rackspace.com> <wwkeyboard@gmail.com> <anotherjesse@gmail.com> <jesse@dancelamb> <anotherjesse@gmail.com> <jesse@gigantor.local> <anotherjesse@gmail.com> <jesse@ubuntu> diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 660824d2e..76a8ab7f6 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 655be744d..0023442b1 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. |
