diff --git a/ocs_ci/ocs/resources/osd_resize.py b/ocs_ci/ocs/resources/osd_resize.py index eb7d4ca7e71..2ed52d1a48c 100644 --- a/ocs_ci/ocs/resources/osd_resize.py +++ b/ocs_ci/ocs/resources/osd_resize.py @@ -82,6 +82,16 @@ def check_resources_state_post_resize_osd(old_osd_pods, old_osd_pvcs, old_osd_pv if old_osd_pods_count == osd_pods_count: break + logger.info("Verify that the new osd pod names are different than the old ones") + osd_pods = get_osd_pods() + new_name_set = {p.name for p in osd_pods} + old_name_set = {p.name for p in old_osd_pods} + if new_name_set.intersection(old_name_set): + raise ResourceWrongStatusException( + f"There are shared values between the new osd pod names and the old osd pod names. " + f"old osd pod names = {old_name_set}, new osd pod names = {new_name_set}" + ) + logger.info("Check that the PVCs are in a Bound state") ocp_pvc = OCP(kind=constants.PVC, namespace=config.ENV_DATA["cluster_namespace"]) ocp_pvc.wait_for_resource( diff --git a/ocs_ci/ocs/resources/storage_cluster.py b/ocs_ci/ocs/resources/storage_cluster.py index fc2ecb58da7..0e9f71722fe 100644 --- a/ocs_ci/ocs/resources/storage_cluster.py +++ b/ocs_ci/ocs/resources/storage_cluster.py @@ -73,7 +73,7 @@ ) from ocs_ci.utility.retry import retry from ocs_ci.utility.rgwutils import get_rgw_count -from ocs_ci.utility.utils import run_cmd, TimeoutSampler +from ocs_ci.utility.utils import run_cmd, TimeoutSampler, convert_device_size from ocs_ci.utility.decorators import switch_to_orig_index_at_last from ocs_ci.helpers.helpers import storagecluster_independent_check from ocs_ci.deployment.helpers.mcg_helpers import check_if_mcg_root_secret_public @@ -2682,17 +2682,35 @@ def get_storage_size(): return storage -def resize_osd(new_osd_size): +def resize_osd(new_osd_size, check_size=True): """ Resize the OSD(e.g., from 512 to 1024, 1024 to 2048, etc.) Args: new_osd_size (str): The new osd size(e.g, 512Gi, 1024Gi, 1Ti, 2Ti, etc.) + check_size (bool): Check that the given osd size is valid Returns: bool: True in case if changes are applied. False otherwise - """ + Raises: + ValueError: In case the osd size is not valid(start with digits and follow by string) + or the new osd size is less than the current osd size + + """ + if check_size: + pattern = r"^\d+[a-zA-Z]+$" + if not re.match(pattern, new_osd_size): + raise ValueError(f"The osd size '{new_osd_size}' is not valid") + new_osd_size_in_gb = convert_device_size(new_osd_size, "GB") + current_osd_size = get_storage_size() + current_osd_size_in_gb = convert_device_size(current_osd_size, "GB") + if new_osd_size_in_gb < current_osd_size_in_gb: + raise ValueError( + f"The new osd size {new_osd_size} is less than the " + f"current osd size {current_osd_size}" + ) + sc = get_storage_cluster() # Patch the OSD storage size path = "/spec/storageDeviceSets/0/dataPVCTemplate/spec/resources/requests/storage"