From 5874a46ba4b2dd034f2f408f8b811b60f2556ef8 Mon Sep 17 00:00:00 2001 From: Mahesh Shetty Date: Thu, 14 Nov 2024 17:15:04 +0530 Subject: [PATCH] Create stress cli pod fixture Signed-off-by: Mahesh Shetty --- ocs_ci/ocs/constants.py | 8 ++ .../mcg/stress-cli-service-ca-configmap.yaml | 7 ++ ocs_ci/templates/mcg/stress-cli-sts.yaml | 33 +++++++ tests/conftest.py | 90 +++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 ocs_ci/templates/mcg/stress-cli-service-ca-configmap.yaml create mode 100644 ocs_ci/templates/mcg/stress-cli-sts.yaml diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 23f9e1bc4dbb..7e5e46c3914f 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -828,6 +828,10 @@ SCALECLI_POD_YAML = os.path.join(TEMPLATE_MCG_DIR, "scalecli_pod.yaml") +STRESS_CLI_SERVICE_CA_YAML = os.path.join( + TEMPLATE_MCG_DIR, "stress-cli-service-ca-configmap.yaml" +) + AWSCLI_SERVICE_CA_YAML = os.path.join( TEMPLATE_MCG_DIR, "aws-cli-service-ca-configmap.yaml" ) @@ -840,6 +844,8 @@ S3CLI_STS_NAME = "s3cli" +STRESS_CLI_STS_YAML = os.path.join(TEMPLATE_MCG_DIR, "stress-cli-sts.yaml") + JAVA_SDK_S3_POD_YAML = os.path.join(TEMPLATE_APP_POD_DIR, "java_sdk_s3_pod.yaml") JAVA_SRC_CODE_PATH = os.path.join(TEMPLATE_MCG_DIR, "java/s3test") @@ -1740,6 +1746,7 @@ MASTER_LABEL = "node-role.kubernetes.io/master" WORKER_LABEL = "node-role.kubernetes.io/worker" APP_LABEL = "node-role.kubernetes.io/app" +STRESS_CLI_APP_LABEL = "app=stress-cli" S3CLI_APP_LABEL = "app=s3cli" OSD_NODE_LABEL = "node.ocs.openshift.io/osd=''" OCS_OSD_DEPLOYER_CSV_LABEL = "operators.coreos.com/ocs-osd-deployer.openshift-storage" @@ -2050,6 +2057,7 @@ AWSCLI_RELAY_POD_NAME = "awscli-relay-pod" JAVAS3_POD_NAME = "java-s3" SCALECLI_SERVICE_CA_CM_NAME = "scalecli-service-ca" +STRESSCLI_SERVICE_CA_CM_NAME = "stress-cli-service-ca" AWSCLI_SERVICE_CA_CONFIGMAP_NAME = "awscli-service-ca" AWSCLI_TEST_OBJ_DIR = "/test_objects/" MCG_CLI_DEV_IMAGE = "quay.io/rhceph-dev/mcg-cli" diff --git a/ocs_ci/templates/mcg/stress-cli-service-ca-configmap.yaml b/ocs_ci/templates/mcg/stress-cli-service-ca-configmap.yaml new file mode 100644 index 000000000000..4cbe7539f3e9 --- /dev/null +++ b/ocs_ci/templates/mcg/stress-cli-service-ca-configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: stress-cli-service-ca + namespace: openshift-storage + annotations: + service.beta.openshift.io/inject-cabundle: "true" diff --git a/ocs_ci/templates/mcg/stress-cli-sts.yaml b/ocs_ci/templates/mcg/stress-cli-sts.yaml new file mode 100644 index 000000000000..381c1bdc53c5 --- /dev/null +++ b/ocs_ci/templates/mcg/stress-cli-sts.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + namespace: openshift-storage + name: nb-stress-cli +spec: + selector: + matchLabels: + app: s3cli + replicas: 1 + updateStrategy: + type: RollingUpdate + podManagementPolicy: OrderedReady + volumeClaimTemplates: [] + template: + metadata: + labels: + app: stress-cli + spec: + volumes: + - name: service-ca + configMap: + name: stress-cli-service-ca + containers: + - name: stress-cli + image: quay.io/ocsci/nb-stress-cli:latest + command: ['/bin/sh'] + stdin: true + tty: true + volumeMounts: + - name: service-ca + mountPath: /cert/service-ca.crt + subPath: service-ca.crt diff --git a/tests/conftest.py b/tests/conftest.py index de5c0ef231da..2ad003d4e6f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -178,6 +178,9 @@ get_current_test_name, modify_deployment_replica_count, modify_statefulset_replica_count, + create_resource, + wait_for_resource_state, + storagecluster_independent_check, ) from ocs_ci.ocs.ceph_debug import CephObjectStoreTool, MonStoreTool, RookCephPlugin from ocs_ci.ocs.bucket_utils import get_rgw_restart_counts @@ -2752,6 +2755,93 @@ def _javas3_pod_cleanup(): return javas3_pod_obj +@pytest.fixture(scope="session") +def nb_stress_cli_pod(request): + """ + A session scoped fixture to create stress cli pod + + """ + return nb_stress_cli_pod_fixture(request, scope_name="session") + + +def nb_stress_cli_pod_fixture(request, scope_name): + """ + Creates AWS cli pod with object data specific to stress testing + + Args: + request: request object + scope_name: scope of the calling fixture used for giving a + descriptive name to the pod and configmap + + Returns: + Pod(): Pod object representing stress cli pod + + """ + namespace = ocsci_config.ENV_DATA["cluster_namespace"] + # Create the service-ca configmap to be mounted upon pod creation + service_ca_data = templating.load_yaml(constants.STRESS_CLI_SERVICE_CA_YAML) + resource_type = scope_name or "caconfigmap" + service_ca_configmap_name = create_unique_resource_name( + constants.STRESSCLI_SERVICE_CA_CM_NAME, resource_type + ) + service_ca_data["metadata"]["name"] = service_ca_configmap_name + service_ca_data["metadata"]["namespace"] = namespace + s3cli_label_k, s3cli_label_v = constants.STRESS_CLI_APP_LABEL.split("=") + service_ca_data["metadata"]["labels"] = {s3cli_label_k: s3cli_label_v} + + log.info("Trying to create the Stress CLI service CA") + service_ca_configmap = create_resource(**service_ca_data) + OCP(namespace=namespace, kind="ConfigMap").wait_for_resource( + resource_name=service_ca_configmap.name, column="DATA", condition="1" + ) + + log.info("Creating the Stress CLI StatefulSet") + stress_cli_sts_dict = templating.load_yaml(constants.STRESS_CLI_STS_YAML) + stress_cli_sts_dict["spec"]["template"]["spec"]["volumes"][0]["configMap"][ + "name" + ] = service_ca_configmap_name + stress_cli_sts_dict["metadata"]["namespace"] = namespace + update_container_with_mirrored_image(stress_cli_sts_dict) + update_container_with_proxy_env(stress_cli_sts_dict) + stress_cli_sts_obj = create_resource(**stress_cli_sts_dict) + + log.info("Verifying the AWS CLI StatefulSet is running") + assert stress_cli_sts_obj, "Failed to create S3CLI STS" + stress_cli_pod_obj = retry(IndexError, tries=3, delay=15)( + lambda: Pod( + **get_pods_having_label(constants.STRESS_CLI_APP_LABEL, namespace)[0] + ) + )() + wait_for_resource_state(stress_cli_pod_obj, constants.STATUS_RUNNING, timeout=180) + + stress_cli_pod_obj.exec_cmd_on_pod( + f"cp {constants.SERVICE_CA_CRT_AWSCLI_PATH} {constants.AWSCLI_CA_BUNDLE_PATH}" + ) + + if storagecluster_independent_check() and ocsci_config.EXTERNAL_MODE.get( + "rgw_secure" + ): + log.info("Concatenating the RGW CA to the Stress CLI pod's CA bundle") + stress_cli_pod_obj.exec_cmd_on_pod( + f"bash -c 'wget -O - {ocsci_config.EXTERNAL_MODE['rgw_cert_ca']} >> {constants.AWSCLI_CA_BUNDLE_PATH}'" + ) + + def cleanup(): + """ + Clean up the Stress CLI resources + + """ + + log.info("Deleting the Stress CLI STS") + stress_cli_sts_obj.delete() + + log.info("Deleting the Stress CLI configmap") + service_ca_configmap.delete() + + request.addfinalizer(cleanup) + return stress_cli_pod_obj + + @pytest.fixture() def test_directory_setup(request, awscli_pod_session): return test_directory_setup_fixture(request, awscli_pod_session)