From 97f7ad2f17aef872a5edde47ff5b539704b28556 Mon Sep 17 00:00:00 2001 From: Amrita Mahapatra <49347640+amr1ta@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:24:10 +0530 Subject: [PATCH] Updated metadata validation testcases to fix issue#7459 (#8094) Signed-off-by: Amrita Mahapatra <49347640+amr1ta@users.noreply.github.com> --- ocs_ci/utility/metadata_utils.py | 63 +++++++++++++++++-- .../add_metadata_feature/test_metadata.py | 26 +++++++- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/ocs_ci/utility/metadata_utils.py b/ocs_ci/utility/metadata_utils.py index 9e11e6f5489..a3b42975621 100644 --- a/ocs_ci/utility/metadata_utils.py +++ b/ocs_ci/utility/metadata_utils.py @@ -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") @@ -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: @@ -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" @@ -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}") @@ -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 diff --git a/tests/manage/add_metadata_feature/test_metadata.py b/tests/manage/add_metadata_feature/test_metadata.py index ebb0efc9945..b59bd9e0eee 100644 --- a/tests/manage/add_metadata_feature/test_metadata.py +++ b/tests/manage/add_metadata_feature/test_metadata.py @@ -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 ( @@ -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() @@ -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 ) @@ -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() @@ -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----") @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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"}}'