ocs_ci.helpers package

Submodules

ocs_ci.helpers.bdi_helpers module

Helper functions specific for bdi

ocs_ci.helpers.bdi_helpers.clean_temp_files(class_instance)

Deletes temporary files created during the execution

ocs_ci.helpers.bdi_helpers.init_configure_workload_yaml(namespace=None, image=None, sf=1, pvc_name=None)

Loads the “configure-workload.yaml” and sets all the relevant parameters according to the type of execution

Parameters
  • namespace (str) – The name of the namespace

  • image (str) – The name of the image to pull

  • sf (int) – scale factor. Can be 1, 10, 100…

  • pvc_name (str) – The name of the pvc to be used

Returns

The dictionary representing the yaml with all the relevant changes

Return type

dict

ocs_ci.helpers.bdi_helpers.init_data_load_yaml(namespace=None, image=None, pvc_name=None, secret_name=None)

Loads the “data-load-job” and sets all the relevant parameters according to the type of execution

Parameters
  • namespace (str) – The name of the namespace

  • image (str) – The name of the image to pull

  • pvc_name (str) – The name of the pvc to be used

  • secret_name (str) – The secret name to be used

Returns

The dictionary representing the yaml with all the relevant changes

Return type

dict

ocs_ci.helpers.bdi_helpers.init_run_workload_yaml(namespace=None, image=None, pvc_name=None, secret_name=None)

Loads the “run-workload-job” and sets all the relevant parameters according to the type of execution

Parameters
  • namespace (str) – The name of the namespace

  • image (str) – The name of the image to pull

  • pvc_name (str) – The name of the pvc to be used

  • secret_name (str) – The secret name to be used

Returns

The dictionary representing the yaml with all the relevant changes

Return type

dict

ocs_ci.helpers.bdi_helpers.install_db2u(class_instance)

Chart installation

ocs_ci.helpers.cluster_exp_helpers module

class ocs_ci.helpers.cluster_exp_helpers.BackgroundOps

Bases: object

EXPANSION_COMPLETED = False
wrap(func, *args, **kwargs)

Wraps the function to run specific iterations

Returns

True if function runs successfully

Return type

bool

class ocs_ci.helpers.cluster_exp_helpers.ClusterFiller(pods_to_fill, percent_required_filled, namespace)

Bases: object

Class for performing IOs on the pods

cluster_filler()
concurrent_copies = 5
filler(fill_pod)

This function copies the file downloaded by ‘downloader’ function in a unique directory to increase the cluster space utilization. Currently it makes 30 copies of the downloaded file in a given directory which is equivalent to almost 4 GiB of storage.

Parameters

fill_pod – the pod on which the storage space need to be filled.

ocs_ci.helpers.cluster_exp_helpers.check_nodes_status()

This function runs in a loop to check the status of nodes. If the node(s) are in NotReady state then an exception is raised. Note: this function needs to be run as a background thread during the execution of a test

ocs_ci.helpers.cluster_exp_helpers.cluster_copy_ops(copy_pod)

Function to do copy operations in a given pod. Mainly used as a background IO during cluster expansion. It does of series of copy operations and verifies the data integrity of the files copied.

Parameters

copy_pod (pod) – on which copy operations need to be done

Returns

False, if there is data integrity check failure. Else, True

Return type

Boolean

ocs_ci.helpers.cluster_exp_helpers.raw_block_io(raw_blk_pod, size='10G')

Runs the block ios on pod baased raw block pvc :param raw_blk_pod: pod on which block IOs should run :type raw_blk_pod: pod :param size: IO size :type size: str

ocs_ci.helpers.disconnected module

ocs_ci.helpers.disconnected.get_opm_tool()

Download and install opm tool.

ocs_ci.helpers.disruption_helpers module

class ocs_ci.helpers.disruption_helpers.Disruptions

Bases: object

This class contains methods of disrupt operations

daemon_pid = None
delete_resource(resource_id=0)
kill_daemon(node_name=None, check_new_pid=True, kill_signal='9')

Kill self.resource daemon

Parameters
  • node_name (str) – Name of node in which the resource daemon has to be killed

  • check_new_pid (bool) – True to check for new pid after killing the daemon. False to skip the check.

  • kill_signal (str) – kill signal type

resource = None
resource_count = 0
resource_obj = None
select_daemon(node_name=None)

Select pid of self.resource daemon

Parameters

node_name (str) – Name of node in which the resource daemon has to be selected.

selector = None
set_resource(resource, leader_type='provisioner')

ocs_ci.helpers.helpers module

Helper functions file for OCS QE

ocs_ci.helpers.helpers.add_scc_policy(sa_name, namespace)

Adding ServiceAccount to scc privileged

Parameters
  • sa_name (str) – ServiceAccount name

  • namespace (str) – The namespace for the scc_policy creation

ocs_ci.helpers.helpers.calc_local_file_md5_sum(path)

Calculate and return the MD5 checksum of a local file

Parameters

path (str) – The path to the file

Returns

The MD5 checksum

Return type

str

ocs_ci.helpers.helpers.change_default_storageclass(scname)

Change the default StorageClass to the given SC name

Parameters

scname (str) – StorageClass name

Returns

True on success

Return type

bool

