diff --git a/HACKING.rst b/HACKING.rst index 5a868f10..b9331dab 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -16,7 +16,6 @@ Cloudkitty Specific Commandments - [C314] str() and unicode() cannot be used on an exception. Remove or use six.text_type(). - [C315] Translated messages cannot be concatenated. String should be included in translated message. -- [C316] Log messages, except debug ones, require translations! - [C317] 'oslo_' should be used instead of 'oslo.' - [C318] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs. diff --git a/cloudkitty/api/app.py b/cloudkitty/api/app.py index 98f1c9fb..43375e97 100644 --- a/cloudkitty/api/app.py +++ b/cloudkitty/api/app.py @@ -26,7 +26,6 @@ import pecan from cloudkitty.api import config as api_config from cloudkitty.api import hooks -from cloudkitty.i18n import _LI from cloudkitty import storage @@ -100,7 +99,7 @@ def load_app(): if not cfg_file: raise cfg.ConfigFilesNotFoundError([cfg.CONF.api_paste_config]) - LOG.info(_LI("Full WSGI config used: %s"), cfg_file) + LOG.info("Full WSGI config used: %s", cfg_file) return deploy.loadapp("config:" + cfg_file) @@ -108,16 +107,16 @@ def build_server(): # Create the WSGI server and start it host = CONF.api.host_ip port = CONF.api.port - LOG.info(_LI('Starting server in PID %s'), os.getpid()) - LOG.info(_LI("Configuration:")) + LOG.info('Starting server in PID %s', os.getpid()) + LOG.info("Configuration:") cfg.CONF.log_opt_values(LOG, logging.INFO) if host == '0.0.0.0': - LOG.info(_LI('serving on 0.0.0.0:%(sport)s, view at ' - 'http://127.0.0.1:%(vport)s'), + LOG.info('serving on 0.0.0.0:%(sport)s, view at \ + http://127.0.0.1:%(vport)s', {'sport': port, 'vport': port}) else: - LOG.info(_LI("serving on http://%(host)s:%(port)s"), + LOG.info("serving on http://%(host)s:%(port)s", {'host': host, 'port': port}) server_cls = simple_server.WSGIServer diff --git a/cloudkitty/api/v1/types.py b/cloudkitty/api/v1/types.py index d564bbfc..27bb1d58 100644 --- a/cloudkitty/api/v1/types.py +++ b/cloudkitty/api/v1/types.py @@ -18,8 +18,6 @@ from oslo_utils import uuidutils from wsme import types as wtypes -from cloudkitty.i18n import _LE - class UuidType(wtypes.UuidType): """A simple UUID type.""" @@ -29,7 +27,7 @@ class UuidType(wtypes.UuidType): @staticmethod def validate(value): if not uuidutils.is_uuid_like(value): - raise ValueError(_LE("Invalid UUID, got '%s'") % value) + raise ValueError("Invalid UUID, got '%s'" % value) return value @@ -56,5 +54,5 @@ class MultiType(wtypes.UserType): return value else: raise ValueError( - _LE("Wrong type. Expected '%(type)s', got '%(value)s'") + "Wrong type. Expected '%(type)s', got '%(value)s'" % {'type': self.types, 'value': type(value)}) diff --git a/cloudkitty/hacking/checks.py b/cloudkitty/hacking/checks.py index d6a3c55e..f13bb480 100644 --- a/cloudkitty/hacking/checks.py +++ b/cloudkitty/hacking/checks.py @@ -38,14 +38,6 @@ UNDERSCORE_IMPORT_FILES = [] log_translation = re.compile( r"(.)*LOG\.(audit|error|info|critical|exception)\(\s*('|\")") -log_translation_LC = re.compile( - r"(.)*LOG\.(critical)\(\s*(_\(|'|\")") -log_translation_LE = re.compile( - r"(.)*LOG\.(error|exception)\(\s*(_\(|'|\")") -log_translation_LI = re.compile( - r"(.)*LOG\.(info)\(\s*(_\(|'|\")") -log_translation_LW = re.compile( - r"(.)*LOG\.(warning|warn)\(\s*(_\(|'|\")") translated_log = re.compile( r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)" "\(\s*_\(\s*('|\")") @@ -189,30 +181,6 @@ class CheckLoggingFormatArgs(BaseASTChecker): return super(CheckLoggingFormatArgs, self).generic_visit(node) -def validate_log_translations(logical_line, physical_line, filename): - # Translations are not required in the test directories. - if ("cloudkitty/tests" in filename): - return - if pep8.noqa(physical_line): - return - msg = "C316: LOG.critical messages require translations `_LC()`!" - if log_translation_LC.match(logical_line): - yield (0, msg) - msg = ("C316: LOG.error and LOG.exception messages require translations " - "`_LE()`!") - if log_translation_LE.match(logical_line): - yield (0, msg) - msg = "C316: LOG.info messages require translations `_LI()`!" - if log_translation_LI.match(logical_line): - yield (0, msg) - msg = "C316: LOG.warning messages require translations `_LW()`!" - if log_translation_LW.match(logical_line): - yield (0, msg) - msg = "C316: Log messages require translations!" - if log_translation.match(logical_line): - yield (0, msg) - - def check_explicit_underscore_import(logical_line, filename): """Check for explicit import of the _ function @@ -293,7 +261,7 @@ class CheckForTransAdd(BaseASTChecker): CHECK_DESC = ('C315 Translated messages cannot be concatenated. ' 'String should be included in translated message.') - TRANS_FUNC = ['_', '_LI', '_LW', '_LE', '_LC'] + TRANS_FUNC = ['_'] def visit_BinOp(self, node): if isinstance(node.op, ast.Add): @@ -372,7 +340,6 @@ def no_log_warn_check(logical_line): def factory(register): - register(validate_log_translations) register(check_explicit_underscore_import) register(no_translate_debug_logs) register(CheckForStrUnicodeExc) diff --git a/cloudkitty/i18n.py b/cloudkitty/i18n.py index 99b763a1..89e27c2e 100644 --- a/cloudkitty/i18n.py +++ b/cloudkitty/i18n.py @@ -21,7 +21,3 @@ _translators = i18n.TranslatorFactory(domain='cloudkitty') i18n.enable_lazy() _ = _translators.primary -_LI = _translators.log_info -_LW = _translators.log_warning -_LE = _translators.log_error -_LC = _translators.log_critical diff --git a/cloudkitty/orchestrator.py b/cloudkitty/orchestrator.py index f33d8c38..0ef3eaa3 100644 --- a/cloudkitty/orchestrator.py +++ b/cloudkitty/orchestrator.py @@ -31,7 +31,6 @@ from tooz import coordination from cloudkitty import collector from cloudkitty import config # noqa from cloudkitty import extension_manager -from cloudkitty.i18n import _LI, _LW from cloudkitty import messaging from cloudkitty import storage from cloudkitty import transformer @@ -86,26 +85,26 @@ class RatingEndpoint(object): return str(worker.quote(res_data)) def reload_modules(self, ctxt): - LOG.info(_LI('Received reload modules command.')) + LOG.info('Received reload modules command.') lock = lockutils.lock('module-reload') with lock: self._global_reload = True def reload_module(self, ctxt, name): - LOG.info(_LI('Received reload command for module %s.'), name) + LOG.info('Received reload command for module %s.', name) lock = lockutils.lock('module-reload') with lock: if name not in self._pending_reload: self._pending_reload.append(name) def enable_module(self, ctxt, name): - LOG.info(_LI('Received enable command for module %s.'), name) + LOG.info('Received enable command for module %s.', name) lock = lockutils.lock('module-state') with lock: self._module_state[name] = True def disable_module(self, ctxt, name): - LOG.info(_LI('Received disable command for module %s.'), name) + LOG.info('Received disable command for module %s.', name) lock = lockutils.lock('module-state') with lock: self._module_state[name] = False @@ -189,8 +188,8 @@ class Worker(BaseWorker): raise except Exception as e: LOG.warning( - _LW('Error while collecting service ' - '%(service)s: %(error)s'), + 'Error while collecting service ' + '%(service)s: %(error)s', {'service': service, 'error': e}) raise collector.NoDataCollected('', service) except collector.NoDataCollected: diff --git a/cloudkitty/storage/gnocchi/__init__.py b/cloudkitty/storage/gnocchi/__init__.py index a95ac96e..5a426c8f 100644 --- a/cloudkitty/storage/gnocchi/__init__.py +++ b/cloudkitty/storage/gnocchi/__init__.py @@ -28,7 +28,6 @@ from oslo_log import log from oslo_utils import uuidutils import six -from cloudkitty.i18n import _LW from cloudkitty import storage from cloudkitty import utils as ck_utils @@ -272,8 +271,8 @@ class GnocchiStorage(storage.BaseStorage): query = {"=": {"project_id": tenant_id}} # TODO(Aaron): need support with groupby if groupby: - LOG.warning(_LW('Now get total with groupby not support ' - 'in gnocchi storage backend')) + LOG.warning('Now get total with groupby not support ' + 'in gnocchi storage backend') # TODO(sheeprine): Use server side aggregation r = self._conn.metric.aggregation(metrics=metric, query=query, start=begin, stop=end, diff --git a/cloudkitty/storage/gnocchi_hybrid/__init__.py b/cloudkitty/storage/gnocchi_hybrid/__init__.py index c22c53f9..5a121498 100644 --- a/cloudkitty/storage/gnocchi_hybrid/__init__.py +++ b/cloudkitty/storage/gnocchi_hybrid/__init__.py @@ -19,7 +19,6 @@ import decimal from oslo_log import log -from cloudkitty.i18n import _LW from cloudkitty.storage.gnocchi_hybrid import migration from cloudkitty.storage.gnocchi_hybrid import models from cloudkitty.storage import sqlalchemy as sql_storage @@ -49,9 +48,9 @@ class GnocchiHybridStorage(sql_storage.SQLAlchemyStorage): else: resource_ref = frame.get('resource_id') if not resource_ref: - LOG.warning(_LW('Trying to store data collected outside of ' - 'gnocchi. This driver can only be used with ' - 'the gnocchi collector. Data not stored!')) + LOG.warning('Trying to store data collected outside of ' + 'gnocchi. This driver can only be used with ' + 'the gnocchi collector. Data not stored!') return self.add_time_frame(begin=self.usage_start_dt.get(tenant_id), end=self.usage_end_dt.get(tenant_id), diff --git a/cloudkitty/tests/test_hacking.py b/cloudkitty/tests/test_hacking.py index f9941e1e..4a39ae64 100644 --- a/cloudkitty/tests/test_hacking.py +++ b/cloudkitty/tests/test_hacking.py @@ -84,7 +84,7 @@ class HackingTestCase(tests.TestCase): "msg = _('My message')", "cloudkitty/tests/other_files.py")))) self.assertEqual(0, len(list(checks.check_explicit_underscore_import( - "from cloudkitty.i18n import _LE, _, _LW", + "from cloudkitty.i18n import _", "cloudkitty/tests/other_files2.py")))) self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", @@ -99,9 +99,6 @@ class HackingTestCase(tests.TestCase): self.assertEqual(0, len(list(checks.check_explicit_underscore_import( "LOG.info('My info message')", "cloudkitty.tests.unit/other_files4.py")))) - self.assertEqual(0, len(list(checks.check_explicit_underscore_import( - "from cloudkitty.i18n import _LW", - "cloudkitty.tests.unit/other_files5.py")))) self.assertEqual(1, len(list(checks.check_explicit_underscore_import( "msg = _('My message')", "cloudkitty.tests.unit/other_files5.py")))) @@ -235,18 +232,10 @@ class HackingTestCase(tests.TestCase): _ = fake_tran - _LI = _ - _LW = _ - _LE = _ - _LC = _ def f(a, b): msg = _('test') + 'add me' - msg = _LI('test') + 'add me' - msg = _LW('test') + 'add me' - msg = _LE('test') + 'add me' - msg = _LC('test') + 'add me' msg = 'add to me' + _('test') return msg """ @@ -255,11 +244,9 @@ class HackingTestCase(tests.TestCase): # parsing. This was reversed in Python 3.4.3, hence the version-based # expected value calculation. See #1499743 for more background. if sys.version_info < (3, 4, 0) or sys.version_info >= (3, 4, 3): - errors = [(13, 10, 'C315'), (14, 10, 'C315'), (15, 10, 'C315'), - (16, 10, 'C315'), (17, 10, 'C315'), (18, 24, 'C315')] + errors = [(9, 10, 'C315'), (10, 24, 'C315')] else: - errors = [(13, 11, 'C315'), (14, 13, 'C315'), (15, 13, 'C315'), - (16, 13, 'C315'), (17, 13, 'C315'), (18, 25, 'C315')] + errors = [(9, 11, 'C315'), (10, 25, 'C315')] self._assert_has_errors(code, checker, expected_errors=errors) code = """