Add hacking check for oslo namespace usage
We want to make sure that we don't have usage of the old oslo.concurrency naming slipping in with new changes where we should be using the oslo_concurrency namespace. This change adds a hacking check to avoid use of the deprecated namespace. As we convert more oslo libraries to the new namespace the check will be updated to enforce use of the new namespace. This hacking check is based upon the same N333 hacking check in Cinder. Change-Id: Ibec6d09e9d313c9e723f7542cedb9da5772d3de2
This commit is contained in:
parent
fadc833474
commit
d8301e58bf
@ -13,6 +13,7 @@ Cinder Specific Commandments
|
||||
- [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
|
||||
|
@ -41,6 +41,10 @@ underscore_import_check = re.compile(r"(.)*i18n\s+import\s+_(.)*")
|
||||
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.
|
||||
@ -124,6 +128,14 @@ def check_assert_called_once(logical_line, filename):
|
||||
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)
|
||||
@ -131,3 +143,4 @@ def factory(register):
|
||||
register(check_explicit_underscore_import)
|
||||
register(check_no_log_audit)
|
||||
register(check_assert_called_once)
|
||||
register(check_oslo_namespace_imports)
|
||||
|
@ -110,3 +110,9 @@ class HackingTestCase(test.TestCase):
|
||||
"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"))))
|
||||
|
@ -10,7 +10,7 @@
|
||||
# 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user