Support i18n part3
Currently, log format is not following to oslo.i18n. This patch set fixes log format to oslo.i18n Change-Id: If5adfb32c424145d3b4f86a5f7e64a76b56921cc Partial-Bug: #1411272
This commit is contained in:
parent
e1008ef8ef
commit
827bbcf560
|
@ -23,6 +23,9 @@ import sys
|
|||
import flask
|
||||
from keystoneclient import exceptions
|
||||
|
||||
from ironic_discoverd.common.i18n import _
|
||||
from ironic_discoverd.common.i18n import _LE
|
||||
from ironic_discoverd.common.i18n import _LW
|
||||
from ironic_discoverd import conf
|
||||
from ironic_discoverd import firewall
|
||||
from ironic_discoverd import introspect
|
||||
|
@ -41,13 +44,13 @@ def check_auth():
|
|||
return
|
||||
|
||||
if not flask.request.headers.get('X-Auth-Token'):
|
||||
LOG.error("No X-Auth-Token header, rejecting request")
|
||||
raise utils.Error('Authentication required', code=401)
|
||||
LOG.error(_LE("No X-Auth-Token header, rejecting request"))
|
||||
raise utils.Error(_('Authentication required'), code=401)
|
||||
try:
|
||||
utils.check_is_admin(token=flask.request.headers['X-Auth-Token'])
|
||||
except exceptions.Unauthorized as exc:
|
||||
LOG.error("Keystone denied access: %s, rejecting request", exc)
|
||||
raise utils.Error('Access denied', code=403)
|
||||
LOG.error(_LE("Keystone denied access: %s, rejecting request"), exc)
|
||||
raise utils.Error(_('Access denied'), code=403)
|
||||
|
||||
|
||||
def convert_exceptions(func):
|
||||
|
@ -115,7 +118,7 @@ def periodic_update(period): # pragma: no cover
|
|||
try:
|
||||
firewall.update_filters()
|
||||
except Exception:
|
||||
LOG.exception('Periodic update failed')
|
||||
LOG.exception(_LE('Periodic update failed'))
|
||||
eventlet.greenthread.sleep(period)
|
||||
|
||||
|
||||
|
@ -126,7 +129,7 @@ def periodic_clean_up(period): # pragma: no cover
|
|||
if node_cache.clean_up():
|
||||
firewall.update_filters()
|
||||
except Exception:
|
||||
LOG.exception('Periodic clean up of node cache failed')
|
||||
LOG.exception(_LE('Periodic clean up of node cache failed'))
|
||||
eventlet.greenthread.sleep(period)
|
||||
|
||||
|
||||
|
@ -148,8 +151,9 @@ def check_ironic_available():
|
|||
except Exception as exc:
|
||||
if i == attempts:
|
||||
raise
|
||||
LOG.warning('Unable to connect to Ironic or Keystone, retrying %d '
|
||||
'times more: %s', attempts - i, exc)
|
||||
LOG.warning(_LW('Unable to connect to Ironic or Keystone, retrying'
|
||||
' %(count)d times more: %(exc)s') %
|
||||
{'count': attempts - i, 'exc': exc})
|
||||
else:
|
||||
break
|
||||
eventlet.greenthread.sleep(retry_period)
|
||||
|
@ -163,7 +167,8 @@ def config_shim(args):
|
|||
|
||||
def init():
|
||||
if not conf.getboolean('discoverd', 'authenticate'):
|
||||
LOG.warning('Starting unauthenticated, please check configuration')
|
||||
LOG.warning(_LW('Starting unauthenticated, please check'
|
||||
' configuration'))
|
||||
|
||||
node_cache.init()
|
||||
check_ironic_available()
|
||||
|
@ -177,7 +182,7 @@ def init():
|
|||
period = conf.getint('discoverd', 'clean_up_period')
|
||||
eventlet.greenthread.spawn_n(periodic_clean_up, period)
|
||||
else:
|
||||
LOG.warning('Timeout is disabled in configuration')
|
||||
LOG.warning(_LW('Timeout is disabled in configuration'))
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
|
@ -200,8 +205,9 @@ def main(): # pragma: no cover
|
|||
logging.INFO if debug else logging.ERROR)
|
||||
|
||||
if old_args:
|
||||
LOG.warning('"ironic-discoverd <config-file>" syntax is deprecated use'
|
||||
' "ironic-discoverd --config-file <config-file>" instead')
|
||||
LOG.warning(_LW('"ironic-discoverd <config-file>" syntax is deprecated'
|
||||
' use "ironic-discoverd --config-file <config-file>"'
|
||||
' instead'))
|
||||
|
||||
init()
|
||||
app.run(debug=debug,
|
||||
|
|
|
@ -21,6 +21,9 @@ import sqlite3
|
|||
import sys
|
||||
import time
|
||||
|
||||
from ironic_discoverd.common.i18n import _
|
||||
from ironic_discoverd.common.i18n import _LC
|
||||
from ironic_discoverd.common.i18n import _LE
|
||||
from ironic_discoverd import conf
|
||||
from ironic_discoverd import utils
|
||||
|
||||
|
@ -109,11 +112,11 @@ class NodeInfo(object):
|
|||
"values(?, ?, ?)",
|
||||
[(name, v, self.uuid) for v in value])
|
||||
except sqlite3.IntegrityError as exc:
|
||||
LOG.error('Database integrity error %s during '
|
||||
'adding attributes', exc)
|
||||
raise utils.Error(
|
||||
LOG.error(_LE('Database integrity error %s during '
|
||||
'adding attributes'), exc)
|
||||
raise utils.Error(_(
|
||||
'Some or all of %(name)s\'s %(value)s are already '
|
||||
'on introspection' % {'name': name, 'value': value})
|
||||
'on introspection') % {'name': name, 'value': value})
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row):
|
||||
|
@ -129,7 +132,8 @@ def init():
|
|||
|
||||
_DB_NAME = conf.get('discoverd', 'database', default='').strip()
|
||||
if not _DB_NAME:
|
||||
LOG.critical('Configuration option discoverd.database should be set')
|
||||
LOG.critical(_LC('Configuration option discoverd.database'
|
||||
' should be set'))
|
||||
sys.exit(1)
|
||||
|
||||
db_dir = os.path.dirname(_DB_NAME)
|
||||
|
@ -197,7 +201,8 @@ def get_node(uuid):
|
|||
"""
|
||||
row = _db().execute('select * from nodes where uuid=?', (uuid,)).fetchone()
|
||||
if row is None:
|
||||
raise utils.Error('Could not find node %s in cache' % uuid, code=404)
|
||||
raise utils.Error(_('Could not find node %s in cache') % uuid,
|
||||
code=404)
|
||||
return NodeInfo.from_row(row)
|
||||
|
||||
|
||||
|
@ -227,25 +232,25 @@ def find_node(**attributes):
|
|||
found.update(item[0] for item in rows)
|
||||
|
||||
if not found:
|
||||
raise utils.Error(
|
||||
'Could not find a node for attributes %s' % attributes, code=404)
|
||||
raise utils.Error(_(
|
||||
'Could not find a node for attributes %s') % attributes, code=404)
|
||||
elif len(found) > 1:
|
||||
raise utils.Error(
|
||||
'Multiple matching nodes found for attributes %s: %s'
|
||||
% (attributes, list(found)), code=404)
|
||||
raise utils.Error(_(
|
||||
'Multiple matching nodes found for attributes %(attr)s: %(found)s')
|
||||
% {'attr': attributes, 'found': list(found)}, code=404)
|
||||
|
||||
uuid = found.pop()
|
||||
row = db.execute('select started_at, finished_at from nodes where uuid=?',
|
||||
(uuid,)).fetchone()
|
||||
if not row:
|
||||
raise utils.Error(
|
||||
raise utils.Error(_(
|
||||
'Could not find node %s in introspection cache, '
|
||||
'probably it\'s not on introspection now' % uuid, code=404)
|
||||
'probably it\'s not on introspection now') % uuid, code=404)
|
||||
|
||||
if row['finished_at']:
|
||||
raise utils.Error(
|
||||
'Introspection for node %s already finished on %s' %
|
||||
(uuid, row['finished_at']))
|
||||
raise utils.Error(_(
|
||||
'Introspection for node %(node)s already finished on %(finish)s') %
|
||||
{'node': uuid, 'finish': row['finished_at']})
|
||||
|
||||
return NodeInfo(uuid=uuid, started_at=row['started_at'])
|
||||
|
||||
|
@ -278,7 +283,7 @@ def clean_up():
|
|||
if not uuids:
|
||||
return []
|
||||
|
||||
LOG.error('Introspection for nodes %s has timed out', uuids)
|
||||
LOG.error(_LE('Introspection for nodes %s has timed out'), uuids)
|
||||
db.execute('update nodes set finished_at=?, error=? '
|
||||
'where started_at < ? and finished_at is null',
|
||||
(time.time(), 'Introspection timeout', threshold))
|
||||
|
|
|
@ -19,6 +19,9 @@ import time
|
|||
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
|
||||
|
@ -50,7 +53,7 @@ def process(node_info):
|
|||
try:
|
||||
node = ironic.node.get(cached_node.uuid)
|
||||
except exceptions.NotFound:
|
||||
msg = ('Node UUID %s was found in cache, but is not found in Ironic'
|
||||
msg = (_('Node UUID %s was found in cache, but is not found in Ironic')
|
||||
% cached_node.uuid)
|
||||
cached_node.finished(error=msg)
|
||||
raise utils.Error(msg, code=404)
|
||||
|
@ -61,7 +64,7 @@ def process(node_info):
|
|||
cached_node.finished(error=str(exc))
|
||||
raise
|
||||
except Exception as exc:
|
||||
msg = 'Unexpected exception during processing'
|
||||
msg = _('Unexpected exception during processing')
|
||||
LOG.exception(msg)
|
||||
cached_node.finished(error=msg)
|
||||
raise utils.Error(msg)
|
||||
|
@ -95,9 +98,9 @@ def _process_node(ironic, node, node_info, cached_node):
|
|||
port = ironic.port.create(node_uuid=node.uuid, address=mac)
|
||||
ports[mac] = port
|
||||
except exceptions.Conflict:
|
||||
LOG.warning('MAC %(mac)s appeared in introspection data for '
|
||||
'node %(node)s, but already exists in '
|
||||
'database - skipping',
|
||||
LOG.warning(_LW('MAC %(mac)s appeared in introspection data for '
|
||||
'node %(node)s, but already exists in '
|
||||
'database - skipping') %
|
||||
{'mac': mac, 'node': node.uuid})
|
||||
|
||||
node_patches, port_patches = _run_post_hooks(node, ports, node_info)
|
||||
|
@ -142,16 +145,17 @@ def _finish_set_ipmi_credentials(ironic, node, cached_node, node_info,
|
|||
# We don't care about boot device, obviously.
|
||||
ironic.node.get_boot_device(cached_node.uuid)
|
||||
except Exception as exc:
|
||||
LOG.info('Waiting for credentials update on node %s, attempt %d'
|
||||
'current error is %s',
|
||||
cached_node.uuid, attempt, exc)
|
||||
LOG.info(_LI('Waiting for credentials update on node %(node)s,'
|
||||
' attempt %(attempt)d current error is %(exc)s') %
|
||||
{'node': cached_node.uuid,
|
||||
'attempt': attempt, 'exc': exc})
|
||||
eventlet.greenthread.sleep(_CREDENTIALS_WAIT_PERIOD)
|
||||
else:
|
||||
_finish(ironic, cached_node)
|
||||
return
|
||||
|
||||
msg = ('Failed to validate updated IPMI credentials for node '
|
||||
'%s, node might require maintenance' % cached_node.uuid)
|
||||
msg = (_('Failed to validate updated IPMI credentials for node '
|
||||
'%s, node might require maintenance') % cached_node.uuid)
|
||||
cached_node.finished(error=msg)
|
||||
raise utils.Error(msg)
|
||||
|
||||
|
@ -162,8 +166,9 @@ def _force_power_off(ironic, cached_node):
|
|||
utils.retry_on_conflict(ironic.node.set_power_state,
|
||||
cached_node.uuid, 'off')
|
||||
except Exception as exc:
|
||||
msg = ('Failed to power off node %s, check it\'s power '
|
||||
'management configuration: %s' % (cached_node.uuid, exc))
|
||||
msg = (_('Failed to power off node %(node)s, check it\'s power '
|
||||
'management configuration: %(exc)s') %
|
||||
{'node': cached_node.uuid, 'exc': exc})
|
||||
cached_node.finished(error=msg)
|
||||
raise utils.Error(msg)
|
||||
|
||||
|
@ -172,11 +177,12 @@ def _force_power_off(ironic, cached_node):
|
|||
node = ironic.node.get(cached_node.uuid)
|
||||
if (node.power_state or '').lower() == 'power off':
|
||||
return
|
||||
LOG.info('Waiting for node %s to power off, current state is %s',
|
||||
cached_node.uuid, node.power_state)
|
||||
LOG.info(_LI('Waiting for node %(node)s to power off,'
|
||||
' current state is %(power_state)s') %
|
||||
{'node': cached_node.uuid, 'power_state': node.power_state})
|
||||
eventlet.greenthread.sleep(_POWER_OFF_CHECK_PERIOD)
|
||||
|
||||
msg = ('Timeout waiting for node %s to power off after introspection' %
|
||||
msg = (_('Timeout waiting for node %s to power off after introspection') %
|
||||
cached_node.uuid)
|
||||
cached_node.finished(error=msg)
|
||||
raise utils.Error(msg)
|
||||
|
@ -190,5 +196,5 @@ def _finish(ironic, cached_node):
|
|||
utils.retry_on_conflict(ironic.node.update, cached_node.uuid, patch)
|
||||
|
||||
cached_node.finished()
|
||||
LOG.info('Introspection finished successfully for node %s',
|
||||
LOG.info(_LI('Introspection finished successfully for node %s'),
|
||||
cached_node.uuid)
|
||||
|
|
Loading…
Reference in New Issue