Support i18n log format for error in magnum.

This patch supports i18n log format for error
level logs in magnum.

Change-Id: I58a3bda63139ef0ef6535601e74100a66016a23f
Partial-Bug: #1424499
This commit is contained in:
Madhuri Kumari 2015-02-26 10:01:00 +00:00
parent dbe3da708f
commit e05e967775
6 changed files with 55 additions and 38 deletions

View File

@ -23,7 +23,7 @@ from oslo_config import cfg
from magnum.api import app as api_app from magnum.api import app as api_app
from magnum.common import service from magnum.common import service
from magnum.openstack.common._i18n import _ from magnum.openstack.common._i18n import _LI
from magnum.openstack.common import log as logging from magnum.openstack.common import log as logging
@ -39,16 +39,16 @@ def main():
host, port = cfg.CONF.api.host, cfg.CONF.api.port host, port = cfg.CONF.api.host, cfg.CONF.api.port
srv = simple_server.make_server(host, port, app) srv = simple_server.make_server(host, port, app)
LOG.info(_('Starting server in PID %s') % os.getpid()) LOG.info(_LI('Starting server in PID %s') % os.getpid())
LOG.debug("Configuration:") LOG.debug("Configuration:")
cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) cfg.CONF.log_opt_values(LOG, std_logging.DEBUG)
if host == '0.0.0.0': if host == '0.0.0.0':
LOG.info(_('serving on 0.0.0.0:%(port)s, ' LOG.info(_LI('serving on 0.0.0.0:%(port)s, '
'view at http://127.0.0.1:%(port)s') % 'view at http://127.0.0.1:%(port)s') %
dict(port=port)) dict(port=port))
else: else:
LOG.info(_('serving on http://%(host)s:%(port)s') % LOG.info(_LI('serving on http://%(host)s:%(port)s') %
dict(host=host, port=port)) dict(host=host, port=port))
srv.serve_forever() srv.serve_forever()

View File

