Skip to content

Commit

Permalink
Fixed default sc tests case which was failing (#10141)
Browse files Browse the repository at this point in the history
Signed-off-by: Parag Kamble <[email protected]>
  • Loading branch information
paraggit committed Sep 17, 2024
1 parent 4c25869 commit cf7330c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
6 changes: 2 additions & 4 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4790,7 +4790,7 @@ def flatten_multilevel_dict(d):
return leaves_list


def is_rbd_default_storage_class(custom_sc=None):
def is_rbd_default_storage_class(sc_name=None):
"""
Check if RDB is a default storageclass for the cluster
Expand All @@ -4800,9 +4800,7 @@ def is_rbd_default_storage_class(custom_sc=None):
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
)
default_rbd_sc = constants.DEFAULT_STORAGECLASS_RBD if sc_name is None else sc_name
cmd = (
f"oc get storageclass {default_rbd_sc} -o=jsonpath='{{.metadata.annotations}}' "
)
Expand Down
18 changes: 6 additions & 12 deletions tests/functional/storageclass/test_rbd_default_storageclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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,
Expand All @@ -29,19 +28,15 @@ 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.
1. Create a PVC and don't provide any storage class name in the YAML file.
2. Verify PVC has created and it has attached to the Default RBD SC.
3. Verify Storagecalss attched to PVC is the default RBD.
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.")
Expand All @@ -52,12 +47,11 @@ def test_pvc_creation_without_storageclass_name(self, pvc_factory, pod_factory):
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."
assert is_rbd_default_storage_class(
sc_name=sc_attached_to_pvc
), f"RBD storageclass {sc_attached_to_pvc} is not default storageclass for Cluster."

log.info("Attaching PVC to pod to start IO workload.")
pod_obj = pod_factory(pvc=pvc_obj, status=constants.STATUS_RUNNING)
Expand Down

0 comments on commit cf7330c

Please sign in to comment.