diff options
author | John Mulligan <jmulligan@redhat.com> | 2017-12-19 17:44:47 -0500 |
---|---|---|
committer | John Mulligan <jmulligan@redhat.com> | 2018-01-19 14:31:07 -0500 |
commit | c9c9f72e2e038643bb96436701ea8abac3fe47c7 (patch) | |
tree | bdeed728e53f0380dbd21d06dde2256d10f51d9b /cns-libs/cnslibs/common/naming.py | |
parent | 993cc40e8e79e9a09114286d018660c98a336ac0 (diff) |
add a test to verify multiple PVC requests create multiple volumes
This is sort of a trial of the both the test framework, my ability
to add tests to it, and the workflow of adding changes to the repo.
Change-Id: I17b61f298c04f45df8b77555b16d292fd2b2a3a8
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Diffstat (limited to 'cns-libs/cnslibs/common/naming.py')
-rw-r--r-- | cns-libs/cnslibs/common/naming.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cns-libs/cnslibs/common/naming.py b/cns-libs/cnslibs/common/naming.py new file mode 100644 index 00000000..b44559ad --- /dev/null +++ b/cns-libs/cnslibs/common/naming.py @@ -0,0 +1,56 @@ +"""Helper functions for working with names for volumes, resources, etc. +""" + +import string +import random +import re + +# we only use lowercase here because kubernetes requires +# names to be lowercase or digits, so that is our default +UNIQUE_CHARS = (string.lowercase + string.digits) + + +def make_unique_label(prefix=None, suffix=None, sep='-', + clean=r'[^a-zA-Z0-9]+', unique_len=8, + unique_chars=UNIQUE_CHARS): + """Generate a unique name string based on an optional prefix, + suffix, and pseudo-random set of alphanumeric characters. + + Args: + prefix (str): Start of the unique string. + suffix (str): End of the unique string. + sep (str): Separator string (between sections/invalid chars). + clean (str): Reqular expression matching invalid chars. + that will be replaced by `sep` if found in the prefix or suffix + unique_len (int): Length of the unique part. + unique_chars (str): String representing the set of characters + the unique part will draw from. + Returns: + str: The uniqueish string. + """ + cre = re.compile(clean) + parts = [] + if prefix: + parts.append(cre.sub(sep, prefix)) + parts.append(''.join(random.choice(unique_chars) + for _ in range(unique_len))) + if suffix: + parts.append(cre.sub(sep, suffix)) + return sep.join(parts) + + +def extract_method_name(full_name, keep_class=False): + """Given a full test name as returned from TestCase.id() return + just the method part or class.method. + + Args: + full_name (str): Dot separated name of test. + keep_class (str): Retain the class name, if false only the + method name will be returned. + Returns: + str: Method name or class.method_name. + """ + offset = -1 + if keep_class: + offset = -2 + return '.'.join(full_name.split('.')[offset:]) |