ocs_ci.helpers.helpers.collect_performance_stats(dir_name)

Collect performance stats and saves them in file in json format.

dir_name (str): directory name to store stats.

Performance stats include:

IOPs and throughput percentage of cluster CPU, memory consumption of each nodes

ocs_ci.helpers.helpers.converge_lists(list_to_converge)

Function to flatten and remove the sublist created during future obj

Parameters

list_to_converge (list) – arg list of lists, eg: [[1,2],[3,4]]

Returns

return converged list eg: [1,2,3,4]

Return type

list (list)

ocs_ci.helpers.helpers.craft_s3_command(cmd, mcg_obj=None, api=False)

Crafts the AWS CLI S3 command including the login credentials and command to be ran

Parameters
  • mcg_obj – An MCG object containing the MCG S3 connection credentials

  • cmd – The AWSCLI command to run

  • api – True if the call is for s3api, false if s3

Returns

The crafted command, ready to be executed on the pod

Return type

str

ocs_ci.helpers.helpers.create_build_from_docker_image(image_name, install_package, namespace, source_image='quay.io/ocsci/fedora', source_image_label='latest')

Allows to create a build config using a Dockerfile specified as an argument, eg.:

$ oc new-build -D $'FROM centos:7\nRUN yum install -y httpd'

creates a build with httpd installed.

Parameters
  • image_name (str) – Name of the image to be created

  • source_image (str) – Source image to build docker image from, defaults to Centos as base image

  • namespace (str) – project where build config should be created

  • source_image_label (str) – Tag to use along with the image name, defaults to ‘latest’

  • install_package (str) – package to install over the base image

Returns

The OCP object for the image Fails on UnavailableBuildException exception if build creation fails

Return type

ocs_ci.ocs.ocp.OCP (obj)

ocs_ci.helpers.helpers.create_ceph_block_pool(pool_name=None, replica=3, compression=None, failure_domain=None, verify=True)

Create a Ceph block pool ** This method should not be used anymore ** ** This method is for internal testing only **

Parameters
  • pool_name (str) – The pool name to create

  • failure_domain (str) – Failure domain name

  • verify (bool) – True to verify the pool exists after creation, False otherwise

  • replica (int) – The replica size for a pool

  • compression (str) – Compression type for a pool

Returns

An OCS instance for the Ceph block pool

Return type

OCS

ocs_ci.helpers.helpers.create_ceph_file_system(pool_name=None)

Create a Ceph file system ** This method should not be used anymore ** ** This method is for internal testing only **

Parameters

pool_name (str) – The pool name to create

Returns

An OCS instance for the Ceph file system

Return type

OCS

ocs_ci.helpers.helpers.create_dummy_osd(deployment)

Replace one of OSD pods with pod that contains all data from original OSD but doesn’t run osd daemon. This can be used e.g. for direct acccess to Ceph Placement Groups.

Parameters

deployment (str) – Name of deployment to use

Returns

first item is dummy deployment object, second item is dummy pod

object

Return type

list

ocs_ci.helpers.helpers.create_multilpe_projects(number_of_project)

Create one or more projects

Parameters

number_of_project (int) – Number of projects to be created

Returns

List of project objects

Return type

list

ocs_ci.helpers.helpers.create_multiple_pvc_parallel(sc_obj, namespace, number_of_pvc, size, access_modes)

Funtion to create multiple PVC in parallel using threads Function will create PVCs based on the available access modes

Parameters
  • sc_obj (str) – Storage Class object

  • namespace (str) – The namespace for creating pvc

  • number_of_pvc (int) – NUmber of pvc to be created

  • size (str) – size of the pvc eg: ‘10Gi’

  • access_modes (list) – List of access modes for PVC creation

Returns

List of pvc objs created in function

Return type

pvc_objs_list (list)

ocs_ci.helpers.helpers.create_multiple_pvcs(sc_name, namespace, number_of_pvc=1, size=None, do_reload=False, access_mode='ReadWriteOnce', burst=False)

Create one or more PVC as a bulk or one by one

Parameters
  • sc_name (str) – The name of the storage class to provision the PVCs from

  • namespace (str) – The namespace for the PVCs creation

  • number_of_pvc (int) – Number of PVCs to be created

  • size (str) – The size of the PVCs to create

  • do_reload (bool) – True for wait for reloading PVC after its creation, False otherwise

  • access_mode (str) – The kind of access mode for PVC

Returns

List of PVC objects

Return type

list

ocs_ci.helpers.helpers.create_pod(interface_type=None, pvc_name=None, do_reload=True, namespace='openshift-storage', node_name=None, pod_dict_path=None, sa_name=None, dc_deployment=False, raw_block_pv=False, raw_block_device='/dev/rbdblock', replica_count=1, pod_name=None, node_selector=None, command=None, command_args=None, deploy_pod_status='Completed')

Create a pod

