diff --git a/magnum/cmd/api.py b/magnum/cmd/api.py index 40325bf1ab..7569fec345 100644 --- a/magnum/cmd/api.py +++ b/magnum/cmd/api.py @@ -23,7 +23,7 @@ from oslo_config import cfg from magnum.api import app as api_app 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 @@ -39,16 +39,16 @@ def main(): host, port = cfg.CONF.api.host, cfg.CONF.api.port 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:") cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) 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') % dict(port=port)) 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)) srv.serve_forever() diff --git a/magnum/cmd/conductor.py b/magnum/cmd/conductor.py index 80815c18e2..ff2944db31 100644 --- a/magnum/cmd/conductor.py +++ b/magnum/cmd/conductor.py @@ -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 docker_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 LOG = logging.getLogger(__name__) @@ -34,7 +35,7 @@ def main(): cfg.CONF(sys.argv[1:], project='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:") 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 # they are a hardcoded dependency and not store them in etc. if not os.path.isfile(cfg.CONF.k8s_heat.template_path): - LOG.error("The Heat template %s is not found. Install template." % - (cfg.CONF.k8s_heat.template_path)) + LOG.error(_LE("The Heat template %s is not found. Install template.") + % (cfg.CONF.k8s_heat.template_path)) exit(-1) server = service.Service(cfg.CONF.conductor.topic, diff --git a/magnum/common/exception.py b/magnum/common/exception.py index 9649f08581..a0a074983f 100644 --- a/magnum/common/exception.py +++ b/magnum/common/exception.py @@ -118,7 +118,9 @@ def wrap_controller_exception(func, func_server_error, func_client_error): # log the error message with its associated # correlation id 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 func_server_error(log_correlation_id, http_error_code) else: @@ -206,7 +208,8 @@ class MagnumException(Exception): # log the issue and the kwargs LOG.exception(_LE('Exception in string format operation')) 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: raise e diff --git a/magnum/common/magnum_keystoneclient.py b/magnum/common/magnum_keystoneclient.py index 66947a0887..0bbbbb44cb 100644 --- a/magnum/common/magnum_keystoneclient.py +++ b/magnum/common/magnum_keystoneclient.py @@ -22,6 +22,7 @@ from oslo_utils import importutils from magnum.common import context as magnum_context from magnum.common import exception 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 @@ -85,7 +86,7 @@ class KeystoneClientV3(object): if c.authenticate(): self._admin_client = c else: - LOG.error("Admin client authentication failed") + LOG.error(_LE("Admin client authentication failed")) raise exception.AuthorizationFailure() return self._admin_client @@ -115,13 +116,13 @@ class KeystoneClientV3(object): kwargs['auth_ref']['version'] = 'v3' kwargs['auth_ref']['auth_token'] = self.context.auth_token else: - LOG.error("Unknown version in auth_token_info") + LOG.error(_LE("Unknown version in auth_token_info")) raise exception.AuthorizationFailure() elif self.context.auth_token is not None: kwargs['token'] = self.context.auth_token kwargs['project_id'] = self.context.project_id else: - LOG.error(_("Keystone v3 API connection failed, no password " + LOG.error(_LE("Keystone v3 API connection failed, no password " "trust or auth_token!")) raise exception.AuthorizationFailure() client = kc_v3.Client(**kwargs) @@ -132,7 +133,7 @@ class KeystoneClientV3(object): if 'trust_id' in kwargs: # Sanity check 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() # All OK so update the context with the token self.context.auth_token = client.auth_ref.auth_token diff --git a/magnum/conductor/handlers/bay_k8s_heat.py b/magnum/conductor/handlers/bay_k8s_heat.py index 0f5d10e146..30e0fb1490 100644 --- a/magnum/conductor/handlers/bay_k8s_heat.py +++ b/magnum/conductor/handlers/bay_k8s_heat.py @@ -21,6 +21,7 @@ from magnum.common import exception from magnum.common import short_id from magnum import objects 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 loopingcall @@ -216,7 +217,8 @@ class Handler(object): if ((stack.status == 'FAILED') or (attempts['count'] > cfg.CONF.k8s_heat.max_attempts)): # 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() lc = loopingcall.FixedIntervalLoopingCall(f=poll_and_check) diff --git a/magnum/conductor/handlers/common/kube_utils.py b/magnum/conductor/handlers/common/kube_utils.py index ef014d5595..47cf882deb 100644 --- a/magnum/conductor/handlers/common/kube_utils.py +++ b/magnum/conductor/handlers/common/kube_utils.py @@ -15,6 +15,7 @@ import tempfile 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 utils @@ -85,8 +86,9 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't create service with contents %s \ - due to error %s" % (service, e)) + LOG.error(_LE("Couldn't create service with contents %(content)s " + "due to error %(error)s") % + {'content': service, 'error': e}) return False return True @@ -98,8 +100,9 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't update service with contents %s \ - due to error %s" % (service, e)) + LOG.error(_LE("Couldn't update service with contents %(content)s " + "due to error %(error)s") % + {'content': service, 'error': e}) return False return True @@ -111,7 +114,8 @@ class KubeClient(object): manifest = [s.split() for s in out.split('\n')] return manifest 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 def service_delete(self, master_address, name): @@ -122,8 +126,8 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't delete service %s due to error %s" - % (name, e)) + LOG.error(_LE("Couldn't delete service %(service)s due to error " + "%(error)s") % {'service': name, 'error': e}) return False return True @@ -135,7 +139,8 @@ class KubeClient(object): # TODO(pkilambi): process the output as needed return out 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 def service_show(self, master_address, uuid): @@ -146,8 +151,8 @@ class KubeClient(object): # TODO(pkilambi): process the output as needed return out except Exception as e: - LOG.error("Couldn't describe service %s due to error %s" - % (uuid, e)) + LOG.error(_LE("Couldn't describe service %(service)s due to error" + " %(error)s") % {'service': uuid, 'error': e}) return None # Pod Operations @@ -159,8 +164,9 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't create pod with contents %s due to error %s" - % (pod, e)) + LOG.error(_LE("Couldn't create pod with contents %(content)s " + "due to error %(error)s") % + {'content': pod, 'error': e}) return False return True @@ -172,8 +178,8 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't update pod with contents %s due to error %s" - % (pod, e)) + LOG.error(_LE("Couldn't update pod with %(content)s due to error " + "%(error)s") % {'content': pod, 'error': e}) return False return True @@ -184,7 +190,7 @@ class KubeClient(object): manifest = [s.split() for s in out.split('\n')] return manifest 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 def pod_delete(self, master_address, name): @@ -193,7 +199,8 @@ class KubeClient(object): out, err = utils.trycmd('kubectl', 'delete', 'pod', name, '-s', master_address,) 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 if err: @@ -212,7 +219,8 @@ class KubeClient(object): # TODO(pkilambi): process the output as needed return out 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 def pod_show(self, master_address, uuid): @@ -223,7 +231,8 @@ class KubeClient(object): # TODO(pkilambi): process the output as needed return out 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 # Replication Controller Operations @@ -235,8 +244,8 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't create rc with contents %s due to error %s" - % (rc, e)) + LOG.error(_LE("Couldn't create rc with contents %(content)s due " + "error %(error)s") % {'content': rc, 'error': e}) return False return True @@ -248,8 +257,8 @@ class KubeClient(object): if err: return False except Exception as e: - LOG.error("Couldn't update rc with contents %s due to error %s" - % (rc, e)) + LOG.error(_LE("Couldn't update rc with contents %(content)s due " + "to error %(error)s") % {'content': rc, 'error': e}) return False return True @@ -261,6 +270,7 @@ class KubeClient(object): if err: return False 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 True