From 1182e1ea9672506e330f2723ad4016cfa1936907 Mon Sep 17 00:00:00 2001 From: YuikoTakada Date: Mon, 16 Feb 2015 04:05:49 +0000 Subject: [PATCH] Support i18n part2 Currently, log format is not following to oslo.i18n. This patch set fixes log format to oslo.i18n Change-Id: I635bd261b84b2e8897bc93d8d2690f9fce4fbb9d Partial-Bug: #1411272 --- ironic_discoverd/firewall.py | 4 +- ironic_discoverd/introspect.py | 80 +++++++++++--------- ironic_discoverd/plugins/edeploy.py | 8 +- ironic_discoverd/plugins/root_device_hint.py | 12 +-- ironic_discoverd/plugins/standard.py | 25 +++--- ironic_discoverd/utils.py | 8 +- 6 files changed, 80 insertions(+), 57 deletions(-) diff --git a/ironic_discoverd/firewall.py b/ironic_discoverd/firewall.py index 62fb3adb5..2731a1f6c 100644 --- a/ironic_discoverd/firewall.py +++ b/ironic_discoverd/firewall.py @@ -16,6 +16,7 @@ import subprocess from eventlet import semaphore +from ironic_discoverd.common.i18n import _LE from ironic_discoverd import conf from ironic_discoverd import node_cache from ironic_discoverd import utils @@ -39,7 +40,8 @@ def _iptables(*args, **kwargs): if ignore: LOG.debug('ignoring failed iptables %s:\n%s', args, exc.output) else: - LOG.error('iptables %s failed:\n%s', args, exc.output) + LOG.error(_LE('iptables %(iptables)s failed:\n%(exc)s') % + {'iptables': args, 'exc': exc.output}) raise diff --git a/ironic_discoverd/introspect.py b/ironic_discoverd/introspect.py index e74285b38..0ece9a2b2 100644 --- a/ironic_discoverd/introspect.py +++ b/ironic_discoverd/introspect.py @@ -19,6 +19,9 @@ import string import eventlet from ironicclient import exceptions +from ironic_discoverd.common.i18n import _ +from ironic_discoverd.common.i18n import _LI +from ironic_discoverd.common.i18n import _LW from ironic_discoverd import conf from ironic_discoverd import firewall from ironic_discoverd import node_cache @@ -36,30 +39,30 @@ PASSWORD_MAX_LENGTH = 20 # IPMI v2.0 def _validate_ipmi_credentials(node, new_ipmi_credentials): if not conf.getboolean('discoverd', 'enable_setting_ipmi_credentials'): raise utils.Error( - 'IPMI credentials setup is disabled in configuration') + _('IPMI credentials setup is disabled in configuration')) if not node.maintenance: # Otherwise Ironic is going to interfer - raise utils.Error('Node should be in maintenance mode to set ' - 'IPMI credentials on it') + raise utils.Error(_('Node should be in maintenance mode to set ' + 'IPMI credentials on it')) new_username, new_password = new_ipmi_credentials if not new_username: new_username = node.driver_info.get('ipmi_username') if not new_username: - raise utils.Error('Setting IPMI credentials requested for node %s,' - ' but neither new user name nor' - ' driver_info[ipmi_username] are provided' + raise utils.Error(_('Setting IPMI credentials requested for node %s,' + ' but neither new user name nor' + ' driver_info[ipmi_username] are provided') % node.uuid) wrong_chars = {c for c in new_password if c not in PASSWORD_ACCEPTED_CHARS} if wrong_chars: - raise utils.Error('Forbidden characters encountered in new IPMI ' - 'password for node %s: "%s"; use only ' - 'letters and numbers' % - (node.uuid, ''.join(wrong_chars))) + raise utils.Error(_('Forbidden characters encountered in new IPMI ' + 'password for node %(node)s: "%(chars)s"; ' + 'use only letters and numbers') % + {'node': node.uuid, 'chars': ''.join(wrong_chars)}) if not 0 < len(new_password) <= PASSWORD_MAX_LENGTH: - raise utils.Error('IPMI password length should be > 0 and <= %d' + raise utils.Error(_('IPMI password length should be > 0 and <= %d') % PASSWORD_MAX_LENGTH) return new_username, new_password @@ -77,25 +80,27 @@ def introspect(uuid, new_ipmi_credentials=None): try: node = ironic.node.get(uuid) except exceptions.NotFound: - raise utils.Error("Cannot find node %s" % uuid, code=404) + raise utils.Error(_("Cannot find node %s") % uuid, code=404) except exceptions.HttpError as exc: - raise utils.Error("Cannot get node %s: %s" % (uuid, exc)) + raise utils.Error(_("Cannot get node %(node)s: %(exc)s") % + {'node': uuid, 'exc': exc}) if not node.maintenance: provision_state = node.provision_state if provision_state and provision_state.lower() not in VALID_STATES: - msg = ('Refusing to introspect node %s with provision state "%s" ' - 'and maintenance mode off') - raise utils.Error(msg % (node.uuid, provision_state)) + msg = _('Refusing to introspect node %(node)s with provision state' + ' "%(state)s" and maintenance mode off') + raise utils.Error(msg % {'node': node.uuid, + 'state': provision_state}) power_state = node.power_state if power_state and power_state.lower() not in VALID_POWER_STATES: - msg = ('Refusing to introspect node %s with power state "%s" ' - 'and maintenance mode off') - raise utils.Error(msg % (node.uuid, power_state)) + msg = _('Refusing to introspect node %(node)s with power state' + ' "%(state)s" and maintenance mode off') + raise utils.Error(msg % {'node': node.uuid, 'state': power_state}) else: - LOG.info('Node %s is in maintenance mode, skipping power and provision' - ' states check', node.uuid) + LOG.info(_LI('Node %s is in maintenance mode, skipping power and' + ' provision states check'), node.uuid) if new_ipmi_credentials: new_ipmi_credentials = ( @@ -103,9 +108,10 @@ def introspect(uuid, new_ipmi_credentials=None): else: validation = utils.retry_on_conflict(ironic.node.validate, node.uuid) if not validation.power['result']: - msg = ('Failed validation of power interface for node %s, ' - 'reason: %s') - raise utils.Error(msg % (node.uuid, validation.power['reason'])) + msg = _('Failed validation of power interface for node %(node)s, ' + 'reason: %(reason)s') + raise utils.Error(msg % {'node': node.uuid, + 'reason': validation.power['reason']}) cached_node = node_cache.add_node(node.uuid, bmc_address=utils.get_ipmi_address(node)) @@ -117,7 +123,7 @@ def introspect(uuid, new_ipmi_credentials=None): except utils.Error as exc: cached_node.finished(error=str(exc)) except Exception as exc: - msg = 'Unexpected exception in background introspection thread' + msg = _('Unexpected exception in background introspection thread') LOG.exception(msg) cached_node.finished(error=msg) @@ -133,8 +139,9 @@ def _background_introspect(ironic, cached_node): limit=0)] if macs: cached_node.add_attribute(node_cache.MACS_ATTRIBUTE, macs) - LOG.info('Whitelisting MAC\'s %s for node %s on the firewall', - macs, cached_node.uuid) + LOG.info(_LI('Whitelisting MAC\'s %(macs)s for node %(node)s on the' + ' firewall') % + {'macs': macs, 'node': cached_node.uuid}) firewall.update_filters(ironic) if not cached_node.options.get('new_ipmi_credentials'): @@ -142,17 +149,20 @@ def _background_introspect(ironic, cached_node): utils.retry_on_conflict(ironic.node.set_boot_device, cached_node.uuid, 'pxe', persistent=False) except Exception as exc: - LOG.warning('Failed to set boot device to PXE for node %s: %s', - cached_node.uuid, exc) + LOG.warning(_LW('Failed to set boot device to PXE for' + ' node %(node)s: %(exc)s') % + {'node': cached_node.uuid, 'exc': exc}) try: utils.retry_on_conflict(ironic.node.set_power_state, cached_node.uuid, 'reboot') except Exception as exc: - raise utils.Error('Failed to power on node %s, check it\'s power ' - 'management configuration:\n%s' - % (cached_node.uuid, exc)) + raise utils.Error(_('Failed to power on node %(node)s,' + ' check it\'s power ' + 'management configuration:\n%(exc)s') + % {'node': cached_node.uuid, 'exc': exc}) else: - LOG.info('Introspection environment is ready for node %s, ' - 'manual power on is required within %d seconds', - cached_node.uuid, conf.getint('discoverd', 'timeout')) + LOG.info(_LI('Introspection environment is ready for node %(node)s, ' + 'manual power on is required within %(timeout)d seconds') % + {'node': cached_node.uuid, + 'timeout': conf.getint('discoverd', 'timeout')}) diff --git a/ironic_discoverd/plugins/edeploy.py b/ironic_discoverd/plugins/edeploy.py index a3a26eb0f..b44077749 100644 --- a/ironic_discoverd/plugins/edeploy.py +++ b/ironic_discoverd/plugins/edeploy.py @@ -22,6 +22,8 @@ import logging from hardware import matcher from hardware import state +from ironic_discoverd.common.i18n import _ +from ironic_discoverd.common.i18n import _LW from ironic_discoverd import conf from ironic_discoverd.plugins import base from ironic_discoverd import utils @@ -46,7 +48,7 @@ class eDeployHook(base.ProcessingHook): if 'data' not in node_info: raise utils.Error( - 'edeploy plugin: no "data" key in the received JSON') + _('edeploy plugin: no "data" key in the received JSON')) LOG.debug('before_processing: %s', node_info['data']) @@ -66,8 +68,8 @@ class eDeployHook(base.ProcessingHook): var['profile'] = prof node_info['hardware'] = var except Exception as excpt: - LOG.warning( - 'Unable to find a matching hardware profile: %s' % excpt) + LOG.warning(_LW( + 'Unable to find a matching hardware profile: %s'), excpt) finally: if sobj: sobj.save() diff --git a/ironic_discoverd/plugins/root_device_hint.py b/ironic_discoverd/plugins/root_device_hint.py index b753ab946..de9c46e21 100644 --- a/ironic_discoverd/plugins/root_device_hint.py +++ b/ironic_discoverd/plugins/root_device_hint.py @@ -15,6 +15,8 @@ import logging +from ironic_discoverd.common.i18n import _LI +from ironic_discoverd.common.i18n import _LW from ironic_discoverd.plugins import base @@ -40,11 +42,11 @@ class RootDeviceHintHook(base.ProcessingHook): def before_update(self, node, ports, node_info): if 'block_devices' not in node_info: - LOG.warning('No block device was received from ramdisk') + LOG.warning(_LW('No block device was received from ramdisk')) return [], {} if 'root_device' in node.properties: - LOG.info('Root device is already known for the node') + LOG.info(_LI('Root device is already known for the node')) return [], {} if 'block_devices' in node.extra: @@ -55,11 +57,11 @@ class RootDeviceHintHook(base.ProcessingHook): if device not in previous_devices] if len(new_devices) > 1: - LOG.warning('Root device cannot be identified because ' - 'multiple new devices were found') + LOG.warning(_LW('Root device cannot be identified because ' + 'multiple new devices were found')) return [], {} elif len(new_devices) == 0: - LOG.warning('No new devices were found') + LOG.warning(_LW('No new devices were found')) return [], {} return [ diff --git a/ironic_discoverd/plugins/standard.py b/ironic_discoverd/plugins/standard.py index 1ad2367e1..64d92fa4b 100644 --- a/ironic_discoverd/plugins/standard.py +++ b/ironic_discoverd/plugins/standard.py @@ -15,6 +15,9 @@ import logging +from ironic_discoverd.common.i18n import _ +from ironic_discoverd.common.i18n import _LI +from ironic_discoverd.common.i18n import _LW from ironic_discoverd import conf from ironic_discoverd.plugins import base from ironic_discoverd import utils @@ -33,11 +36,11 @@ class SchedulerHook(base.ProcessingHook): missing = [key for key in self.KEYS if not node_info.get(key)] if missing: raise utils.Error( - 'The following required parameters are missing: %s' % + _('The following required parameters are missing: %s') % missing) - LOG.info('Discovered data: CPUs: %(cpus)s %(cpu_arch)s, ' - 'memory %(memory_mb)s MiB, disk %(local_gb)s GiB', + LOG.info(_LI('Discovered data: CPUs: %(cpus)s %(cpu_arch)s, ' + 'memory %(memory_mb)s MiB, disk %(local_gb)s GiB'), {key: node_info.get(key) for key in self.KEYS}) def before_update(self, node, ports, node_info): @@ -57,7 +60,7 @@ class ValidateInterfacesHook(base.ProcessingHook): """Validate information about network interfaces.""" bmc_address = node_info.get('ipmi_address') if not node_info.get('interfaces'): - raise utils.Error('No interfaces supplied by the ramdisk') + raise utils.Error(_('No interfaces supplied by the ramdisk')) valid_interfaces = { n: iface for n, iface in node_info['interfaces'].items() @@ -70,7 +73,7 @@ class ValidateInterfacesHook(base.ProcessingHook): pxe_mac = node_info.get('boot_interface') if only_pxe and pxe_mac: - LOG.info('PXE boot interface was %s', pxe_mac) + LOG.info(_LI('PXE boot interface was %s'), pxe_mac) if '-' in pxe_mac: # pxelinux format: 01-aa-bb-cc-dd-ee-ff pxe_mac = pxe_mac.split('-', 1)[1] @@ -87,20 +90,20 @@ class ValidateInterfacesHook(base.ProcessingHook): } if not valid_interfaces: - raise utils.Error('No valid interfaces found for node with ' - 'BMC %(ipmi_address)s, got %(interfaces)s' % + raise utils.Error(_('No valid interfaces found for node with ' + 'BMC %(ipmi_address)s, got %(interfaces)s') % {'ipmi_address': bmc_address, 'interfaces': node_info['interfaces']}) elif valid_interfaces != node_info['interfaces']: - LOG.warning( + LOG.warning(_LW( 'The following interfaces were invalid or not eligible in ' 'introspection data for node with BMC %(ipmi_address)s and ' - 'were excluded: %(invalid)s', + 'were excluded: %(invalid)s'), {'invalid': {n: iface for n, iface in node_info['interfaces'].items() if n not in valid_interfaces}, 'ipmi_address': bmc_address}) - LOG.info('Eligible interfaces are %s', valid_interfaces) + LOG.info(_LI('Eligible interfaces are %s'), valid_interfaces) node_info['all_interfaces'] = node_info['interfaces'] node_info['interfaces'] = valid_interfaces @@ -115,4 +118,4 @@ class RamdiskErrorHook(base.ProcessingHook): if not node_info.get('error'): return - raise utils.Error('Ramdisk reported error: %s' % node_info['error']) + raise utils.Error(_('Ramdisk reported error: %s') % node_info['error']) diff --git a/ironic_discoverd/utils.py b/ironic_discoverd/utils.py index 333e19ea1..bff20beb6 100644 --- a/ironic_discoverd/utils.py +++ b/ironic_discoverd/utils.py @@ -21,6 +21,7 @@ from keystoneclient import exceptions as keystone_exc from keystoneclient.v2_0 import client as keystone import six +from ironic_discoverd.common.i18n import _LW from ironic_discoverd import conf @@ -84,8 +85,11 @@ def retry_on_conflict(call, *args, **kwargs): try: return call(*args, **kwargs) except exceptions.Conflict as exc: - LOG.warning('Conflict on calling %s: %s, retry attempt %d', - getattr(call, '__name__', repr(call)), exc, i + 1) + LOG.warning(_LW('Conflict on calling %(call)s: %(exc)s,' + ' retry attempt %(count)d') % + {'call': getattr(call, '__name__', repr(call)), + 'exc': exc, + 'count': i + 1}) if i == RETRY_COUNT - 1: raise eventlet.greenthread.sleep(RETRY_DELAY)