Add generate_uuid to uuidutils.

Currently many projects have their own nearly identical methods for generating
uuids. This patch will change that.

Change-Id: I0af348ddbdea658331e8e701dcf1f8a12d968479
This commit is contained in:
Alex Meade 2012-11-09 10:53:02 -05:00
parent ac4515559f
commit 251c4f54dc
2 changed files with 11 additions and 0 deletions

View File

@ -22,6 +22,10 @@ UUID related utilities and helper functions.
import uuid
def generate_uuid():
return str(uuid.uuid4())
def is_uuid_like(val):
"""Returns validation of a value as a UUID.

View File

@ -23,6 +23,13 @@ from openstack.common import uuidutils
class UUIDUtilsTest(unittest.TestCase):
def test_generate_uuid(self):
uuid_string = uuidutils.generate_uuid()
self.assertTrue(isinstance(uuid_string, str))
self.assertEqual(len(uuid_string), 36)
# make sure there are 4 dashes
self.assertEqual(len(uuid_string.replace('-', '')), 32)
def test_is_uuid_like(self):
self.assertTrue(uuidutils.is_uuid_like(str(uuid.uuid4())))