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
This commit is contained in:
parent
0086109850
commit
98d30423b3
1
.mailmap
1
.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>
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user