Remove locals() from various places.
fixes bug 1171936 Remove usage of locals() for string formatting Change-Id: Ib05538095086ddefdb486c84da506af662ec5c9b
This commit is contained in:
parent
536f37906d
commit
20eac6c1df
@ -121,7 +121,7 @@ class QuotaSetsController(object):
|
||||
value = int(value)
|
||||
except (ValueError, TypeError):
|
||||
msg = _("Quota '%(value)s' for %(key)s should be "
|
||||
"integer.") % locals()
|
||||
"integer.") % {'value': value, 'key': key}
|
||||
LOG.warn(msg)
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
self._validate_quota_limit(value)
|
||||
|
@ -111,7 +111,7 @@ class QuotaSetsController(object):
|
||||
value = int(value)
|
||||
except (ValueError, TypeError):
|
||||
msg = _("Quota '%(value)s' for %(key)s should be "
|
||||
"integer.") % locals()
|
||||
"integer.") % {'value': value, 'key': key}
|
||||
LOG.warn(msg)
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
self._validate_quota_limit(value)
|
||||
|
@ -63,7 +63,8 @@ class MuteChildWeigher(weights.BaseCellWeigher):
|
||||
if timeutils.is_older_than(last_seen, secs):
|
||||
# yep, that's a mute child; recommend highly that it be skipped!
|
||||
LOG.warn(_("%(cell)s has not been seen since %(last_seen)s and is "
|
||||
"being treated as mute.") % locals())
|
||||
"being treated as mute."),
|
||||
{'cell': cell, 'last_seen': last_seen})
|
||||
return CONF.cells.mute_weight_value
|
||||
else:
|
||||
return 0
|
||||
|
@ -242,7 +242,8 @@ class Worker(threading.Thread):
|
||||
else:
|
||||
# Requests comes here from BareMetalDeploy.post()
|
||||
LOG.info(_('start deployment for node %(node_id)s, '
|
||||
'params %(params)s') % locals())
|
||||
'params %(params)s'),
|
||||
{'node_id': node_id, 'params': params})
|
||||
context = nova_context.get_admin_context()
|
||||
try:
|
||||
db.bm_node_update(context, node_id,
|
||||
|
@ -690,7 +690,8 @@ class ServiceCommands(object):
|
||||
except exception.NotFound as ex:
|
||||
print _("error: %s") % ex
|
||||
return(2)
|
||||
print _("Service %(service)s on host %(host)s enabled.") % locals()
|
||||
print (_("Service %(service)s on host %(host)s enabled.") %
|
||||
{'service': service, 'host': host})
|
||||
|
||||
@args('--host', metavar='<host>', help='Host')
|
||||
@args('--service', metavar='<service>', help='Nova service')
|
||||
@ -703,7 +704,8 @@ class ServiceCommands(object):
|
||||
except exception.NotFound as ex:
|
||||
print _("error: %s") % ex
|
||||
return(2)
|
||||
print _("Service %(service)s on host %(host)s disabled.") % locals()
|
||||
print (_("Service %(service)s on host %(host)s disabled.") %
|
||||
{'service': service, 'host': host})
|
||||
|
||||
def _show_host_resources(self, context, host):
|
||||
"""Shows the physical/usage resource given by hosts.
|
||||
@ -968,8 +970,9 @@ class InstanceTypeCommands(object):
|
||||
ctxt,
|
||||
inst_type["flavorid"],
|
||||
ext_spec)
|
||||
print _("Key %(key)s set to %(value)s on instance"
|
||||
" type %(name)s") % locals()
|
||||
print (_("Key %(key)s set to %(value)s on instance "
|
||||
"type %(name)s") %
|
||||
{'key': key, 'value': value, 'name': name})
|
||||
except db_exc.DBError as e:
|
||||
_db_error(e)
|
||||
|
||||
@ -990,7 +993,8 @@ class InstanceTypeCommands(object):
|
||||
inst_type["flavorid"],
|
||||
key)
|
||||
|
||||
print _("Key %(key)s on instance type %(name)s unset") % locals()
|
||||
print (_("Key %(key)s on instance type %(name)s unset") %
|
||||
{'key': key, 'name': name})
|
||||
except db_exc.DBError as e:
|
||||
_db_error(e)
|
||||
|
||||
@ -1099,7 +1103,8 @@ class GetLogCommands(object):
|
||||
print log_file + ":-"
|
||||
print_name = 1
|
||||
linenum = len(lines) - index
|
||||
print _('Line %(linenum)d : %(line)s') % locals()
|
||||
print (_('Line %(linenum)d : %(line)s') %
|
||||
{'linenum': linenum, 'line': line})
|
||||
if error_found == 0:
|
||||
print _('No errors in logfiles!')
|
||||
|
||||
|
@ -120,7 +120,8 @@ class ConductorManager(manager.Manager):
|
||||
for key, value in updates.iteritems():
|
||||
if key not in allowed_updates:
|
||||
LOG.error(_("Instance update attempted for "
|
||||
"'%(key)s' on %(instance_uuid)s") % locals())
|
||||
"'%(key)s' on %(instance_uuid)s"),
|
||||
{'key': key, 'instance_uuid': instance_uuid})
|
||||
raise KeyError("unexpected update keyword '%s'" % key)
|
||||
if key in datetime_fields and isinstance(value, basestring):
|
||||
updates[key] = timeutils.parse_strtime(value)
|
||||
|
@ -84,7 +84,8 @@ class ConsoleAuthManager(manager.Manager):
|
||||
self.mc.set(instance_uuid.encode('UTF-8'),
|
||||
jsonutils.dumps(tokens))
|
||||
|
||||
LOG.audit(_("Received Token: %(token)s, %(token_dict)s)"), locals())
|
||||
LOG.audit(_("Received Token: %(token)s, %(token_dict)s"),
|
||||
{'token': token, 'token_dict': token_dict})
|
||||
|
||||
def _validate_token(self, context, token):
|
||||
instance_uuid = token['instance_uuid']
|
||||
@ -108,7 +109,8 @@ class ConsoleAuthManager(manager.Manager):
|
||||
def check_token(self, context, token):
|
||||
token_str = self.mc.get(token.encode('UTF-8'))
|
||||
token_valid = (token_str is not None)
|
||||
LOG.audit(_("Checking Token: %(token)s, %(token_valid)s)"), locals())
|
||||
LOG.audit(_("Checking Token: %(token)s, %(token_valid)s"),
|
||||
{'token': token, 'token_valid': token_valid})
|
||||
if token_valid:
|
||||
token = jsonutils.loads(token_str)
|
||||
if self._validate_token(context, token):
|
||||
|
@ -2953,7 +2953,7 @@ def quota_reserve(context, resources, quotas, deltas, expire,
|
||||
|
||||
if unders:
|
||||
LOG.warning(_("Change will make usage less than 0 for the following "
|
||||
"resources: %(unders)s") % locals())
|
||||
"resources: %s"), unders)
|
||||
if overs:
|
||||
usages = dict((k, dict(in_use=v['in_use'], reserved=v['reserved']))
|
||||
for k, v in usages.items())
|
||||
|
@ -66,7 +66,8 @@ class HookManager(stevedore.hook.HookManager):
|
||||
obj = e.obj
|
||||
pre = getattr(obj, 'pre', None)
|
||||
if pre:
|
||||
LOG.debug(_("Running %(name)s pre-hook: %(obj)s") % locals())
|
||||
LOG.debug(_("Running %(name)s pre-hook: %(obj)s"),
|
||||
{'name': name, 'obj': obj})
|
||||
if f:
|
||||
pre(f, *args, **kwargs)
|
||||
else:
|
||||
@ -77,7 +78,8 @@ class HookManager(stevedore.hook.HookManager):
|
||||
obj = e.obj
|
||||
post = getattr(obj, 'post', None)
|
||||
if post:
|
||||
LOG.debug(_("Running %(name)s post-hook: %(obj)s") % locals())
|
||||
LOG.debug(_("Running %(name)s post-hook: %(obj)s"),
|
||||
{'name': name, 'obj': obj})
|
||||
if f:
|
||||
post(f, rv, *args, **kwargs)
|
||||
else:
|
||||
|
@ -184,14 +184,17 @@ class GlanceClientWrapper(object):
|
||||
host = self.host
|
||||
port = self.port
|
||||
extra = "retrying"
|
||||
error_msg = _("Error contacting glance server "
|
||||
"'%(host)s:%(port)s' for '%(method)s', %(extra)s.")
|
||||
error_msg = (_("Error contacting glance server "
|
||||
"'%(host)s:%(port)s' for '%(method)s', "
|
||||
"%(extra)s.") %
|
||||
{'host': host, 'port': port,
|
||||
'method': method, 'extra': extra})
|
||||
if attempt == num_attempts:
|
||||
extra = 'done trying'
|
||||
LOG.exception(error_msg, locals())
|
||||
LOG.exception(error_msg)
|
||||
raise exception.GlanceConnectionFailed(
|
||||
host=host, port=port, reason=str(e))
|
||||
LOG.exception(error_msg, locals())
|
||||
LOG.exception(error_msg)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
@ -85,7 +85,7 @@ class FloatingIP(object):
|
||||
fixed_ip_id,
|
||||
get_network=True)
|
||||
except exception.FixedIpNotFound:
|
||||
msg = _('Fixed ip %(fixed_ip_id)s not found') % locals()
|
||||
msg = _('Fixed ip %s not found') % fixed_ip_id
|
||||
LOG.debug(msg)
|
||||
continue
|
||||
interface = CONF.public_interface or floating_ip['interface']
|
||||
@ -95,7 +95,7 @@ class FloatingIP(object):
|
||||
interface,
|
||||
fixed_ip['network'])
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.debug(_('Interface %(interface)s not found'), locals())
|
||||
LOG.debug(_('Interface %s not found'), interface)
|
||||
raise exception.NoFloatingIpInterface(interface=interface)
|
||||
|
||||
def allocate_for_instance(self, context, **kwargs):
|
||||
@ -120,7 +120,7 @@ class FloatingIP(object):
|
||||
floating_address = self.allocate_floating_ip(context, project_id,
|
||||
True)
|
||||
LOG.debug(_("floating IP allocation for instance "
|
||||
"|%(floating_address)s|") % locals(),
|
||||
"|%s|"), floating_address,
|
||||
instance_uuid=instance_uuid, context=context)
|
||||
# set auto_assigned column to true for the floating ip
|
||||
self.db.floating_ip_set_auto_assigned(context, floating_address)
|
||||
@ -217,9 +217,8 @@ class FloatingIP(object):
|
||||
if use_quota:
|
||||
reservations = QUOTAS.reserve(context, floating_ips=1)
|
||||
except exception.OverQuota:
|
||||
pid = context.project_id
|
||||
LOG.warn(_("Quota exceeded for %(pid)s, tried to allocate "
|
||||
"floating IP") % locals())
|
||||
LOG.warn(_("Quota exceeded for %s, tried to allocate "
|
||||
"floating IP"), context.project_id)
|
||||
raise exception.FloatingIpLimitExceeded()
|
||||
|
||||
try:
|
||||
@ -371,7 +370,7 @@ class FloatingIP(object):
|
||||
except processutils.ProcessExecutionError as e:
|
||||
self.db.floating_ip_disassociate(context, floating_address)
|
||||
if "Cannot find device" in str(e):
|
||||
LOG.error(_('Interface %(interface)s not found'), locals())
|
||||
LOG.error(_('Interface %s not found'), interface)
|
||||
raise exception.NoFloatingIpInterface(interface=interface)
|
||||
raise
|
||||
|
||||
@ -529,16 +528,17 @@ class FloatingIP(object):
|
||||
if not floating_addresses or (source and source == dest):
|
||||
return
|
||||
|
||||
LOG.info(_("Starting migration network for instance"
|
||||
" %(instance_uuid)s"), locals())
|
||||
LOG.info(_("Starting migration network for instance %s"),
|
||||
instance_uuid)
|
||||
for address in floating_addresses:
|
||||
floating_ip = self.db.floating_ip_get_by_address(context,
|
||||
address)
|
||||
|
||||
if self._is_stale_floating_ip_address(context, floating_ip):
|
||||
LOG.warn(_("Floating ip address |%(address)s| no longer "
|
||||
"belongs to instance %(instance_uuid)s. Will not"
|
||||
"migrate it "), locals())
|
||||
"belongs to instance %(instance_uuid)s. Will not "
|
||||
"migrate it "),
|
||||
{'address': address, 'instance_uuid': instance_uuid})
|
||||
continue
|
||||
|
||||
interface = CONF.public_interface or floating_ip['interface']
|
||||
@ -571,8 +571,8 @@ class FloatingIP(object):
|
||||
if not floating_addresses or (source and source == dest):
|
||||
return
|
||||
|
||||
LOG.info(_("Finishing migration network for instance"
|
||||
" %(instance_uuid)s"), locals())
|
||||
LOG.info(_("Finishing migration network for instance %s"),
|
||||
instance_uuid)
|
||||
|
||||
for address in floating_addresses:
|
||||
floating_ip = self.db.floating_ip_get_by_address(context,
|
||||
@ -581,7 +581,8 @@ class FloatingIP(object):
|
||||
if self._is_stale_floating_ip_address(context, floating_ip):
|
||||
LOG.warn(_("Floating ip address |%(address)s| no longer "
|
||||
"belongs to instance %(instance_uuid)s. Will not"
|
||||
"setup it."), locals())
|
||||
"setup it."),
|
||||
{'address': address, 'instance_uuid': instance_uuid})
|
||||
continue
|
||||
|
||||
self.db.floating_ip_update(context,
|
||||
|
@ -1474,7 +1474,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
||||
|
||||
if interface:
|
||||
msg = _('Adding interface %(interface)s to bridge %(bridge)s')
|
||||
LOG.debug(msg % locals())
|
||||
LOG.debug(msg, {'interface': interface, 'bridge': bridge})
|
||||
out, err = _execute('brctl', 'addif', bridge, interface,
|
||||
check_exit_code=False, run_as_root=True)
|
||||
|
||||
|
@ -485,8 +485,8 @@ class NetworkManager(manager.Manager):
|
||||
requested_networks=requested_networks)
|
||||
networks_list = [self._get_network_dict(network)
|
||||
for network in networks]
|
||||
LOG.debug(_('networks retrieved for instance: |%(networks_list)s|'),
|
||||
locals(), context=context, instance_uuid=instance_uuid)
|
||||
LOG.debug(_('networks retrieved for instance: |%s|'),
|
||||
networks_list, context=context, instance_uuid=instance_uuid)
|
||||
|
||||
try:
|
||||
self._allocate_mac_addresses(context, instance_uuid, networks,
|
||||
@ -824,9 +824,8 @@ class NetworkManager(manager.Manager):
|
||||
try:
|
||||
reservations = QUOTAS.reserve(context, fixed_ips=1)
|
||||
except exception.OverQuota:
|
||||
pid = context.project_id
|
||||
LOG.warn(_("Quota exceeded for %(pid)s, tried to allocate "
|
||||
"fixed IP") % locals())
|
||||
LOG.warn(_("Quota exceeded for %s, tried to allocate "
|
||||
"fixed IP"), context.project_id)
|
||||
raise exception.FixedIpLimitExceeded()
|
||||
|
||||
try:
|
||||
@ -948,7 +947,7 @@ class NetworkManager(manager.Manager):
|
||||
|
||||
def lease_fixed_ip(self, context, address):
|
||||
"""Called by dhcp-bridge when ip is leased."""
|
||||
LOG.debug(_('Leased IP |%(address)s|'), locals(), context=context)
|
||||
LOG.debug(_('Leased IP |%s|'), address, context=context)
|
||||
fixed_ip = self.db.fixed_ip_get_by_address(context, address)
|
||||
|
||||
if fixed_ip['instance_uuid'] is None:
|
||||
@ -966,7 +965,7 @@ class NetworkManager(manager.Manager):
|
||||
|
||||
def release_fixed_ip(self, context, address):
|
||||
"""Called by dhcp-bridge when ip is released."""
|
||||
LOG.debug(_('Released IP |%(address)s|'), locals(), context=context)
|
||||
LOG.debug(_('Released IP |%s|'), address, context=context)
|
||||
fixed_ip = self.db.fixed_ip_get_by_address(context, address)
|
||||
|
||||
if fixed_ip['instance_uuid'] is None:
|
||||
|
@ -383,8 +383,8 @@ class API(base.Base):
|
||||
try:
|
||||
neutronv2.get_client(context).delete_port(port_id)
|
||||
except Exception as ex:
|
||||
LOG.exception(_("Failed to delete neutron port %(port_id)s ") %
|
||||
locals())
|
||||
LOG.exception(_("Failed to delete neutron port %s") %
|
||||
port_id)
|
||||
|
||||
return self._get_instance_nw_info(context, instance)
|
||||
|
||||
|
@ -302,7 +302,7 @@ class NovaObject(object):
|
||||
be useful for future load operations.
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
_("Cannot load '%(attrname)s' in the base class") % locals())
|
||||
_("Cannot load '%s' in the base class") % attrname)
|
||||
|
||||
def save(self, context):
|
||||
"""Save the changed fields back to the store.
|
||||
|
@ -969,7 +969,7 @@ class QuotaEngine(object):
|
||||
expire=expire,
|
||||
project_id=project_id)
|
||||
|
||||
LOG.debug(_("Created reservations %(reservations)s") % locals())
|
||||
LOG.debug(_("Created reservations %s"), reservations)
|
||||
|
||||
return reservations
|
||||
|
||||
@ -991,10 +991,9 @@ class QuotaEngine(object):
|
||||
# usage resynchronization and the reservation expiration
|
||||
# mechanisms will resolve the issue. The exception is
|
||||
# logged, however, because this is less than optimal.
|
||||
LOG.exception(_("Failed to commit reservations "
|
||||
"%(reservations)s") % locals())
|
||||
LOG.exception(_("Failed to commit reservations %s"), reservations)
|
||||
return
|
||||
LOG.debug(_("Committed reservations %(reservations)s") % locals())
|
||||
LOG.debug(_("Committed reservations %s"), reservations)
|
||||
|
||||
def rollback(self, context, reservations, project_id=None):
|
||||
"""Roll back reservations.
|
||||
@ -1014,10 +1013,10 @@ class QuotaEngine(object):
|
||||
# usage resynchronization and the reservation expiration
|
||||
# mechanisms will resolve the issue. The exception is
|
||||
# logged, however, because this is less than optimal.
|
||||
LOG.exception(_("Failed to roll back reservations "
|
||||
"%(reservations)s") % locals())
|
||||
LOG.exception(_("Failed to roll back reservations %s"),
|
||||
reservations)
|
||||
return
|
||||
LOG.debug(_("Rolled back reservations %(reservations)s") % locals())
|
||||
LOG.debug(_("Rolled back reservations %s"), reservations)
|
||||
|
||||
def usage_reset(self, context, resources):
|
||||
"""
|
||||
|
@ -97,8 +97,7 @@ class AggregateCoreFilter(BaseCoreFilter):
|
||||
try:
|
||||
ratio = float(min(aggregate_vals))
|
||||
except ValueError as e:
|
||||
LOG.warning(_("Could not decode cpu_allocation_ratio: "
|
||||
"'%(e)s'") % locals())
|
||||
LOG.warning(_("Could not decode cpu_allocation_ratio: '%s'"), e)
|
||||
ratio = CONF.cpu_allocation_ratio
|
||||
|
||||
return ratio
|
||||
|
@ -98,8 +98,7 @@ class AggregateRamFilter(BaseRamFilter):
|
||||
try:
|
||||
ratio = float(min(aggregate_vals))
|
||||
except ValueError as e:
|
||||
LOG.warning(_("Could not decode ram_allocation_ratio: "
|
||||
"'%(e)s'") % locals())
|
||||
LOG.warning(_("Could not decode ram_allocation_ratio: '%s'"), e)
|
||||
ratio = CONF.ram_allocation_ratio
|
||||
|
||||
return ratio
|
||||
|
@ -82,7 +82,8 @@ class API(object):
|
||||
"""
|
||||
msg = _('Join new ServiceGroup member %(member_id)s to the '
|
||||
'%(group_id)s group, service = %(service)s')
|
||||
LOG.debug(msg, locals())
|
||||
LOG.debug(msg, {'member_id': member_id, 'group_id': group_id,
|
||||
'service': service})
|
||||
return self._driver.join(member_id, group_id, service)
|
||||
|
||||
def service_is_up(self, member):
|
||||
@ -98,7 +99,7 @@ class API(object):
|
||||
"""
|
||||
msg = _('Explicitly remove the given member %(member_id)s from the'
|
||||
'%(group_id)s group monitoring')
|
||||
LOG.debug(msg, locals())
|
||||
LOG.debug(msg, {'member_id': member_id, 'group_id': group_id})
|
||||
return self._driver.leave(member_id, group_id)
|
||||
|
||||
def get_all(self, group_id):
|
||||
|
@ -40,7 +40,8 @@ class DbDriver(api.ServiceGroupDriver):
|
||||
|
||||
msg = _('DB_Driver: join new ServiceGroup member %(member_id)s to '
|
||||
'the %(group_id)s group, service = %(service)s')
|
||||
LOG.debug(msg, locals())
|
||||
LOG.debug(msg, {'member_id': member_id, 'group_id': group_id,
|
||||
'service': service})
|
||||
if service is None:
|
||||
raise RuntimeError(_('service is a mandatory argument for DB based'
|
||||
' ServiceGroup driver'))
|
||||
|
@ -51,7 +51,8 @@ class MemcachedDriver(api.ServiceGroupDriver):
|
||||
msg = _('Memcached_Driver: join new ServiceGroup member '
|
||||
'%(member_id)s to the %(group_id)s group, '
|
||||
'service = %(service)s')
|
||||
LOG.debug(msg, locals())
|
||||
LOG.debug(msg, {'member_id': member_id, 'group_id': group_id,
|
||||
'service': service})
|
||||
if service is None:
|
||||
raise RuntimeError(_('service is a mandatory argument for '
|
||||
'Memcached based ServiceGroup driver'))
|
||||
|
@ -119,11 +119,10 @@ def find_multipath_device(device):
|
||||
mdev_id = mdev_id.replace(')', '')
|
||||
|
||||
if mdev is None:
|
||||
LOG.warn(_("Couldn't find multipath device %(line)s")
|
||||
% locals())
|
||||
LOG.warn(_("Couldn't find multipath device %s"), line)
|
||||
return None
|
||||
|
||||
LOG.debug(_("Found multipath device = %(mdev)s") % locals())
|
||||
LOG.debug(_("Found multipath device = %s"), mdev)
|
||||
device_lines = lines[3:]
|
||||
for dev_line in device_lines:
|
||||
if dev_line.find("policy") != -1:
|
||||
|
@ -398,7 +398,7 @@ def get_my_linklocal(interface):
|
||||
raise exception.NovaException(msg)
|
||||
except Exception as ex:
|
||||
msg = _("Couldn't get Link Local IP of %(interface)s"
|
||||
" :%(ex)s") % locals()
|
||||
" :%(ex)s") % {'interface': interface, 'ex': ex}
|
||||
raise exception.NovaException(msg)
|
||||
|
||||
|
||||
@ -1105,12 +1105,12 @@ def check_string_length(value, name, min_length=0, max_length=None):
|
||||
|
||||
if len(value) < min_length:
|
||||
msg = _("%(name)s has less than %(min_length)s "
|
||||
"characters.") % locals()
|
||||
"characters.") % {'name': name, 'min_length': min_length}
|
||||
raise exception.InvalidInput(message=msg)
|
||||
|
||||
if max_length and len(value) > max_length:
|
||||
msg = _("%(name)s has more than %(max_length)s "
|
||||
"characters.") % locals()
|
||||
"characters.") % {'name': name, 'max_length': max_length}
|
||||
raise exception.InvalidInput(message=msg)
|
||||
|
||||
|
||||
|
@ -62,7 +62,8 @@ def _load_config():
|
||||
NOVA_PACKAGE = cfg.get("Nova", "package")
|
||||
except Exception as ex:
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG.error("Failed to load %(cfgfile)s: %(ex)s" % locals())
|
||||
LOG.error("Failed to load %(cfgfile)s: %(ex)s",
|
||||
{'cfgfile': cfgfile, 'ex': ex})
|
||||
|
||||
|
||||
def vendor_string():
|
||||
|
Loading…
Reference in New Issue
Block a user