Browse Source

Add a hacking rule for string interpolation at logging

String interpolation should be delayed to be handled by
the logging code, rather than being done at the point
of the logging call.
See the oslo i18n guideline
* https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html#adding-variables-to-log-messages
and
* https://github.com/openstack-dev/hacking/blob/master/hacking/checks/other.py#L39
Closes-Bug: #1596829

Change-Id: Iba231be2476dcbeeb0edd76d6a921e549d183758
tags/12.0.0.0b3
ForestLee 2 years ago
parent
commit
d02a66d6bf

+ 4
- 4
keystone/cmd/cli.py View File

@@ -504,10 +504,10 @@ class DbSync(BaseApp):
504 504
         LOG.info('The latest installed migration script version is: '
505 505
                  '%(script)d.\nCurrent repository versions:\nExpand: '
506 506
                  '%(expand)d \nMigrate: %(migrate)d\nContract: '
507
-                 '%(contract)d' % {'script': migration_script_version,
508
-                                   'expand': expand_version,
509
-                                   'migrate': migrate_version,
510
-                                   'contract': contract_version})
507
+                 '%(contract)d', {'script': migration_script_version,
508
+                                  'expand': expand_version,
509
+                                  'migrate': migrate_version,
510
+                                  'contract': contract_version})
511 511
         return status
512 512
 
513 513
     @staticmethod

+ 2
- 3
keystone/common/fernet_utils.py View File

@@ -96,7 +96,7 @@ class FernetUtils(object):
96 96
                 LOG.warning(
97 97
                     'Unable to change the ownership of key_repository without '
98 98
                     'a keystone user ID and keystone group ID both being '
99
-                    'provided: %s' % self.key_repository)
99
+                    'provided: %s', self.key_repository)
100 100
 
101 101
     def _create_new_key(self, keystone_user_id, keystone_group_id):
102 102
         """Securely create a new encryption key.
@@ -128,8 +128,7 @@ class FernetUtils(object):
128 128
             LOG.warning(
129 129
                 'Unable to change the ownership of the new key without a '
130 130
                 'keystone user ID and keystone group ID both being provided: '
131
-                '%s' %
132
-                self.key_repository)
131
+                '%s', self.key_repository)
133 132
         # Determine the file name of the new key
134 133
         key_file = os.path.join(self.key_repository, '0.tmp')
135 134
         create_success = False

+ 1
- 1
keystone/resource/backends/sql.py View File

@@ -214,7 +214,7 @@ class Resource(base.ResourceDriverBase):
214 214
                 if (project_id not in project_ids_from_bd or
215 215
                         project_id == base.NULL_DOMAIN_ID):
216 216
                     LOG.warning('Project %s does not exist and was not '
217
-                                'deleted.' % project_id)
217
+                                'deleted.', project_id)
218 218
             query.delete(synchronize_session=False)
219 219
 
220 220
 

+ 1
- 1
keystone/resource/core.py View File

@@ -1353,7 +1353,7 @@ class DomainConfigManager(manager.Manager):
1353 1353
                     'value: %(value)s.')
1354 1354
 
1355 1355
             if warning_msg:
1356
-                LOG.warning(warning_msg % {
1356
+                LOG.warning(warning_msg, {
1357 1357
                     'domain': domain_id,
1358 1358
                     'group': each_whitelisted['group'],
1359 1359
                     'option': each_whitelisted['option'],

+ 1
- 1
keystone/tests/unit/fakeldap.py View File

@@ -347,7 +347,7 @@ class FakeLdap(common.LDAPHandler):
347 347
                         id_attr_in_modlist = True
348 348
 
349 349
         if not id_attr_in_modlist:
350
-            LOG.debug('id_attribute=%(attr)s missing, attributes=%(attrs)s' %
350
+            LOG.debug('id_attribute=%(attr)s missing, attributes=%(attrs)s',
351 351
                       {'attr': id_attr, 'attrs': modlist})
352 352
             raise ldap.NAMING_VIOLATION
353 353
         key = self.key(dn)

+ 1
- 1
keystone/tests/unit/resource/test_core.py View File

@@ -557,7 +557,7 @@ class DomainConfigTests(object):
557 557
             with mock.patch('keystone.resource.core.LOG', mock_log):
558 558
                 res = self.domain_config_api.get_config_with_sensitive_info(
559 559
                     self.domain['id'])
560
-            mock_log.warning.assert_any_call(mock.ANY)
560
+            mock_log.warning.assert_any_call(mock.ANY, mock.ANY)
561 561
             self.assertEqual(
562 562
                 invalid_option_config['ldap']['url'], res['ldap']['url'])
563 563
 

+ 1
- 1
tox.ini View File

@@ -99,7 +99,7 @@ passenv =
99 99
 [flake8]
100 100
 filename= *.py,keystone-manage
101 101
 show-source = true
102
-enable-extensions = H203
102
+enable-extensions = H203,H904
103 103
 
104 104
 # D100: Missing docstring in public module
105 105
 # D101: Missing docstring in public class

Loading…
Cancel
Save