Parameters
  • interface_type (str) – The interface type (CephFS, RBD, etc.)

  • pvc_name (str) – The PVC that should be attached to the newly created pod

  • do_reload (bool) – True for reloading the object after creation, False otherwise

  • namespace (str) – The namespace for the new resource creation

  • node_name (str) – The name of specific node to schedule the pod

  • pod_dict_path (str) – YAML path for the pod

  • sa_name (str) – Serviceaccount name

  • dc_deployment (bool) – True if creating pod as deploymentconfig

  • raw_block_pv (bool) – True for creating raw block pv based pod, False otherwise

  • raw_block_device (str) – raw block device for the pod

  • replica_count (int) – Replica count for deployment config

  • pod_name (str) – Name of the pod to create

  • node_selector (dict) – dict of key-value pair to be used for nodeSelector field eg: {‘nodetype’: ‘app-pod’}

  • command (list) – The command to be executed on the pod

  • command_args (list) – The arguments to be sent to the command running on the pod

  • deploy_pod_status (str) – Expected status of deploy pod. Applicable only if dc_deployment is True

Returns

A Pod instance

Return type

Pod

Raises

AssertionError – In case of any failure

ocs_ci.helpers.helpers.create_pods(pvc_objs, pod_factory, interface, pods_for_rwx=1, status='', nodes=None)

Create pods

Parameters
  • pvc_objs (list) – List of ocs_ci.ocs.resources.pvc.PVC instances

  • pod_factory (function) – pod_factory function

  • interface (int) – Interface type

  • pods_for_rwx (int) – Number of pods to be created if access mode of PVC is RWX

  • status (str) – If provided, wait for desired state of each pod before creating next one

  • nodes (list) – Node name for each pod will be selected from this list.

Returns

list of Pod objects

Return type

list

ocs_ci.helpers.helpers.create_pods_parallel(pvc_list, namespace, interface, pod_dict_path=None, sa_name=None, raw_block_pv=False, dc_deployment=False, node_selector=None)

Function to create pods in parallel

Parameters
  • pvc_list (list) – List of pvcs to be attached in pods

  • namespace (str) – The namespace for creating pod

  • interface (str) – The interface backed the PVC

  • pod_dict_path (str) – pod_dict_path for yaml

  • sa_name (str) – sa_name for providing permission

  • raw_block_pv (bool) – Either RAW block or not

  • dc_deployment (bool) – Either DC deployment or not

  • node_selector (dict) – dict of key-value pair to be used for nodeSelector field eg: {‘nodetype’: ‘app-pod’}

Returns

Returns list of pods created

Return type

pod_objs (list)

ocs_ci.helpers.helpers.create_project(project_name=None)

Create a project

Parameters

project_name (str) – The name for the new project

Returns

Project object

Return type

ocs_ci.ocs.ocp.OCP

ocs_ci.helpers.helpers.create_pvc(sc_name, pvc_name=None, namespace='openshift-storage', size=None, do_reload=True, access_mode='ReadWriteOnce', volume_mode=None)

Create a PVC

Parameters
  • sc_name (str) – The name of the storage class for the PVC to be associated with

  • pvc_name (str) – The name of the PVC to create

  • namespace (str) – The namespace for the PVC creation

  • size (str) – Size of pvc to create

  • do_reload (bool) – True for wait for reloading PVC after its creation, False otherwise

  • access_mode (str) – The access mode to be used for the PVC

  • volume_mode (str) – Volume mode for rbd RWX pvc i.e. ‘Block’

Returns

PVC instance

Return type

PVC

ocs_ci.helpers.helpers.create_resource(do_reload=True, **kwargs)

Create a resource

Parameters
  • do_reload (bool) – True for reloading the resource following its creation, False otherwise

  • kwargs (dict) – Dictionary of the OCS resource

Returns

An OCS instance

Return type

OCS

Raises

AssertionError – In case of any failure

ocs_ci.helpers.helpers.create_secret(interface_type)

Create a secret ** This method should not be used anymore ** ** This method is for internal testing only **

Parameters

interface_type (str) – The type of the interface (e.g. CephBlockPool, CephFileSystem)

Returns

An OCS instance for the secret

Return type

OCS

ocs_ci.helpers.helpers.create_serviceaccount(namespace)

Create a Serviceaccount

Parameters

namespace (str) – The namespace for the serviceaccount creation

Returns

An OCS instance for the service_account

Return type

OCS

ocs_ci.helpers.helpers.create_storage_class(interface_type, interface_name, secret_name, reclaim_policy='Delete', sc_name=None, provisioner=None, rbd_thick_provision=False)

Create a storage class ** This method should not be used anymore ** ** This method is for internal testing only **

Parameters
  • interface_type (str) – The type of the interface (e.g. CephBlockPool, CephFileSystem)

  • interface_name (str) – The name of the interface

  • secret_name (str) – The name of the secret

  • sc_name (str) – The name of storage class to create

  • reclaim_policy (str) – Type of reclaim policy. Defaults to ‘Delete’ (eg., ‘Delete’, ‘Retain’)

  • rbd_thick_provision (bool) – True to enable RBD thick provisioning. Applicable if interface_type is CephBlockPool

Returns

An OCS instance for the storage class

Return type

OCS

ocs_ci.helpers.helpers.create_unique_resource_name(resource_description, resource_type)

Creates a unique object name by using the object_description, object_type and a random uuid(in hex) as suffix trimmed due to kubernetes limitation of 63 characters

Parameters
  • resource_description (str) – The user provided object description

  • resource_type (str) – The type of object for which the unique name will be created. For example: project, pvc, etc

