- [N323] Add check for explicit import of _() to ensure proper translation.
- [N324] Enforce no use of LOG.audit messages. LOG.info should be used instead.
- [N327] assert_called_once is not a valid Mock method.
+- [N333] Ensure that oslo namespaces are used for namespaced libraries.
General
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
no_audit_log = re.compile(r"(.)*LOG\.audit(.)*")
+# NOTE(jsbryant): When other oslo libraries switch over non-namespaced
+# imports, we will need to add them to the regex below.
+oslo_namespace_imports = re.compile(r"from[\s]*oslo[.](concurrency)")
+
def no_vi_headers(physical_line, line_number, lines):
"""Check for vi editor configuration in source files.
yield (pos, msg)
+def check_oslo_namespace_imports(logical_line):
+ if re.match(oslo_namespace_imports, logical_line):
+ msg = ("N333: '%s' must be used instead of '%s'.") % (
+ logical_line.replace('oslo.', 'oslo_'),
+ logical_line)
+ yield(0, msg)
+
+
def factory(register):
register(no_vi_headers)
register(no_translate_debug_logs)
register(check_explicit_underscore_import)
register(check_no_log_audit)
register(check_assert_called_once)
+ register(check_oslo_namespace_imports)
"LOG.audit('My test audit log')"))), 1)
self.assertEqual(len(list(checks.check_no_log_audit(
"LOG.info('My info test log.')"))), 0)
+
+ def test_oslo_namespace_imports_check(self):
+ self.assertEqual(1, len(list(checks.check_oslo_namespace_imports(
+ "from oslo.concurrency import foo"))))
+ self.assertEqual(0, len(list(checks.check_oslo_namespace_imports(
+ "from oslo_concurrency import bar"))))
# License for the specific language governing permissions and limitations
# under the License.
-from oslo.concurrency import processutils
+from oslo_concurrency import processutils
from cinder import exception
from cinder.i18n import _, _LW, _LE