Neutron Specific Commandments
--------------------------
-None so far
+- [N320] Validate that LOG messages, except debug ones, have translations
Creating Unit Tests
-------------------
def is_firewall_enabled():
if not _is_valid_driver_combination():
- LOG.warn("Driver configuration don't match with enable_security_group")
+ LOG.warn(_("Driver configuration doesn't match with "
+ "enable_security_group"))
return cfg.CONF.SECURITYGROUP.enable_security_group
firewall_driver = cfg.CONF.SECURITYGROUP.firewall_driver
LOG.debug(_("Init firewall settings (driver=%s)"), firewall_driver)
if not _is_valid_driver_combination():
- LOG.warn("Driver configuration doesn't match "
- "with enable_security_group")
+ LOG.warn(_("Driver configuration doesn't match "
+ "with enable_security_group"))
if not firewall_driver:
firewall_driver = 'neutron.agent.firewall.NoopFirewallDriver'
self.firewall = importutils.import_object(firewall_driver)
--- /dev/null
+# Copyright (c) 2014 OpenStack Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import re
+
+import pep8
+
+"""
+Guidelines for writing new hacking checks
+
+ - Use only for Neutron specific tests. OpenStack general tests
+ should be submitted to the common 'hacking' module.
+ - Pick numbers in the range N3xx. Find the current test with
+ the highest allocated number and then pick the next value.
+ - Keep the test method code in the source file ordered based
+ on the N3xx value.
+ - List the new rule in the top level HACKING.rst file
+ - Add test cases for each new rule to
+ neutron/tests/unit/test_hacking.py
+
+"""
+
+log_translation = re.compile(
+ r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)\(\s*('|\")")
+
+
+def validate_log_translations(logical_line, physical_line, filename):
+ # Translations are not required in the test directory
+ if "neutron/tests" in filename:
+ return
+ if pep8.noqa(physical_line):
+ return
+ msg = "N320: Log messages require translations!"
+ if log_translation.match(logical_line):
+ yield (0, msg)
+
+
+def factory(register):
+ register(validate_log_translations)
}
def apply_port_filter(self, port):
- LOG.info('Aplying port filter.')
+ LOG.info(_('Aplying port filter.'))
def update_port_filter(self, port):
- LOG.info('Updating port rules.')
+ LOG.info(_('Updating port rules.'))
if port['device'] not in self._security_ports:
self.prepare_port_filter(port)
new_rules = [r for r in param_port_rules if r not in rules]
remove_rules = [r for r in rules if r not in param_port_rules]
- LOG.info("Creating %s new rules, removing %s old rules." % (
- len(new_rules), len(remove_rules)))
+ LOG.info(_("Creating %(new)s new rules, removing %(old)s "
+ "old rules."),
+ {'new': len(new_rules),
+ 'old': len(remove_rules)})
self._remove_port_rules(old_port['id'], remove_rules)
self._create_port_rules(port['id'], new_rules)
self._security_ports[port['device']] = port
def remove_port_filter(self, port):
- LOG.info('Removing port filter')
+ LOG.info(_('Removing port filter'))
self._security_ports.pop(port['device'], None)
@property
force_v1_flag = CONF.hyperv.force_hyperv_utils_v1
if _check_min_windows_version(6, 3):
if force_v1_flag:
- LOG.warning('V1 virtualization namespace no longer supported on '
- 'Windows Server / Hyper-V Server 2012 R2 or above.')
+ LOG.warning(_('V1 virtualization namespace no longer supported on '
+ 'Windows Server / Hyper-V Server 2012 R2 or above.'))
cls = utilsv2.HyperVUtilsV2R2
elif not force_v1_flag and _check_min_windows_version(6, 2):
cls = utilsv2.HyperVUtilsV2
def _network_admin_state(self, network):
if network["network"].get("admin_state_up") is False:
- LOG.warning("Networks with admin_state_up=False are not "
- "supported by PLUMgrid plugin yet.")
+ LOG.warning(_("Networks with admin_state_up=False are not "
+ "supported by PLUMgrid plugin yet."))
return network
def _allocate_pools_for_subnet(self, context, subnet):
--- /dev/null
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from neutron.hacking import checks
+from neutron.tests import base
+
+
+class HackingTestCase(base.BaseTestCase):
+
+ def test_log_translations(self):
+ logs = ['audit', 'error', 'info', 'warn', 'warning', 'critical',
+ 'exception']
+ levels = ['_LI', '_LW', '_LE', '_LC']
+ debug = "LOG.debug('OK')"
+ self.assertEqual(
+ 0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
+ for log in logs:
+ bad = 'LOG.%s("Bad")' % log
+ self.assertEqual(
+ 1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
+ ok = "LOG.%s(_('OK'))" % log
+ self.assertEqual(
+ 0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
+ ok = "LOG.%s('OK') # noqa" % log
+ self.assertEqual(
+ 0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
+ ok = "LOG.%s(variable)" % log
+ self.assertEqual(
+ 0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
+ for level in levels:
+ ok = "LOG.%s(%s('OK'))" % (log, level)
+ self.assertEqual(
+ 0, len(list(checks.validate_log_translations(ok,
+ ok, 'f'))))
show-source = true
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools,.ropeproject
+
+[hacking]
+local-check-factory = neutron.hacking.checks.factory