diff --git a/oslo_utils/tests/test_uuidutils.py b/oslo_utils/tests/test_uuidutils.py index 43ed0b93..e4de301e 100644 --- a/oslo_utils/tests/test_uuidutils.py +++ b/oslo_utils/tests/test_uuidutils.py @@ -29,6 +29,12 @@ class UUIDUtilsTest(test_base.BaseTestCase): # make sure there are 4 dashes self.assertEqual(len(uuid_string.replace('-', '')), 32) + def test_generate_uuid_dashed_false(self): + uuid_string = uuidutils.generate_uuid(dashed=False) + self.assertIsInstance(uuid_string, str) + self.assertEqual(len(uuid_string), 32) + self.assertFalse('-' in uuid_string) + def test_is_uuid_like(self): self.assertTrue(uuidutils.is_uuid_like(str(uuid.uuid4()))) self.assertTrue(uuidutils.is_uuid_like( diff --git a/oslo_utils/uuidutils.py b/oslo_utils/uuidutils.py index 5a48ae68..01615e91 100644 --- a/oslo_utils/uuidutils.py +++ b/oslo_utils/uuidutils.py @@ -22,12 +22,16 @@ UUID related utilities and helper functions. import uuid -def generate_uuid(): +def generate_uuid(dashed=True): """Creates a random uuid string. + :param dashed: Generate uuid with dashes or not + :type dashed: bool :returns: string """ - return str(uuid.uuid4()) + if dashed: + return str(uuid.uuid4()) + return uuid.uuid4().hex def _format_uuid_string(string):