Fix log message interpolation bugs

Apparently, variable interpolation in the log
messages turned out to be buggy and inconsistent.
This patch hopefully fixes all such issues and unifies
interpolation code across the project.

Change-Id: If49fd2d3c012a1792fe978c77a216a52fc52f6bf
This commit is contained in:
Ilya Etingof 2018-08-01 12:49:07 +02:00
parent cad28ace17
commit 9ebc73b63b
4 changed files with 37 additions and 30 deletions

View File

@ -310,9 +310,9 @@ class VirtualBMCApp(App):
self.zmq = ZmqClient()
def clean_up(self, cmd, result, err):
self.LOG.debug('clean_up %s', cmd.__class__.__name__)
self.LOG.debug('clean_up %(name)s', {'name': cmd.__class__.__name__})
if err:
self.LOG.debug('got an error: %s', err)
self.LOG.debug('got an error: %(error)s', {'error': err})
def main(argv=sys.argv[1:]):

View File

@ -55,7 +55,7 @@ def main(argv=sys.argv[1:]):
pass
else:
LOG.error('server PID #%(pid)d still running' % {'pid': pid})
LOG.error('server PID #%(pid)d still running', {'pid': pid})
return 1
def wrap_with_pidfile(func, pid):

View File

@ -128,8 +128,8 @@ class VirtualBMCManager(object):
except Exception as ex:
LOG.error(
'Error running vBMC with configuration '
'%(opts)s: %(error)s' % {'opts': show_options,
'error': ex}
'%(opts)s: %(error)s', {'opts': show_options,
'error': ex}
)
return
@ -139,8 +139,8 @@ class VirtualBMCManager(object):
except Exception as ex:
LOG.info(
'Shutdown vBMC for domain %(domain)s, cause '
'%(error)s' % {'domain': show_options['domain_name'],
'error': ex}
'%(error)s', {'domain': show_options['domain_name'],
'error': ex}
)
return
@ -182,7 +182,7 @@ class VirtualBMCManager(object):
LOG.info(
'Started vBMC instance for domain '
'%(domain)s' % {'domain': domain_name}
'%(domain)s', {'domain': domain_name}
)
else:
@ -191,15 +191,15 @@ class VirtualBMCManager(object):
instance.terminate()
LOG.info(
'Terminated vBMC instance for domain '
'%(domain)s' % {'domain': domain_name}
'%(domain)s', {'domain': domain_name}
)
if instance and not instance.is_alive():
del self._running_domains[domain_name]
LOG.debug(
'Reaped vBMC instance for domain %(domain)s '
'(rc %(rc)s)' % {'domain': domain_name,
'rc': instance.exitcode}
'(rc %(rc)s)', {'domain': domain_name,
'rc': instance.exitcode}
)
def _show(self, domain_name):

View File

@ -62,7 +62,8 @@ class VirtualBMC(bmc.Bmc):
'sasl_password': libvirt_sasl_password}
def get_boot_device(self):
LOG.debug('Get boot device called for %s', self.domain_name)
LOG.debug('Get boot device called for %(domain)s',
{'domain': self.domain_name})
with utils.libvirt_open(readonly=True, **self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
boot_element = ET.fromstring(domain.XMLDesc()).find('.//os/boot')
@ -115,7 +116,8 @@ class VirtualBMC(bmc.Bmc):
return IPMI_COMMAND_NODE_BUSY
def get_power_state(self):
LOG.debug('Get power state called for domain %s', self.domain_name)
LOG.debug('Get power state called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(readonly=True, **self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -123,15 +125,16 @@ class VirtualBMC(bmc.Bmc):
return POWERON
except libvirt.libvirtError as e:
msg = ('Error getting the power state of domain %(domain)s. '
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
LOG.error(msg)
raise exception.VirtualBMCError(message=msg)
return POWEROFF
def pulse_diag(self):
LOG.debug('Power diag called for domain %s', self.domain_name)
LOG.debug('Power diag called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -139,13 +142,14 @@ class VirtualBMC(bmc.Bmc):
domain.injectNMI()
except libvirt.libvirtError as e:
LOG.error('Error powering diag the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
# Command failed, but let client to retry
return IPMI_COMMAND_NODE_BUSY
def power_off(self):
LOG.debug('Power off called for domain %s', self.domain_name)
LOG.debug('Power off called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -153,13 +157,14 @@ class VirtualBMC(bmc.Bmc):
domain.destroy()
except libvirt.libvirtError as e:
LOG.error('Error powering off the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
# Command failed, but let client to retry
return IPMI_COMMAND_NODE_BUSY
def power_on(self):
LOG.debug('Power on called for domain %s', self.domain_name)
LOG.debug('Power on called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -167,13 +172,14 @@ class VirtualBMC(bmc.Bmc):
domain.create()
except libvirt.libvirtError as e:
LOG.error('Error powering on the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
# Command failed, but let client to retry
return IPMI_COMMAND_NODE_BUSY
def power_shutdown(self):
LOG.debug('Soft power off called for domain %s', self.domain_name)
LOG.debug('Soft power off called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -181,13 +187,14 @@ class VirtualBMC(bmc.Bmc):
domain.shutdown()
except libvirt.libvirtError as e:
LOG.error('Error soft powering off the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
# Command failed, but let client to retry
return IPMI_COMMAND_NODE_BUSY
def power_reset(self):
LOG.debug('Power reset called for domain %s', self.domain_name)
LOG.debug('Power reset called for domain %(domain)s',
{'domain': self.domain_name})
try:
with utils.libvirt_open(**self._conn_args) as conn:
domain = utils.get_libvirt_domain(conn, self.domain_name)
@ -195,7 +202,7 @@ class VirtualBMC(bmc.Bmc):
domain.reset()
except libvirt.libvirtError as e:
LOG.error('Error reseting the domain %(domain)s. '
'Error: %(error)s' % {'domain': self.domain_name,
'error': e})
'Error: %(error)s', {'domain': self.domain_name,
'error': e})
# Command not supported in present state
return IPMI_COMMAND_NODE_BUSY