Allow to import _LC, _LE, _LI and _LW functions directly
_LC, _LE, _LI, _LW are translation helper functions. This change updates hacking rules to allow importing them directly: from neutron.openstack.common.gettextutils import _LC from neutron.openstack.common.gettextutils import _LE from neutron.openstack.common.gettextutils import _LI from neutron.openstack.common.gettextutils import _LW neutron.policy module has been updated as an example of _LE, _LI and _LW uses. Change-Id: I11cba6bca48a179945385fce69e6f642270f5563
This commit is contained in:
parent
d42dbd093f
commit
984c468f1c
@ -25,6 +25,7 @@ from neutron.api.v2 import attributes
|
|||||||
from neutron.common import exceptions
|
from neutron.common import exceptions
|
||||||
import neutron.common.utils as utils
|
import neutron.common.utils as utils
|
||||||
from neutron.openstack.common import excutils
|
from neutron.openstack.common import excutils
|
||||||
|
from neutron.openstack.common.gettextutils import _LE, _LI, _LW
|
||||||
from neutron.openstack.common import importutils
|
from neutron.openstack.common import importutils
|
||||||
from neutron.openstack.common import log as logging
|
from neutron.openstack.common import log as logging
|
||||||
from neutron.openstack.common import policy
|
from neutron.openstack.common import policy
|
||||||
@ -90,7 +91,7 @@ def _set_rules(data):
|
|||||||
for pol in policies.keys():
|
for pol in policies.keys():
|
||||||
if any([pol.startswith(depr_pol) for depr_pol in
|
if any([pol.startswith(depr_pol) for depr_pol in
|
||||||
DEPRECATED_POLICY_MAP.keys()]):
|
DEPRECATED_POLICY_MAP.keys()]):
|
||||||
LOG.warn(_("Found deprecated policy rule:%s. Please consider "
|
LOG.warn(_LW("Found deprecated policy rule:%s. Please consider "
|
||||||
"upgrading your policy configuration file"), pol)
|
"upgrading your policy configuration file"), pol)
|
||||||
pol_name, action = pol.rsplit(':', 1)
|
pol_name, action = pol.rsplit(':', 1)
|
||||||
try:
|
try:
|
||||||
@ -102,15 +103,16 @@ def _set_rules(data):
|
|||||||
new_policies)]:
|
new_policies)]:
|
||||||
if actual_policy not in policies:
|
if actual_policy not in policies:
|
||||||
# New policy, same rule
|
# New policy, same rule
|
||||||
LOG.info(_("Inserting policy:%(new_policy)s in place "
|
LOG.info(_LI("Inserting policy:%(new_policy)s in "
|
||||||
"of deprecated policy:%(old_policy)s"),
|
"place of deprecated "
|
||||||
|
"policy:%(old_policy)s"),
|
||||||
{'new_policy': actual_policy,
|
{'new_policy': actual_policy,
|
||||||
'old_policy': pol})
|
'old_policy': pol})
|
||||||
policies[actual_policy] = policies[pol]
|
policies[actual_policy] = policies[pol]
|
||||||
# Remove old-style policy
|
# Remove old-style policy
|
||||||
del policies[pol]
|
del policies[pol]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.error(_("Backward compatibility unavailable for "
|
LOG.error(_LE("Backward compatibility unavailable for "
|
||||||
"deprecated policy %s. The policy will "
|
"deprecated policy %s. The policy will "
|
||||||
"not be enforced"), pol)
|
"not be enforced"), pol)
|
||||||
policy.set_rules(policies)
|
policy.set_rules(policies)
|
||||||
@ -132,7 +134,7 @@ def _build_subattr_match_rule(attr_name, attr, action, target):
|
|||||||
validate = attr['validate']
|
validate = attr['validate']
|
||||||
key = filter(lambda k: k.startswith('type:dict'), validate.keys())
|
key = filter(lambda k: k.startswith('type:dict'), validate.keys())
|
||||||
if not key:
|
if not key:
|
||||||
LOG.warn(_("Unable to find data type descriptor for attribute %s"),
|
LOG.warn(_LW("Unable to find data type descriptor for attribute %s"),
|
||||||
attr_name)
|
attr_name)
|
||||||
return
|
return
|
||||||
data = validate[key[0]]
|
data = validate[key[0]]
|
||||||
@ -275,7 +277,8 @@ class OwnerCheck(policy.Check):
|
|||||||
target[self.target_field] = data[parent_field]
|
target[self.target_field] = data[parent_field]
|
||||||
except Exception:
|
except Exception:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
LOG.exception(_('Policy check error while calling %s!'), f)
|
LOG.exception(_LE('Policy check error while calling %s!'),
|
||||||
|
f)
|
||||||
match = self.match % target
|
match = self.match % target
|
||||||
if self.kind in creds:
|
if self.kind in creds:
|
||||||
return match == unicode(creds[self.kind])
|
return match == unicode(creds[self.kind])
|
||||||
|
1
tox.ini
1
tox.ini
@ -64,4 +64,5 @@ builtins = _
|
|||||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios
|
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios
|
||||||
|
|
||||||
[hacking]
|
[hacking]
|
||||||
|
import_exceptions = neutron.openstack.common.gettextutils
|
||||||
local-check-factory = neutron.hacking.checks.factory
|
local-check-factory = neutron.hacking.checks.factory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user