@ -24,7 +24,8 @@ from magnum.common import rpc_service as service
from magnum.conductor.handlers import bay_k8s_heat from magnum.conductor.handlers import bay_k8s_heat
from magnum.conductor.handlers import docker_conductor from magnum.conductor.handlers import docker_conductor
from magnum.conductor.handlers import kube as k8s_conductor from magnum.conductor.handlers import kube as k8s_conductor
from magnum.openstack.common._i18n import _ from magnum.openstack.common._i18n import _LE
from magnum.openstack.common._i18n import _LI
from magnum.openstack.common import log as logging from magnum.openstack.common import log as logging
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -34,7 +35,7 @@ def main():
cfg.CONF(sys.argv[1:], project='magnum') cfg.CONF(sys.argv[1:], project='magnum')
logging.setup('magnum') logging.setup('magnum')
LOG.info(_('Starting server in PID %s') % os.getpid()) LOG.info(_LI('Starting server in PID %s') % os.getpid())
LOG.debug("Configuration:") LOG.debug("Configuration:")
cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) cfg.CONF.log_opt_values(LOG, std_logging.DEBUG)
@ -51,8 +52,8 @@ def main():
# sense to move these under the magnum/magnum/templates directory since # sense to move these under the magnum/magnum/templates directory since
# they are a hardcoded dependency and not store them in etc. # they are a hardcoded dependency and not store them in etc.
if not os.path.isfile(cfg.CONF.k8s_heat.template_path): if not os.path.isfile(cfg.CONF.k8s_heat.template_path):
LOG.error("The Heat template %s is not found. Install template." % LOG.error(_LE("The Heat template %s is not found. Install template.")
(cfg.CONF.k8s_heat.template_path)) % (cfg.CONF.k8s_heat.template_path))
exit(-1) exit(-1)
server = service.Service(cfg.CONF.conductor.topic, server = service.Service(cfg.CONF.conductor.topic,

View File

@ -118,7 +118,9 @@ def wrap_controller_exception(func, func_server_error, func_client_error):
# log the error message with its associated # log the error message with its associated
# correlation id # correlation id
log_correlation_id = str(uuid.uuid4()) log_correlation_id = str(uuid.uuid4())
LOG.error("%s:%s", log_correlation_id, str(excp)) LOG.error(_LE("%(correlation_id)s:%(excp)s") %
{'correlation_id': log_correlation_id,
'excp': str(excp)})
# raise a client error with an obfuscated message # raise a client error with an obfuscated message
func_server_error(log_correlation_id, http_error_code) func_server_error(log_correlation_id, http_error_code)
else: else:
@ -206,7 +208,8 @@ class MagnumException(Exception):
# log the issue and the kwargs # log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation')) LOG.exception(_LE('Exception in string format operation'))
for name, value in kwargs.iteritems(): for name, value in kwargs.iteritems():
LOG.error("%s: %s" % (name, value)) LOG.error(_LE("%(name)s: %(value)s") %
{'name': name, 'value': value})
if CONF.fatal_exception_format_errors: if CONF.fatal_exception_format_errors:
raise e raise e

View File

@ -22,6 +22,7 @@ from oslo_utils import importutils
from magnum.common import context as magnum_context from magnum.common import context as magnum_context
from magnum.common import exception from magnum.common import exception
from magnum.openstack.common._i18n import _ from magnum.openstack.common._i18n import _
from magnum.openstack.common._i18n import _LE
from magnum.openstack.common._i18n import _LI from magnum.openstack.common._i18n import _LI
from magnum.openstack.common import log as logging from magnum.openstack.common import log as logging
@ -85,7 +86,7 @@ class KeystoneClientV3(object):
if c.authenticate(): if c.authenticate():
self._admin_client = c self._admin_client = c
else: else:
LOG.error("Admin client authentication failed") LOG.error(_LE("Admin client authentication failed"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
return self._admin_client return self._admin_client
@ -115,13 +116,13 @@ class KeystoneClientV3(object):
kwargs['auth_ref']['version'] = 'v3' kwargs['auth_ref']['version'] = 'v3'
kwargs['auth_ref']['auth_token'] = self.context.auth_token kwargs['auth_ref']['auth_token'] = self.context.auth_token
else: else:
LOG.error("Unknown version in auth_token_info") LOG.error(_LE("Unknown version in auth_token_info"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
elif self.context.auth_token is not None: elif self.context.auth_token is not None:
kwargs['token'] = self.context.auth_token kwargs['token'] = self.context.auth_token
kwargs['project_id'] = self.context.project_id kwargs['project_id'] = self.context.project_id
else: else:
LOG.error(_("Keystone v3 API connection failed, no password " LOG.error(_LE("Keystone v3 API connection failed, no password "
"trust or auth_token!")) "trust or auth_token!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
client = kc_v3.Client(**kwargs) client = kc_v3.Client(**kwargs)
@ -132,7 +133,7 @@ class KeystoneClientV3(object):
if 'trust_id' in kwargs: if 'trust_id' in kwargs:
# Sanity check # Sanity check
if not client.auth_ref.trust_scoped: if not client.auth_ref.trust_scoped:
LOG.error(_("trust token re-scoping failed!")) LOG.error(_LE("trust token re-scoping failed!"))
raise exception.AuthorizationFailure() raise exception.AuthorizationFailure()
# All OK so update the context with the token # All OK so update the context with the token
self.context.auth_token = client.auth_ref.auth_token self.context.auth_token = client.auth_ref.auth_token

View File

@ -21,6 +21,7 @@ from magnum.common import exception
from magnum.common import short_id from magnum.common import short_id
from magnum import objects from magnum import objects
from magnum.openstack.common._i18n import _ from magnum.openstack.common._i18n import _
from magnum.openstack.common._i18n import _LE
from magnum.openstack.common._i18n import _LI from magnum.openstack.common._i18n import _LI
from magnum.openstack.common import log as logging from magnum.openstack.common import log as logging
from magnum.openstack.common import loopingcall from magnum.openstack.common import loopingcall
@ -216,7 +217,8 @@ class Handler(object):
if ((stack.status == 'FAILED') or if ((stack.status == 'FAILED') or
(attempts['count'] > cfg.CONF.k8s_heat.max_attempts)): (attempts['count'] > cfg.CONF.k8s_heat.max_attempts)):
# TODO(yuanying): update status to failed # TODO(yuanying): update status to failed
LOG.error('Unable to create bay, stack_id: %s' % bay.stack_id) LOG.error(_LE('Unable to create bay, stack_id: %s')
% bay.stack_id)
raise loopingcall.LoopingCallDone() raise loopingcall.LoopingCallDone()
lc = loopingcall.FixedIntervalLoopingCall(f=poll_and_check) lc = loopingcall.FixedIntervalLoopingCall(f=poll_and_check)

View File

@ -15,6 +15,7 @@
import tempfile import tempfile
from magnum.common import exception from magnum.common import exception
from magnum.openstack.common._i18n import _LE
from magnum.openstack.common import log as logging from magnum.openstack.common import log as logging
from magnum.openstack.common import utils from magnum.openstack.common import utils
@ -85,8 +86,9 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't create service with contents %s \ LOG.error(_LE("Couldn't create service with contents %(content)s "
due to error %s" % (service, e)) "due to error %(error)s") %
{'content': service, 'error': e})
return False return False
return True return True
@ -98,8 +100,9 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't update service with contents %s \ LOG.error(_LE("Couldn't update service with contents %(content)s "
due to error %s" % (service, e)) "due to error %(error)s") %
{'content': service, 'error': e})
return False return False
return True return True
@ -111,7 +114,8 @@ class KubeClient(object):
manifest = [s.split() for s in out.split('\n')] manifest = [s.split() for s in out.split('\n')]
return manifest return manifest
except Exception as e: except Exception as e:
LOG.error("Couldn't get list of services due to error %s" % e) LOG.error(_LE("Couldn't get list of services due to error %s")
% e)
return None return None
def service_delete(self, master_address, name): def service_delete(self, master_address, name):
@ -122,8 +126,8 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't delete service %s due to error %s" LOG.error(_LE("Couldn't delete service %(service)s due to error "
% (name, e)) "%(error)s") % {'service': name, 'error': e})
return False return False
return True return True
@ -135,7 +139,8 @@ class KubeClient(object):
# TODO(pkilambi): process the output as needed # TODO(pkilambi): process the output as needed
return out return out
except Exception as e: except Exception as e:
LOG.error("Couldn't get service %s due to error %s" % (uuid, e)) LOG.error(_LE("Couldn't get service %(service)s due to error "
"%(error)s") % {'service': uuid, 'error': e})
return None return None
def service_show(self, master_address, uuid): def service_show(self, master_address, uuid):
@ -146,8 +151,8 @@ class KubeClient(object):
# TODO(pkilambi): process the output as needed # TODO(pkilambi): process the output as needed
return out return out
except Exception as e: except Exception as e:
LOG.error("Couldn't describe service %s due to error %s" LOG.error(_LE("Couldn't describe service %(service)s due to error"
% (uuid, e)) " %(error)s") % {'service': uuid, 'error': e})
return None return None
# Pod Operations # Pod Operations
@ -159,8 +164,9 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't create pod with contents %s due to error %s" LOG.error(_LE("Couldn't create pod with contents %(content)s "
% (pod, e)) "due to error %(error)s") %
{'content': pod, 'error': e})
return False return False
return True return True
@ -172,8 +178,8 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't update pod with contents %s due to error %s" LOG.error(_LE("Couldn't update pod with %(content)s due to error "
% (pod, e)) "%(error)s") % {'content': pod, 'error': e})
return False return False
return True return True
@ -184,7 +190,7 @@ class KubeClient(object):
manifest = [s.split() for s in out.split('\n')] manifest = [s.split() for s in out.split('\n')]
return manifest return manifest
except Exception as e: except Exception as e:
LOG.error("Couldn't get list of pods due to error %s" % e) LOG.error(_LE("Couldn't get list of pods due to error %s") % e)
return None return None
def pod_delete(self, master_address, name): def pod_delete(self, master_address, name):
@ -193,7 +199,8 @@ class KubeClient(object):
out, err = utils.trycmd('kubectl', 'delete', 'pod', name, out, err = utils.trycmd('kubectl', 'delete', 'pod', name,
'-s', master_address,) '-s', master_address,)
except Exception as e: except Exception as e:
LOG.error("Couldn't delete pod %s due to error %s" % (name, e)) LOG.error(_LE("Couldn't delete pod %(pod)s due to error "
"%(error)s") % {'pod': name, 'error': e})
return False return False
if err: if err:
@ -212,7 +219,8 @@ class KubeClient(object):
# TODO(pkilambi): process the output as needed # TODO(pkilambi): process the output as needed
return out return out
except Exception as e: except Exception as e:
LOG.error("Couldn't get pod %s due to error %s" % (uuid, e)) LOG.error(_LE("Couldn't get pod %(pod)s due to error %(error)s")
% {'pod': uuid, 'error': e})
return None return None
def pod_show(self, master_address, uuid): def pod_show(self, master_address, uuid):
@ -223,7 +231,8 @@ class KubeClient(object):
# TODO(pkilambi): process the output as needed # TODO(pkilambi): process the output as needed
return out return out
except Exception as e: except Exception as e:
LOG.error("Couldn't show pod %s due to error %s" % (uuid, e)) LOG.error(_LE("Couldn't show pod %(pod)s due to error %(error)s")
% {'pod': uuid, 'error': e})
return None return None
# Replication Controller Operations # Replication Controller Operations
@ -235,8 +244,8 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't create rc with contents %s due to error %s" LOG.error(_LE("Couldn't create rc with contents %(content)s due "
% (rc, e)) "error %(error)s") % {'content': rc, 'error': e})
return False return False
return True return True
@ -248,8 +257,8 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't update rc with contents %s due to error %s" LOG.error(_LE("Couldn't update rc with contents %(content)s due "
% (rc, e)) "to error %(error)s") % {'content': rc, 'error': e})
return False return False
return True return True
@ -261,6 +270,7 @@ class KubeClient(object):
if err: if err:
return False return False
except Exception as e: except Exception as e:
LOG.error("Couldn't delete rc %s due to error %s" % (name, e)) LOG.error(_LE("Couldn't delete rc %(rc)s due to error %(error)s")
% {'rc': name, 'error': e})
return False return False
return True return True