ocs_ci.utility package¶
Subpackages¶
Submodules¶
ocs_ci.utility.aws module¶
-
class
ocs_ci.utility.aws.AWS(region_name=None)¶ Bases:
objectThis is wrapper class for AWS
-
append_security_group(security_group_id, instance_id)¶ Append security group to selected ec2 nodes
- Parameters
instance_id (str) – Instances to attach security group
security_group_id (str) – Security group to attach
out (print) – security group <id> added to selected nodes
-
attach_volume(volume, instance_id, device='/dev/sdx')¶ Attach volume to an ec2 instance
- Parameters
volume (Volume) – Volume instance
instance_id (str) – id of instance where to attach the volume
device (str) – The name of the device where to attach (default: /dev/sdx)
-
block_instances_access(security_group_id, instances_id)¶ Block ec2 instances by:
Append security group without access permissions
Remove original security groups
- Parameters
security_group_id (str) – security group without access permissions
instances_id (list) – list of ec2 instances ids
-
property
cf_client¶ Property for cloudformation client
- Returns
instance of cloudformation
- Return type
boto3.client
-
create_security_group(group_name, dict_permissions, vpc_id)¶ Create security group with predefined group name and permissions
- Parameters
group_name (str) – Group name (aws tag: “Group Name”)
dict_permissions (dict) – The security group’s inbound/outbound permissions
vpc_id (str) – For group to be attached
- Returns
newly created security group id
- Return type
str
-
create_stack(s3_url, index, params_list, capabilities)¶ Create a new cloudformation stack for worker creation
- Parameters
s3_url (str) – An aws url for accessing s3 object
index (int) – Integer index for stack name
params_list (list) – of parameters (k,v) for create_stack
capabilities (list) – of valid AWS capabilities like CAPABILITY_NAMED_IAM etc
- Returns
of (stack_name, stack_id)
- Return type
tuple
-
create_volume(availability_zone, name, encrypted=False, size=100, timeout=20, volume_type='gp2')¶ Create volume
- Parameters
availability_zone (str) – The availability zone e.g.: us-west-1b
name (str) – The name of the volume
encrypted (boolean) – True if encrypted, False otherwise (default: False)
size (int) – The size in GB (default: 100)
timeout (int) – The timeout in seconds for volume creation (default: 20)
volume_type (str) – ‘standard’|’io1’|’gp2’|’sc1’|’st1’ (default: gp2)
- Returns
AWS Resource instance of the newly created volume
- Return type
Volume
-
create_volume_and_attach(availability_zone, instance_id, name, device='/dev/sdx', encrypted=False, size=100, timeout=20, volume_type='gp2')¶ Create volume and attach to instance
- Parameters
availability_zone (str) – The availability zone e.g.: us-west-1b
instance_id (str) – The id of the instance where to attach the volume
name (str) – The name of volume
device (str) – The name of device where to attach (default: /dev/sdx)
encrypted (boolean) – True if encrypted, False otherwise (default: False)
size (int) – The size in GB (default: 100)
timeout (int) – The timeout in seconds for volume creation (default: 20)
volume_type (str) – ‘standard’|’io1’|’gp2’|’sc1’|’st1’ (default: gp2)
-
delete_all_record_sets(hosted_zone_id)¶ Deletes all record sets in a hosted zone
- Parameters
hosted_zone_id (str) – Hosted Zone ID example: /hostedzone/Z91022921MMOZDVPPC8D6
-
delete_apps_record_set(cluster_name=None, from_base_domain=False)¶ - Delete apps record set that sometimes blocks sg stack deletion.
- Parameters
cluster_name (str) – Name of the cluster
from_base_domain (bool) – Delete apps record set from base domain created by Flexy
-
delete_cf_stack_including_dependencies(cfs_name)¶ Delete cloudformation stack including dependencies.
Some of the depending resources are not deletable, so related errors are ignored and only logged. Thsi method is mainly used as a WORKAROUND for folowing Flexy issue: https://issues.redhat.com/browse/OCPQE-1521
- Parameters
cfs_name (str) – CloudFormation stack name to cleanup
-
delete_cloudformation_stacks(stack_names)¶ Delete cloudformation stacks
- Parameters
stack_names (list) – List of cloudformation stacks
-
delete_hosted_zone(cluster_name)¶ Deletes the hosted zone
- Parameters
cluster_name (str) – Name of the cluster
-
delete_record(record, hosted_zone_id)¶ Deletes the record from Hosted Zone
- Parameters
record (dict) – record details to delete e.g:{ ‘Name’: ‘vavuthu-eco1.qe.rh-ocs.com.’, ‘Type’: ‘NS’, ‘TTL’: 300, ‘ResourceRecords’:[ {‘Value’: ‘ns-1389.awsdns-45.org’}, {‘Value’: ‘ns-639.awsdns-15.net’}, {‘Value’: ‘ns-1656.awsdns-15.co.uk’}, {‘Value’: ‘ns-183.awsdns-22.com’} ] }
hosted_zone_id (str) – Hosted Zone ID example: /hostedzone/Z91022921MMOZDVPPC8D6
-
delete_record_from_base_domain(cluster_name, base_domain=None)¶ Deletes the record for cluster name in base domain
- Parameters
cluster_name (str) – Name of the cluster
base_domain (str) – Base domain name
-
delete_s3_object(bucket_name, object_key)¶ Delete an object from s3 bucket
- Parameters
bucket_name (str) – name of a valid s3 bucket
object_key (str) – the key for s3 object
-
delete_security_group(security_group_id)¶ Delete selected security group print out: Security group <id> deleted
- Parameters
security_group_id (str) – Id of selected security group
-
delete_volume(volume)¶ Delete an ec2 volume from AWS
- Parameters
volume (Volume) – The volume to delete
-
detach_and_delete_volume(volume, timeout=120)¶ Detach volume if attached and then delete it from AWS
- Parameters
volume (Volume) – The volume to delete
timeout (int) – Timeout in seconds for API calls
-
detach_volume(volume, timeout=120)¶ Detach volume if attached
- Parameters
volume (Volume) – The volume to delete
timeout (int) – Timeout in seconds for API calls
- Returns
ec2 Volume instance
- Return type
Volume
-
property
ec2_client¶ Property for ec2 client
- Returns
instance of ec2
- Return type
boto3.client
-
property
ec2_resource¶ Property for ec2 resource
- Returns
boto3.resource instance of ec2 resource
-
property
elb_client¶ Property for elb client
- Returns
instance of elb client
- Return type
boto3.client
-
get_all_security_groups()¶ Get all security groups in AWS region
- Returns
All security groups
- Return type
list
-
get_all_stacks()¶ Get all the cloudformation stacks
- Returns
of all cloudformation stacks
- Return type
list
-
get_availability_zone_id_by_instance_id(instance_id)¶ Fetch availability zone out of ec2 node (EC2.Instances.placement)
- Parameters
instance_id (str) – ID of the instance - to get availability zone info from ec2 node
- Returns
availability_zone: The availability zone name
- Return type
str
-
get_cloudformation_stacks(pattern)¶ Get cloudformation stacks
- Parameters
pattern (str) – The pattern of the stack name
-
get_ec2_instance(instance_id)¶ Get instance of ec2 Instance
- Parameters
instance_id (str) – The ID of the instance to get
- Returns
instance of ec2 instance resource
- Return type
boto3.Instance
-
get_ec2_instance_volumes(instance_id)¶ Get all volumes attached to an ec2 instance
- Parameters
instance_id (str) – The ec2 instance ID
- Returns
ec2 Volume instances
- Return type
list
-
get_instance_id_from_private_dns_name(private_dns_name)¶ Get the instance id from the private dns name of the instance
- Parameters
private_dns_name (str) – The private DNS name of the instance
- Returns
- The instance id associated to the private DNS name.
If not found returns None
- Return type
str
-
get_instances_by_name_pattern(pattern)¶ Get instances by Name tag pattern
The instance details do not contain all the values but just those we are consuming.
Those parameters we are storing for instance are: * id: id of instance * avz: Availability Zone * name: The value of Tag Name if define otherwise None * vpc_id: VPC ID * security_groups: Security groups of the instance
- Parameters
pattern (str) – Pattern of tag name like: pbalogh-testing-cluster-55jx2-worker*
- Returns
contains dictionaries with instance details mentioned above
- Return type
list
-
get_instances_response_by_name_pattern(pattern=None, filter_by_cluster_name=True)¶ Get the instances by name tag pattern. If not specified it will return all the instances, or will return the instances filtered by the cluster name.
- Parameters
pattern (str) – Pattern of tag name like: pbalogh-testing-cluster-55jx2-worker*
filter_by_cluster_name – Will be used only if the ‘pattern’ param not specified. If True it filters the instances by the cluster name, else if False it returns all instances.
- Returns
list of instances dictionaries.
- Return type
list
-
get_instances_status_by_id(instance_id)¶ Get instances by ID
- Parameters
instance_id (str) – ID of the instance
- Returns
The instance status
- Return type
str
-
get_matching_stacks(pattern)¶ Get only the stacks which matches the pattern
- Parameters
pattern (str) – A raw string which is re compliant
- Returns
of strings which are matching stack name
- Return type
list
-
get_s3_bucket_object_url(bucket_name, object_key)¶ Get s3 bucket object url
- Parameters
bucket_name (str) – Name of a valid s3 bucket
object_key (str) – Name of the key for s3 object
- Returns
An s3 url
- Return type
s3_url (str)
-
get_security_groups_by_instance_id(instance_id)¶ Get all attached security groups of ec2 instance
- Parameters
instance_id (str) – Required instance to get security groups from it
- Returns
all_sg_ids: all attached security groups id.
- Return type
list
-
get_stack_instance_id(stack_name, logical_id)¶ Get the instance id associated with the cloudformation stack
- Parameters
stack_name (str) – Name of the cloudformation stack
logical_id (str) – LogicalResourceId of the resource ex: “Worker0”
- Returns
Id of the instance
- Return type
instance_id (str)
-
get_stack_name_by_instance_id(instance_id)¶ Get the stack name by the instance id
- Parameters
instance_id (str) – The instance id
- Returns
- The stack name associated to the instance id.
If not found returns None
- Return type
str
-
get_stack_params(stack_name, param_name)¶ Get value of a particular param
- Parameters
stack_name (str) – AWS cloudformation stack name
param_name (str) – Stack parameter name
- Returns
Parameter value
- Return type
str
-
get_volumes_by_name_pattern(pattern)¶ Get volumes by pattern
- Parameters
pattern (str) – Pattern of volume name (e.g. ‘cl-vol-‘)
- Returns
Volume information like id and attachments
- Return type
list
-
get_vpc_id_by_instance_id(instance_id)¶ Fetch vpc id out of ec2 node (EC2.Instances.vpc_id)
- Parameters
instance_id (str) – ID of the instance - to get vpc id info from ec2 node
- Returns
vpc_id: The vpc id
- Return type
str
-
get_worker_ignition_location(stack_name)¶ Get the ignition location from given stack
- Parameters
stack_name (str) – AWS cloudformation stack name
- Returns
An AWS URL ignition location
- Return type
ignition_location (str)
-
get_worker_instance_profile_name(stack_name)¶ Get the worker instance profile name
- Parameters
stack_name (str) – AWS cloudformation stack name
- Returns
instance profile name
- Return type
worker_instance_profile_name (str)
-
get_worker_stacks()¶ Get the cloudformation stacks only for workers of this cluster
- Returns
of worker stacks
- Return type
list
-
remove_security_group(security_group_id, instance_id)¶ Remove security group from selected ec2 instance (by instance id) print out: security group <id> removed from selected nodes
- Parameters
security_group_id (str) – Security group to be removed
instance_id (str) – Instance attached with selected security group
-
restart_ec2_instances(instances)¶ Restart ec2 instances
- Parameters
instances (dict) – A dictionary of instance IDs and names to restart
-
restart_ec2_instances_by_stop_and_start(instances, wait=False, force=True)¶ Restart EC2 instances by stop and start
- Parameters
instances (dict) – A dictionary of instance IDs and names to stop & start
wait (bool) – True in case wait for status is needed, False otherwise
force (bool) – True for force instance stop, False otherwise
-
restore_instances_access(security_group_id_to_remove, original_security_group_dict)¶ Restore access to instances by removing blocking security group and append original security group.
- Parameters
security_group_id_to_remove (str) – id of the security group
original_security_group_dict (dict) – dict with: keys: blocked instances: ec2 instances id values: list of original security groups
-
property
route53_client¶ Property for route53 client
- Returns
instance of route53 client
- Return type
boto3.client
-
property
s3_client¶ Property for s3 client
- Returns
boto3.resource instance of s3
-
start_ec2_instances(instances, wait=False)¶ Starting an instance
- Parameters
instances (dict) – A dictionary of instance IDs and names to start
wait (bool) – True in case wait for status is needed, False otherwise
-
stop_ec2_instances(instances, wait=False, force=True)¶ Stopping an instance
- Parameters
instances (dict) – A dictionary of instance IDs and names to stop
wait (bool) – True in case wait for status is needed, False otherwise
force (bool) – True for force instance stop, False otherwise
-
store_security_groups_for_instances(instances_id)¶ Stored all security groups attached to selected ec2 instances
- Parameters
instances_id (list) – ec2 instance_id
- Returns
- security_group_dict: keys: blocked instances: ec2_instances ids
values: list of original security groups of each instance
- Return type
dict
-
terminate_ec2_instances(instances, wait=True)¶ Terminate an instance
- Parameters
instances (dict) – A dictionary of instance IDs and names
wait (bool) – True in case wait for status is needed, False otherwise
-
upload_file_to_s3_bucket(bucket_name, object_key, file_path)¶ Upload objects to s3 bucket
- Parameters
bucket_name (str) – Name of a valid s3 bucket
object_key (str) – the key for the s3 object
file_path (str) – path for the file to be uploaded
-
-
exception
ocs_ci.utility.aws.AWSTimeoutException¶ Bases:
Exception
-
exception
ocs_ci.utility.aws.StackStatusError¶ Bases:
Exception
-
ocs_ci.utility.aws.check_root_volume(volume)¶ Checks whether given EBS volume is root device or not
- Parameters
volume (dict) – EBS volume dictionary
- Returns
True if EBS volume is root device, False otherwise
- Return type
bool
-
ocs_ci.utility.aws.delete_cluster_buckets(cluster_name)¶ Delete s3 buckets corresponding to a particular OCS cluster
- Parameters
cluster_name (str) – name of the cluster the buckets belong to
-
ocs_ci.utility.aws.destroy_volumes(cluster_name)¶ Destroy cluster volumes
- Parameters
cluster_name (str) – The name of the cluster
-
ocs_ci.utility.aws.get_data_volumes(deviceset_pvs)¶ Get the instance data volumes (which doesn’t include root FS)
- Parameters
deviceset_pvs (list) – PVC objects of the deviceset PVs
- Returns
ec2 Volume instances
- Return type
list
-
ocs_ci.utility.aws.get_instances_ids_and_names(instances)¶ Get the instances IDs and names according to nodes dictionary
- Parameters
instances (list) – Nodes dictionaries, returned by ‘oc get node -o yaml’
- Returns
The ID keys and the name values of the instances
- Return type
dict
-
ocs_ci.utility.aws.get_rhel_worker_instances(cluster_path)¶ Get list of rhel worker instance IDs
- Parameters
cluster_path (str) – The cluster path
- Returns
list of instance IDs of rhel workers
- Return type
list
-
ocs_ci.utility.aws.get_stack_name_from_instance_dict(instance_dict)¶ Get the stack name by the given instance dictionary from AWS
- Parameters
instance_dict (dict) – The instance dictionary from AWS
- Returns
- The stack name of the given instance dictionary from AWS.
If not found returns None
- Return type
str
-
ocs_ci.utility.aws.get_vpc_id_by_node_obj(aws_obj, instances)¶ This function getting vpc id by randomly selecting instances out of user aws deployment
- Parameters
aws_obj (obj) – AWS() object
instances (dict) – cluster ec2 instances objects
- Returns
vpc_id: The vpc id
- Return type
str
-
ocs_ci.utility.aws.terminate_rhel_workers(worker_list)¶ Terminate the RHEL worker EC2 instances
- Parameters
worker_list (list) – Instance IDs of rhel workers
- Raises
exceptions.FailedToDeleteInstance – if failed to terminate
-
ocs_ci.utility.aws.update_config_from_s3(bucket_name='ocs-ci-data', filename='auth.yaml')¶ Get the config file that has secrets/configs from the S3 and update the config
- Parameters
bucket_name (string) – name of the bucket
filename (string) – name of the file in bucket
- Returns
returns the updated file contents as python dict None: In case the private bucket could not be accessed
- Return type
dict
ocs_ci.utility.azure_utils module¶
Module for interactions with OCP/OCS Cluster on Azure platform level.
-
class
ocs_ci.utility.azure_utils.AZURE(subscription_id=None, tenant_id=None, client_id=None, client_secret=None, cluster_resource_group=None)¶ Bases:
objectUtility wrapper class for Azure OCP cluster. Design of the class follows similar AWS class.
-
property
cluster_resource_group¶ Azure resource group of the OCP cluster. This group is created by openshift-installer during OCP deployment.
If the value is not yet available and it’s not specified anywhere, it returns None.
-
property
compute_client¶ Property for Azure vm resource
- Returns
ComputeManagementClient instance for managing Azure vm resource
-
property
credentials¶ Property for azure service principle credentials used to authenticate the client.
-
detach_volume(volume, node, timeout=120)¶ Detach volume if attached
- Parameters
volume (disk) – disk object required to delete a volume
node (OCS) – The OCS object representing the node
timeout (int) – Timeout in seconds for API calls
-
get_data_volumes(deviceset_pvs)¶ Get the instance data disk objects
- Parameters
deviceset_pvs (list) – PVC objects of the deviceset PVs
- Returns
Azure Vm disk objects
- Return type
list
-
get_disk_state(volume_name)¶ Get the state of the disk
- Parameters
volume_name (str) – Name of the volume/disk
- Returns
Azure Vm disk state
- Return type
str
-
get_node_by_attached_volume(volume)¶ Get the Azure Vm instance that has the volume attached to
- Parameters
volume (Disk) – The disk object to get the Azure Vm according to
- Returns
An Azure Vm instance
- Return type
vm
-
get_vm_instance(vm_name)¶ Get instance of Azure vm Instance
- Parameters
vm_name (str) – The name of the Azure instance to get
- Returns
instance of Azure vm instance resource
- Return type
vm
-
get_vm_names()¶ Get list of vms in azure resource group
- Returns
list of Azure vm names
- Return type
(list)
-
get_vm_power_status(vm_name)¶ Get the power status of VM
- Parameters
vm_name (str) – Azure VM name
- Returns :
str: Power status of Azure VM
-
property
resource_client¶ Azure ResourceManagementClient instance
-
restart_vm_instances(vm_names)¶ Restart Azure vm instances
- Parameters
vm_names (list) – Names of azure vm instances
-
restart_vm_instances_by_stop_and_start(vm_names, force=False)¶ Stop and Start Azure vm instances
- Parameters
vm_names (list) – Names of azure vm instances
force (bool) – True for non-graceful VM shutdown, False for graceful VM shutdown
-
start_vm_instances(vm_names)¶ Start Azure vm instances
- Parameters
vm_names (list) – Names of azure vm instances
-
stop_vm_instances(vm_names, force=False)¶ Stop Azure vm instances
- Parameters
vm_names (list) – Names of azure vm instances
force (bool) – True for non-graceful VM shutdown, False for graceful VM shutdown
-
property
-
ocs_ci.utility.azure_utils.load_cluster_resource_group(cluster_path, terraform_filename='terraform.azure.auto.tfvars.json')¶ Read terraform tfvars.json file created by
openshift-installerin a cluster dir to get azureresource groupof an OCP cluster. All Azure resources of the cluster are placed in this group.- Parameters
cluster_path (str) – full file path of the openshift cluster directory
terraform_filename (str) – name of azure terraform vars file, this is optional and you need to specify this only if you want to override the default
- Returns
string with resource group name
-
ocs_ci.utility.azure_utils.load_service_principal_dict(filepath='/home/docs/.azure/osServicePrincipal.json')¶ Load Azure Service Principal from osServicePrincipal.json file and parse it into a dictionary.
- Parameters
filepath (str) – path of the
- Returns
dictionary with the service principal details (3 IDs and 1 secret)
ocs_ci.utility.baremetal module¶
-
class
ocs_ci.utility.baremetal.BAREMETAL¶ Bases:
objectwrapper for Baremetal
-
get_ipmi_ctx(host, user, password)¶ Function to get ipmi handler :param host: Host mgmt address :type host: str :param user: User Name for accessing mgmt console :type user: str :param password: Password for accessing mgmt console :type password: str
Returns (object): ipmi handler
-
get_nodes_ipmi_ctx(baremetal_machine)¶ Get Node Ipmi handler
- Parameters
baremetal_machine – BM objects
-
get_power_status(ipmi_ctx)¶ Get BM Power status
- Parameters
ipmi_ctx (object) – Ipmi host handler
Returns: (bool): bm power status
-
restart_baremetal_machines(baremetal_machine, force=True)¶ Restart Baremetal Machines
- Parameters
baremetal_machine (list) – BM objects
force (bool) – True for BM ungraceful power off, False for graceful BM shutdown
-
start_baremetal_machines(baremetal_machine, wait=True)¶ Start Baremetal Machines
- Parameters
baremetal_machine (list) – BM objects
wait (bool) – Wait for BMs to start
-
start_baremetal_machines_with_ipmi_ctx(ipmi_ctxs, wait=True)¶ Start Baremetal Machines using Ipmi ctx
- Parameters
ipmi_ctxs (list) – List of BM ipmi_ctx
wait (bool) – Wait for BMs to start
-
stop_baremetal_machines(baremetal_machine, force=True)¶ Stop Baremetal Machines
- Parameters
baremetal_machine (list) – BM objects
force (bool) – True for BM ungraceful power off, False for graceful BM shutdown
- Raises
UnexpectedBehaviour – If baremetal machine is still up
-
verify_machine_is_down(node)¶ Verifiy Baremetal machine is completely power off
- Parameters
node (object) – Node objects
- Returns
True if machine is down, False otherwise
- Return type
bool
-
ocs_ci.utility.bootstrap module¶
-
ocs_ci.utility.bootstrap.gather_bootstrap()¶ Gather debugging data for a failing-to-bootstrap control plane. Data is placed in the gather_bootstrap directory under the log directory.
- Raises
NodeNotFoundError – If we are unable to retrieve the IP of any master nodes
-
ocs_ci.utility.bootstrap.get_gather_bootstrap_node_data()¶ Retrieve node IPs required by the gather bootstrap command
- Raises
UnsupportedPlatformError – If we do not support gathering bootstrap data for the configured provider
- Returns
Public IP of the bootstrap node and Private IPs of master nodes
- Return type
dict
-
ocs_ci.utility.bootstrap.get_node_data_aws()¶ Retrieve bootstrap public IP and master node private IPs running in aws
- Raises
NodeNotFoundError – If we are unable to find the bootstrap node or IP
- Returns
bootstrap and master node IP data
- Return type
dict
-
ocs_ci.utility.bootstrap.get_node_data_vsphere()¶ Retrieve bootstrap public IP and master node private IPs running in vsphere
- Raises
NodeNotFoundError – If we are unable to find the bootstrap node or IP
- Returns
bootstrap and master node IP data
- Return type
dict
ocs_ci.utility.connection module¶
Module that connects to remote server and execute operations on remote server
-
class
ocs_ci.utility.connection.Connection(host, user=None, private_key=None)¶ Bases:
objectA class that connects to remote server
-
exec_cmd(cmd)¶ Executes command on server
- Parameters
cmd (str) – Command to run on server
- Returns
tuple which contains command return code, output and error
- Return type
tuple
-
ocs_ci.utility.csr module¶
-
ocs_ci.utility.csr.approve_csrs(pending_csrs)¶ Approves the CSRs
- Parameters
csrs (list) – List of CSRs
-
ocs_ci.utility.csr.approve_pending_csr(expected=None)¶ After node addition CSR could be in pending state, we have to approve it.
- Parameters
expected (int) – Expected number of CSRs. By default, it will approve all the pending CSRs if exists.
- Raises
-
ocs_ci.utility.csr.check_no_pending_csr()¶ Check whether we have any pending CSRs.
- Raises
-
ocs_ci.utility.csr.get_csr_resource()¶ Retrieve the latest CSR data
- Returns
CSR data
- Return type
-
ocs_ci.utility.csr.get_nodes_csr()¶ Fetches the CSRs
- Returns
- Dictionary with node as keys and CSRs as values
- e.g:{
‘control-plane-1’: [‘csr-6hx8z’], ‘compute-2’: [‘csr-blz2n’], ‘compute-0’: [‘csr-p46bz’], ‘control-plane-2’: [‘csr-tzhn5’], ‘control-plane-0’: [‘csr-wm4g5’] }
- Return type
dict
-
ocs_ci.utility.csr.get_pending_csr()¶ Gets the pending CSRs
- Returns
list of pending CSRs
- Return type
list
-
ocs_ci.utility.csr.wait_for_all_nodes_csr_and_approve(timeout=900, sleep=10, expected_node_num=None)¶ Wait for CSR to generate for nodes
- Parameters
timeout (int) – Time in seconds to wait
sleep (int) – Sampling time in seconds
expected_node_num (int) – Number of nodes to verify CSR is generated
- Returns
True if all nodes are generated CSR
- Return type
bool
- Raises
TimeoutExpiredError – in case CSR not found
ocs_ci.utility.deployment module¶
Utility functions that are used as a part of OCP or OCS deployments
-
ocs_ci.utility.deployment.get_ocp_ga_version(channel)¶ Retrieve the latest GA version for
- Parameters
channel (str) – the OCP version channel to retrieve GA version for
- Returns
- latest GA version for the provided channel.
An empty string is returned if no version exists.
- Return type
str
ocs_ci.utility.deployment_openshift_logging module¶
This module deploys the openshift-logging on the cluster EFK stack
-
ocs_ci.utility.deployment_openshift_logging.check_health_of_clusterlogging()¶ - Checks for ElasticSearch, curator, fluentd and kibana pods in
openshift-logging namespace
- And check for the health of cluster logging, If status is green then the
cluster is healthy,if status is red then health is bad
- Returns
Gives all the pods that are present in the namespace
- Return type
list
-
ocs_ci.utility.deployment_openshift_logging.create_clusterlogging_operator_group(yaml_file)¶ Creation of operator-group for clusterlogging operator.
- Parameters
yaml_file (str) – Path to yaml file to create operator group for cluster-logging operator
resource_name (str) – Name of the operator group to create for cluster-logging operator
- Returns
- True if operator group for cluster-logging is created
successfully, false otherwise
- Return type
bool
Example
create_clusterlogging_operator_group(yaml_file=constants.CL_OG_YAML)
-
ocs_ci.utility.deployment_openshift_logging.create_elasticsearch_operator_group(yaml_file, resource_name)¶ Creation of operator-group for Elastic-search operator
- Parameters
yaml_file (str) – Path to yaml file to create operator group for elastic-search
resource_name (str) – Name of the operator group to create for elastic-search
- Returns
- True if operator group for elastic search is created
successfully, false otherwise
- Return type
bool
Example:
create_elasticsearch_operator_group( constants.EO_OG_YAML, 'openshift-operators-redhat' )
-
ocs_ci.utility.deployment_openshift_logging.create_instance()¶ The function is used to create instance for cluster-logging
-
ocs_ci.utility.deployment_openshift_logging.create_instance_in_clusterlogging()¶ Creation of instance for clusterlogging that creates PVCs, ElasticSearch, curator fluentd and kibana pods and checks for all the pods and PVCs
- Parameters
sc_name (str) – Storage class name to create PVCs
- Returns
- Contains all detailed information of the
instance such as pods that got created, its resources and limits values, storage class and size details etc.
- Return type
dict
-
ocs_ci.utility.deployment_openshift_logging.create_namespace(yaml_file)¶ Creation of namespace “openshift-operators-redhat” for Elasticsearch-operator and “openshift-logging” for ClusterLogging-operator
- Parameters
yaml_file (str) – Path to yaml file to create namespace
Example
create_namespace(yaml_file=constants.EO_NAMESPACE_YAML)
-
ocs_ci.utility.deployment_openshift_logging.get_clusterlogging_subscription()¶ Creation of subscription for clusterlogging to subscribe a namespace to an operator
- Parameters
yaml_file (str) – Path to yaml file to create subscription for the namespace
resource_name (str) – Name of the subscription
- Returns
Contains all the details of the subscription.
- Return type
dict
Example
cl_create_subscription(yaml_file=constants.CL_SUB_YAML)
-
ocs_ci.utility.deployment_openshift_logging.get_elasticsearch_subscription()¶ Creation of Subscription for the namespace to subscribe a Namespace to an Operator.
- Parameters
yaml_file (str) – Path to yaml file to create subscription for a namespace
resource_name (str) – Name of the subscription
- Returns
Contains all the details of the subscription
- Return type
dict
Example
create_elasticsearch_subscription(constants.EO_SUB_YAML)
-
ocs_ci.utility.deployment_openshift_logging.set_rbac(yaml_file, resource_name)¶ Setting Role Based Access Control to grant Prometheus permission to access the openshift-operators-redhat namespace
- Parameters
yaml_file (str) – Path to yaml file to create RBAC (ROLE BASED ACCESS CONTROL)
resource_name (str) – Name of the resource for which we give RBAC permissions
- Returns
- True if RBAC is set successfully,
false otherwise
- Return type
bool
Example
set_rbac(constants.EO_RBAC_YAML, ‘prometheus-k8s’)
ocs_ci.utility.environment_check module¶
Util for environment check before and after test to compare and find stale leftovers
-
ocs_ci.utility.environment_check.assign_get_values(env_status_dict, key, kind=None, exclude_labels=None)¶ Assigning kind status into env_status_dict
- Parameters
env_status_dict (dict) – Dictionary which is copy.deepcopy(ENV_STATUS_DICT)
key (str) – Name of the resource
kind (OCP obj) – OCP object for a resource
exclude_labels (list) – App labels to ignore leftovers
-
ocs_ci.utility.environment_check.compare_dicts(before, after)¶ Comparing 2 dicts and providing diff list of [added items, removed items]
- Parameters
before (dict) – Dictionary before execution
after (dict) – Dictionary after execution
- Returns
List of 2 lists - (‘added’ and ‘removed’ are lists)
- Return type
list
-
ocs_ci.utility.environment_check.get_environment_status(env_dict, exclude_labels=None)¶ Get the environment status per kind in KINDS and save it in a dictionary
- Parameters
env_dict (dict) – Dictionary that is a copy.deepcopy(ENV_STATUS_DICT)
exclude_labels (list) – App labels to ignore leftovers
-
ocs_ci.utility.environment_check.get_status_after_execution(exclude_labels=None)¶ Set the environment status and assign it into ENV_STATUS_PRE dictionary. In addition compare the dict before the execution and after using DeepDiff
- Parameters
exclude_labels (list) – App labels to ignore leftovers
- Raises
ResourceLeftoversException – In case there are leftovers in the environment after the execution
-
ocs_ci.utility.environment_check.get_status_before_execution(exclude_labels=None)¶ Set the environment status and assign it into ENV_STATUS_PRE dictionary
- Parameters
exclude_labels (list) – App labels to ignore leftovers
ocs_ci.utility.flexy module¶
Utility functions related to OCP deployment done via Flexy
-
ocs_ci.utility.flexy.configure_allowed_domains_in_proxy()¶ Configure squid proxy server - add domains which needs to be accessible from disconnected cluster for test execution.
-
ocs_ci.utility.flexy.load_cluster_info()¶ Parse cluster_info.json file generated by Flexy and load relevant configuratin.
ocs_ci.utility.gcp module¶
Module for interactions with OCP/OCS Cluster on Google Cloud platform level.
It’s using libcloud module as much as possible, but if that is not feasible, we can use module from Google Cloud python libraries as well. This is not the case so far.
-
class
ocs_ci.utility.gcp.GoogleCloudUtil(region_name=None)¶ Bases:
objectUtility wrapper class for Google Cloud OCP cluster. Design of the class follows similar AWS and Azure class.
-
property
compute_driver¶ Compute Driver instance for GCP.
-
property
service_account¶ Dictionary with GCP service account details, which contains authentication keys and cluster details loaded from Service Account Key file.
-
property
-
ocs_ci.utility.gcp.SERVICE_ACCOUNT_KEY_FILEPATH= '/home/docs/.gcp/osServiceAccount.json'¶ absolute filepath of json file with service account key
This is json key file of
sg-serv-accountservice account, which has full admin rights in given GCP project. The same key file is used by openshift installer during OCP installation to create all cluster resources from virtual machines to hostnames. Modules from ocs-ci are using the same key to get full cluster access as well.For more details, see GCP documentation on ServiceAccountKey resource
- Type
str
-
ocs_ci.utility.gcp.load_service_account_key_dict(filepath='/home/docs/.gcp/osServiceAccount.json')¶ Load GCP Service Account key from osServiceAccount.json file and parse it into a dictionary.
- Parameters
filepath (str) – path of the osServiceAccount.json file
- Returns
dictionary with the service account details
ocs_ci.utility.ibmcloud module¶
Module for interactions with IBM Cloud Cluster.
-
ocs_ci.utility.ibmcloud.add_deployment_dependencies()¶ Adding dependencies for IBM Cloud deployment
-
ocs_ci.utility.ibmcloud.create_cluster(cluster_name)¶ Create OCP cluster.
- Parameters
cluster_name (str) – Cluster name.
- Raises
UnexpectedBehaviour – in the case, the cluster is not installed successfully.
-
ocs_ci.utility.ibmcloud.destroy_cluster(cluster)¶ Destroy the cluster on IBM Cloud.
- Parameters
cluster (str) – Cluster name or ID.
-
ocs_ci.utility.ibmcloud.get_cluster_details(cluster)¶ Returns info about the cluster which is taken from the ibmcloud command.
- Parameters
cluster (str) – Cluster name or ID
-
ocs_ci.utility.ibmcloud.get_ibmcloud_ocp_version()¶ Get OCP version available in IBM Cloud.
-
ocs_ci.utility.ibmcloud.get_kubeconfig(cluster, path)¶ Export kubeconfig to provided path.
- Parameters
cluster (str) – Cluster name or ID.
path (str) – Path where to create kubeconfig file.
-
ocs_ci.utility.ibmcloud.is_cluster_installed(cluster)¶ Check if cluster is installed and return True if so, False otherwise.
- Parameters
cluster (str) – Cluster name or ID
-
ocs_ci.utility.ibmcloud.list_clusters(provider=None)¶ Returns info about the cluster which is taken from the ibmcloud command.
- Parameters
provider (str) – Provider type (classic, vpc-classic, vpc-gen2).
-
ocs_ci.utility.ibmcloud.login()¶ Login to IBM Cloud cluster
ocs_ci.utility.load_balancer module¶
Module that contains all operations related to load balancer in a cluster
-
class
ocs_ci.utility.load_balancer.LoadBalancer(host=None, user=None, private_key=None)¶ Bases:
objectA class that handles all operations related to load balancer
-
remove_boostrap_in_proxy()¶ Removes bootstrap IP from haproxy.conf
-
restart_haproxy()¶ Restarts haproxy service
- Returns
True if successful restarts of haproxy, False otherwise
- Return type
bool
-
restart_service(service_name)¶ Restarts the given service
-
update_haproxy_with_nodes(nodes)¶ - Parameters
nodes (list) – List of nodes to update in haproxy
-
ocs_ci.utility.localstorage module¶
This module contains local-storage related methods
-
ocs_ci.utility.localstorage.check_local_volume()¶ Function to check if Local-volume is present or not
- Returns
True if LV present, False if LV not present
- Return type
bool
-
ocs_ci.utility.localstorage.check_pvs_created(num_pvs_required)¶ Verify that exact number of PVs were created and are in the Available state
- Parameters
num_pvs_required (int) – number of PVs required
- Raises
AssertionError – if the number of PVs are not in the Available state
-
ocs_ci.utility.localstorage.fetch_all_device_paths()¶ Return all device paths inside worker nodes
- Returns
List containing all device paths
- Return type
list
-
ocs_ci.utility.localstorage.get_local_volume_cr()¶ Get localVolumeCR object
- Returns
Local Volume object handler
- Return type
local volume (obj)
-
ocs_ci.utility.localstorage.get_lso_channel()¶ Get the channel to use for installing the local storage operator
- Returns
local storage operator channel
- Return type
str
-
ocs_ci.utility.localstorage.get_new_device_paths(device_sets_required, osd_size_capacity_requested)¶ Get new device paths to add capacity over Baremetal cluster
- Parameters
device_sets_required (int) – Count of device sets to be added
osd_size_capacity_requested (int) – Requested OSD size capacity
- Returns
List containing added device paths
- Return type
list
ocs_ci.utility.lvm_utils module¶
-
ocs_ci.utility.lvm_utils.lvcreate(osd, lv_name, vg_name, size)¶
-
ocs_ci.utility.lvm_utils.make_partition(osd, device, start=None, end=None, gpt=False)¶
-
ocs_ci.utility.lvm_utils.osd_scenario1(osd, devices_dict, dmcrypt=False)¶ OSD scenario type1 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt
-
ocs_ci.utility.lvm_utils.osd_scenario1_dmcrypt(osd, devices_dict)¶ OSD scenario type2 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt(overridden to True)
-
ocs_ci.utility.lvm_utils.osd_scenario2(osd, devices_dict, dmcrypt=False)¶ OSD scenario type3 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt
-
ocs_ci.utility.lvm_utils.osd_scenario2_dmcrypt(osd, devices_dict)¶ OSD scenario type4 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt(overridden to True)
-
ocs_ci.utility.lvm_utils.osd_scenario3(osd, devices_dict, dmcrypt=False)¶ OSD scenario type5 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt
-
ocs_ci.utility.lvm_utils.osd_scenario3_dmcrypt(osd, devices_dict)¶ OSD scenario type6 generator :param osd: osd node :param devices_dict: dict of devices of the osd node supplied :param dmcrypt: False by default
- Returns
generated scenario, dmcrypt(overridden to True)
-
ocs_ci.utility.lvm_utils.pvcreate(osd, devices)¶
-
ocs_ci.utility.lvm_utils.vgcreate(osd, vg_name, devices)¶
ocs_ci.utility.openshift_console module¶
-
class
ocs_ci.utility.openshift_console.OpenshiftConsole(browser='chrome')¶ Bases:
object-
run_openshift_console(suite, env_vars=None, timeout=1500, log_suffix='')¶ Run openshift console suite
- Parameters
suite (str) – openshift console suite to execute
env_vars (dict) – env variables to expose for openshift console
timeout (int) – timeout for test-gui.sh script
- Raises
OpenshiftConsoleSuiteNotDefined – if suite is not defined
-
setup_console_prereq()¶ Setup openshift console prerequisites
- Raises
UnsupportedBrowser – in case the browser is not supported
-
ocs_ci.utility.openshift_dedicated module¶
Module for interactions with Openshift Dedciated Cluster.
-
ocs_ci.utility.openshift_dedicated.create_cluster(cluster_name)¶ Create OCP cluster.
- Parameters
cluster_name (str) – Cluster name.
-
ocs_ci.utility.openshift_dedicated.destroy_cluster(cluster)¶ Destroy the cluster on Openshift Dedicated.
- Parameters
cluster (str) – Cluster name or ID.
-
ocs_ci.utility.openshift_dedicated.download_ocm_cli()¶ Method to download OCM cli
- Returns
path to the installer
- Return type
str
-
ocs_ci.utility.openshift_dedicated.get_cluster_details(cluster)¶ Returns info about the cluster which is taken from the OCM command.
- Parameters
cluster (str) – Cluster name.
-
ocs_ci.utility.openshift_dedicated.get_kubeconfig(cluster, path)¶ Export kubeconfig to provided path.
- Parameters
cluster (str) – Cluster name.
path (str) – Path where to create kubeconfig file.
-
ocs_ci.utility.openshift_dedicated.list_cluster()¶ Returns info about the openshift dedciated clusters which is taken from the OCM command.
-
ocs_ci.utility.openshift_dedicated.login()¶ Login to OCM client
ocs_ci.utility.performance_dashboard module¶
Script to save result data using json into the performance dashboard Database structure: commitid: The specific buid id. : v4.3.0-407 E.g. 407 project: The project we are currently testing. E.g. 4.3 branch: OCS full version. E.g. 4.3.0 executable: Which OCS version we are testing. E.g. 4.3 benchmark: The benchmark type (based on interface) environment: The platform we are testing. E.g, AWS result_value: The value of this benchmark.
-
ocs_ci.utility.performance_dashboard.initialize_data()¶ Initialize the data dictionary with cluster data
- Returns
A dictionary contains the data to push to the dashboard
- Return type
dict
-
ocs_ci.utility.performance_dashboard.push_perf_dashboard(interface, read_iops, write_iops, bw_read, bw_write)¶ Push JSON data to performance dashboard
- Parameters
interface (str) – The interface used for getting the results
read_iops (str) – Read IOPS
write_iops (str) – Write IOPS
bw_read (str) – Read bandwidth
bw_write (str) – Write bandwidth
-
ocs_ci.utility.performance_dashboard.push_results(json_data)¶ Pushing the JSON data to the codespeed
- Parameters
json_data (dict) – The json file to push
-
ocs_ci.utility.performance_dashboard.push_to_pvc_time_dashboard(interface, action, duration)¶ Push JSON data to time pvc dashboard
- Parameters
interface (str) – The interface used for getting the results
action (str) – Can be either creation or deletion
duration (str) –
ocs_ci.utility.powernodes module¶
-
class
ocs_ci.utility.powernodes.POWERNodes¶ Bases:
objectWrapper for PowerNodes
-
iskvm()¶ Verify if this environment is libvirt or kvm.
- Returns
True if this is kvm environment, False otherwise
- Return type
bool
-
restart_powernodes_machines(powernode_machines, timeout, wait, force=True)¶ Restart PowerNode Machines
- Parameters
powernode_machines (list) – PowerNode objects
timeout (int) – time in seconds to wait for node to reach ‘not ready’ state, and ‘ready’ state.
wait (bool) – True if need to wait till the restarted node reaches timeout
force (bool) – True for PowerNode ungraceful power off, False for graceful PowerNode shutdown - for future use
-
start_powernodes_machines(powernode_machines, timeout=900, wait=True, force=True)¶ Start PowerNode Machines
- Parameters
powernode_machines (list) – List of PowerNode machines
timeout (int) – time in seconds to wait for node to reach ‘not ready’ state, and ‘ready’ state.
wait (bool) – Wait for PowerNodes to start - for future use
force (bool) – True for PowerNode ungraceful power off, False for graceful PowerNode shutdown - for future use
-
stop_powernodes_machines(powernode_machines, timeout=900, wait=True, force=True)¶ Stop PowerNode Machines
- Parameters
powernode_machines (list) – PowerNode objects
timeout (int) – time in seconds to wait for node to reach ‘not ready’ state
wait (bool) – True if need to wait till the restarted node reaches timeout - for future use
force (bool) – True for PowerNode ungraceful power off, False for graceful PowerNode shutdown - for future use
- Raises
UnexpectedBehaviour – If PowerNode machine is still up
-
verify_machine_is_down(node)¶ Verify if PowerNode is completely powered off
- Parameters
node (object) – Node objects
- Returns
True if machine is down, False otherwise
- Return type
bool
-
ocs_ci.utility.prometheus module¶
-
class
ocs_ci.utility.prometheus.PrometheusAPI(user=None, password=None)¶ Bases:
objectThis is wrapper class for Prometheus API.
-
check_alert_cleared(label, measure_end_time, time_min=120)¶ Check that all alerts with provided label are cleared.
- Parameters
label (str) – Alerts label
measure_end_time (int) – Timestamp of measurement end
time_min (int) – Number of seconds to wait for alert to be cleared since measurement end
-
generate_cert()¶ Generate CA certificate from kubeconfig for API.
TODO: find proper way how to generate/load cert files.
-
get(resource, payload=None)¶ Get alerts from Prometheus API.
- Parameters
resource (str) – Represents part of uri that specifies given resource
payload (dict) – Provide parameters to GET API call. e.g. for alerts resource this can be {‘silenced’: False, ‘inhibited’: False}
- Returns
Response from Prometheus alerts api
- Return type
dict
-
query(query, timestamp=None, timeout=None, validate=True, mute_logs=False)¶ Perform Prometheus instant query. This is a simple wrapper over
get()method with plumbing code for instant queries, additional validation and logging.- Parameters
query (str) – Prometheus expression query string.
timestamp (str) – Evaluation timestamp (rfc3339 or unix timestamp). Optional.
timeout (str) – Evaluation timeout in duration format. Optional.
validate (bool) – Perform basic validation on the response. Optional,
Trueis the default. UseFalsewhen you expect query to fail eg. during negative testing.mute_logs (bool) – True for muting the logs, False otherwise
- Returns
Result of the query (value(s) for a single timestamp)
- Return type
list
-
query_range(query, start, end, step, timeout=None, validate=True)¶ Perform Prometheus range query. This is a simple wrapper over
get()method with plumbing code for range queries, additional validation and logging.- Parameters
query (str) – Prometheus expression query string.
start (str) – start timestamp (rfc3339 or unix timestamp)
end (str) – end timestamp (rfc3339 or unix timestamp)
step (float) – Query resolution step width as float number of seconds.
timeout (str) – Evaluation timeout in duration format. Optional.
validate (bool) – Perform basic validation on the response. Optional,
Trueis the default. UseFalsewhen you expect query to fail eg. during negative testing.
- Returns
result of the query
- Return type
list
-
refresh_connection()¶ Login into OCP, refresh endpoint and token.
-
wait_for_alert(name, state=None, timeout=1200, sleep=5)¶ Search for alerts that have requested name and state.
- Parameters
name (str) – Alert name
state (str) – Alert state, if provided then there are searched alerts with provided state. If not provided then alerts are searched for absence of the alert. Loop that looks for alerts is broken when there are no alerts returned from API. This is done because API is not returning any alerts that are not in pending or firing state
timeout (int) – Number of seconds for how long the alert should be searched
sleep (int) – Number of seconds to sleep in between alert search
- Returns
List of alert records
- Return type
list
-
-
ocs_ci.utility.prometheus.check_alert_list(label, msg, alerts, states, severity='warning', ignore_more_occurences=True)¶ Check list of alerts that there are alerts with requested label and message for each provided state. If some alert is missing then this check fails.
- Parameters
label (str) – Alert label
msg (str) – Alert message
alerts (list) – List of alerts to check
states (list) – List of states to check, order is important
ignore_more_occurences (bool) – If true then there is checkced only occurence of alert with requested label, message and state but it is not checked if there is more of occurences than one.
-
ocs_ci.utility.prometheus.check_query_range_result_enum(result, good_values, bad_values=(), exp_metric_num=None, exp_delay=None, exp_good_time=None)¶ Check that result of range query matches given expectations. Useful for metrics which convey status (eg. ceph health, ceph_osd_up), so that you can assume that during a given period, it’s value should match given single (or tuple of) value(s).
- Parameters
result (list) – Data from
query_range()method.good_values (tuple) – Tuple of values considered good
bad_values (tuple) – Tuple of values considered bad, indicating a problem (optional, use if you need to distinguish bad and invalid values)
exp_metric_num (int) – expected number of data series in the result, optional (eg. for
ceph_health_statusthis would be 1, but for something likeceph_osd_upthis will be a number of OSDs in the cluster)exp_delay (int) – Number of seconds from the start of the query time range for which we should tolerate bad values. This is useful if you change cluster state and processing of this change is expected to take some time.
exp_good_time (int) – Number of seconds during which we should see good values in the metrics data. When this time passess values can go bad (but can’t be invalid). If not specified, good values should be presend during the whole time.
- Returns
True if result matches given expectations, False otherwise
- Return type
bool
-
ocs_ci.utility.prometheus.check_query_range_result_limits(result, good_min, good_max, exp_metric_num=None, exp_delay=None, exp_good_time=None)¶ Check that result of range query matches given expectations. Useful for metrics which convey continuous value, eg. storage or cpu utilization.
- Parameters
result (list) – Data from
query_range()method.good_min (float) – Min. value which is considered good.
good_max (float) – Max. value which is still considered as good.
exp_metric_num (int) – expected number of data series in the result, optional (eg. for
ceph_health_statusthis would be 1, but for something likeceph_osd_upthis will be a number of OSDs in the cluster)exp_delay (int) – Number of seconds from the start of the query time range for which we should tolerate bad values. This is useful if you change cluster state and processing of this change is expected to take some time.
exp_good_time (int) – Number of seconds during which we should see good values in the metrics data. When this time passess values can go bad (but can’t be invalid). If not specified, good values should be presend during the whole time.
- Returns
True if result matches given expectations, False otherwise
- Return type
bool
-
ocs_ci.utility.prometheus.check_query_range_result_viafunction(result, is_value_good, is_value_bad=<function <lambda>>, exp_metric_num=None, exp_delay=None, exp_good_time=None, is_float=False)¶ Check that result of range query matches expectations expressed via
is_value_good(and optionallyis_value_bad) functions, which takes a value and returns True if the value is good (or bad).- Parameters
result (list) – Data from
query_range()method.is_value_good (function) – returns True for a good value
is_value_bad (function) – returns True for a bad balue, indicating a problem (optional, use if you need to distinguish bad and invalid values)
exp_metric_num (int) – expected number of data series in the result, optional (eg. for
ceph_health_statusthis would be 1, but for something likeceph_osd_upthis will be a number of OSDs in the cluster)exp_delay (int) – Number of seconds from the start of the query time range for which we should tolerate bad values. This is useful if you change cluster state and processing of this change is expected to take some time.
exp_good_time (int) – Number of seconds during which we should see good values in the metrics data. When this time passess values can go bad (but can’t be invalid). If not specified, good values should be presend during the whole time.
is_float (bool) – assume that the value is float, otherwise assume int
- Returns
True if result matches given expectations, False otherwise
- Return type
bool
-
ocs_ci.utility.prometheus.log_parsing_error(query, resp_content, ex)¶ Log an error raised during parsing of a prometheus query.
- Parameters
query (dict) – Full specification of a prometheus query.
resp_content (bytes) – Response from prometheus
ex (Exception) – Exception raised during parsing of prometheus reply.
ocs_ci.utility.psiutils module¶
A module for all PSI-openstack related utilities
-
class
ocs_ci.utility.psiutils.PSIUtils(psi_conf)¶ Bases:
objectA class for handling PSI functionalities
-
attach_volume(vol, instance_id)¶ Attach the given volume to the specific PSI openstack instance
- Parameters
vol (Volume) – cinder volume object
instance_id (str) – uuid of the instance
-
check_expected_vol_status(vol, expected_state)¶ Check status of the volume and return true if it matches the expected state
- Parameters
vol (cinderclient.volume) – Volume object for which state needs to be checked
expected_state (str) – Expected state of the volume
- Returns
True if state is same as expected else False
- Return type
bool
-
check_vol_deleted(vol)¶ Check whether its delete
- Parameters
vol (cinderclient.Volume) – volume object
- Returns
True if deleted else False
- Return type
bool
-
create_volume(name, size=100, volume_type='tripleo', metadata=None)¶ A function to create openstack volumes
- Parameters
name (str) – display name of the volume
size (int) – of the volume in GBs
volume_type (str) – type of volume to be created
metadata (dict) – Any {k,v} to be associated with volume
- Returns
cinderclient.Client.Volumes
- Return type
Volume
-
detach_and_delete_vols(volumes)¶ Detach and delete volumes from the list
- Parameters
volumes (list) – of Volume objects
-
get_instances_with_pattern(pattern)¶ Get instances matching pattern
- Parameters
pattern (str) – Pattern for matching instance name note: we are looking for only ‘name’ param for pattern matching
- Returns
novaclient.base.ListWithMeta
-
get_volumes_with_tag(tag)¶ Get PSI volumes having this tag (k,v)
- Parameters
tag (dict) – of desired (k,v)
- Returns
of cinderclient.<vers>.volumes object
- Return type
list
-
ocs_ci.utility.reporting module¶
-
ocs_ci.utility.reporting.get_polarion_id(upgrade=False)¶ Determine the polarion_id of the deployment or upgrade
- Parameters
upgrade (bool) – get upgrade_id if true, else get deployment_id
- Returns
polarion_id of the deployment or upgrade
- Return type
str
ocs_ci.utility.retry module¶
-
ocs_ci.utility.retry.retry(exception_to_check, tries=4, delay=3, backoff=2)¶ Retry calling the decorated function using exponential backoff.
- Parameters
exception_to_check – the exception to check. may be a tuple of exceptions to check
tries – number of times to try (not retry) before giving up
delay – initial delay between retries in seconds
backoff – backoff multiplier e.g. value of 2 will double the delay each retry
ocs_ci.utility.rgwutils module¶
-
ocs_ci.utility.rgwutils.get_rgw_count(ocs_version, is_upgrade, version_before_upgrade)¶ Get RGW Count
- RGW Count is 2 if:
OCS 4.5 unless upgraded from a prior version OCS 4.6
Otherwise, RGW Count is 1
- Parameters
ocs_version (str, float) – OCS Version
is_upgrade (bool) – If cluster was upgraded to current version
version_before_upgrade (str, float) – OCS Version prior to upgrade
- Returns
RGW Count
- Return type
int
ocs_ci.utility.svt module¶
-
ocs_ci.utility.svt.svt_cleanup()¶ Removes clonned SVT project and virtual environemt and Projects Created while running SVT
- Raises
BaseException – In case any erros occured while removing project and ENV.
- Returns
True if No exceptions, False otherwise
- Return type
bool
-
ocs_ci.utility.svt.svt_cluster_loader(clusterload_file='/tmp/svt/openshift_scalability/config/master-vert.yaml')¶
-
ocs_ci.utility.svt.svt_create_venv_setup()¶ This function creates Virtual environemt for SVT project, and installs all the dependencies and activate the environment
-
ocs_ci.utility.svt.svt_project_clone()¶ This function clones the SVT project.
-
ocs_ci.utility.svt.svt_setup(iterations)¶ Creates and run svt workload
ocs_ci.utility.system module¶
-
ocs_ci.utility.system.is_path_empty(path)¶ Returns True if the given path does not contain any files, False otherwise.
- Parameters
path (str) – Path to be checked
ocs_ci.utility.templating module¶
-
class
ocs_ci.utility.templating.Templating(base_path='/home/docs/checkouts/readthedocs.org/user_builds/ocs-ci-pbalogh/checkouts/stable/ocs_ci/templates')¶ Bases:
objectClass which provides all functionality for templating
-
property
base_path¶ Setter for self._base_path property
-
render_template(template_path, data)¶ Render a template with the given data.
- Parameters
template_path (str) – location of the j2 template from the self._base_path
data (dict) – the data to be formatted into the template
Returns: rendered template
-
property
-
ocs_ci.utility.templating.dump_data_to_json(data, json_file)¶ Dump data to json file
- Parameters
data (dict) – dictionary with data to dump to the json file.
json_file (str) – file path to json file
-
ocs_ci.utility.templating.dump_data_to_temp_yaml(data, temp_yaml)¶ Dump data to temporary yaml file
- Parameters
data (dict or list) – dict or list (in case of multi_document) with data to dump to the yaml file.
temp_yaml (str) – file path of yaml file
- Returns
dumped yaml data
- Return type
str
-
ocs_ci.utility.templating.dump_to_temp_yaml(src_file, dst_file, **kwargs)¶ - Dump a jinja2 template file content into a yaml file
- Args:
src_file (str): Template Yaml file path dst_file: the path to the destination Yaml file
-
ocs_ci.utility.templating.generate_yaml_from_jinja2_template_with_data(file_, **kwargs)¶ Generate yaml fron jinja2 yaml with processed data
- Parameters
file_ (str) – Template Yaml file path
- Keyword Arguments
jinja2 attributes (All) –
- Returns
Generated from template file
- Return type
dict
Examples
generate_yaml_from_template(file_=’path/to/file/name’, pv_data_dict’)
-
ocs_ci.utility.templating.get_n_document_from_yaml(yaml_generator, index=0)¶ Returns n document from yaml generator loaded by load_yaml with multi_document = True.
- Parameters
yaml_generator (generator) – Generator from yaml.safe_load_all
index (int) – Index of document to return. (0 - 1st, 1 - 2nd document)
- Returns
Data from n document from yaml file.
- Return type
dict
- Raises
IndexError – In case that yaml generator doesn’t have such index.
-
ocs_ci.utility.templating.json_to_dict(json_file)¶ Converts JSON to dictionary format
- Parameters
json_file (str) – file path to json file
- Returns
JSON data in dictionary format
- Return type
dict
-
ocs_ci.utility.templating.load_config_data(data_path)¶ Loads YAML data from the specified path
- Parameters
data_path – location of the YAML data file
Returns: loaded YAML data
-
ocs_ci.utility.templating.load_yaml(file, multi_document=False)¶ Load yaml file (local or from URL) and convert it to dictionary
- Parameters
file (str) – Path to the file or URL address
multi_document (bool) – True if yaml contains more documents
- Returns
- If multi_document == False, returns loaded data from yaml file
with one document.
- generator: If multi_document == True, returns generator which each
iteration returns dict from one loaded document from a file.
- Return type
dict
-
ocs_ci.utility.templating.to_nice_yaml(a, indent=2, *args, **kw)¶ This is a j2 filter which allows you from dictionary to print nice human readable yaml.
- Parameters
a (dict) – dictionary with data to print as yaml
indent (int) – number of spaces for indent to be applied for whole dumped yaml. First line is not indented! (default: 2)
*args – Other positional arguments which will be passed to yaml.dump
*args – Other keywords arguments which will be passed to yaml.dump
- Returns
transformed yaml data in string format
- Return type
str
ocs_ci.utility.uninstall_openshift_logging module¶
Function to teardown the openshift-logging
-
ocs_ci.utility.uninstall_openshift_logging.check_pod_vanished(pod_names)¶ A function to check all the pods are vanished from the namespace
-
ocs_ci.utility.uninstall_openshift_logging.uninstall_cluster_logging()¶ Function to uninstall cluster-logging from the cluster Deletes the project “openshift-logging” and “openshift-operators-redhat”
ocs_ci.utility.users module¶
-
ocs_ci.utility.users.add_htpasswd_user(username, password, htpasswd_path)¶ Create a new user credentials with provided username and password. These will be saved in file located on htpasswd_path. The file will be created if it doesn’t exist.
- Parameters
username (str) – Name of a new user
password (str) – Password for a new user
htpasswd_path (str) – Path to httpasswd file
-
ocs_ci.utility.users.create_htpasswd_idp()¶ Create OAuth identity provider of HTPasswd type. It uses htpass-secret secret as a source for list of users.
-
ocs_ci.utility.users.create_htpasswd_secret(htpasswd_path, replace=False)¶ Create or update htpass-secret secret from file located on htpasswd_path.
- Parameters
htpasswd_path (str) – Path to httpasswd file
replace (bool) – If secret already exists then this will replace it
-
ocs_ci.utility.users.delete_htpasswd_secret()¶ Delete HTPasswd secret.
-
ocs_ci.utility.users.user_factory(request, htpasswd_path)¶ Create a user factory.
- Parameters
request (obj) – request fixture
htpasswd_path (str) – Path to htpasswd file
- Returns
User factory function
- Return type
func
ocs_ci.utility.utils module¶
-
class
ocs_ci.utility.utils.AZInfo¶ Bases:
objectA class for getting different az numbers across calls
-
get_zone_number()¶ Increment current zone_number and perform modulus op to roll-on to next available number
- Returns
zone number index
- Return type
int
-
zone_number= 0¶
-
-
class
ocs_ci.utility.utils.TimeoutIterator(timeout, sleep, func, func_args=None, func_kwargs=None)¶ Bases:
ocs_ci.utility.utils.TimeoutSamplerWrapper of TimeoutSampler which separates parameters of the class itself and func arguments in __init__ method. Such way of passing function with parameters is used in python standard library.
This allows more explicit usage, which improves readability, eg.:
t1 = TimeoutIterator(timeout=60, sleep=5, func=foo, func_args=[bar]) t2 = TimeoutIterator(3600, sleep=10, func=foo, func_args=[bar])
-
class
ocs_ci.utility.utils.TimeoutSampler(timeout, sleep, func, *func_args, **func_kwargs)¶ Bases:
objectSamples 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.
-
func= None¶ A function to sample.
-
func_args= None¶ Args for func.
-
func_kwargs= None¶ Kwargs for func.
-
last_sample_time= None¶ Time of last sample.
-
sleep= None¶ Sleep interval seconds.
-
start_time= None¶ Time of starting the sampling.
-
timeout= None¶ Timeout in seconds.
-
timeout_exc_args= None¶ An args for __init__ of the timeout exception.
-
timeout_exc_cls= None¶ Class of exception to be raised.
-
wait_for_func_status(result)¶ Get function and run it for given time until success or timeout. (using __iter__ function)
- Parameters
result (bool) – Expected result from func.
Examples:
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
-
wait_for_func_value(value)¶ Implements common usecase of TimeoutSampler: waiting until func (given function) returns a given value.
- Parameters
value – Expected return value of func we are waiting for.
-
-
ocs_ci.utility.utils.activate_multiple_mdss(mds_nodes)¶
-
ocs_ci.utility.utils.add_path_to_env_path(path)¶ Add path to the PATH environment variable (if not already there).
- Parameters
path (str) – Path which should be added to the PATH env. variable
-
ocs_ci.utility.utils.add_squad_analysis_to_email(session, soup)¶ Add squad analysis to the html test results used in email reporting
- Parameters
session (obj) – Pytest session object
soup (obj) – BeautifulSoup object of HTML Report data
-
ocs_ci.utility.utils.add_stage_cert()¶ Deploy stage certificate to the cluster.
-
ocs_ci.utility.utils.allow_dir_fragmentation(mds_nodes)¶
-
ocs_ci.utility.utils.auth_list(clients, mon_node)¶
-
ocs_ci.utility.utils.censor_values(data_to_censor)¶ This function censor string and numeric values in dictionary based on keys that match pattern defined in config_keys_patterns_to_censor in constants. It is performed recursively for nested dictionaries.
- Parameters
data_to_censor (dict) – Data to censor.
- Returns
filtered data
- Return type
dict
-
ocs_ci.utility.utils.ceph_health_check(namespace=None, tries=20, delay=30)¶ - Parameters
namespace (str) – Namespace of OCS (default: config.ENV_DATA[‘cluster_namespace’])
tries (int) – Number of retries
delay (int) – Delay in seconds between retries
- Returns
- ceph_health_check_base return value with default retries of 20,
delay of 30 seconds if default values are not changed via args.
- Return type
bool
-
ocs_ci.utility.utils.ceph_health_check_base(namespace=None)¶ Exec ceph health cmd on tools pod to determine health of cluster.
- Parameters
namespace (str) – Namespace of OCS (default: config.ENV_DATA[‘cluster_namespace’])
- Raises
CephHealthException – If the ceph health returned is not HEALTH_OK
CommandFailed – If the command to retrieve the tools pod name or the command to get ceph health returns a non-zero exit code
- Returns
True if HEALTH_OK
- Return type
boolean
-
ocs_ci.utility.utils.check_for_rhcos_images(url)¶ Check for rhcos images are present in given location
- Parameters
url (str) – rhcos_images url
- Returns
True if images present if not false
- Return type
(bool)
-
ocs_ci.utility.utils.check_if_executable_in_path(exec_name)¶ Checks whether an executable can be found in the $PATH
- Parameters
exec_name – Name of executable to look for
- Returns
Whether the executable was found
- Return type
Boolean
-
ocs_ci.utility.utils.check_timeout_reached(start_time, timeout, err_msg=None)¶ Check if timeout reached and if so raise the exception.
- Parameters
start_time (time) – Star time of the operation.
timeout (int) – Timeout in seconds.
err_msg (str) – Error message for the exception.
- Raises
TimeoutException – In case the timeout reached.
-
ocs_ci.utility.utils.clone_repo(url, location, branch='master', to_checkout=None)¶ - Clone a repository or checkout latest changes if it already exists at
specified location.
- Parameters
url (str) – location of the repository to clone
location (str) – path where the repository will be cloned to
branch (str) – branch name to checkout
to_checkout (str) – commit id or tag to checkout
-
ocs_ci.utility.utils.config_to_string(config)¶ Convert ConfigParser object to string in INI format.
- Parameters
config (obj) – ConfigParser object
- Returns
Config in one string
- Return type
str
-
ocs_ci.utility.utils.configure_chrony_and_wait_for_machineconfig_status(node_type='worker', timeout=900)¶ Configure chrony on the nodes
- Parameters
node_type (str) – The node type to configure chrony e.g: worker, master and all if we want to configure on all nodes
timeout (int) – Time in seconds to wait
-
ocs_ci.utility.utils.convert_device_size(unformatted_size, units_to_covert_to)¶ Convert a string representing a size to an int according to the given units to convert to
- Parameters
unformatted_size (str) – The size to convert (i.e, ‘1Gi’/’100Mi’)
units_to_covert_to (str) – The units to convert the size to (i.e, TB/GB/MB)
- Returns
The converted size
- Return type
int
-
ocs_ci.utility.utils.convert_yaml2tfvars(yaml)¶ Converts yaml file to tfvars. It creates the tfvars with the same filename in the required format which is used for deployment.
- Parameters
yaml (str) – File path to yaml
- Returns
File path to tfvars
- Return type
str
-
ocs_ci.utility.utils.create_directory_path(path)¶ Creates directory if path doesn’t exists
-
ocs_ci.utility.utils.create_rhelpod(namespace, pod_name, timeout=300)¶ Creates the RHEL pod
- Parameters
namespace (str) – Namespace to create RHEL pod
pod_name (str) – Pod name
timeout (int) – wait time for RHEL pod to be in Running state
- Returns
Pod instance for RHEL
- Return type
pod
-
ocs_ci.utility.utils.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
- Parameters
suite_config – ceph_conf_overrides that currently exist in the test suite
custom_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
-
ocs_ci.utility.utils.decompose_html_attributes(soup, attributes)¶ Decomposes the given html attributes
- Parameters
soup (obj) – BeautifulSoup object
attributes (list) – attributes to decompose
Returns: None
-
ocs_ci.utility.utils.delete_dir(dir_name)¶ Deletes the directory
- Parameters
dir_name (str) – Directory path to delete
-
ocs_ci.utility.utils.delete_file(file_name)¶ Delete file_name
- Parameters
file_name (str) – Path to the file you want to delete
-
ocs_ci.utility.utils.destroy_cluster(installer, cluster_path, log_level='DEBUG')¶ Destroy OCP cluster specific
- Parameters
installer (str) – The path to the installer binary
cluster_path (str) – The path of the cluster
log_level (str) – log level openshift-installer (default: DEBUG)
-
ocs_ci.utility.utils.download_file(url, filename, **kwargs)¶ Download a file from a specified url
- Parameters
url (str) – URL of the file to download
filename (str) – Name of the file to write the download to
kwargs (dict) – additional keyword arguments passed to requests.get(…)
-
ocs_ci.utility.utils.download_file_from_git_repo(git_repo_url, path_to_file_in_git, filename)¶ Download a file from a specified git repository
- Parameters
git_repo_url (str) – The git repository url
path_to_file_in_git (str) – Path to the file to download in git repository
filename (str) – Name of the file to write the download to
-
ocs_ci.utility.utils.dump_config_to_file(file_path)¶ Dump the config to the yaml file with censored secret values.
- Parameters
file_path (str) – Path to file where to write the configuration.
-
ocs_ci.utility.utils.email_reports(session)¶ Email results of test run
-
ocs_ci.utility.utils.ensure_nightly_build_availability(build_url)¶
-
ocs_ci.utility.utils.exec_cmd(cmd, secrets=None, timeout=600, ignore_error=False, **kwargs)¶ Run an arbitrary command locally
- Parameters
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)timeout (int) – Timeout for the command, defaults to 600 seconds.
ignore_error (bool) – True if ignore non zero return code and do not raise the exception.
- Raises
CommandFailed – In case the command execution fails
- Returns
(CompletedProcess) A CompletedProcess object of the command that was executed CompletedProcess attributes: args: The list or str args passed to run(). returncode (str): The exit code of the process, negative for signals. stdout (str): The standard output (None if not captured). stderr (str): The standard error (None if not captured).
-
ocs_ci.utility.utils.expose_ocp_version(version)¶ This helper function exposes latest nightly version or GA 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) If the version ends with -ga than it will find the latest GA OCP version and will expose 4.2-ga to for example 4.2.22.
- Parameters
version (str) – Verison of OCP
- Returns
Version of OCP exposed to full version if latest nighly passed
- Return type
str
-
ocs_ci.utility.utils.file_locking(client)¶
-
ocs_ci.utility.utils.fuse_client_io(client, mounting_dir)¶
-
ocs_ci.utility.utils.fuse_client_md5(fuse_clients, md5sum_list1)¶
-
ocs_ci.utility.utils.fuse_mount(fuse_clients, mounting_dir)¶
-
ocs_ci.utility.utils.get_available_ocp_versions(channel)¶ Find all available OCP versions for specific channel.
- Parameters
channel (str) – Channel of OCP (e.g. stable-4.2 or fast-4.2)
- Returns
list: Sorted list with OCP versions for specified channel.
-
ocs_ci.utility.utils.get_az_count()¶ Using a number of different configuration attributes, determine how many availability zones the cluster is configured for.
- Returns
number of availability zones
- Return type
int
-
ocs_ci.utility.utils.get_ceph_version()¶ Gets the ceph version
- Returns
ceph version
- Return type
str
-
ocs_ci.utility.utils.get_client_info(ceph_nodes, clients)¶
-
ocs_ci.utility.utils.get_cluster_id(cluster_path)¶ Get ClusterID from metadata.json in given cluster_path
- Parameters
cluster_path – path to cluster install directory
- Returns
metadata.json[‘clusterID’]
- Return type
str
-
ocs_ci.utility.utils.get_cluster_image()¶ Gets the cluster image
- Returns
cluster image
- Return type
str
-
ocs_ci.utility.utils.get_cluster_name(cluster_path)¶ Get clusterName from metadata.json in given cluster_path
- Parameters
cluster_path – path to cluster install directory
- Returns
metadata.json[‘clusterName’]
- Return type
str
-
ocs_ci.utility.utils.get_cluster_version()¶ Gets the cluster version
- Returns
cluster version
- Return type
str
-
ocs_ci.utility.utils.get_cluster_version_info()¶ Gets the complete cluster version information
- Returns
cluster version information
- Return type
dict
-
ocs_ci.utility.utils.get_csi_versions()¶ Gets the CSI related version information
- Returns
CSI related version information
- Return type
dict
-
ocs_ci.utility.utils.get_image_with_digest(image)¶ Return image with sha256 digest for usage in disconnected environment
- Parameters
image (str) – image
- Raises
UnexpectedImage – In case the image information is unexpected
- Returns
image with sha256 digest specification
- Return type
str
-
ocs_ci.utility.utils.get_infra_id(cluster_path)¶ Get infraID from metadata.json in given cluster_path
- Parameters
cluster_path – path to cluster install directory
- Returns
metadata.json[‘infraID’]
- Return type
str
-
ocs_ci.utility.utils.get_kubeadmin_password()¶
-
ocs_ci.utility.utils.get_latest_ds_olm_tag(upgrade=False, latest_tag=None)¶ This function returns latest tag of OCS downstream registry or one before latest if upgrade parameter is True
- Parameters
upgrade (str) – If True then it returns one version of the build before the latest.
latest_tag (str) – Tag of the latest build. If not specified config.DEPLOYMENT[‘default_latest_tag’] or ‘latest’ will be used.
- Returns
latest tag for downstream image from quay registry
- Return type
str
- Raises
TagNotFoundException – In case no tag found
-
ocs_ci.utility.utils.get_latest_ocp_version(channel, index=-1)¶ Find latest OCP version for specific channel.
- Parameters
channel (str) – Channel of OCP (e.g. stable-4.2 or fast-4.2)
index (int) – Index to get from all available versions list e.g. default -1 is latest version (version[-1]). If you want to get previous version pass index -2 and so on.
- Returns
str: Latest OCP version for specified channel.
-
ocs_ci.utility.utils.get_module_ip(terraform_state_file, module)¶ Gets the node IP from terraform.tfstate file
- Parameters
terraform_state_file (str) – Path to terraform state file
module (str) – Module name in terraform.tfstate file e.g: constants.LOAD_BALANCER_MODULE
- Returns
IP of the node
- Return type
list
-
ocs_ci.utility.utils.get_next_version_available_for_upgrade(current_tag)¶ This function returns the tag built after the current_version
- Parameters
current_tag (str) – Current build tag from which to search the next one build tag.
- Returns
- tag for downstream image from quay registry built after
the current_tag.
- Return type
str
- Raises
TagNotFoundException – In case no tag suitable for upgrade found
-
ocs_ci.utility.utils.get_ocm_cli(version=None, bin_dir=None, force_download=False)¶ Download the OCM binary, if not already present. Update env. PATH and get path of the OCM binary.
- Parameters
version (str) – Version of the OCM to download
bin_dir (str) – Path to bin directory (default: config.RUN[‘bin_dir’])
force_download (bool) – Force OCM download even if already present
- Returns
Path to the OCM binary
- Return type
str
-
ocs_ci.utility.utils.get_ocp_repo()¶ Get ocp repo file, name will be generated dynamically based on ocp version.
- Returns
Path to ocp repo file
- Return type
string
-
ocs_ci.utility.utils.get_ocp_upgrade_history()¶ Gets the OCP upgrade history for the cluster
- Returns
- List of OCP upgrade paths. Latest version in the
beginning of the list
- Return type
list
-
ocs_ci.utility.utils.get_ocp_version(seperator=None)¶ Get current ocp version
- Parameters
seperator (str) – String that would seperate major and minor version nubers
- Returns
- If seperator is ‘None’, version string will be returned as is
eg: ‘4.2’, ‘4.3’. If seperator is provided then ‘.’ in the version string would be replaced by seperator and resulting string will be returned. eg: If seperator is ‘_’ then string returned would be ‘4_2’
- Return type
string
-
ocs_ci.utility.utils.get_ocs_build_number()¶ Gets the build number for ocs operator
- Returns
build number for ocs operator version
- Return type
str
Query the OCS OLM Operator repo and retrieve a list of tags.
- Parameters
limit – the number of tags to limit the request to
- Raises
KeyError – if the auth config isn’t setup properly
requests.RequestException – if the response return code is not ok
- Returns
OCS OLM Operator tags
- Return type
list
-
ocs_ci.utility.utils.get_ocs_version_from_image(image)¶ Parse major.minor version from OCS image tag.
- Parameters
image (str) – image in format url:tag
- Returns
str: Version in x.y format
- Raises
ValueError – In case of the tag which we cannot parse to version.
-
ocs_ci.utility.utils.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.
- Parameters
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
- Returns
Path to the client binary
- Return type
str
-
ocs_ci.utility.utils.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.
- Parameters
version (str) – Version of the installer to download
bin_dir (str) – Path to bin directory (default: config.RUN[‘bin_dir’])
force_download (bool) – Force installer download even if already present
- Returns
Path to the installer binary
- Return type
str
-
ocs_ci.utility.utils.get_openshift_mirror_url(file_name, version)¶ Format url to OpenShift mirror (for client and installer download).
- Parameters
file_name (str) – Name of file
version (str) – Version of the installer or client to download
- Returns
Url of the desired file (installer or client)
- Return type
str
- Raises
UnsupportedOSType – In case the OS type is not supported
UnavailableBuildException – In case the build url is not reachable
-
ocs_ci.utility.utils.get_random_str(size=13)¶ generates the random string of given size
- Parameters
size (int) – number of random characters to generate
- Returns
string of random characters of given size
- Return type
str
-
ocs_ci.utility.utils.get_rook_repo(branch='master', to_checkout=None)¶ Clone and checkout the rook repository to specific branch/commit.
- Parameters
branch (str) – Branch name to checkout
to_checkout (str) – Commit id or tag to checkout
-
ocs_ci.utility.utils.get_rook_version()¶ Gets the rook version
- Returns
rook version
- Return type
str
-
ocs_ci.utility.utils.get_running_ocp_version(separator=None)¶ Get current running ocp version
- Parameters
separator (str) – String that would separate major and minor version numbers
- Returns
- If separator is ‘None’, version string will be returned as is
eg: ‘4.2’, ‘4.3’. If separator is provided then ‘.’ in the version string would be replaced by separator and resulting string will be returned. eg: If separator is ‘_’ then string returned would be ‘4_2’
- Return type
string
-
ocs_ci.utility.utils.get_system_architecture()¶ Get output from ‘uname -m’ command run on first worker node.
- Returns
Architecture of system
- Return type
str
-
ocs_ci.utility.utils.get_terraform(version=None, bin_dir=None)¶ Downloads the terraform binary
- Parameters
version (str) – Version of the terraform to download
bin_dir (str) – Path to bin directory (default: config.RUN[‘bin_dir’])
- Returns
Path to the terraform binary
- Return type
str
-
ocs_ci.utility.utils.get_terraform_ignition_provider(terraform_dir, version=None)¶ Downloads the terraform ignition provider
- Parameters
terraform_dir (str) – Path to terraform working directory
version (str) – Version of the terraform ignition provider to download
-
ocs_ci.utility.utils.get_testrun_name()¶ Prepare testrun ID for Polarion (and other reports).
- Returns
String containing testrun name
- Return type
str
-
ocs_ci.utility.utils.get_trim_mean(values, percentage=20)¶ Get the trimmed mean of a list of values. Explanation: This function finds the arithmetic mean of given values, ignoring values outside the given limits.
- Parameters
values (list) – The list of values
percentage (int) – The percentage to be trimmed
- Returns
- Trimmed mean. In case trimmed mean calculation fails,
the regular mean average is returned
- Return type
float
-
ocs_ci.utility.utils.get_url_content(url, **kwargs)¶ Return URL content
- Parameters
url (str) – URL address to return
kwargs (dict) – additional keyword arguments passed to requests.get(…)
- Returns
Content of URL
- Return type
str
- Raises
AssertionError – When couldn’t load URL
-
ocs_ci.utility.utils.inspect_image(image, authfile_fo)¶ Inspect image
- Parameters
image (str) – image to inspect
authfile_fo (NamedTemporaryFile) – pull-secret required for pulling the given image
- Returns
json object of the inspected image
- Return type
dict
-
ocs_ci.utility.utils.is_cluster_running(cluster_path)¶
-
ocs_ci.utility.utils.kernel_client_io(client, mounting_dir)¶
-
ocs_ci.utility.utils.kernel_client_md5(kernel_clients, md5sum_list2)¶
-
ocs_ci.utility.utils.kernel_mount(mounting_dir, mon_node_ip, kernel_clients)¶
-
ocs_ci.utility.utils.load_auth_config()¶ Load the authentication config YAML from /data/auth.yaml
- Raises
FileNotFoundError – if the auth config is not found
- Returns
A dictionary reprensenting the YAML file
- Return type
dict
-
ocs_ci.utility.utils.load_config_file(config_file)¶ Loads config file to the ocs-ci config
- Parameters
config_file (str) – Path to yaml config file.
- Raises
FileNotFoundError – In the case the config file not found.
-
ocs_ci.utility.utils.login_to_mirror_registry(authfile)¶ Login to mirror registry
- Parameters
authfile (str) – authfile (pull-secret) path
-
ocs_ci.utility.utils.mask_secrets(plaintext, secrets)¶ Replace secrets in plaintext with asterisks
- Parameters
plaintext (str or list) – The plaintext to remove the secrets from or list of strings to remove secrets from
secrets (list) – List of secret strings to replace in the plaintext
- Returns
The censored version of plaintext
- Return type
str
-
ocs_ci.utility.utils.mds_fail_over(mds_nodes)¶
-
ocs_ci.utility.utils.mirror_image(image)¶ Mirror image to mirror image registry.
- Parameters
image (str) – image to be mirrored, can be defined just with name or with full url, with or without tag or digest
- Returns
the mirrored image link
- Return type
str
-
ocs_ci.utility.utils.mkdir_pinning(clients, range1, range2, dir_name, pin_val)¶
-
ocs_ci.utility.utils.modify_csv(csv, replace_from, replace_to)¶ Modify the CSV
- Parameters
csv (str) – The CSV name
replace_from (str) – The pattern to replace from in the CSV
replace_to (str) – The pattern to replace to in the CSV
-
ocs_ci.utility.utils.move_summary_to_top(soup)¶ Move summary to the top of the eamil report
-
ocs_ci.utility.utils.ocsci_log_path()¶ Construct the full path for the log directory.
- Returns
full path for ocs-ci log directory
- Return type
str
-
ocs_ci.utility.utils.parse_html_for_email(soup)¶ Parses the html and filters out the unnecessary data/tags/attributes for email reporting
- Parameters
soup (obj) – BeautifulSoup object
-
ocs_ci.utility.utils.parse_pgsql_logs(data)¶ Parse the pgsql benchmark data from ripsaw and return the data in list format
- Parameters
data (str) – log data from pgsql bench run
- Returns
- data digestable by scripts with below format
e.g.:
[ {1: {‘num_clients’: ‘2’,’num_threads’: ‘7’,’latency_avg’: ‘7’, ‘lat_stddev’: ‘0’, ‘tps_incl’: ‘234’, ‘tps_excl’: ‘243’}, {2: {‘num_clients’: ‘2’,’num_threads’: ‘7’,’latency_avg’: ‘7’, ‘lat_stddev’: ‘0’, ‘tps_incl’: ‘234’, ‘tps_excl’: ‘243’}, {3: {‘num_clients’: ‘2’,’num_threads’: ‘7’,’latency_avg’: ‘7’, ‘lat_stddev’: ‘0’, ‘tps_incl’: ‘234’, ‘tps_excl’: ‘243’}, ] where keys{1,2,3} are run-IDs
- Return type
list_data (list)
-
ocs_ci.utility.utils.pinned_dir_io(clients, mds_fail_over, num_of_files, range1, range2)¶
-
ocs_ci.utility.utils.prepare_bin_dir(bin_dir=None)¶ Prepare bin directory for OpenShift client and installer
- Parameters
bin_dir (str) – Path to bin directory (default: config.RUN[‘bin_dir’])
-
ocs_ci.utility.utils.prepare_customized_pull_secret(images=None)¶ Prepare customized pull-secret containing auth section related to given image(s). If image(s) not defined or no related section is found, it will use whole content of pull-secret.
- Parameters
images (str, list) – image (or images) to match with auth section
- Returns
prepared pull-secret
- Return type
NamedTemporaryFile
-
ocs_ci.utility.utils.read_file_as_str(filepath)¶ Reads the file content
- Parameters
filepath (str) – File to read
- Returns
File contents in string
- Return type
str
-
ocs_ci.utility.utils.remove_keys_from_tf_variable_file(tf_file, keys)¶ Removes the keys from the tf files and convert to json format
- Parameters
tf_file (str) – path to tf file
keys (list) – list of keys to remove
-
ocs_ci.utility.utils.replace_content_in_file(file, old, new)¶ Replaces contents in file, if old value is not found, it adds new value to the file
- Parameters
file (str) – Name of the file in which contents will be replaced
old (str) – Data to search for
new (str) – Data to replace the old value
-
ocs_ci.utility.utils.run_async(command)¶ Run command locally and return without waiting for completion
- Parameters
command (str) – The command to run.
- Returns
An open descriptor to be used by the calling function.
Example
command = ‘oc delete pvc pvc1’ proc = run_async(command) ret, out, err = proc.async_communicate()
-
ocs_ci.utility.utils.run_cmd(cmd, secrets=None, timeout=600, ignore_error=False, **kwargs)¶ The deprecated form of exec_cmd. Run an arbitrary command locally
- Parameters
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)timeout (int) – Timeout for the command, defaults to 600 seconds.
ignore_error (bool) – True if ignore non zero return code and do not raise the exception.
- Raises
CommandFailed – In case the command execution fails
- Returns
(str) Decoded stdout of command
-
ocs_ci.utility.utils.set_aws_region(region=None)¶ Exports environment variable AWS_REGION
- Parameters
region (str) – AWS region to export
-
ocs_ci.utility.utils.set_registry_to_managed_state()¶ In order to be able to deploy from stage we need to change image registry config to Managed state. More described in BZs: https://bugzilla.redhat.com/show_bug.cgi?id=1806593 https://bugzilla.redhat.com/show_bug.cgi?id=1807471#c3 We need to change to managed state as described here: https://github.com/red-hat-storage/ocs-ci/issues/1436 So this is not suppose to be deleted as WA case we really need to do this operation for OCS deployment as was originally done here: https://github.com/red-hat-storage/ocs-ci/pull/1437 Currently it has to be moved here to enable CA certificate to be properly propagated for the stage deployment as mentioned in BZ.
-
ocs_ci.utility.utils.set_selinux_permissions(workers=None)¶ Workaround for #1777384 - enable container_use_cephfs on RHEL workers Ticket: RHSTOR-787, see more details in the issue: #1151
- Parameters
workers (list) – List of worker nodes to set selinux permissions
-
ocs_ci.utility.utils.skipif_ocp_version(expressions)¶ This function evaluates the condition for test skip based on expression
- Parameters
expressions (str OR list) – condition for which we need to check,
eg – A single expression string ‘>=4.2’ OR A list of expressions like [‘<4.3’, ‘>4.2’], [‘<=4.3’, ‘>=4.2’]
- Returns
‘True’ if test needs to be skipped else ‘False’
-
ocs_ci.utility.utils.skipif_ocs_version(expressions)¶ This function evaluates the condition for test skip based on expression
- Parameters
expressions (str OR list) – condition for which we need to check,
eg – A single expression string ‘>=4.2’ OR A list of expressions like [‘<4.3’, ‘>4.2’], [‘<=4.3’, ‘>=4.2’]
- Returns
‘True’ if test needs to be skipped else ‘False’
-
ocs_ci.utility.utils.skipif_upgraded_from(version_list)¶ This function evaluates the condition to skip a test if the cluster is upgraded from a particular OCS version
- Parameters
version_list (list) – List of versions to check
- Returns
True if test needs to be skipped else False
- Return type
(bool)
-
ocs_ci.utility.utils.update_container_with_mirrored_image(job_pod_dict)¶ Update Job or Pod configuration dict with mirrored image (required for disconnected installation).
- Parameters
job_pod_dict (dict) – dictionary with Job or Pod configuration
- Returns
- for disconnected installation, returns updated Job or Pod dict,
for normal installation return unchanged job_pod_dict
- Return type
dict
-
ocs_ci.utility.utils.upload_file(server, localpath, remotepath, user=None, password=None, key_file=None)¶ Upload a file to remote server
- Parameters
server (str) – Name of the server to upload
localpath (str) – Local file to upload
remotepath (str) – Target path on the remote server. filename should be included
user (str) – User to use for the remote connection
-
ocs_ci.utility.utils.wait_for_co(operator)¶ Waits for ClusterOperator to created
- Parameters
operator (str) – Name of the ClusterOperator
-
ocs_ci.utility.utils.wait_for_machineconfigpool_status(node_type, timeout=900)¶ Check for Machineconfigpool status
- Parameters
node_type (str) – The node type to check machineconfigpool status is updated. e.g: worker, master and all if we want to check for all nodes
timeout (int) – Time in seconds to wait
ocs_ci.utility.vsphere module¶
This module contains the vSphere related methods
-
class
ocs_ci.utility.vsphere.VSPHERE(host, user, password, port=443)¶ Bases:
objectwrapper for vSphere
-
add_disk(vm, size, disk_type='thin')¶ Attaches disk to VM
- Parameters
vm (vim.VirtualMachine) – VM instance
size (int) – size of disk in GB
disk_type (str) – disk type
-
add_disks(num_disks, vm, size, disk_type='thin')¶ Adds multiple disks to the VM
- Parameters
num_disks – number of disks to add
vm (vim.VirtualMachine) – VM instance
size (int) – size of disk in GB
disk_type (str) – disk type
-
add_rdm_disk(vm, device_name, disk_mode=None, compatibility_mode=None)¶ Attaches RDM disk to vm
- Parameters
vm (vim.VirtualMachine) – VM instance
device_name (str) – Device name to add to VM. e.g:”/vmfs/devices/disks/naa.600304801b540c0125ef160f3048faba”
disk_mode (str) – Disk mode. By default it will add ‘independent_persistent’. Available modes are ‘append’, ‘independent_nonpersistent’, ‘independent_persistent’, ‘nonpersistent’, ‘persistent’, and ‘undoable’
compatibility_mode (str) – Compatabilty mode. Either ‘physicalMode’ or ‘virtualMode’. By default it will add ‘physicalMode’.
-
available_storage_devices(host, datastore_type='VMFS')¶ Fetches the available storage devices on Host.
- Parameters
host (vim.HostSystem) – Host instance
datastore_type (str) – Type of datastore. Either VMFS or vsan By default, it will take VMFS as datastore type.
- Returns
List of storage devices available for use
- Return type
list
-
check_folder_exists(name, cluster, dc)¶ Checks whether folder exists in Templates
- Parameters
name (str) – Folder name
cluster (str) – Cluster name
dc (str) – Datacenter name
- Returns
True if folder exists, False otherwise
- Return type
bool
-
clone_vm(vm_name, template_name, datacenter_name, resource_pool_name, datastore_name, cluster_name, cpus=4, memory=8, root_disk_size=125829120, network_adapter='VM Network', power_on=True, **kwargs)¶ Clones the VM from template
- Parameters
vm_name (str) – Name of the VM to create
template_name (str) – Template name to clone
datacenter_name (str) – Name of the Datacenter
resource_pool_name (str) – Name of the Resource Pool
datastore_name (str) – Name of the Datastore
cluster_name (str) – Name of the Cluster in Datacenter
cpus (int) – Number of CPU’s
memory (int) – Memory in MB
root_disk_size (int) – Root Disk size in KB
network_adapter (str) – Name of the Network Adapter
power_on (bool) – True to power on the VM after cloning
-
destroy_folder(name, cluster, dc)¶ Removes the folder from Templates
- Parameters
name (str) – Folder name
cluster (str) – Cluster name
dc (str) – Datacenter name
-
destroy_pool(pool, dc, cluster)¶ Deletes the Resource Pool
- Parameters
pool (str) – Resource pool name
dc (str) – Datacenter name
cluster (str) – Cluster name
-
destroy_vms(vms)¶ Destroys the VM’s
- Parameters
vms (list) – VM instance list
-
erase_partition(host, device_path)¶ Erase the partitions on the disk
- Parameters
host (vim.HostSystem) – Host instance
device_path (str) – Device path to erase the partition e.g:”/vmfs/devices/disks/naa.910229801b540c0125ef160f3048faba”
-
find_datacenter_by_name(datacenter_name)¶ Fetches the Datacenter
- Parameters
datacenter_name (str) – Name of the Datacenter
- Returns
Datacenter instance
- Return type
vim.Datacenter
-
find_datastore_by_name(datastore_name, datacenter_name)¶ Fetches the Datastore
- Parameters
datastore_name (str) – Name of the Datastore
datacenter_name (str) – Name of the Datacenter
- Returns
Datastore instance
- Return type
vim.Datastore
-
find_ip_by_vm(vm, datacenter_name, cluster_name, resource_pool_name)¶ Fetches the IP for the VM
- Parameters
vm (str) – Name of VM
datacenter_name – Name of the Datacenter
cluster_name – Name of the cluster
resource_pool_name – Name of the Resource Pool
- Returns
IP of the VM
- Return type
str
-
find_object_by_name(content, name, obj_type, folder=None, recurse=True)¶ Finds object by given name
- Parameters
content (vim.ServiceInstanceContent) – Service Instance Content
name (str) – Name to search
obj_type (list) – list of vim.type (e.g: For VM’s, type is vim.VirtualMachine For Hosts, type is vim.HostSystem)
folder (str) – Folder name
recurse (bool) – True for recursive search
- Returns
Type of vim instance None: If vim.type doesn’t exists
- Return type
vim.type
-
find_resource_pool_by_name(resource_pool_name)¶ Fetches the Resource Pool
- Parameters
resource_pool_name (str) – Name of the Resource Pool
- Returns
Resource Pool instance
- Return type
instance
-
find_vms_without_ip_and_restart()¶ Find all VMs from current cluster and restart those without IP
-
get_active_partition(host)¶ Fetches the active partition disk on Host
- Parameters
host (vim.HostSystem) – Host instance
- Returns
Active partition disk
- Return type
str
-
get_active_partition_from_mount_info(host)¶ Gets the active partition from mount info
- Parameters
host (vim.HostSystem) – Host instance
- Returns
Active partition disk
- Return type
str
-
get_all_objs(content, vimtype, folder=None, recurse=True)¶ Generate objects of type vimtype
- Parameters
content (vim.ServiceInstanceContent) – Service Instance Content
vimtype (vim.type) – Type of vim (e.g: For VM’s, type is vim.VirtualMachine For Hosts, type is vim.HostSystem)
folder (str) – Folder name
recurse (bool) – True for recursive search
- Returns
- Dictionary of objects and corresponding name
- e.g:{
‘vim.Datastore:datastore-12158’: ‘datastore1 (1)’, ‘vim.Datastore:datastore-12157’: ‘datastore1 (2)’ }
- Return type
dict
-
get_all_vms_in_dc(dc)¶ Fetches all VMs in Datacenter
- Parameters
dc (str) – Datacenter name
- Returns
List of VMs instance in a Datacenter
- Return type
list
-
get_all_vms_in_pool(name, dc, cluster)¶ Gets all VM’s in Resource pool
- Parameters
name (str) – Resource pool name
dc (str) – Datacenter name
cluster (str) – Cluster name
- Returns
VM instances (vim.VirtualMachine)
- Return type
list
-
get_cluster(name, dc)¶ Gets the cluster
- Parameters
name (str) – Cluster name
dc (str) – Datacenter name
- Returns
Cluster instance
- Return type
vim.ClusterComputeResource
-
get_compute_vms_in_pool(name, dc, cluster)¶ Gets all compute VM’s in Resource pool
- Parameters
name (str) – Resource pool name
dc (str) – Datacenter name
cluster (str) – Cluster name
- Returns
VM instances (vim.VirtualMachine)
- Return type
list
-
property
get_content¶ Retrieves the content
- Returns
Service Instance Content for Host
- Return type
vim.ServiceInstanceContent
-
get_controller_for_adding_disk(vm)¶ Gets the controller for adding disk
- Parameters
vm (vim.VirtualMachine) – VM instance
- Returns
controller instance
-
get_controllers(vm)¶ Get the controllers for VM
- Parameters
vm (vim.VirtualMachine) – VM instance
- Returns
list of controllers
- Return type
list
-
get_datastore_free_capacity(datastore_name, datacenter_name)¶ Gets the Datastore capacity
- Parameters
datastore_name (str) – Name of the Datastore
datacenter_name (str) – Name of the Datacenter
- Returns
Datastore capacity in bytes
- Return type
int
-
get_datastore_type(datastore)¶ Gets the Datastore Type
- Parameters
datastore (vim.Datastore) – Datastore instance
- Returns
Datastore type. Either VMFS or vsan
- Return type
str
-
get_datastore_type_by_name(datastore_name, datacenter_name)¶ Gets the Datastore Type
- Parameters
datastore_name (str) – Name of the Datastore
datacenter_name (str) – Name of the Datacenter
- Returns
Datastore type. Either VMFS or vsan
- Return type
str
-
get_dc(name)¶ Gets the Datacenter
- Parameters
name (str) – Datacenter name
- Returns
Datacenter instance
- Return type
vim.Datacenter
-
get_device_by_key(vm, identifier, key='unit_number')¶ Get the device by key, and a specific identifier
- Parameters
vm (vim.VirtualMachine) – VM instance
identifier (str) – The value of either ‘unit_number’ (Disk unit number to remove), ‘volume_path’ (The volume path in the datastore (i.e, ‘[vsanDatastore] d4210a5e-40ce-efb8-c87e-040973d176e1/control-plane-1.vmdk’), or ‘disk_name’(The disk name (i.e, ‘scsi-36000c290a2cffeb9fcf4a5f748e21909’)
key (str) – Either ‘unit_number’, ‘volume_path’, or ‘disk_name’
- Returns
- The virtual disk device object that
matches the key and the identifier
- Return type
pyVmomi.VmomiSupport.vim.vm.device.VirtualDisk
-
get_host(vm)¶ Fetches the Host for the VM. Host where VM resides
- Parameters
vm (vim.VirtualMachine) – VM instance
- Returns
Host instance
- Return type
vim.HostSystem
-
get_host_obj(host_name)¶ Fetches the Host object
- Parameters
host_name (str) – Host name
- Returns
Host instance
- Return type
vim.HostSystem
-
get_lunids(dc)¶ Fetches the LUN ids from the Datacenter
- Parameters
dc (str) – Datacenter name
- Returns
- Dictionary contains host name as key and
- values as list lun ids
- e.g:{
‘HostName1’: [‘02000000193035e73d534’], ‘HostName2’: [‘020000000060034d43333’] }
- Return type
dict
-
get_mounted_devices(host, datastore_type='VMFS')¶ Fetches the available storage devices on Host.
- Parameters
host (vim.HostSystem) – Host instance
datastore_type (str) – Type of datastore. Either VMFS or vsan By default, it will take VMFS as datastore type.
- Returns
List of storage devices available for use
- Return type
list
-
get_mounted_devices_in_vmfs(host)¶ Fetches the devices which was mounted in VMFS
- Parameters
host (vim.HostSystem) – Host instance
- Returns
List of storage devices which was mounted
- Return type
list
-
get_mounted_devices_in_vsan(host)¶ Fetches the devices which was mounted in VSAN
- Parameters
host (vim.HostSystem) – Host instance
- Returns
List of storage devices which was mounted
- Return type
list
-
get_pool(name, dc, cluster)¶ Gets the Resource pool
- Parameters
name (str) – Resource pool name
dc (str) – Datacenter name
cluster (str) – Cluster name
- Returns
Resource pool instance
- Return type
vim.ResourcePool
-
property
get_search_index¶ Get the search index
- Returns
Instance of Search Index
- Return type
vim.SearchIndex
-
get_storage_devices(host)¶ Fetches all the storage devices in the Host. It excludes the enclosures.
- Parameters
host (vim.HostSystem) – Host instance
- Returns
List of storage devices in Host
- Return type
list
-
get_unit_number(vm)¶ Gets the available unit number for the disk
- Parameters
vm (vim.VirtualMachine) – VM instance
- Returns
available unit number for disk
- Return type
int
-
get_used_devices(host)¶ Fetches the used storage devices in Host.
Note: Storage devices may be used in different Resource Pools of OCS clusters.
- Parameters
host (vim.HostSystem) – Host instance
- Returns
List of storage devices used
- Return type
list
-
get_used_unit_number(vm)¶ Gets the used unit numbers for a VM
- Parameters
vm (vim.VirtualMachine) – VM instance
- Returns
list of unit numbers
- Return type
list
-
get_vm_by_ip(ip, dc, vm_search=True)¶ Gets the VM using IP address
- Parameters
ip (str) – IP address
dc (str) – Datacenter name
vm_search (bool) – Search for VMs if True, Hosts if False
- Returns
VM instance
- Return type
vim.VirtualMachine
-
get_vm_in_pool_by_name(name, dc, cluster, pool)¶ Gets the VM instance in a resource pool
- Parameters
name (str) – VM name
dc (str) – Datacenter name
cluster (str) – Cluster name
pool (str) – pool name
- Returns
VM instances
- Return type
vim.VirtualMachine
-
get_vm_power_status(vm)¶ Get the VM power status
- Parameters
vm (vm) – VM object
- Returns
VM power status
- Return type
str
-
get_vms_ips(vms)¶ Get VMs IPs
- Parameters
vms (list) – VM (vm) objects
- Returns
VMs IPs
- Return type
list
-
is_resource_pool_exist(pool, dc, cluster)¶ Check whether resource pool exists in cluster or not
- Parameters
pool (str) – Resource pool name
dc (str) – Datacenter name
cluster (str) – Cluster name
- Returns
True if resource pool exists, otherwise False
- Return type
bool
-
is_resource_pool_prefix_exist(pool_prefix, dc, cluster)¶ Check whether or not resource pool with the provided prefix exist
- Parameters
pool_prefix (str) – The prefix to look for
dc (str) – Datacenter name
cluster (str) – Cluster name
- Returns
True if a resource pool with the same name prefix exists, False otherwise
- Return type
bool
-
map_lunids_to_devices(**kwargs)¶ Maps the LUN ids to storage devices
- Parameters
**kwargs (dict) – Host to LUN mapping e.g:
data = get_lunids(dc) map_lunids_to_devices(**data)- Returns
- Dictionary contains host instance as key and
value as list of device path
- Return type
dict
-
poweroff_vms(vms)¶ Powers off the VM and wait for operation to complete
- Parameters
vms (list) – VM instance list
-
poweron_vms(vms)¶ Powers on the VM and wait for operation to complete
- Parameters
vms (list) – VM instance list
-
remove_disk(vm, identifier, key='unit_number', datastore=True)¶ Removes the Disk from VM and datastore. By default, it will delete the disk ( vmdk ) from VM and backend datastore. If datastore parameter is set to False, then it will ONLY removes the disk from VM
- Parameters
vm (vim.VirtualMachine) – VM instance
identifier (str) – The value of either ‘unit_number’ (Disk unit number to remove), ‘volume_path’ (The volume path in the datastore (i.e, ‘[vsanDatastore] d4210a5e-40ce-efb8-c87e-040973d176e1/control-plane-1.vmdk’), or ‘disk_name’(The disk name (i.e, ‘scsi-36000c290a2cffeb9fcf4a5f748e21909’)
key (str) – Either ‘unit_number’, ‘volume_path’, or ‘disk_name’
datastore (bool) – Delete the disk (vmdk) from backend datastore if True
-
remove_disks(vm)¶ Removes all the extra disks for a VM
- Parameters
vm (vim.VirtualMachine) – VM instance
-
restart_vms(vms, force=False)¶ Restart VMs by VM Reset or Guest reboot
- Parameters
vms (list) – VM (vm) objects
force (bool) – True for Hard reboot(VM Reset), False for Soft reboot(Guest Reboot)
-
restart_vms_by_stop_and_start(vms, force=True)¶ Stop and Start VMs
- Parameters
vms (list) – VM (vm) objects
force (bool) – True for VM ungraceful power off, False for graceful VM shutdown
-
start_vms(vms, wait=True)¶ Start VMs
- Parameters
vms (list) – VM (vm) objects
wait (bool) – Wait for VMs to start
-
stop_vms(vms, force=True)¶ Stop VMs
- Parameters
vms (list) – VM (vm) objects
force (bool) – True for VM ungraceful power off, False for graceful VM shutdown
-
wait_for_task(task)¶ Wait for a task to finish
- Parameters
task (instance) – Instance for the task
- Returns
VM instance
- Return type
instance
-
ocs_ci.utility.vsphere_nodes module¶
Module that contains operations related to vSphere nodes in a cluster This module directly interacts with VM nodes
-
class
ocs_ci.utility.vsphere_nodes.VSPHERENode(host, user=None, private_key=None)¶ Bases:
objectA class that handles operations related to VM node
-
reboot()¶ Reboots the node
- Returns
tuple which contains command return code, output and error
- Return type
tuple
-
replace_ntp_server_in_chrony(server=None)¶ Replace default NTP server to given server
- Parameters
server (str) – NTP server
-
restart_chrony()¶ Restarts chrony service
- Returns
True if successful restarts of chrony, False otherwise
- Return type
bool
-
restart_service(service_name)¶ Restarts the given service
-
set_host_name(host_name)¶ Sets the host name
- Parameters
host_name (str) – Name to set as host name
- Returns
tuple which contains command return code, output and error
- Return type
tuple
-
-
ocs_ci.utility.vsphere_nodes.get_node_ips_from_module(module)¶ Fetches the node IP’s in cluster from terraform state file
- Parameters
module (str) – Module name in terraform.tfstate file e.g: constants.COMPUTE_MODULE
- Returns
List of module node IP’s
- Return type
list
-
ocs_ci.utility.vsphere_nodes.update_ntp_and_restart_chrony(node, server=None)¶ Update the NTP in the node and restarts chronyd service
- Parameters
node (str) – Hostname/IP of node
server (str) – NTP server to update in chrony config
-
ocs_ci.utility.vsphere_nodes.update_ntp_compute_nodes()¶ Updates NTP server on all compute nodes
ocs_ci.utility.workloadfixture module¶
This module contains functions implementing functionality of workload fixtures in ocs-ci.
-
ocs_ci.utility.workloadfixture.is_measurement_done(result_file)¶ Has the measurement been already performed and stored in a result file?
- Returns
True if the measurement has been already performed.
- Return type
bool
-
ocs_ci.utility.workloadfixture.measure_operation(operation, result_file, minimal_time=None, metadata=None, measure_after=False)¶ Get dictionary with keys ‘start’, ‘stop’, ‘metadata’ and ‘result’ that contain information about start and stop time of given function and its result.
- Parameters
operation (function) – Function to be performed
result_file (str) – File name that should contain measurement results including logs in json format. If this file exists then it is used for test.
minimal_time (int) – Minimal number of seconds to monitor a system. If provided then monitoring of system continues even when operation is finshed. If not specified then measurement is finished when operation is complete
metadata (dict) – This can contain dictionary object with information relevant to test (e.g. volume name, operating host, …)
measure_after (bool) – Determine if time measurement is done before or after the operation returns its state. This can be useful e.g. for capacity utilization testing where operation fills capacity and utilized data are measured after the utilization is completed
- Returns
- contains information about start and stop time of given
function and its result and provided metadata Example:
{ 'start': 1569827653.1903834, 'stop': 1569828313.6469617, 'result': 'rook-ceph-osd-2', 'metadata': {'status': 'success'}, 'prometheus_alerts': [{'labels': ...}, {...}, ...] }
- Return type
dict