From 4a2cd4251140b8271ffe3bea3cec580c1882ec7e Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 25 Mar 2015 08:51:42 -0400 Subject: Add optional prefix parameter to rand_name function This commits an optional prefix kwarg to the rand_name function in data utils. The intet of this argument is to allow a consumer of the function to wrap randname to specify a project specific prefix to all the generated names. For example, this will be useful for identification of test created resources in case of bugs causing resource leaks. Change-Id: I7f7a1313ccbd8c5ef1e720537c16d60c89ed5923 --- tempest_lib/common/utils/data_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tempest_lib/common/utils/data_utils.py b/tempest_lib/common/utils/data_utils.py index eec2474..dc799fe 100644 --- a/tempest_lib/common/utils/data_utils.py +++ b/tempest_lib/common/utils/data_utils.py @@ -27,12 +27,14 @@ def rand_uuid_hex(): return uuid.uuid4().hex -def rand_name(name=''): +def rand_name(name='', prefix=None): randbits = str(random.randint(1, 0x7fffffff)) + rand_name = randbits if name: - return name + '-' + randbits - else: - return randbits + rand_name = name + '-' + rand_name + if prefix: + rand_name = prefix + '-' + rand_name + return rand_name def rand_url(): -- cgit v1.2.1