Skip to content

Commit

Permalink
Test automation for Default RBD storageclass for cluster (#9469)
Browse files Browse the repository at this point in the history
Signed-off-by: Parag Kamble <pakamble@redhat.com>
  • Loading branch information
paraggit authored May 27, 2024
1 parent dbec6e3 commit c5cb2ba
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ocs_ci/framework/pytest_customization/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
HCI_CLIENT,
MS_CONSUMER_TYPE,
HCI_PROVIDER,
BAREMETAL_PLATFORMS,
)
from ocs_ci.utility import version
from ocs_ci.utility.aws import update_config_from_s3
from ocs_ci.utility.utils import load_auth_config


# tier marks

tier1 = pytest.mark.tier1(value=1)
Expand Down Expand Up @@ -625,3 +627,15 @@ def get_current_test_marks():
"""
return current_test_marks


baremetal_deployment_required = pytest.mark.skipif(
(config.ENV_DATA["platform"].lower() not in BAREMETAL_PLATFORMS)
or (not vsphere_platform_required),
reason="Test required baremetal or vsphere deployment.",
)

ui_deployment_required = pytest.mark.skipif(
not config.DEPLOYMENT.get("ui_deployment"),
reason="UI Deployment required to run the test.",
)
30 changes: 30 additions & 0 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4738,3 +4738,33 @@ def flatten_multilevel_dict(d):
else:
leaves_list.append(value)
return leaves_list


def is_rbd_default_storage_class(custom_sc=None):
"""
Check if RDB is a default storageclass for the cluster
Args:
custom_sc: custom storageclass name.
Returns:
bool : True if RBD is set as the Default storage class for the cluster, False otherwise.
"""
default_rbd_sc = (
constants.DEFAULT_STORAGECLASS_RBD if custom_sc is None else custom_sc
)
cmd = (
f"oc get storageclass {default_rbd_sc} -o=jsonpath='{{.metadata.annotations}}' "
)
try:
check_annotations = json.loads(run_cmd(cmd))
except json.decoder.JSONDecodeError:
logger.error("Error to get annotation value from storageclass.")
return False

if check_annotations.get("storageclass.kubernetes.io/is-default-class") == "true":
logger.info(f"Storageclass {default_rbd_sc} is a default RBD StorageClass.")
return True

logger.error("Storageclass {default_rbd_sc} is not a default RBD StorageClass.")
return False
7 changes: 6 additions & 1 deletion ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,12 @@
ROSA_PLATFORM,
FUSIONAAS_PLATFORM,
]
BAREMETAL_PLATFORMS = [BAREMETAL_PLATFORM, BAREMETALPSI_PLATFORM]
BAREMETAL_PLATFORMS = [
BAREMETAL_PLATFORM,
BAREMETALPSI_PLATFORM,
HCI_BAREMETAL,
IBM_POWER_PLATFORM,
]
DEFAULT_AWS_REGION = "us-east-2"

HCI_PROVIDER_CLIENT_PLATFORMS = [
Expand Down
16 changes: 16 additions & 0 deletions ocs_ci/ocs/ui/helpers_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,19 @@ def get_element_by_text(text):
"""
return (f"//*[text()= '{text}']", By.XPATH)


def is_ui_deployment():
"""
This function checks if the current deployment is UI deployment or not.
"""

if (
(config.RUN["kubeconfig"] is not None)
and (config.DEPLOYMENT["ui_deployment"])
and (ui_deployment_conditions())
):
return True

return False
72 changes: 72 additions & 0 deletions tests/functional/storageclass/test_rbd_default_storageclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import logging
import pytest
from ocs_ci.helpers.helpers import is_rbd_default_storage_class
from ocs_ci.ocs import constants
from ocs_ci.utility import templating
from ocs_ci.helpers.helpers import create_unique_resource_name
from ocs_ci.helpers.helpers import default_storage_class
from ocs_ci.framework.pytest_customization.marks import (
tier1,
green_squad,
polarion_id,
baremetal_deployment_required,
ui_deployment_required,
)
from ocs_ci.ocs.ui.helpers_ui import is_ui_deployment


log = logging.getLogger(__name__)


@green_squad
@baremetal_deployment_required
@ui_deployment_required
class TestRBDStorageClassAsDefaultStorageClass:
@tier1
@polarion_id("OCS-5459")
def test_pvc_creation_without_storageclass_name(self, pvc_factory, pod_factory):
"""
Test PVC creation without mentioning storageclass name in the spec.
Steps:
1. Verify RBD storageclass is set as default.
2. Create a PVC and don't provide any storage class name in the YAML file.
3. Verify PVC has created and it has attached to the Default RBD SC.
4. Create a POD and attached the above PVC to the Pod.
5. Start IO on verify that IO is successful on the PV.
"""
if not is_ui_deployment():
pytest.skip("cluster is not deployed from UI. Skipping test.")

assert (
is_rbd_default_storage_class()
), "RBD is not default storageclass for Cluster."

pvc_data = templating.load_yaml(constants.CSI_PVC_YAML)
pvc_data["metadata"]["name"] = create_unique_resource_name("test", "pvc")
log.info("Removing 'storageClassName' Parameter from the PVC yaml file.")
del pvc_data["spec"]["storageClassName"]

pvc_obj = pvc_factory(custom_data=pvc_data, status=constants.STATUS_BOUND)
log.info("Created PVC without providing storage class name")
assert pvc_obj, "PVC creation failed."

sc_attached_to_pvc = pvc_obj.get().get("spec").get("storageClassName")
sc_default_in_cluster = default_storage_class(constants.CEPHBLOCKPOOL)
log.info("Verifying the storageclass attached to PVC is correct.")

assert (
sc_attached_to_pvc == sc_default_in_cluster.name
), "Storageclass attached to PVC is different from StorageClass set as default for BlockPool."

log.info("Attaching PVC to pod to start IO workload.")
pod_obj = pod_factory(pvc=pvc_obj, status=constants.STATUS_RUNNING)
pod_obj.run_io(direct=1, runtime=60, storage_type="fs", size="1G")

# Wait for IO completion
fio_result = pod_obj.get_fio_results()
log.info("IO completed on all pods")
err_count = fio_result.get("jobs")[0].get("error")
assert err_count == 0, (
f"IO error on pod {pod_obj.name}. " f"FIO result: {fio_result}"
)

0 comments on commit c5cb2ba

Please sign in to comment.