Amend uuid4 hacking rule
Starting from oslo.utils 3.20.0, oslo_utils.uuidutils.generate_uuid can return "uuid.uuid4().hex" string. So the following rule has been amended to use "oslo_utils.uuidutils.generate_uuid(dashed=False)" instead of "uuid.uuid4().hex". * N357: Use oslo_utils.uuidutils or uuidsentinel (in case of test cases) to generate UUID instead of uuid4(). Change-Id: I990cbfcefb33cc52d70e9be80c780593c536397a
This commit is contained in:
parent
e795c8a09b
commit
bb24320ba2
@ -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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user