Returns

A unique name

Return type

str

ocs_ci.helpers.helpers.default_ceph_block_pool()

Returns default CephBlockPool

Returns

default CephBlockPool

ocs_ci.helpers.helpers.default_storage_class(interface_type)

Return default storage class based on interface_type

Parameters

interface_type (str) – The type of the interface (e.g. CephBlockPool, CephFileSystem)

Returns

Existing StorageClass Instance

Return type

OCS

ocs_ci.helpers.helpers.default_thick_storage_class()

Return default RBD thick storage class

Returns

Existing RBD thick StorageClass instance

Return type

OCS

ocs_ci.helpers.helpers.default_volumesnapshotclass(interface_type)

Return default VolumeSnapshotClass based on interface_type

Parameters

interface_type (str) – The type of the interface (e.g. CephBlockPool, CephFileSystem)

Returns

VolumeSnapshotClass Instance

Return type

OCS

ocs_ci.helpers.helpers.delete_cephblockpools(cbp_objs)

Function for deleting CephBlockPool

Parameters

cbp_objs (list) – List of CBP objects for deletion

Returns

True if deletion of CephBlockPool is successful

Return type

bool

ocs_ci.helpers.helpers.delete_objs_parallel(obj_list)

Function to delete objs specified in list :param obj_list: List can be obj of pod, pvc, etc :type obj_list: list

Returns

True if obj deleted else False

Return type

bool

ocs_ci.helpers.helpers.delete_storageclasses(sc_objs)

” Function for Deleting storageclasses

Parameters

sc_objs (list) – List of SC objects for deletion

Returns

True if deletion is successful

Return type

bool

ocs_ci.helpers.helpers.delete_volume_in_backend(img_uuid, pool_name=None)

Delete an Image/Subvolume in the backend

Parameters
  • img_uuid (str) – Part of VolID which represents corresponding image/subvolume in backend, eg: oc get pv/<volumeName> -o jsonpath='{.spec.csi.volumeHandle}' Output is the CSI generated VolID and looks like: 0001-000c-rook-cluster-0000000000000001-f301898c-a192-11e9-852a-1eeeb6975c91 where image_uuid is f301898c-a192-11e9-852a-1eeeb6975c91

  • pool_name (str) – The of the pool

Returns

True if image deleted successfully
False if:

Pool not found image not found image not deleted

Return type

bool

ocs_ci.helpers.helpers.fetch_used_size(cbp_name, exp_val=None)

Fetch used size in the pool :param exp_val: Expected size in GB :type exp_val: float

Returns

Used size in GB

Return type

float

ocs_ci.helpers.helpers.get_admin_key()

Fetches admin key secret from Ceph

Returns

The admin key

Return type

str

ocs_ci.helpers.helpers.get_all_pvs()

Gets all pv in openshift-storage namespace

Returns

Dict of all pv in openshift-storage namespace

Return type

dict

ocs_ci.helpers.helpers.get_all_storageclass_names()

Function for getting all storageclass

Returns

list of storageclass name

Return type

list

ocs_ci.helpers.helpers.get_cephblockpool_names()

Function for getting all CephBlockPool

Returns

list of cephblockpool name

Return type

list

ocs_ci.helpers.helpers.get_cephfs_data_pool_name()

Fetches ceph fs datapool name from Ceph

Returns

fs datapool name

Return type

str

ocs_ci.helpers.helpers.get_cephfs_name()

Function to retrive CephFS name :returns: Name of CFS :rtype: str

ocs_ci.helpers.helpers.get_default_storage_class()

Get the default StorageClass(es)

Returns

default StorageClass(es) list

Return type

list

ocs_ci.helpers.helpers.get_end_creation_time(interface, pvc_name)

Get the ending creation time of a PVC based on provisioner logs

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name (str) – Name of the PVC for creation time measurement

Returns

End time of PVC creation

Return type

datetime object

ocs_ci.helpers.helpers.get_end_deletion_time(interface, pv_name)

Get the ending deletion time of a PVC based on provisioner logs

Parameters
  • interface (str) – The interface backed the PVC

  • pv_name (str) – Name of the PVC for deletion time measurement

Returns

End time of PVC deletion

Return type

datetime object

ocs_ci.helpers.helpers.get_failure_domin()

Function is used to getting failure domain of pool

Returns

Failure domain from cephblockpool

Return type

str

ocs_ci.helpers.helpers.get_full_test_logs_path(cname)

Getting the full path of the logs file for particular test

this function use the inspect module to find the name of the caller function, so it need to be call once from the main test function. the output is in the form of ocsci_log_path/<full test file path>/<test filename>/<test class name>/<test function name>

Parameters

cname (obj) – the Class object which was run and called this function

Returns

full path of the test logs relative to the ocs-ci base logs path

Return type

str

ocs_ci.helpers.helpers.get_logs_with_errors(errors=None)

From logs of all pods and nodes, get only logs containing any of specified errors

Parameters

errors (list) – List of errors to look for

Returns

node/pod name as key, logs content as value; may be empty

Return type

dict

ocs_ci.helpers.helpers.get_memory_leak_median_value()

Function to calculate memory leak Median value by collecting the data for 180 sec and find the median value which will be considered as starting point to evaluate memory leak using “RES” value of ceph-osd daemon i.e. list[7] in code

