Skip to content

Commit

Permalink
Check that the new osd pod names are different than the old ones, add…
Browse files Browse the repository at this point in the history
… validation check for the 'resize_osd' function

Signed-off-by: Itzhak Kave <[email protected]>
  • Loading branch information
Itzhak Kave committed Apr 11, 2024
1 parent 21101de commit 8838210
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ocs_ci/ocs/resources/osd_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 common 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(
Expand Down
25 changes: 22 additions & 3 deletions ocs_ci/ocs/resources/storage_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2682,17 +2682,36 @@ 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}"
)

return True
sc = get_storage_cluster()
# Patch the OSD storage size
path = "/spec/storageDeviceSets/0/dataPVCTemplate/spec/resources/requests/storage"
Expand Down

0 comments on commit 8838210

Please sign in to comment.