hacking: Use uuidutils to generate UUID

Added hacking check to ensure that UUIDs are not generated
by uuid4() since we should do this using oslo_utils.uuidutils.

Based on this nova change [1].

[1] I73ee63fbd4f451d3aa5dc1a2a734d68c308b4440

Change-Id: Ic7783c29fbd838c827ccc8ee44aa757fef8e9169
This commit is contained in:
Tom Barron 2016-11-14 12:47:25 -05:00
parent 34f5274931
commit f2ffae1870
3 changed files with 33 additions and 0 deletions

@ -26,6 +26,7 @@ Manila Specific Commandments
- [M336] Must use a dict comprehension instead of a dict constructor
with a sequence of key-value pairs.
- [M337] Ensure to not use xrange().
- [M354] Use oslo_utils.uuidutils to generate UUID instead of uuid4().
LOG Translations
----------------

@ -342,6 +342,24 @@ def validate_assertIsNone(logical_line):
yield(0, msg)
def check_uuid4(logical_line):
"""Generating UUID
Use oslo_utils.uuidutils to generate UUID instead of uuid4().
M354
"""
msg = ("M354: Use oslo_utils.uuidutils to generate UUID instead "
"of uuid4().")
if "uuid4()." in logical_line:
return
if "uuid4()" in logical_line:
yield (0, msg)
def factory(register):
register(validate_log_translations)
register(check_explicit_underscore_import)
@ -354,3 +372,4 @@ def factory(register):
register(no_xrange)
register(validate_assertTrue)
register(validate_assertIsNone)
register(check_uuid4)

@ -316,3 +316,16 @@ class HackingTestCase(test.TestCase):
"assertIsNone(None)"))))
self.assertEqual(1, len(list(checks.validate_assertIsNone(
"assertEqual(None, %s)" % test_value))))
def test_check_uuid4(self):
code = """
fake_uuid = uuid.uuid4()
"""
errors = [(1, 0, 'M354')]
self._assert_has_errors(code, checks.check_uuid4,
expected_errors=errors)
code = """
hex_uuid = uuid.uuid4().hex
"""
self._assert_has_no_errors(code, checks.check_uuid4)