From bda65350b91ee3ee4eeb52a7be3e20b6b5b1991c Mon Sep 17 00:00:00 2001 From: Elad Ben Aharon Date: Wed, 26 Jul 2023 14:30:21 +0300 Subject: [PATCH] ClusterLoad: Replace FIO DeploymentConfig with Deployment (#7604) Signed-off-by: Elad Ben Aharon --- ocs_ci/helpers/helpers.py | 48 +++++++++++++------ ocs_ci/ocs/cluster_load.py | 9 ++-- ocs_ci/ocs/constants.py | 1 + .../workloads/fio/fedora_deployment.yaml | 47 ++++++++++++++++++ ocs_ci/templates/workloads/fio/fio_dc.yaml | 3 -- tests/conftest.py | 25 ++++++---- 6 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 ocs_ci/templates/workloads/fio/fedora_deployment.yaml diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index c2708bb863e..69c1bb50b75 100644 --- a/ocs_ci/helpers/helpers.py +++ b/ocs_ci/helpers/helpers.py @@ -241,6 +241,7 @@ def create_pod( ports=None, deploy_pod_status=constants.STATUS_COMPLETED, subpath=None, + deployment=False, ): """ Create a pod @@ -268,6 +269,7 @@ def create_pod( deploy_pod_status (str): Expected status of deploy pod. Applicable only if dc_deployment is True subpath (str): Value of subPath parameter in pod yaml + deployment (bool): True for Deployment creation, False otherwise Returns: Pod: A Pod instance @@ -276,6 +278,7 @@ def create_pod( AssertionError: In case of any failure """ + if ( interface_type == constants.CEPHBLOCKPOOL or interface_type == constants.CEPHBLOCKPOOL_THICK @@ -285,20 +288,19 @@ def create_pod( else: pod_dict = pod_dict_path if pod_dict_path else constants.CSI_CEPHFS_POD_YAML interface = constants.CEPHFS_INTERFACE - if dc_deployment: + if dc_deployment or deployment: pod_dict = pod_dict_path if pod_dict_path else constants.FEDORA_DC_YAML pod_data = templating.load_yaml(pod_dict) if not pod_name: pod_name = create_unique_resource_name(f"test-{interface}", "pod") pod_data["metadata"]["name"] = pod_name pod_data["metadata"]["namespace"] = namespace - if dc_deployment: + if dc_deployment or deployment: pod_data["metadata"]["labels"]["app"] = pod_name pod_data["spec"]["template"]["metadata"]["labels"]["name"] = pod_name pod_data["spec"]["replicas"] = replica_count - if pvc_name: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["volumes"][0]["persistentVolumeClaim"][ "claimName" ] = pvc_name @@ -313,7 +315,11 @@ def create_pod( pod_data["spec"]["containers"][0]["ports"][0] = ports if interface_type == constants.CEPHBLOCKPOOL and raw_block_pv: - if pod_dict_path in [constants.FEDORA_DC_YAML, constants.FIO_DC_YAML]: + if pod_dict_path in [ + constants.FEDORA_DC_YAML, + constants.FIO_DC_YAML, + constants.FIO_DEPLOYMENT_YAML, + ]: temp_dict = [ { "devicePath": raw_block_device, @@ -328,7 +334,6 @@ def create_pod( del pod_data["spec"]["template"]["spec"]["containers"][0][ "volumeMounts" ] - pod_data["spec"]["template"]["spec"]["containers"][0][ "volumeDevices" ] = temp_dict @@ -357,40 +362,40 @@ def create_pod( pod_data.get("spec").get("volumes")[0].get("name") ) if security_context: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["containers"][0][ "securityContext" ] = security_context else: pod_data["spec"]["containers"][0]["securityContext"] = security_context if command: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["containers"][0]["command"] = command else: pod_data["spec"]["containers"][0]["command"] = command if command_args: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["containers"][0]["args"] = command_args else: pod_data["spec"]["containers"][0]["args"] = command_args if node_name: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["nodeName"] = node_name else: pod_data["spec"]["nodeName"] = node_name if node_selector: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["nodeSelector"] = node_selector else: pod_data["spec"]["nodeSelector"] = node_selector - if sa_name and dc_deployment: + if sa_name and (dc_deployment or deployment): pod_data["spec"]["template"]["spec"]["serviceAccountName"] = sa_name if subpath: - if dc_deployment: + if dc_deployment or deployment: pod_data["spec"]["template"]["spec"]["containers"][0]["volumeMounts"][0][ "subPath" ] = subpath @@ -415,9 +420,24 @@ def create_pod( ) dpod_list = pod.get_all_pods(namespace=namespace) for dpod in dpod_list: - if "-1-deploy" not in dpod.name: + labels = dpod.get().get("metadata").get("labels") + if not any("deployer-pod-for" in label for label in labels): if pod_name in dpod.name: return dpod + elif deployment: + deployment_obj = create_resource(**pod_data) + logger.info(deployment_obj.name) + deployment_name = deployment_obj.name + label = f"name={deployment_name}" + assert (ocp.OCP(kind="pod", namespace=namespace)).wait_for_resource( + condition=constants.STATUS_RUNNING, + selector=label, + timeout=360, + sleep=3, + ) + pod_dict = pod.get_pods_having_label(label=label, namespace=namespace)[0] + return pod.Pod(**pod_dict) + else: pod_obj = pod.Pod(**pod_data) pod_name = pod_data.get("metadata").get("name") diff --git a/ocs_ci/ocs/cluster_load.py b/ocs_ci/ocs/cluster_load.py index 6ca6f35f0eb..8068dd6f6f0 100644 --- a/ocs_ci/ocs/cluster_load.py +++ b/ocs_ci/ocs/cluster_load.py @@ -108,9 +108,9 @@ def increase_load(self, rate, wait=True): # Set new arguments with the updated file size to be used for # DeploymentConfig of FIO pod creation - fio_dc_data = templating.load_yaml(constants.FIO_DC_YAML) + fio_deployment_data = templating.load_yaml(constants.FIO_DEPLOYMENT_YAML) args = ( - fio_dc_data.get("spec") + fio_deployment_data.get("spec") .get("template") .get("spec") .get("containers")[0] @@ -126,11 +126,12 @@ def increase_load(self, rate, wait=True): new_args.append(f"--rate={rate}") dc_obj = self.pod_factory( pvc=pvc_obj, - pod_dict_path=constants.FIO_DC_YAML, + pod_dict_path=constants.FIO_DEPLOYMENT_YAML, raw_block_pv=True, - deployment_config=True, service_account=service_account, command_args=new_args, + status=None, + deployment=True, ) self.dc_objs.append(dc_obj) if wait: diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 9431b623c8d..583e66cc0cd 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -712,6 +712,7 @@ FIO_IO_RW_PARAMS_YAML = os.path.join(TEMPLATE_FIO_DIR, "workload_io_rw.yaml") FIO_IO_FILLUP_PARAMS_YAML = os.path.join(TEMPLATE_FIO_DIR, "workload_io_fillup.yaml") FIO_DC_YAML = os.path.join(TEMPLATE_FIO_DIR, "fio_dc.yaml") +FIO_DEPLOYMENT_YAML = os.path.join(TEMPLATE_FIO_DIR, "fedora_deployment.yaml") # fio configuration files FIO_S3 = os.path.join(TEMPLATE_FIO_DIR, "config_s3.fio") diff --git a/ocs_ci/templates/workloads/fio/fedora_deployment.yaml b/ocs_ci/templates/workloads/fio/fedora_deployment.yaml new file mode 100644 index 00000000000..9e79f3dd22d --- /dev/null +++ b/ocs_ci/templates/workloads/fio/fedora_deployment.yaml @@ -0,0 +1,47 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fio_deployment_raw_block + labels: + app: fio-benchmark + name: fio_deployment_raw_block +spec: + replicas: 1 + selector: + matchLabels: + app: fio_deployment_raw_block + template: + metadata: + labels: + app: fio_deployment_raw_block + spec: + containers: + - name: fio + image: datawiseio/fio:latest + volumeDevices: + - devicePath: /dev/rbdblock + name: my-volume + command: + - /usr/bin/fio + args: + - --name=fio-rand-readwrite + - --filename=/dev/rbdblock + - --readwrite=randrw + - --bs=128K + - --direct=1 + - --numjobs=1 + - --iodepth=4 + - --time_based=1 + - --runtime=1000000 + - --filesize=1G + - --invalidate=1 + - --rwmixread=25 + - --rate=15M + - --ioengine=libaio + - --output-format=json + imagePullPolicy: IfNotPresent + volumes: + - name: my-volume + persistentVolumeClaim: + claimName: test-raw-block-pv diff --git a/ocs_ci/templates/workloads/fio/fio_dc.yaml b/ocs_ci/templates/workloads/fio/fio_dc.yaml index 5b30d647d95..19b94449bc7 100644 --- a/ocs_ci/templates/workloads/fio/fio_dc.yaml +++ b/ocs_ci/templates/workloads/fio/fio_dc.yaml @@ -14,9 +14,6 @@ spec: containers: - name: fio image: datawiseio/fio:latest - securityContext: - capabilities: - add: ["SYS_ADMIN"] volumeDevices: - devicePath: /dev/rbdblock name: my-volume diff --git a/tests/conftest.py b/tests/conftest.py index 61ef048a02b..b251f3e3877 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1035,6 +1035,7 @@ def factory( command=None, command_args=None, subpath=None, + deployment=False, ): """ Args: @@ -1062,6 +1063,7 @@ def factory( command_args (list): The arguments to be sent to the command running on the pod subpath (str): Value of subPath parameter in pod yaml + deployment (bool): True for Deployment creation, False otherwise Returns: object: helpers.create_pod instance @@ -1087,15 +1089,20 @@ def factory( command=command, command_args=command_args, subpath=subpath, + deployment=deployment, ) assert pod_obj, "Failed to create pod" - if deployment_config: - dc_name = pod_obj.get_labels().get("name") - dc_ocp_dict = ocp.OCP( - kind=constants.DEPLOYMENTCONFIG, namespace=pod_obj.namespace - ).get(resource_name=dc_name) - dc_obj = OCS(**dc_ocp_dict) - instances.append(dc_obj) + + if deployment_config or deployment: + d_name = pod_obj.get_labels().get("name") + d_ocp_dict = ocp.OCP( + kind=constants.DEPLOYMENTCONFIG + if deployment_config + else constants.DEPLOYMENT, + namespace=pod_obj.namespace, + ).get(resource_name=d_name) + d_obj = OCS(**d_ocp_dict) + instances.append(d_obj) else: instances.append(pod_obj) @@ -1103,8 +1110,8 @@ def factory( helpers.wait_for_resource_state(pod_obj, status, timeout=300) pod_obj.reload() pod_obj.pvc = pvc - if deployment_config: - return dc_obj + if deployment_config or deployment: + return d_obj return pod_obj def finalizer():