summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Lee <wwkeyboard@gmail.com>2011-11-08 20:23:14 -0600
committerAaron Lee <aaron.lee@rackspace.com>2011-11-09 11:49:52 -0600
commit98d30423b31894265342693d618820425382add3 (patch)
treef32c43f6327e8b0eff5f98400869905343be83b1
parent00861098508fc675ba2d90a5c34fec152ddf5c3d (diff)
downloadnova-98d30423b31894265342693d618820425382add3.tar.gz
nova-98d30423b31894265342693d618820425382add3.tar.xz
nova-98d30423b31894265342693d618820425382add3.zip
Refactor logging_error into utils
update: pep8, and fixing log output. update2: more pep8, I'm looking at you vim update3: more formating update4: mailmap update5: more pep8 Change-Id: I38617e14260e65ed5cb81b3554479d3720850aae
-rw-r--r--.mailmap1
-rw-r--r--nova/compute/manager.py20
-rw-r--r--nova/utils.py13
3 files changed, 23 insertions, 11 deletions
diff --git a/.mailmap b/.mailmap
index f081ccf1b..2bbc329fc 100644
--- a/.mailmap
+++ b/.mailmap
@@ -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.