mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Refactor test.rand_str to reuse later
Signed-off-by: Mathieu Le Marec - Pasquet <kiorky@cryptelium.net>
This commit is contained in:
parent
7646cb16ea
commit
1b8e0d0483
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Module for running arbitrary tests
|
||||
'''
|
||||
@ -14,6 +13,7 @@ import random
|
||||
|
||||
# Import Salt libs
|
||||
import salt
|
||||
import salt.utils
|
||||
import salt.version
|
||||
import salt.loader
|
||||
import salt.ext.six as six
|
||||
@ -469,18 +469,26 @@ def opts_pkg():
|
||||
return ret
|
||||
|
||||
|
||||
def rand_str(size=9999999999):
|
||||
def rand_str(size=9999999999, hash_type='md5'):
|
||||
'''
|
||||
Return a random string
|
||||
|
||||
size
|
||||
size of the string to generate
|
||||
hash_type
|
||||
hash type to use
|
||||
|
||||
.. versionadded:: 2015.5.2
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' test.rand_str
|
||||
'''
|
||||
hasher = getattr(hashlib, __opts__.get('hash_type', 'md5'))
|
||||
return hasher(str(random.SystemRandom().randint(0, size))).hexdigest()
|
||||
return salt.utils.rand_str(
|
||||
hash_type= __opts__.get('hash_type', hash_type),
|
||||
size=size)
|
||||
|
||||
|
||||
def exception(message='Test Exception'):
|
||||
|
@ -437,6 +437,16 @@ def profile_func(filename=None):
|
||||
return proffunc
|
||||
|
||||
|
||||
def rand_str(size=9999999999, hash_type=None):
|
||||
'''
|
||||
Return a random string
|
||||
'''
|
||||
if not hash_type:
|
||||
hash_type = 'md5'
|
||||
hasher = getattr(hashlib, hash_type)
|
||||
return hasher(str(random.SystemRandom().randint(0, size))).hexdigest()
|
||||
|
||||
|
||||
def which(exe=None):
|
||||
'''
|
||||
Python clone of /usr/bin/which
|
||||
|
Loading…
Reference in New Issue
Block a user