Add back in instance to logging entries

In a previous commit, I erroneously deleted the instance=instance dict
entry from some of the logging calls, not realising they were a feature
of oslo.logging.  This commit puts them back, and adds them in a few
more useful places for debuggin purposes.

Change-Id: I0a1be5a46a888db9f0782db90815a74d50ead298
This commit is contained in:
Alex Kavanagh 2018-06-06 11:12:16 +01:00 committed by Alex Kavanagh (tinwood)
parent 33a55bc978
commit dbe0846b60
3 changed files with 30 additions and 20 deletions

View File

@ -125,7 +125,8 @@ def _last_bytes(file_like_object, num):
def _neutron_failed_callback(event_name, instance):
LOG.error("Neutron Reported failure on event "
"{event} for instance {uuid}"
.format(event=event_name, uuid=instance.name))
.format(event=event_name, uuid=instance.name),
instance=instance)
if CONF.vif_plugging_is_fatal:
raise exception.VirtualInterfaceCreateException()
@ -1275,7 +1276,7 @@ class LXDDriver(driver.ComputeDriver):
except processutils.ProcessExecutionError as e:
with excutils.save_and_reraise_exception():
LOG.error("Creating config drive failed with error: {}"
.format(e))
.format(e), instance=instance)
configdrive_dir = os.path.join(
nova.conf.CONF.instances_path, instance.name, 'configdrive')

View File

@ -74,7 +74,8 @@ class LXDAPISession(object):
try:
LOG.info("Creating container {instance} with {image}"
.format(instance=instance.name,
image=instance.image_ref))
image=instance.image_ref),
instance=instance)
client = self.get_session(host=host)
(state, data) = client.container_init(config)
@ -88,7 +89,8 @@ class LXDAPISession(object):
LOG.info("Successfully created container {instance} with {image}"
.format(instance=instance.name,
image=instance.image_ref))
image=instance.image_ref),
instance=instance)
except lxd_exceptions.APIError as ex:
msg = (_("Failed to communicate with LXD API {instance}: {reason}")
.format(instance=instance.name, reason=ex))
@ -96,7 +98,8 @@ class LXDAPISession(object):
except Exception as ex:
with excutils.save_and_reraise_exception():
LOG.error("Failed to create container {instance}: {reason}"
.format(instance=instance.name, reason=ex))
.format(instance=instance.name, reason=ex),
instance=instance)
#
# Operation methods
@ -108,7 +111,7 @@ class LXDAPISession(object):
:param operation_id: The operation to wait for.
:param instance: nova instace object
"""
LOG.debug("wait_for_container for instance: {}".format(instance))
LOG.debug("wait_for_container for instance", instance=instance)
try:
client = self.get_session(host=host)
if not client.wait_container_operation(operation_id, 200, -1):
@ -118,7 +121,7 @@ class LXDAPISession(object):
msg = _("Failed to communicate with LXD API {instance}: "
"{reason}").format(instance=instance.image_ref,
reason=ex)
LOG.error(msg)
LOG.error(msg, instance=instance)
raise exception.NovaException(msg)
except Exception as e:
with excutils.save_and_reraise_exception():
@ -127,7 +130,7 @@ class LXDAPISession(object):
.format(instance=instance.image_ref, reason=e))
def operation_info(self, operation_id, instance, host=None):
LOG.debug("operation_info called for instance {}".format(instance))
LOG.debug("operation_info called for instance", instance=instance)
try:
client = self.get_session(host=host)
return client.operation_info(operation_id)
@ -135,7 +138,7 @@ class LXDAPISession(object):
msg = _("Failed to communicate with LXD API {instance}:"
" {reason}").format(instance=instance.image_ref,
reason=ex)
LOG.error(msg)
LOG.error(msg, instance=instance)
raise exception.NovaException(msg)
except Exception as e:
with excutils.save_and_reraise_exception():
@ -155,7 +158,7 @@ class LXDAPISession(object):
:return: dictionary of the container keys
"""
LOG.debug("container_migrate called for instance {}".format(instance))
LOG.debug("container_migrate called for instance", instance=instance)
try:
LOG.info("Migrating instance {instance} with {image}"
.format(instance=instance_name,

View File

@ -161,15 +161,18 @@ def _post_plug_wiring(instance, vif):
:type vif: :class:`nova.network.model.VIF`
"""
LOG.debug("Performing post plug wiring for VIF {}".format(vif))
LOG.debug("Performing post plug wiring for VIF {}".format(vif),
instance=instance)
vif_type = vif['type']
try:
POST_PLUG_WIRING[vif_type](instance, vif)
LOG.debug("Post plug wiring step for VIF {} done".format(vif))
LOG.debug("Post plug wiring step for VIF {} done".format(vif),
instance=instance)
except KeyError:
LOG.debug("No post plug wiring step "
"for vif type: {}".format(vif_type))
"for vif type: {}".format(vif_type),
instance=instance)
# VIF_TYPE_OVS = 'ovs'
@ -191,8 +194,8 @@ def _post_unplug_wiring_delete_veth(instance, vif):
else:
network_utils.delete_net_dev(v1_name)
except processutils.ProcessExecutionError:
LOG.exception("Failed to delete veth for vif",
vif=vif)
LOG.exception("Failed to delete veth for vif {}".foramt(vif),
instance=instance)
POST_UNPLUG_WIRING = {
@ -213,15 +216,18 @@ def _post_unplug_wiring(instance, vif):
:type vif: :class:`nova.network.model.VIF`
"""
LOG.debug("Performing post unplug wiring for VIF {}".format(vif))
LOG.debug("Performing post unplug wiring for VIF {}".format(vif),
instance=instance)
vif_type = vif['type']
try:
POST_UNPLUG_WIRING[vif_type](instance, vif)
LOG.debug("Post unplug wiring for VIF {} done".format(vif))
LOG.debug("Post unplug wiring for VIF {} done".format(vif),
instance=instance)
except KeyError:
LOG.debug("No post unplug wiring step "
"for vif type: {}".format(vif_type))
"for vif type: {}".format(vif_type),
instance=instance)
class LXDGenericVifDriver(object):
@ -288,5 +294,5 @@ class LXDGenericVifDriver(object):
try:
network_utils.delete_net_dev(dev)
except processutils.ProcessExecutionError:
LOG.exception("Failed while unplugging vif for instance: {}"
.format(instance))
LOG.exception("Failed while unplugging vif for instance",
instance=instance)