Fix string interpolations in logging calls

String interpolation should be delayed to be handled
by the logging code, rather than being done
at the point of the logging call.

* https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages

The check rule for string format method will be added
in openstack/hacking.

TrivialFix
Change-Id: I6ec56ec35bcb33d6627a47b66c4f7fc2c6f22658
This commit is contained in:
Takashi NATSUME 2019-01-29 13:06:47 +09:00
parent c134feda3d
commit 552213e79f
4 changed files with 23 additions and 21 deletions

View File

@ -234,10 +234,10 @@ def verify_deprecated_policy(old_policy, new_policy, default_rule, context):
current_rule = None
if current_rule != default_rule:
LOG.warning("Start using the new action '{0}'. The existing "
"action '{1}' is being deprecated and will be "
"removed in future release.".format(new_policy,
old_policy))
LOG.warning("Start using the new action '%(new_policy)s'. "
"The existing action '%(old_policy)s' is being deprecated "
"and will be removed in future release.",
{'new_policy': new_policy, 'old_policy': old_policy})
context.can(old_policy)
return True
else:

View File

@ -563,10 +563,11 @@ class FlavorManagerPolicyEnforcementV21(test.TestCase):
self.assertEqual(
"Policy doesn't allow %s to be performed." % default_flavor_policy,
exc.format_message())
mock_warning.assert_called_with("Start using the new "
"action '{0}'. The existing action '{1}' is being deprecated and "
"will be removed in future release.".format(create_flavor_policy,
default_flavor_policy))
mock_warning.assert_called_with("Start using the new action "
"'%(new_policy)s'. The existing action '%(old_policy)s' is being "
"deprecated and will be removed in future release.",
{'new_policy': create_flavor_policy,
'old_policy': default_flavor_policy})
@mock.patch.object(policy.LOG, 'warning')
def test_delete_policy_rbac_inherit_default(self, mock_warning):
@ -597,9 +598,10 @@ class FlavorManagerPolicyEnforcementV21(test.TestCase):
}
self.flavor = self.controller._create(self.adm_req, body=body)
mock_warning.assert_called_once_with("Start using the new "
"action '{0}'. The existing action '{1}' is being deprecated and "
"will be removed in future release.".format(create_flavor_policy,
default_flavor_policy))
"action '%(new_policy)s'. The existing action '%(old_policy)s' "
"is being deprecated and will be removed in future release.",
{'new_policy': create_flavor_policy,
'old_policy': default_flavor_policy})
# check for success as admin
flavor = self.flavor
self.controller._delete(self.adm_req, flavor['flavor']['id'])
@ -614,9 +616,10 @@ class FlavorManagerPolicyEnforcementV21(test.TestCase):
"Policy doesn't allow %s to be performed." % default_flavor_policy,
exc.format_message())
mock_warning.assert_called_with("Start using the new "
"action '{0}'. The existing action '{1}' is being deprecated and "
"will be removed in future release.".format(delete_flavor_policy,
default_flavor_policy))
"action '%(new_policy)s'. The existing action '%(old_policy)s' "
"is being deprecated and will be removed in future release.",
{'new_policy': delete_flavor_policy,
'old_policy': default_flavor_policy})
def test_create_policy_rbac_no_change_to_default_action_rule(self):
"""Test to verify the correct action is being enforced. When the

View File

@ -193,9 +193,9 @@ class PolicyTestCase(test.NoDBTestCase):
old_policy, new_policy, default_rule, self.context)
mock_warning.assert_called_once_with("Start using the new "
"action '{0}'. The existing action '{1}' is being deprecated and "
"will be removed in future release.".format(new_policy,
old_policy))
"action '%(new_policy)s'. The existing action '%(old_policy)s' "
"is being deprecated and will be removed in future release.",
{'new_policy': new_policy, 'old_policy': old_policy})
self.assertTrue(using_old_action)
def test_verify_deprecated_policy_using_new_action(self):

View File

@ -210,10 +210,9 @@ class RBDDriver(object):
return False
if image_meta.get('disk_format') != 'raw':
reason = ("rbd image clone requires image format to be "
"'raw' but image {0} is '{1}'").format(
url, image_meta.get('disk_format'))
LOG.debug(reason)
LOG.debug("rbd image clone requires image format to be "
"'raw' but image %s is '%s'",
url, image_meta.get('disk_format'))
return False
# check that we can read the image