Merge "hacking: Use uuidutils to generate UUID"

This commit is contained in:
Jenkins 2016-11-28 22:06:02 +00:00 committed by Gerrit Code Review
commit b05900b422
3 changed files with 33 additions and 0 deletions

View File

@ -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
----------------

View File

@ -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)

View File

@ -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)