Don't translate debug level logs in nova.api

Our translation policy
(https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation) calls
for not translating debug level logs. This is to help prioritize log
translation. Furthermore translation has a performance overhead, even if
the log isn't used (since nova doesn't support lazy translation yet).

Change-Id: Ifb04bf41a47f485e8c668632d3a6ac51e02a16f8
This commit is contained in:
Gary Kotton 2014-04-25 01:25:36 -07:00
parent e64f30f423
commit fbc1a1606b
23 changed files with 79 additions and 82 deletions

View File

@ -320,9 +320,9 @@ class Requestify(wsgi.Middleware):
except exception.InvalidRequest as err:
raise webob.exc.HTTPBadRequest(explanation=unicode(err))
LOG.debug(_('action: %s'), action)
LOG.debug('action: %s', action)
for key, value in args.items():
LOG.debug(_('arg: %(key)s\t\tval: %(value)s'),
LOG.debug('arg: %(key)s\t\tval: %(value)s',
{'key': key, 'value': value})
# Success!

View File

@ -1063,7 +1063,7 @@ class CloudController(object):
root_device_type = 'ebs'
vol = self.volume_api.get(context, volume_id)
LOG.debug(_("vol = %s\n"), vol)
LOG.debug("vol = %s\n", vol)
# TODO(yamahata): volume attach time
ebs = {'volumeId': ec2utils.id_to_ec2_vol_id(volume_id),
'deleteOnTermination': bdm['delete_on_termination'],
@ -1415,7 +1415,7 @@ class CloudController(object):
previous_states = self._ec2_ids_to_instances(context, instance_id,
objects=True)
self._remove_client_token(context, instance_id)
LOG.debug(_("Going to start terminating instances"))
LOG.debug("Going to start terminating instances")
for instance in previous_states:
self.compute_api.delete(context, instance)
return self._format_terminate_instances(context,
@ -1436,7 +1436,7 @@ class CloudController(object):
Here instance_id is a list of instance ids
"""
instances = self._ec2_ids_to_instances(context, instance_id, True)
LOG.debug(_("Going to stop instances"))
LOG.debug("Going to stop instances")
for instance in instances:
extensions.check_compute_policy(context, 'stop', instance)
self.compute_api.stop(context, instance)
@ -1447,7 +1447,7 @@ class CloudController(object):
Here instance_id is a list of instance ids
"""
instances = self._ec2_ids_to_instances(context, instance_id, True)
LOG.debug(_("Going to start instances"))
LOG.debug("Going to start instances")
for instance in instances:
extensions.check_compute_policy(context, 'start', instance)
self.compute_api.start(context, instance)

View File

@ -16,7 +16,6 @@ import webob.exc
import nova.api.ec2
from nova import context
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
from nova import utils
@ -26,8 +25,8 @@ LOG = logging.getLogger(__name__)
def ec2_error_response(request_id, code, message, status=500):
"""Helper to construct an EC2 compatible error response."""
LOG.debug(_('EC2 error response: %(code)s: %(message)s') %
{'code': code, 'message': message})
LOG.debug('EC2 error response: %(code)s: %(message)s',
{'code': code, 'message': message})
resp = webob.Response()
resp.status = status
resp.headers['Content-Type'] = 'text/xml'

View File

@ -34,7 +34,6 @@ from nova.objects import base as obj_base
from nova.objects import block_device as block_device_obj
from nova.objects import instance as instance_obj
from nova.objects import security_group as secgroup_obj
from nova.openstack.common.gettextutils import _
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
@ -406,7 +405,7 @@ class InstanceMetadata():
today = timeutils.utcnow().strftime("%Y-%m-%d")
versions = [v for v in OPENSTACK_VERSIONS if v <= today]
if OPENSTACK_VERSIONS != versions:
LOG.debug(_("future versions %s hidden in version list"),
LOG.debug("future versions %s hidden in version list",
[v for v in OPENSTACK_VERSIONS
if v not in versions])
versions += ["latest"]

View File

@ -198,7 +198,7 @@ class APIRouter(base_wsgi.Router):
def _setup_ext_routes(self, mapper, ext_mgr, init_only):
for resource in ext_mgr.get_resources():
LOG.debug(_('Extending resource: %s'),
LOG.debug('Extending resource: %s',
resource.collection)
if init_only is not None and resource.collection not in init_only:
@ -238,8 +238,8 @@ class APIRouter(base_wsgi.Router):
msg_format_dict)
continue
LOG.debug(_('Extension %(ext_name)s extended resource: '
'%(collection)s'),
LOG.debug('Extension %(ext_name)s extended resource: '
'%(collection)s',
msg_format_dict)
resource = self.resources[collection]
@ -296,9 +296,9 @@ class APIRouterV3(base_wsgi.Router):
return
self.init_only = init_only
LOG.debug(_("v3 API Extension Blacklist: %s"),
LOG.debug("v3 API Extension Blacklist: %s",
CONF.osapi_v3.extensions_blacklist)
LOG.debug(_("v3 API Extension Whitelist: %s"),
LOG.debug("v3 API Extension Whitelist: %s",
CONF.osapi_v3.extensions_whitelist)
in_blacklist_and_whitelist = set(
@ -357,10 +357,10 @@ class APIRouterV3(base_wsgi.Router):
"""
handler = ext.obj
LOG.debug(_("Running _register_resources on %s"), ext.obj)
LOG.debug("Running _register_resources on %s", ext.obj)
for resource in handler.get_resources():
LOG.debug(_('Extended resource: %s'), resource.collection)
LOG.debug('Extended resource: %s', resource.collection)
inherits = None
if resource.inherits:
@ -399,7 +399,7 @@ class APIRouterV3(base_wsgi.Router):
"""
handler = ext.obj
LOG.debug(_("Running _register_controllers on %s"), ext.obj)
LOG.debug("Running _register_controllers on %s", ext.obj)
for extension in handler.get_controller_extensions():
ext_name = extension.extension.name
@ -412,8 +412,8 @@ class APIRouterV3(base_wsgi.Router):
{'ext_name': ext_name, 'collection': collection})
continue
LOG.debug(_('Extension %(ext_name)s extending resource: '
'%(collection)s'),
LOG.debug('Extension %(ext_name)s extending resource: '
'%(collection)s',
{'ext_name': ext_name, 'collection': collection})
resource = self.resources[collection]

View File

@ -33,7 +33,7 @@ class NetworkAssociateActionController(wsgi.Controller):
def _disassociate_host_only(self, req, id, body):
context = req.environ['nova.context']
authorize(context)
LOG.debug(_("Disassociating host with network with id %s"), id)
LOG.debug("Disassociating host with network with id %s", id)
try:
self.network_api.associate(context, id, host=None)
except exception.NetworkNotFound:
@ -49,7 +49,7 @@ class NetworkAssociateActionController(wsgi.Controller):
def _disassociate_project_only(self, req, id, body):
context = req.environ['nova.context']
authorize(context)
LOG.debug(_("Disassociating project with network with id %s"), id)
LOG.debug("Disassociating project with network with id %s", id)
try:
self.network_api.associate(context, id, project=None)
except exception.NetworkNotFound:

View File

@ -70,7 +70,7 @@ class NetworkController(wsgi.Controller):
def _disassociate_host_and_project(self, req, id, body):
context = req.environ['nova.context']
authorize(context)
LOG.debug(_("Disassociating network with id %s"), id)
LOG.debug("Disassociating network with id %s", id)
try:
self.network_api.associate(context, id, host=None, project=None)
@ -86,7 +86,7 @@ class NetworkController(wsgi.Controller):
def show(self, req, id):
context = req.environ['nova.context']
authorize_view(context)
LOG.debug(_("Showing network with id %s") % id)
LOG.debug("Showing network with id %s", id)
try:
network = self.network_api.get(context, id)
except exception.NetworkNotFound:
@ -123,7 +123,7 @@ class NetworkController(wsgi.Controller):
if not cidr:
raise bad(_("Network cidr or cidr_v6 is required"))
LOG.debug(_("Creating network with label %s") % params["label"])
LOG.debug("Creating network with label %s", params["label"])
params["num_networks"] = 1
params["network_size"] = netaddr.IPNetwork(cidr).size
@ -139,8 +139,8 @@ class NetworkController(wsgi.Controller):
network_id = body.get('id', None)
project_id = context.project_id
LOG.debug(_("Associating network %(network)s"
" with project %(project)s") %
LOG.debug("Associating network %(network)s"
" with project %(project)s",
{"network": network_id or "",
"project": project_id})
try:

View File

@ -103,7 +103,7 @@ class NetworkController(object):
def show(self, req, id):
context = req.environ['nova.context']
authorize(context)
LOG.debug(_("Showing network with id %s") % id)
LOG.debug("Showing network with id %s", id)
try:
network = self.network_api.get(context, id)
except exception.NetworkNotFound:

View File

@ -157,7 +157,7 @@ class QuotaSetsController(wsgi.Controller):
raise webob.exc.HTTPBadRequest(
explanation=e.format_message())
LOG.debug(_("force update quotas: %s") % force_update)
LOG.debug("force update quotas: %s", force_update)
if len(bad_keys) > 0:
msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys)
@ -181,8 +181,8 @@ class QuotaSetsController(wsgi.Controller):
if quota_value and quota_value['limit'] >= 0:
quota_used = (quota_value['in_use'] +
quota_value['reserved'])
LOG.debug(_("Quota %(key)s used: %(quota_used)s, "
"value: %(value)s."),
LOG.debug("Quota %(key)s used: %(quota_used)s, "
"value: %(value)s.",
{'key': key, 'quota_used': quota_used,
'value': value})
if quota_used > value:

View File

@ -149,7 +149,7 @@ class SecurityGroupDefaultRulesController(sg.SecurityGroupControllerBase):
id = self.security_group_api.validate_id(id)
LOG.debug(_("Showing security_group_default_rule with id %s") % id)
LOG.debug("Showing security_group_default_rule with id %s", id)
try:
rule = self.security_group_api.get_default_rule(context, id)
except exception.SecurityGroupDefaultRuleNotFound:

View File

@ -108,9 +108,9 @@ class ServerExternalEventsController(wsgi.Controller):
context, event.instance_uuid)
instances[event.instance_uuid] = instance
except exception.InstanceNotFound:
LOG.debug(_('Dropping event %(name)s:%(tag)s for unknown '
'instance %(instance_uuid)s'),
dict(event.iteritems()))
LOG.debug('Dropping event %(name)s:%(tag)s for unknown '
'instance %(instance_uuid)s',
dict(event.iteritems()))
_event['status'] = 'failed'
_event['code'] = 404
result = 207

View File

@ -46,7 +46,7 @@ class ServerStartStopActionController(wsgi.Controller):
context = req.environ['nova.context']
instance = self._get_instance(context, id)
extensions.check_compute_policy(context, 'start', instance)
LOG.debug(_('start instance'), instance=instance)
LOG.debug('start instance', instance=instance)
try:
self.compute_api.start(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked,
@ -60,7 +60,7 @@ class ServerStartStopActionController(wsgi.Controller):
context = req.environ['nova.context']
instance = self._get_instance(context, id)
extensions.check_compute_policy(context, 'stop', instance)
LOG.debug(_('stop instance'), instance=instance)
LOG.debug('stop instance', instance=instance)
try:
self.compute_api.stop(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked,

View File

@ -359,7 +359,7 @@ class VolumeAttachmentController(wsgi.Controller):
context, instance['uuid'])
if not bdms:
LOG.debug(_("Instance %s is not attached."), server_id)
LOG.debug("Instance %s is not attached.", server_id)
raise exc.HTTPNotFound()
assigned_mountpoint = None
@ -515,7 +515,7 @@ class VolumeAttachmentController(wsgi.Controller):
bdms = block_device_obj.BlockDeviceMappingList.get_by_instance_uuid(
context, instance['uuid'])
if not bdms:
LOG.debug(_("Instance %s is not attached."), server_id)
LOG.debug("Instance %s is not attached.", server_id)
raise exc.HTTPNotFound()
found = False

View File

@ -42,11 +42,11 @@ class LoadedExtensionInfo(object):
def _check_extension(self, extension):
"""Checks for required methods in extension objects."""
try:
LOG.debug(_('Ext name: %s'), extension.name)
LOG.debug(_('Ext alias: %s'), extension.alias)
LOG.debug(_('Ext description: %s'),
LOG.debug('Ext name: %s', extension.name)
LOG.debug('Ext alias: %s', extension.alias)
LOG.debug('Ext description: %s',
' '.join(extension.__doc__.strip().split()))
LOG.debug(_('Ext version: %i'), extension.version)
LOG.debug('Ext version: %i', extension.version)
except AttributeError as ex:
LOG.exception(_("Exception loading extension: %s"), unicode(ex))
return False

View File

@ -15,7 +15,6 @@
import webob.exc
from nova.api.openstack import extensions
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
@ -45,7 +44,7 @@ class ExtensionInfoController(object):
if authorize(context, action='discoverable'):
discoverable_extensions[alias] = ext
else:
LOG.debug(_("Filter out extension %s from discover list"),
LOG.debug("Filter out extension %s from discover list",
alias)
return discoverable_extensions

View File

@ -151,7 +151,7 @@ class QuotaSetsController(wsgi.Controller):
except exception.NotAuthorized:
raise webob.exc.HTTPForbidden()
LOG.debug(_("Force update quotas: %s"), force_update)
LOG.debug("Force update quotas: %s", force_update)
for key, value in body['quota_set'].iteritems():
if key == 'force' or (not value and value != 0):
@ -165,8 +165,8 @@ class QuotaSetsController(wsgi.Controller):
if quota_value and quota_value['limit'] >= 0:
quota_used = (quota_value['in_use'] +
quota_value['reserved'])
LOG.debug(_("Quota %(key)s used: %(quota_used)s, "
"value: %(value)s."),
LOG.debug("Quota %(key)s used: %(quota_used)s, "
"value: %(value)s.",
{'key': key, 'quota_used': quota_used,
'value': value})
if quota_used > value:

View File

@ -81,9 +81,9 @@ class ServerExternalEventsController(wsgi.Controller):
context, event.instance_uuid)
instances[event.instance_uuid] = instance
except exception.InstanceNotFound:
LOG.debug(_('Dropping event %(name)s:%(tag)s for unknown '
'instance %(instance_uuid)s'),
dict(event.iteritems()))
LOG.debug('Dropping event %(name)s:%(tag)s for unknown '
'instance %(instance_uuid)s',
dict(event.iteritems()))
_event['status'] = 'failed'
_event['code'] = 404
result = 207

View File

@ -115,14 +115,14 @@ class ServersController(wsgi.Controller):
# to implement multiple server (and other) entry
# points if hasattr(ext.obj, 'server_create'):
if hasattr(ext.obj, required_function):
LOG.debug(_('extension %(ext_alias)s detected by '
'servers extension for function %(func)s'),
{'ext_alias': ext.obj.alias,
'func': required_function})
LOG.debug('extension %(ext_alias)s detected by '
'servers extension for function %(func)s',
{'ext_alias': ext.obj.alias,
'func': required_function})
return check_whiteblack_lists(ext)
else:
LOG.debug(
_('extension %(ext_alias)s is missing %(func)s'),
'extension %(ext_alias)s is missing %(func)s',
{'ext_alias': ext.obj.alias,
'func': required_function})
return False
@ -143,7 +143,7 @@ class ServersController(wsgi.Controller):
invoke_kwds={"extension_info": self.extension_info},
propagate_map_exceptions=True)
if not list(self.create_extension_manager):
LOG.debug(_("Did not find any server create extensions"))
LOG.debug("Did not find any server create extensions")
# Look for implementation of extension point of server rebuild
self.rebuild_extension_manager = \
@ -154,7 +154,7 @@ class ServersController(wsgi.Controller):
invoke_kwds={"extension_info": self.extension_info},
propagate_map_exceptions=True)
if not list(self.rebuild_extension_manager):
LOG.debug(_("Did not find any server rebuild extensions"))
LOG.debug("Did not find any server rebuild extensions")
# Look for implementation of extension point of server update
self.update_extension_manager = \
@ -165,7 +165,7 @@ class ServersController(wsgi.Controller):
invoke_kwds={"extension_info": self.extension_info},
propagate_map_exceptions=True)
if not list(self.update_extension_manager):
LOG.debug(_("Did not find any server update extensions"))
LOG.debug("Did not find any server update extensions")
def index(self, req):
"""Returns a list of server names and ids for a given user."""
@ -545,25 +545,25 @@ class ServersController(wsgi.Controller):
def _create_extension_point(self, ext, server_dict, create_kwargs):
handler = ext.obj
LOG.debug(_("Running _create_extension_point for %s"), ext.obj)
LOG.debug("Running _create_extension_point for %s", ext.obj)
handler.server_create(server_dict, create_kwargs)
def _rebuild_extension_point(self, ext, rebuild_dict, rebuild_kwargs):
handler = ext.obj
LOG.debug(_("Running _rebuild_extension_point for %s"), ext.obj)
LOG.debug("Running _rebuild_extension_point for %s", ext.obj)
handler.server_rebuild(rebuild_dict, rebuild_kwargs)
def _resize_extension_point(self, ext, resize_dict, resize_kwargs):
handler = ext.obj
LOG.debug(_("Running _resize_extension_point for %s"), ext.obj)
LOG.debug("Running _resize_extension_point for %s", ext.obj)
handler.server_resize(resize_dict, resize_kwargs)
def _update_extension_point(self, ext, update_dict, update_kwargs):
handler = ext.obj
LOG.debug(_("Running _update_extension_point for %s"), ext.obj)
LOG.debug("Running _update_extension_point for %s", ext.obj)
handler.server_update(update_dict, update_kwargs)
def _delete(self, context, req, instance_uuid):
@ -972,7 +972,7 @@ class ServersController(wsgi.Controller):
context = req.environ['nova.context']
instance = self._get_instance(context, id)
authorizer(context, instance, 'start')
LOG.debug(_('start instance'), instance=instance)
LOG.debug('start instance', instance=instance)
try:
self.compute_api.start(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked,
@ -987,7 +987,7 @@ class ServersController(wsgi.Controller):
context = req.environ['nova.context']
instance = self._get_instance(context, id)
authorizer(context, instance, 'stop')
LOG.debug(_('stop instance'), instance=instance)
LOG.debug('stop instance', instance=instance)
try:
self.compute_api.stop(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked,
@ -1004,7 +1004,7 @@ def remove_invalid_options(context, search_options, allowed_search_options):
# Otherwise, strip out all unknown options
unknown_options = [opt for opt in search_options
if opt not in allowed_search_options]
LOG.debug(_("Removing options '%s' from query"),
LOG.debug("Removing options '%s' from query",
", ".join(unknown_options))
for opt in unknown_options:
search_options.pop(opt, None)

View File

@ -1511,7 +1511,7 @@ def remove_invalid_options(context, search_options, allowed_search_options):
# Otherwise, strip out all unknown options
unknown_options = [opt for opt in search_options
if opt not in allowed_search_options]
LOG.debug(_("Removing options '%s' from query"),
LOG.debug("Removing options '%s' from query",
", ".join(unknown_options))
for opt in unknown_options:
search_options.pop(opt, None)

View File

@ -233,12 +233,12 @@ class ExtensionManager(object):
def _check_extension(self, extension):
"""Checks for required methods in extension objects."""
try:
LOG.debug(_('Ext name: %s'), extension.name)
LOG.debug(_('Ext alias: %s'), extension.alias)
LOG.debug(_('Ext description: %s'),
LOG.debug('Ext name: %s', extension.name)
LOG.debug('Ext alias: %s', extension.alias)
LOG.debug('Ext description: %s',
' '.join(extension.__doc__.strip().split()))
LOG.debug(_('Ext namespace: %s'), extension.namespace)
LOG.debug(_('Ext updated: %s'), extension.updated)
LOG.debug('Ext namespace: %s', extension.namespace)
LOG.debug('Ext updated: %s', extension.updated)
except AttributeError as ex:
LOG.exception(_("Exception loading extension: %s"), unicode(ex))
return False
@ -254,7 +254,7 @@ class ExtensionManager(object):
expected to call the register() method at least once.
"""
LOG.debug(_("Loading extension %s"), ext_factory)
LOG.debug("Loading extension %s", ext_factory)
if isinstance(ext_factory, six.string_types):
# Load the factory
@ -263,7 +263,7 @@ class ExtensionManager(object):
factory = ext_factory
# Call it
LOG.debug(_("Calling extension factory %s"), ext_factory)
LOG.debug("Calling extension factory %s", ext_factory)
factory(self)
def _load_extensions(self):

View File

@ -812,7 +812,7 @@ class Resource(wsgi.Application):
try:
content_type = request.get_content_type()
except exception.InvalidContentType:
LOG.debug(_("Unrecognized Content-Type provided in request"))
LOG.debug("Unrecognized Content-Type provided in request")
return None, ''
return content_type, request.body
@ -938,8 +938,8 @@ class Resource(wsgi.Application):
"%(body)s") % {'action': action,
'body': unicode(body, 'utf-8')}
LOG.debug(logging.mask_password(msg))
LOG.debug(_("Calling method '%(meth)s' (Content-type='%(ctype)s', "
"Accept='%(accept)s')"),
LOG.debug("Calling method '%(meth)s' (Content-type='%(ctype)s', "
"Accept='%(accept)s')",
{'meth': str(meth),
'ctype': content_type,
'accept': accept})
@ -1211,7 +1211,7 @@ class Fault(webob.exc.HTTPException):
code = self.wrapped_exc.status_int
fault_name = self._fault_names.get(code, "computeFault")
explanation = self.wrapped_exc.explanation
LOG.debug(_("Returning %(code)s to user: %(explanation)s"),
LOG.debug("Returning %(code)s to user: %(explanation)s",
{'code': code, 'explanation': explanation})
explanation = gettextutils.translate(explanation,

View File

@ -18,7 +18,6 @@ import re
import six
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
@ -128,8 +127,8 @@ def validate(args, validator):
assert callable(f)
if not f(args[key]):
LOG.debug(_("%(key)s with value %(value)s failed"
" validator %(name)s"),
LOG.debug("%(key)s with value %(value)s failed"
" validator %(name)s",
{'key': key, 'value': args[key], 'name': f.__name__})
return False
return True

View File

@ -209,6 +209,7 @@ def no_translate_debug_logs(logical_line, filename):
dirs = ["nova/scheduler",
"nova/network",
"nova/volume",
"nova/api",
]
if max([name in filename for name in dirs]):
if logical_line.startswith("LOG.debug(_("):