summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2019-01-29 13:06:47 +0900
committerTakashi NATSUME <natsume.takashi@lab.ntt.co.jp>2019-01-29 15:06:39 +0900
commit552213e79f0beda26caa80d993cc4740bbad0f28 (patch)
tree0b90639745cc04ad86900998fe42e59e6831deb6
parentc134feda3d9527dbc9735e4ae9cd35c4782f1fb4 (diff)
downloadnova-552213e79f0beda26caa80d993cc4740bbad0f28.tar.gz
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
-rw-r--r--nova/policy.py8
-rw-r--r--nova/tests/unit/api/openstack/compute/test_flavor_manage.py23
-rw-r--r--nova/tests/unit/test_policy.py6
-rw-r--r--nova/virt/libvirt/storage/rbd_utils.py7
4 files changed, 23 insertions, 21 deletions
diff --git a/nova/policy.py b/nova/policy.py
index cfdb1097a3..5a5e9f2af8 100644
--- a/nova/policy.py
+++ b/nova/policy.py
@@ -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:
diff --git a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py
index 2b6048d45c..36bf1f3a88 100644
--- a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py
+++ b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py
@@ -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
diff --git a/nova/tests/unit/test_policy.py b/nova/tests/unit/test_policy.py
index 5ddf5d2034..542281de1c 100644
--- a/nova/tests/unit/test_policy.py
+++ b/nova/tests/unit/test_policy.py
@@ -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):
diff --git a/nova/virt/libvirt/storage/rbd_utils.py b/nova/virt/libvirt/storage/rbd_utils.py
index 1fd2e71ad3..d51d8e51af 100644
--- a/nova/virt/libvirt/storage/rbd_utils.py
+++ b/nova/virt/libvirt/storage/rbd_utils.py
@@ -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