Auto-generated documentation for ocs_ci.utility.utils module.
- Ocs-ci / Modules / Ocs Ci / Utility / Utils
- TimeoutSampler
- activate_multiple_mdss
- add_path_to_env_path
- allow_dir_fragmentation
- auth_list
- censor_values
- ceph_health_check
- check_if_executable_in_path
- clone_repo
- create_directory_path
- create_rhelpod
- custom_ceph_config
- decompose_html_attributes
- delete_file
- download_file
- dump_config_to_file
- email_reports
- ensure_nightly_build_availability
- expose_nightly_ocp_version
- file_locking
- fuse_client_io
- fuse_client_md5
- fuse_mount
- get_ceph_version
- get_client_info
- get_cluster_image
- get_cluster_version
- get_cluster_version_info
- get_csi_versions
- get_latest_ds_olm_tag
- get_next_version_available_for_upgrade
- get_ocs_build_number
- get_openshift_client
- get_openshift_installer
- get_openshift_mirror_url
- get_random_str
- get_rook_repo
- get_rook_version
- get_testrun_name
- get_url_content
- is_cluster_running
- kernel_client_io
- kernel_client_md5
- kernel_mount
- mask_secrets
- mds_fail_over
- mkdir_pinning
- ocsci_log_path
- parse_html_for_email
- parse_pgsql_logs
- pinned_dir_io
- prepare_bin_dir
- read_file_as_str
- replace_content_in_file
- run_async
- run_cmd
- run_mcg_cmd
- upload_file
- wait_for_co
mounting_dir
- variables:'/mnt/cephfs/'
class TimeoutSampler(object):
def __init__(timeout, sleep, func, *func_args, **func_kwargs):
Samples the function output.
This is a generator object that at first yields the output of function
func
. After the yield, it either raises instance of timeout_exc_cls
or
sleeps sleep
seconds.
Yielding the output allows you to handle every value as you wish.
Feel free to set the instance variables.
def wait_for_func_status(result):
Get function and run it for given time until success or timeout. (using iter function)
result
bool - Expected result from func.
sample = TimeoutSampler( timeout=60, sleep=1, func=some_func, func_arg1="1", func_arg2="2" ) if not sample.wait_for_func_status(result=True): raise Exception
def activate_multiple_mdss(mds_nodes):
def add_path_to_env_path(path):
Add path to the PATH environment variable (if not already there).
path
str - Path which should be added to the PATH env. variable
def allow_dir_fragmentation(mds_nodes):
def auth_list(clients, mon_node):
def censor_values(data_to_censor):
This function censor values in dictionary keys that match pattern defined in config_keys_patterns_to_censor in constants.
data_to_censor
dict - Data to censor.
@retry((CephHealthException, CommandFailed), tries=20, delay=30, backoff=1)
def ceph_health_check(namespace=None):
Exec ceph health
cmd on tools pod to determine health of cluster.
namespace
str - Namespace of OCS(default
- config.ENV_DATA['cluster_namespace'])
CephHealthException
- If the ceph health returned is not HEALTH_OKCommandFailed
- If the command to retrieve the tools pod name or the command to get ceph health returns a non-zero exit code
boolean
- True if HEALTH_OK
def check_if_executable_in_path(exec_name):
Checks whether an executable can be found in the $PATH
exec_name
- Name of executable to look for
Boolean
- Whether the executable was found
def clone_repo(url, location, branch='master', to_checkout=None):
Clone a repository or checkout latest changes if it already exists at specified location.
url
str - location of the repository to clonelocation
str - path where the repository will be cloned tobranch
str - branch name to checkoutto_checkout
str - commit id or tag to checkout
def create_directory_path(path):
Creates directory if path doesn't exists
def create_rhelpod(namespace, pod_name):
Creates the RHEL pod
namespace
str - Namespace to create RHEL podpod_name
str - Pod name
pod
- Pod instance for RHEL
def custom_ceph_config(suite_config, custom_config, custom_config_file):
Combines and returns custom configuration overrides for ceph. Hierarchy is as follows: custom_config > custom_config_file > suite_config
suite_config
- ceph_conf_overrides that currently exist in the test suitecustom_config
- custom config args provided by the cli (these all go to the global scope)custom_config_file
- path to custom config yaml file provided by the cli
Returns New value to be used for ceph_conf_overrides in test config
def decompose_html_attributes(soup, attributes):
Decomposes the given html attributes
-
soup
obj - BeautifulSoup object -
attributes
list - attributes to decompose -
Returns
- None
def delete_file(file_name):
Delete file_name
file_name
str - Path to the file you want to delete
def download_file(url, filename):
Download a file from a specified url
url
str - URL of the file to downloadfilename
str - Name of the file to write the download to
def dump_config_to_file(file_path):
Dump the config to the yaml file with censored secret values.
file_path
str - Path to file where to write the configuration.
def email_reports():
Email results of test run
def ensure_nightly_build_availability(build_url):
def expose_nightly_ocp_version(version):
This helper function exposes latest nightly version of OCP. When the version string ends with .nightly (e.g. 4.2.0-0.nightly) it will expose the version to latest accepted OCP build (e.g. 4.2.0-0.nightly-2019-08-08-103722)
version
str - Verison of OCP
str
- Version of OCP exposed to full version if latest nighly passed
def file_locking(client):
def fuse_client_io(client, mounting_dir):
def fuse_client_md5(fuse_clients, md5sum_list1):
def fuse_mount(fuse_clients, mounting_dir):
def get_ceph_version():
Gets the ceph version
str
- ceph version
def get_client_info(ceph_nodes, clients):
def get_cluster_image():
Gets the cluster image
str
- cluster image
def get_cluster_version():
Gets the cluster version
str
- cluster version
def get_cluster_version_info():
Gets the complete cluster version information
dict
- cluster version information
def get_csi_versions():
Gets the CSI related version information
dict
- CSI related version information
def get_latest_ds_olm_tag(upgrade=False):
This function returns latest tag of OCS downstream registry or one before latest if upgrade parameter is True
upgrade
str - If True then it returns one version of the build before the latest.
str
- latest tag for downstream image from quay registry
TagNotFoundException
- In case no tag found
def get_next_version_available_for_upgrade(current_tag):
This function returns the tag built after the current_version
current_tag
str - Current build tag from which to search the next one build tag.
str
- tag for downstream image from quay registry built after the current_tag.
TagNotFoundException
- In case no tag suitable for upgrade found
def get_ocs_build_number():
Gets the build number for ocs operator
str
- build number for ocs operator version
def get_openshift_client(version=None, bin_dir=None, force_download=False):
Download the OpenShift client binary, if not already present. Update env. PATH and get path of the oc binary.
version
str - Version of the client to download(default
- config.RUN['client_version'])
bin_dir
str - Path to bin directory (default: config.RUN['bin_dir'])force_download
bool - Force client download even if already present
str
- Path to the client binary
def get_openshift_installer(version=None, bin_dir=None, force_download=False):
Download the OpenShift installer binary, if not already present. Update env. PATH and get path of the openshift installer binary.
version
str - Version of the installer to downloadbin_dir
str - Path to bin directory (default: config.RUN['bin_dir'])force_download
bool - Force installer download even if already present
str
- Path to the installer binary
def get_openshift_mirror_url(file_name, version):
Format url to OpenShift mirror (for client and installer download).
file_name
str - Name of fileversion
str - Version of the installer or client to download
str
- Url of the desired file (installer or client)
UnsupportedOSType
- In case the OS type is not supportedUnavailableBuildException
- In case the build url is not reachable
def get_random_str(size=13):
generates the random string of given size
size
int - number of random characters to generate
str : string of random characters of given size
def get_rook_repo(branch='master', to_checkout=None):
Clone and checkout the rook repository to specific branch/commit.
branch
str - Branch name to checkoutto_checkout
str - Commit id or tag to checkout
def get_rook_version():
Gets the rook version
str
- rook version
def get_testrun_name():
Prepare testrun ID for Polarion (and other reports).
Return config.REPORTING["polarion"]["testrun_name"], if configured. Otherwise prepare testrun ID based on Upstream/Downstream information, OCS version and used markers.
str
- String containing testrun ID
def get_url_content(url):
Return URL content
url
str - URL address to return
str
- Content of URL
AssertionError
- When couldn't load URL
def is_cluster_running(cluster_path):
def kernel_client_io(client, mounting_dir):
def kernel_client_md5(kernel_clients, md5sum_list2):
def kernel_mount(mounting_dir, mon_node_ip, kernel_clients):
def mask_secrets(plaintext, secrets):
Replace secrets in plaintext with asterisks
plaintext
str - The plaintext to remove the secrets fromsecrets
list - List of secret strings to replace in the plaintext
str
- The censored version of plaintext
def mds_fail_over(mds_nodes):
def mkdir_pinning(clients, range1, range2, dir_name, pin_val):
def ocsci_log_path():
Construct the full path for the log directory.
str
- full path for ocs-ci log directory
def parse_html_for_email(soup):
Parses the html and filters out the unnecessary data/tags/attributes for email reporting
soup
obj - BeautifulSoup object
def parse_pgsql_logs(data):
Parse the pgsql benchmark data from ripsaw and return the data in list format
data
str - log data from pgsql bench run
list_data
list - data digestable by scripts with below formateg
- ( with only one item in the list)[{'num_clients'
- '2', 'num_threads': '7', 'latency_avg': '7','lat_stddev'
- '0', 'tps_incl': '234', 'tps_excl': '243'}]
def pinned_dir_io(clients, mds_fail_over, num_of_files, range1, range2):
def prepare_bin_dir(bin_dir=None):
Prepare bin directory for OpenShift client and installer
bin_dir
str - Path to bin directory (default: config.RUN['bin_dir'])
def read_file_as_str(filepath):
Reads the file content
filepath
str - File to read
str : File contents in string
def replace_content_in_file(file, old, new):
Replaces contents in file, if old value is not found, it adds new value to the file
file
str - Name of the file in which contents will be replacedold
str - Data to search fornew
str - Data to replace the old value
def run_async(command):
Run command locally and return without waiting for completion
command
str - The command to run.
An open descriptor to be used by the calling function.
command = 'oc delete pvc pvc1' proc = run_async(command) ret, out, err = proc.async_communicate()
def run_cmd(cmd, secrets=None, **kwargs):
Run an arbitrary command locally
-
cmd
str - command to run -
secrets
list - A list of secrets to be masked with asterisks This kwarg is popped in order to not interfere with subprocess.run(**kwargs)
CommandFailed
- In case the command execution fails
(str) Decoded stdout of command
def run_mcg_cmd(cmd, namespace=None):
Invokes run_cmd with a noobaa prefix
cmd
- The MCG command to be runnamespace
- The namespace to use for the command
str
- Stdout of the command
def upload_file(server, localpath, remotepath, user=None, password=None):
Upload a file to remote server
server
str - Name of the server to uploadlocalpath
str - Local file to uploadremotepath
str - Target path on the remote server. filename should be includeduser
str - User to use for the remote connection
@retry(CommandFailed, tries=100, delay=10, backoff=1)
def wait_for_co(operator):
Waits for ClusterOperator to created
operator
str - Name of the ClusterOperator