Returns

dict of worker nodes and respective median value

Return type

median_dict (dict)

ocs_ci.helpers.helpers.get_mon_pdb()

Check for Mon PDB

Returns

Count of mon allowed disruption min_available_mon (int): Count of minimum mon available max_unavailable_mon (int): Count of maximun mon unavailable

Return type

disruptions_allowed (int)

ocs_ci.helpers.helpers.get_pods_nodes_logs()

Get logs from all pods and nodes

Returns

node/pod name as key, logs content as value (string)

Return type

dict

ocs_ci.helpers.helpers.get_pool_cr(pool_name)

Get the pool CR even if the kind is unknown.

Parameters

pool_name (str) – The name of the pool to get the CR for.

Returns

If the resource is found, None otherwise.

Return type

dict

ocs_ci.helpers.helpers.get_provision_time(interface, pvc_name, status='start')

Get the starting/ending creation time of a PVC based on provisioner logs

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name (str / list) – Name of the PVC(s) for creation time the list will be list of pvc objects

  • status (str) – the status that we want to get - Start / End

Returns

Time of PVC(s) creation

Return type

datetime object

ocs_ci.helpers.helpers.get_pv_names()

Get Pv names

Returns

list of pv names

Return type

list

ocs_ci.helpers.helpers.get_pv_size(storageclass=None)

Get Pv size from requested storageclass

Parameters

storageclass (str) – Name of storageclass

Returns

list of pv’s size

Return type

list

ocs_ci.helpers.helpers.get_serviceaccount_obj(sa_name, namespace)

Get serviceaccount obj

Parameters
  • sa_name (str) – Service Account name

  • namespace (str) – The namespace for the serviceaccount creation

Returns

An OCS instance for the service_account

Return type

OCS

ocs_ci.helpers.helpers.get_snapshot_content_obj(snap_obj)

Get volume snapshot content of a volume snapshot

Parameters

snap_obj (OCS) – OCS instance of kind VolumeSnapshot

Returns

OCS instance of kind VolumeSnapshotContent

Return type

OCS

ocs_ci.helpers.helpers.get_snapshot_time(interface, snap_name, status)

Get the starting/ending creation time of a PVC based on provisioner logs

The time and date extraction code below has been modified to read the month and day data in the logs. This fixes an error where negative time values are calculated when test runs cross midnight. Also, previous calculations would not set the year, and so the calculations were done as if the year were 1900. This is not a problem except that 1900 was not a leap year and so the next February 29th would throw ValueErrors for the whole day. To avoid this problem, changes were made to also include the current year.

Incorrect times will still be given for tests that cross over from December 31 to January 1.

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name (str / list) – Name of the PVC(s) for creation time the list will be list of pvc objects

  • status (str) – the status that we want to get - Start / End

Returns

Time of PVC(s) creation

Return type

datetime object

ocs_ci.helpers.helpers.get_start_creation_time(interface, pvc_name)

Get the starting creation time of a PVC based on provisioner logs

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name (str) – Name of the PVC for creation time measurement

Returns

Start time of PVC creation

Return type

datetime object

ocs_ci.helpers.helpers.get_start_deletion_time(interface, pv_name)

Get the starting deletion time of a PVC based on provisioner logs

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name (str) – Name of the PVC for deletion time measurement

Returns

Start time of PVC deletion

Return type

datetime object

ocs_ci.helpers.helpers.is_volume_present_in_backend(interface, image_uuid, pool_name=None)

Check whether Image/Subvolume is present in the backend.

Parameters
  • interface (str) – The interface backed the PVC

  • image_uuid (str) – Part of VolID which represents corresponding image/subvolume in backend, eg: oc get pv/<volumeName> -o jsonpath='{.spec.csi.volumeHandle}' Output is the CSI generated VolID and looks like: 0001-000c-rook-cluster-0000000000000001-f301898c-a192-11e9-852a-1eeeb6975c91 where image_uuid is f301898c-a192-11e9-852a-1eeeb6975c91

  • pool_name (str) – Name of the rbd-pool if interface is CephBlockPool

Returns

True if volume is present and False if volume is not present

Return type

bool

ocs_ci.helpers.helpers.label_worker_node(node_list, label_key, label_value)

Function to label worker node for running app pods on specific worker nodes.

Parameters
  • node_list (list) – List of node name

  • label_key (str) – Label_key to be added in worker

  • label_value (str) – Label_value

ocs_ci.helpers.helpers.measure_pv_deletion_time_bulk(interface, pv_name_list, wait_time=60)

Measure PV deletion time of bulk PV, based on logs.

Parameters
  • interface (str) – The interface backed the PV

  • pv_name_list (list) – List of PV Names for measuring deletion time

  • wait_time (int) – Seconds to wait before collecting CSI log

Returns

Dictionary of pv_name with deletion time.

Return type

pv_dict (dict)

ocs_ci.helpers.helpers.measure_pvc_creation_time(interface, pvc_name)

Measure PVC creation time based on logs

Parameters

interface (str) – The interface backed the PVC pvc_name (str): Name of the PVC for creation time measurement

Returns

Creation time for the PVC

Return type

float

