Skip to content

Commit

Permalink
Updated metadata validation testcases to fix issue#7459 (#8094)
Browse files Browse the repository at this point in the history
Signed-off-by: Amrita Mahapatra <[email protected]>
  • Loading branch information
amr1ta authored Oct 17, 2023
1 parent 0dd88c8 commit 97f7ad2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
63 changes: 58 additions & 5 deletions ocs_ci/utility/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,23 @@ def available_subvolumes(sc_name, toolbox_pod, fs):
list: subvolumes available for rbd or cephfs
"""
if sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS:
if (
sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS
or sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_CEPHFS
):
cephfs_subvolumes = toolbox_pod.exec_cmd_on_pod(
f"ceph fs subvolume ls {fs} --group_name csi"
)
log.info(f"available cephfs subvolumes-----{cephfs_subvolumes}")
return cephfs_subvolumes

elif sc_name == constants.DEFAULT_STORAGECLASS_RBD:
rbd_cephblockpool = toolbox_pod.exec_cmd_on_pod(f"rbd ls {fs} --format json")
log.info(f"available rbd cephblockpool-----{rbd_cephblockpool}")
return rbd_cephblockpool
elif sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_RBD:
rbd_cephblockpool = toolbox_pod.exec_cmd_on_pod("rbd ls --format json")
log.info(f"available rbd cephblockpool-----{rbd_cephblockpool}")
return rbd_cephblockpool
else:
log.exception("Metadata feature is not supported for this storage class")

Expand All @@ -207,10 +213,16 @@ def created_subvolume(available_subvolumes, updated_subvolumes, sc_name):
for sub_vol in updated_subvolumes:
if sub_vol not in available_subvolumes:
created_subvolume = sub_vol
if sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS:
if (
sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS
or sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_CEPHFS
):
log.info(f"created sub volume---- {created_subvolume['name']}")
return created_subvolume["name"]
elif sc_name == constants.DEFAULT_STORAGECLASS_RBD:
elif (
sc_name == constants.DEFAULT_STORAGECLASS_RBD
or sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_RBD
):
log.info(f"created sub volume---- {created_subvolume}")
return created_subvolume
else:
Expand Down Expand Up @@ -244,7 +256,10 @@ def fetch_metadata(
json: metadata details
"""
if sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS:
if (
sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS
or sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_CEPHFS
):
if snapshot:
snap_subvolume = toolbox_pod.exec_cmd_on_pod(
f"ceph fs subvolume snapshot ls {fs} {created_subvol} --group_name=csi --format=json"
Expand All @@ -266,6 +281,14 @@ def fetch_metadata(
metadata = toolbox_pod.exec_cmd_on_pod(
f"rbd image-meta ls {fs}/{created_subvol} --format=json"
)
elif sc_name == constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_RBD:
if snapshot:
created_subvol = created_subvolume(
available_subvolumes, updated_subvolumes, sc_name
)
metadata = toolbox_pod.exec_cmd_on_pod(
f"rbd image-meta ls {created_subvol} --format=json"
)
else:
log.exception("Metadata feature is not supported for this storage class")
log.info(f"metadata is ------ {metadata}")
Expand Down Expand Up @@ -320,3 +343,33 @@ def validate_metadata(
assert (
namespace == metadata["csi.storage.k8s.io/volumesnapshot/namespace"]
), "Error: namespace is not as expected"


def update_testdata_for_external_modes(
sc_name,
fs,
external_mode=False,
):
"""
Update the file sytem and storage class names for external mode clusters
Args:
sc_name (str): storage class
fs (str): file system
external_mode(bool): External mode or not
Returns:
sc_name (str): storage class
fs (str): file system
"""
if external_mode:
if sc_name == constants.DEFAULT_STORAGECLASS_CEPHFS:
fs = "fsvol001"
sc_name = constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_CEPHFS
elif sc_name == constants.DEFAULT_STORAGECLASS_RBD:
fs = ""
sc_name = constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_RBD
else:
log.exception("Metadata feature is not supported for this storage class")
return fs, sc_name
26 changes: 25 additions & 1 deletion tests/manage/add_metadata_feature/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ocs_ci.utility import metadata_utils
from ocs_ci.ocs import constants, ocp
from ocs_ci.helpers import helpers
from ocs_ci.framework import config
from ocs_ci.framework.pytest_customization.marks import green_squad
from ocs_ci.ocs.resources import pod
from ocs_ci.framework.testlib import (
Expand Down Expand Up @@ -60,6 +61,10 @@ def test_metadata_feature_unavailable_for_previous_versions(
and not suported in previous ODF versions (<4.12) and setmetadata is unavailable,
for csi-cephfsplugin-provisioner and csi-rbdplugin-provisioner pods
"""
external_mode = config.DEPLOYMENT["external_mode"]
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=external_mode
)
config_map_obj = ocp.OCP(kind="Configmap", namespace="openshift-storage")
pod_obj = ocp.OCP(kind="Pod", namespace="openshift-storage")
toolbox = pod.get_ceph_tools_pod()
Expand Down Expand Up @@ -118,7 +123,6 @@ def test_create_pvc(self, pvc_factory):
and not suported in previous ODF versions (<4.12) and setmetadata is unavailable,
for csi-cephfsplugin-provisioner and csi-rbdplugin-provisioner pods
"""
# create a pvc with cephfs sc
pvc_obj = pvc_factory(
interface=constants.CEPHFILESYSTEM, status=constants.STATUS_BOUND
)
Expand Down Expand Up @@ -169,6 +173,10 @@ def test_metadata_not_enabled_by_default(
2. PVC clone
"""
external_mode = config.DEPLOYMENT["external_mode"]
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=external_mode
)
config_map_obj = ocp.OCP(kind="Configmap", namespace="openshift-storage")
pod_obj = ocp.OCP(kind="Pod", namespace="openshift-storage")
toolbox = pod.get_ceph_tools_pod()
Expand Down Expand Up @@ -251,6 +259,7 @@ def setup(self, request, project_factory):
self.pod_obj = ocp.OCP(kind="Pod", namespace=self.namespace)
self.pv_obj = ocp.OCP(kind=constants.PV, namespace=self.namespace)
self.toolbox = pod.get_ceph_tools_pod()
self.external_mode = config.DEPLOYMENT["external_mode"]

# Enable metadata feature
log.info("----Enable metadata----")
Expand Down Expand Up @@ -299,6 +308,9 @@ def test_verify_metadata_details(
4. Restore volume from snapshot
"""
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=self.external_mode
)
available_subvolumes = metadata_utils.available_subvolumes(
sc_name, self.toolbox, fs
)
Expand Down Expand Up @@ -428,6 +440,9 @@ def test_verify_metadata_details_for_new_pvc_same_named(self, fs, sc_name):
5. Validate the metadata created for the new PVC
is different than previous metadata
"""
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=self.external_mode
)
available_subvolumes = metadata_utils.available_subvolumes(
sc_name, self.toolbox, fs
)
Expand Down Expand Up @@ -533,6 +548,9 @@ def test_metadata_details_available_only_when_metadata_flag_enabled(
no metadata details available for the volume clone and snapshot created
"""
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=self.external_mode
)
available_subvolumes = metadata_utils.available_subvolumes(
sc_name, self.toolbox, fs
)
Expand Down Expand Up @@ -676,6 +694,9 @@ def test_disable_metadata_flag_after_enabling(self, fs, sc_name):
for csi-cephfsplugin-provisioner and csi-rbdplugin-provisioner pods
"""
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=self.external_mode
)
available_subvolumes = metadata_utils.available_subvolumes(
sc_name, self.toolbox, fs
)
Expand Down Expand Up @@ -793,6 +814,9 @@ def test_metadata_update_for_PV_Retain(self, fs, sc_name, project_factory_class)
16. validate metadata for new PVC created
"""
fs, sc_name = metadata_utils.update_testdata_for_external_modes(
sc_name, fs, external_mode=self.external_mode
)
# Enable CSI_ENABLE_OMAP_GENERATOR flag
enable_omap_generator = '{"data":{"CSI_ENABLE_OMAP_GENERATOR": "true"}}'

Expand Down

0 comments on commit 97f7ad2

Please sign in to comment.