diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index bc6fcddca9..0a460dfb30 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -97,6 +97,7 @@ doubled_words_re = re.compile( log_remove_context = re.compile( r"(.)*LOG\.(.*)\(.*(context=[_a-zA-Z0-9].*)+.*\)") return_not_followed_by_space = re.compile(r"^\s*return(?:\(|{|\"|'|#).*$") +uuid4_re = re.compile(r"uuid4\(\)($|[^\.]|\.hex)") class BaseASTChecker(ast.NodeVisitor): @@ -779,10 +780,7 @@ def check_uuid4(logical_line): msg = ("N357: Use oslo_utils.uuidutils or uuidsentinel(in case of test " "cases) to generate UUID instead of uuid4().") - if "uuid4()." in logical_line: - return - - if "uuid4()" in logical_line: + if uuid4_re.search(logical_line): yield (0, msg) diff --git a/nova/tests/unit/test_hacking.py b/nova/tests/unit/test_hacking.py index 47b4ce518f..82b822a793 100644 --- a/nova/tests/unit/test_hacking.py +++ b/nova/tests/unit/test_hacking.py @@ -758,12 +758,12 @@ class HackingTestCase(test.NoDBTestCase): def test_check_uuid4(self): code = """ fake_uuid = uuid.uuid4() + hex_uuid = uuid.uuid4().hex """ - errors = [(1, 0, 'N357')] + errors = [(1, 0, 'N357'), (2, 0, 'N357')] self._assert_has_errors(code, checks.check_uuid4, expected_errors=errors) code = """ - hex_uuid = uuid.uuid4().hex int_uuid = uuid.uuid4().int urn_uuid = uuid.uuid4().urn variant_uuid = uuid.uuid4().variant