ocs_ci.helpers.helpers.measure_pvc_creation_time_bulk(interface, pvc_name_list, wait_time=60)

Measure PVC creation time of bulk PVC based on logs.

Parameters
  • interface (str) – The interface backed the PVC

  • pvc_name_list (list) – List of PVC Names for measuring creation time

  • wait_time (int) – Seconds to wait before collecting CSI log

Returns

Dictionary of pvc_name with creation time.

Return type

pvc_dict (dict)

ocs_ci.helpers.helpers.measure_pvc_deletion_time(interface, pv_name)

Measure PVC deletion time based on logs

Parameters
  • interface (str) – The interface backed the PVC

  • pv_name (str) – Name of the PV for creation time measurement

Returns

Deletion time for the PVC

Return type

float

ocs_ci.helpers.helpers.measure_snapshot_creation_time(interface, snap_name, snap_con_name)

Measure Snapshot creation time based on logs

Parameters

snap_name (str) – Name of the snapshot for creation time measurement

Returns

Creation time for the snapshot

Return type

float

ocs_ci.helpers.helpers.memory_leak_analysis(median_dict)

Function to analyse Memory leak after execution of test case Memory leak is analyzed based on top output “RES” value of ceph-osd daemon, i.e. list[7] in code.

More Detail on Median value: For calculating memory leak require a constant value, which should not be start or end of test, so calculating it by getting memory for 180 sec before TC execution and take a median out of it. Memory value could be different for each nodes, so identify constant value for each node and update in median_dict

Parameters
  • median_dict (dict) – dict of worker nodes and respective median value

  • eg – median_dict = {‘worker_node_1’:102400, ‘worker_node_2’:204800, …}

Usage:

test_case(.., memory_leak_function):
    .....
    median_dict = helpers.get_memory_leak_median_value()
    .....
    TC execution part, memory_leak_fun will capture data
    ....
    helpers.memory_leak_analysis(median_dict)
    ....
ocs_ci.helpers.helpers.modify_deployment_replica_count(deployment_name, replica_count)

Function to modify deployment replica count, i.e to scale up or down deployment

Parameters
  • deployment_name (str) – Name of deployment

  • replica_count (int) – replica count to be changed to

Returns

True in case if changes are applied. False otherwise

Return type

bool

ocs_ci.helpers.helpers.modify_osd_replica_count(resource_name, replica_count)

Function to modify osd replica count to 0 or 1

Parameters
  • resource_name (str) – Name of osd i.e, ‘rook-ceph-osd-0-c9c4bc7c-bkf4b’

  • replica_count (int) – osd replica count to be changed to

Returns

True in case if changes are applied. False otherwise

Return type

bool

ocs_ci.helpers.helpers.pod_start_time(pod_obj)

Function to measure time taken for container(s) to get into running state by measuring the difference between container’s start time (when container went into running state) and started time (when container was actually started)

Parameters

pod_obj (obj) – pod object to measure start time

Returns

Returns the name and start time of container(s) in a pod

Return type

containers_start_time(dict)

ocs_ci.helpers.helpers.pull_images(image_name)

Function to pull images on all nodes

Parameters

image_name (str) – Name of the container image to be pulled

Returns: None

ocs_ci.helpers.helpers.refresh_oc_login_connection(user=None, password=None)

Function to refresh oc user login Default login using kubeadmin user and password

Parameters
  • user (str) – Username to login

  • password (str) – Password to login

ocs_ci.helpers.helpers.remove_label_from_worker_node(node_list, label_key)

Function to remove label from worker node.

Parameters
  • node_list (list) – List of node name

  • label_key (str) – Label_key to be remove from worker node

ocs_ci.helpers.helpers.remove_scc_policy(sa_name, namespace)

Removing ServiceAccount from scc privileged

Parameters
  • sa_name (str) – ServiceAccount name

  • namespace (str) – The namespace for the scc_policy deletion

ocs_ci.helpers.helpers.retrieve_default_ingress_crt()

Copy the default ingress certificate from the router-ca secret to the local code runner for usage with boto3.

ocs_ci.helpers.helpers.rsync_kubeconf_to_node(node)

Function to copy kubeconfig to OCP node

Parameters

node (str) – OCP node to copy kubeconfig if not present

ocs_ci.helpers.helpers.run_cmd_verify_cli_output(cmd=None, expected_output_lst=(), cephtool_cmd=False, debug_node=None)

Run command and verify its output

Parameters
  • cmd (str) – cli command

  • expected_output_lst (set) – A set of strings that need to be included in the command output.

  • cephtool_cmd (bool) – command on ceph-tool pod

  • debug_node (str) – name of node

Returns

True of all strings are included in the command output, False otherwise

Return type

bool

ocs_ci.helpers.helpers.run_io_with_rados_bench(**kw)

A task for radosbench. Runs radosbench command on specified pod . If parameters are not provided task assumes few default parameters.This task runs command in synchronous fashion.

Parameters

kw (dict) –

a dictionary of various radosbench parameters. ex:

pool_name:pool
pg_num:number of pgs for pool
op: type of operation {read, write}
cleanup: True OR False

Returns

return value of radosbench command

Return type

ret

ocs_ci.helpers.helpers.set_image_lookup(image_name)

