summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2015-03-25 08:51:42 -0400
committerMatthew Treinish <mtreinish@kortar.org>2015-03-25 08:51:42 -0400
commit4a2cd4251140b8271ffe3bea3cec580c1882ec7e (patch)
tree835c5a30c62764adb1d41777db6915832ef2b1a3
parent59b3f34774e0f1e9308ddf611d58520a5bd848bc (diff)
downloadtempest-lib-4a2cd4251140b8271ffe3bea3cec580c1882ec7e.tar.gz
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
-rw-r--r--tempest_lib/common/utils/data_utils.py10
1 files 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():