From 432e04aa1a54cccae2c68803473164b780c5dd53 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Tue, 7 Feb 2012 13:31:52 +1100 Subject: Pass instance to log messages. This patch converts more log messages to passing their instance. Having the instance in a consistant format in the logs makes it easier for operations staff to debug instance problems. Change-Id: I842f26309e17c0923e71fbfb00bdcdb033f92297 --- nova/tests/test_virt_drivers.py | 3 ++- nova/virt/libvirt/connection.py | 47 ++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 58d295a6f..3ec2155cf 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -211,7 +211,8 @@ class _VirtDriverTestCase(test.TestCase): @catch_notimplementederror def test_destroy_instance_nonexistant(self): - fake_instance = {'id': 42, 'name': 'I just made this up!'} + fake_instance = {'id': 42, 'name': 'I just made this up!', + 'uuid': 'bda5fb9e-b347-40e8-8256-42397848cb00'} network_info = test_utils.get_test_network_info() self.connection.destroy(fake_instance, network_info) diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index eca954b76..2a65c89fb 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -346,10 +346,9 @@ class LibvirtConnection(driver.ComputeDriver): is_okay = True if not is_okay: - LOG.warning(_("Error from libvirt during destroy of " - "%(instance_name)s. Code=%(errcode)s " - "Error=%(e)s") % - locals()) + LOG.warning(_("Error from libvirt during destroy. " + "Code=%(errcode)s Error=%(e)s") % + locals(), instance=instance) raise try: @@ -360,8 +359,8 @@ class LibvirtConnection(driver.ComputeDriver): except libvirt.libvirtError as e: errcode = e.get_error_code() LOG.warning(_("Error from libvirt during saved instance " - "removal %(instance_name)s. Code=%(errcode)s" - " Error=%(e)s") % locals()) + "removal. Code=%(errcode)s Error=%(e)s") % + locals(), instance=instance) try: # NOTE(justinsb): We remove the domain definition. We probably @@ -370,10 +369,9 @@ class LibvirtConnection(driver.ComputeDriver): virt_dom.undefine() except libvirt.libvirtError as e: errcode = e.get_error_code() - LOG.warning(_("Error from libvirt during undefine of " - "%(instance_name)s. Code=%(errcode)s " - "Error=%(e)s") % - locals()) + LOG.warning(_("Error from libvirt during undefine. " + "Code=%(errcode)s Error=%(e)s") % + locals(), instance=instance) raise self.unplug_vifs(instance, network_info) @@ -385,8 +383,8 @@ class LibvirtConnection(driver.ComputeDriver): try: state = self.get_info(instance_name)['state'] except exception.NotFound: - msg = _("Instance %s destroyed successfully.") % instance_name - LOG.info(msg) + LOG.info(_("Instance destroyed successfully."), + instance=instance) raise utils.LoopingCallDone timer = utils.LoopingCall(_wait_for_destroy) @@ -416,18 +414,19 @@ class LibvirtConnection(driver.ComputeDriver): def _cleanup(self, instance): target = os.path.join(FLAGS.instances_path, instance['name']) instance_name = instance['name'] - LOG.info(_('instance %(instance_name)s: deleting instance files' - ' %(target)s') % locals()) + LOG.info(_('Deleting instance files %(target)s') % locals(), + instance=instance) if FLAGS.libvirt_type == 'lxc': disk.destroy_container(self.container) if os.path.exists(target): shutil.rmtree(target) - def get_volume_connector(self, _instance): + def get_volume_connector(self, instance): if not self._initiator: self._initiator = libvirt_utils.get_iscsi_initiator() if not self._initiator: - LOG.warn(_('Could not determine iscsi initiator name')) + LOG.warn(_('Could not determine iscsi initiator name'), + instance=instance) return { 'ip': FLAGS.my_ip, 'initiator': self._initiator, @@ -599,13 +598,13 @@ class LibvirtConnection(driver.ComputeDriver): try: state = self.get_info(instance_name)['state'] except exception.NotFound: - msg = _("During reboot, %s disappeared.") % instance_name - LOG.error(msg) + LOG.error(_("During reboot, instance disappeared."), + instance=instance) raise utils.LoopingCallDone if state == power_state.RUNNING: - msg = _("Instance %s rebooted successfully.") % instance_name - LOG.info(msg) + LOG.info(_("Instance rebooted successfully."), + instance=instance) raise utils.LoopingCallDone timer = utils.LoopingCall(_wait_for_reboot) @@ -703,7 +702,7 @@ class LibvirtConnection(driver.ComputeDriver): block_device_info=block_device_info) domain = self._create_new_domain(xml) - LOG.debug(_("instance is running"), instance=instance) + LOG.debug(_("Instance is running"), instance=instance) self.firewall_driver.apply_instance_filter(instance, network_info) def _wait_for_boot(): @@ -768,7 +767,7 @@ class LibvirtConnection(driver.ComputeDriver): fpath = self._append_to_file(data, console_log) elif FLAGS.libvirt_type == 'lxc': # LXC is also special - LOG.info(_("Unable to read LXC console")) + LOG.info(_("Unable to read LXC console"), instance=instance) else: fpath = console_log @@ -1244,11 +1243,11 @@ class LibvirtConnection(driver.ComputeDriver): def to_xml(self, instance, network_info, image_meta=None, rescue=False, block_device_info=None): # TODO(termie): cache? - LOG.debug(_('instance %s: starting toXML method'), instance['name']) + LOG.debug(_('Starting toXML method'), instance=instance) xml_info = self._prepare_xml_info(instance, network_info, image_meta, rescue, block_device_info) xml = str(Template(self.libvirt_xml, searchList=[xml_info])) - LOG.debug(_('instance %s: finished toXML method'), instance['name']) + LOG.debug(_('Finished toXML method'), instance=instance) return xml def _lookup_by_name(self, instance_name): -- cgit