Function to enable lookup, which allows reference to the image stream tag in the image field of the object. Example:

$ oc set image-lookup mysql
$ oc run mysql --image=mysql
Parameters

image_name (str) – Name of the image stream to pull the image locally

Returns

output of set image-lookup command

Return type

str

ocs_ci.helpers.helpers.storagecluster_independent_check()

Check whether the storagecluster is running in independent mode by checking the value of spec.externalStorage.enable

Returns

True if storagecluster is running on external mode False otherwise

Return type

bool

ocs_ci.helpers.helpers.validate_cephfilesystem(fs_name)

Verify CephFileSystem exists at Ceph and OCP

Parameters

fs_name (str) – The name of the Ceph FileSystem

Returns

True if CephFileSystem is created at Ceph and OCP side else

will return False with valid msg i.e Failure cause

Return type

bool

ocs_ci.helpers.helpers.validate_pod_oomkilled(pod_name, namespace='openshift-storage', container=None)

Validate pod oomkilled message are found on log

Parameters
  • pod_name (str) – Name of the pod

  • namespace (str) – Namespace of the pod

  • container (str) – Name of the container

Returns

True if oomkill messages are not found on log.

False Otherwise.

Return type

bool

Raises

Assertion if failed to fetch logs

ocs_ci.helpers.helpers.validate_pods_are_running_and_not_restarted(pod_name, pod_restart_count, namespace)

Validate given pod is in running state and not restarted or re-spinned

Parameters
  • pod_name (str) – Name of the pod

  • pod_restart_count (int) – Restart count of pod

  • namespace (str) – Namespace of the pod

Returns

True if pod is in running state and restart

count matches the previous one

Return type

bool

ocs_ci.helpers.helpers.validate_pv_delete(pv_name)

validates if pv is deleted after pvc deletion

Parameters

pv_name (str) – pv from pvc to validates

Returns

True if deletion is successful

Return type

bool

Raises

AssertionError – If pv is not deleted

ocs_ci.helpers.helpers.validate_scc_policy(sa_name, namespace, scc_name='privileged')

Validate serviceaccount is added to scc of privileged

Parameters
  • sa_name (str) – Service Account name

  • namespace (str) – The namespace for the serviceaccount creation

  • scc_name (str) – SCC name

Returns

True if sc_name is present in scc of privileged else False

Return type

bool

ocs_ci.helpers.helpers.verify_block_pool_exists(pool_name)

Verify if a Ceph block pool exist

Parameters

pool_name (str) – The name of the Ceph block pool

Returns

True if the Ceph block pool exists, False otherwise

Return type

bool

ocs_ci.helpers.helpers.verify_pv_mounted_on_node(node_pv_dict)

Check if mount point of a PV exists on a node

Parameters

node_pv_dict (dict) – Node to PV list mapping eg: {‘node1’: [‘pv1’, ‘pv2’, ‘pv3’], ‘node2’: [‘pv4’, ‘pv5’]}

Returns

Node to existing PV list mapping

eg: {‘node1’: [‘pv1’, ‘pv3’], ‘node2’: [‘pv5’]}

Return type

dict

ocs_ci.helpers.helpers.verify_volume_deleted_in_backend(interface, image_uuid, pool_name=None, timeout=180)

Ensure that Image/Subvolume is deleted in the backend.

Parameters
  • interface (str) – The interface backed the PVC

  • image_uuid (str) – Part of VolID which represents corresponding image/subvolume in backend, eg: oc get pv/<volumeName> -o jsonpath='{.spec.csi.volumeHandle}' Output is the CSI generated VolID and looks like: 0001-000c-rook-cluster-0000000000000001-f301898c-a192-11e9-852a-1eeeb6975c91 where image_uuid is f301898c-a192-11e9-852a-1eeeb6975c91

  • pool_name (str) – Name of the rbd-pool if interface is CephBlockPool

  • timeout (int) – Wait time for the volume to be deleted.

Returns

True if volume is deleted before timeout.

False if volume is not deleted.

Return type

bool

ocs_ci.helpers.helpers.wait_for_ct_pod_recovery()

In case the of node failures scenarios, in which the selected node is running the ceph tools pod, we’ll want to wait for the pod recovery

Returns

True in case the ceph tools pod was recovered, False otherwise

Return type

bool

ocs_ci.helpers.helpers.wait_for_pv_delete(pv_objs)

Wait for PVs to delete. Delete PVs having ReclaimPolicy ‘Retain’

Parameters

pv_objs (list) – OCS instances of kind PersistentVolume

ocs_ci.helpers.helpers.wait_for_resource_count_change(func_to_use, previous_num, namespace, change_type='increase', min_difference=1, timeout=20, interval=2, **func_kwargs)

Wait for a change in total count of PVC or pod

Parameters
  • func_to_use (function) – Function to be used to fetch resource info Supported functions: pod.get_all_pvcs(), pod.get_all_pods()

  • previous_num (int) – Previous number of pods/PVCs for comparison

  • namespace (str) – Name of the namespace

  • change_type (str) – Type of change to check. Accepted values are ‘increase’ and ‘decrease’. Default is ‘increase’.

  • min_difference (int) – Minimum required difference in PVC/pod count

  • timeout (int) – Maximum wait time in seconds

  • interval (int) – Time in seconds to wait between consecutive checks

Returns

True if difference in count is greater than or equal to

’min_difference’. False in case of timeout.

ocs_ci.helpers.helpers.wait_for_resource_state(resource, state, timeout=60)

Wait for a resource to get to a given status

Parameters
  • resource (OCS obj) – The resource object

  • state (str) – The status to wait for

  • timeout (int) – Time in seconds to wait

Raises

ResourceWrongStatusException – In case the resource hasn’t reached the desired state

ocs_ci.helpers.performance_lib module

ocs_ci.helpers.performance_lib.get_logfile_names(interface)

Finds names for log files pods in which logs for pvc creation are located For CephFS: 2 pods that start with “csi-cephfsplugin-provisioner” prefix For RBD: 2 pods that start with “csi-rbdplugin-provisioner” prefix

Parameters

interface (str) – an interface (RBD or CephFS) to run on

Returns

names of the log files relevant for searching in

Return type

log names (list)

ocs_ci.helpers.performance_lib.measure_pvc_creation_time(interface, pvc_name, start_time)

Measure PVC creation time, provided pvc name and time after which the PVC was created

Parameters
  • interface (str) – an interface (RBD or CephFS) to run on

  • pvc_name (str) – Name of the pvc for which we measure the time

  • start_time (str) – Formatted time from which and on to search the relevant logs

Returns

(float) creation time for PVC in seconds

ocs_ci.helpers.performance_lib.run_command(cmd, timeout=600, out_format='string', **kwargs)

Running command on the OS and return the STDOUT & STDERR outputs in case of argument is not string or list, return error message

Parameters
  • cmd (str/list) – the command to execute

  • timeout (int) – the command timeout in seconds, default is 10 Min.

  • out_format (str) – in which format to return the output: string / list

  • kwargs (dict) – dictionary of argument as subprocess get

Returns

all STDOUT and STDERR output as list of lines, or one string separated by NewLine

Return type

list or str

ocs_ci.helpers.performance_lib.run_oc_command(cmd, namespace='openshift-storage')

Running an ‘oc’ command This function is needed in Performance tests in order to be able to run a separate command within the test without creating additional objects which increases memory consumed by the test.

Parameters
  • cmd (str) – the command to run

  • namespace (str) – the namespace where to run the command

Returns

the results of the command as list of lines

Return type

list

ocs_ci.helpers.performance_lib.write_fio_on_pod(pod_obj, file_size)

Writes IO of file_size size to a pod

Parameters
  • pod_obj – pod object to write IO

  • file_size – the size of the IO to be written opn pod

ocs_ci.helpers.proxy module

ocs_ci.helpers.proxy.get_cluster_proxies()

Get http and https proxy configuration:

  • If configuration ENV_DATA['http_proxy'] (and prospectively ENV_DATA['https_proxy']) exists, return the respective values. (If https_proxy not defined, use value from http_proxy.)

  • If configuration ENV_DATA['http_proxy'] doesn’t exist, try to gather cluster wide proxy configuration.

  • If no proxy configuration found, return empty string for all http_proxy, https_proxy and no_proxy.

Returns

(http_proxy, https_proxy, no_proxy)

Return type

tuple

ocs_ci.helpers.proxy.update_container_with_proxy_env(job_pod_dict)

If applicable, update Job or Pod configuration dict with http_proxy, https_proxy and no_proxy env variables (required for disconnected clusters and clusters behind proxy).

Parameters

job_pod_dict (dict) – dictionary with Job or Pod configuration (updated in-place)

ocs_ci.helpers.pvc_ops module

ocs_ci.helpers.pvc_ops.create_pvcs(multi_pvc_factory, interface, project=None, status='', storageclass=None)
ocs_ci.helpers.pvc_ops.delete_pods(pod_objs)

Delete pods

ocs_ci.helpers.pvc_ops.test_create_delete_pvcs(multi_pvc_factory, pod_factory, project=None)

ocs_ci.helpers.sanity_helpers module

class ocs_ci.helpers.sanity_helpers.Sanity

Bases: object

Class for cluster health and functional validations

create_pvc_delete(multi_pvc_factory, project=None)

Creates and deletes all types of PVCs

create_resources(pvc_factory, pod_factory, bucket_factory, rgw_bucket_factory, run_io=True)

Sanity validation: Create resources - pods, OBCs (RGW and MCG), PVCs (FS and RBD) and run IO

Parameters
  • pvc_factory (function) – A call to pvc_factory function

  • pod_factory (function) – A call to pod_factory function

  • bucket_factory (function) – A call to bucket_factory function

  • rgw_bucket_factory (function) – A call to rgw_bucket_factory function

  • run_io (bool) – True for run IO, False otherwise

delete_resources()

Sanity validation - Delete resources (pods, PVCs and OBCs)

health_check(cluster_check=True, tries=20)

Perform Ceph and cluster health checks

obc_put_obj_create_delete(mcg_obj, bucket_factory)

Creates bucket then writes, reads and deletes objects

class ocs_ci.helpers.sanity_helpers.SanityExternalCluster

Bases: ocs_ci.helpers.sanity_helpers.Sanity

Helpers for health check and functional validation in External mode

Module contents