Skip to content

Commit

Permalink
Check that the ceph osd df tree weight and size are equal and the osd…
Browse files Browse the repository at this point in the history
… size values are eqaul to the expected osd size

Signed-off-by: Itzhak Kave <[email protected]>
  • Loading branch information
Itzhak Kave committed Oct 9, 2024
1 parent 92040eb commit 45222fc
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ocs_ci/helpers/osd_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
get_deviceset_count,
resize_osd,
)
from ocs_ci.ocs.cluster import check_ceph_osd_tree, CephCluster
from ocs_ci.ocs.cluster import check_ceph_osd_tree, CephCluster, check_ceph_osd_df_tree
from ocs_ci.ocs.ui.page_objects.page_navigator import PageNavigator
from ocs_ci.utility.utils import (
ceph_health_check,
Expand Down Expand Up @@ -227,6 +227,10 @@ def check_ceph_state_post_resize_osd():
raise CephHealthException(ex)
if not check_ceph_osd_tree():
raise CephHealthException("The ceph osd tree checks didn't finish successfully")
if not check_ceph_osd_df_tree():
raise CephHealthException(
"The ceph osd df tree output is not formatted correctly"
)


def base_ceph_verification_steps_post_resize_osd(
Expand Down
92 changes: 91 additions & 1 deletion ocs_ci/ocs/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3458,7 +3458,6 @@ def ceph_health_detail():


def get_active_mds_info():

"""Return information about the active Ceph MDS.
Returns:
Expand Down Expand Up @@ -3602,3 +3601,94 @@ def bring_down_mds_memory_usage_gradually():
assert (
time_elapsed <= 1800
), "Memory usage remained high for more than 30 minutes. Failed to bring down the memory usage of MDS"


def parse_ceph_osd_df_tree_weight_and_size():
"""
Parses the Ceph osd df tree output and returns a list of dictionaries
where keys are 'ID', 'WEIGHT', and 'SIZE', and values are the corresponding data from each line.
Returns:
list: A list of dictionaries with 'ID', 'WEIGHT', and 'SIZE' keys.
"""
result = []
min_line_length = 18

ceph_cmd = "ceph osd df tree"
ct_pod = pod.get_ceph_tools_pod()
output = ct_pod.exec_ceph_cmd(
ceph_cmd=ceph_cmd, format=False, out_yaml_format=False
)
logger.info(f"ceph osd df tree output = {output}")
# Split the output into lines
lines = output.strip().split("\n")
lines = lines[1:] # Skip the first line (header)

for line in lines:
parts = re.split(r"\s+", line.strip()) # Split line into parts by spaces
if len(parts) < min_line_length:
continue # Skip any lines that don't have enough parts

# Create a dictionary for the current line with 'ID', 'WEIGHT', and 'SIZE'
if parts[0].startswith("-"):
entry = {
"ID": parts[0],
"WEIGHT": parts[1],
"SIZE": parts[3] + " " + parts[4], # Combine size and unit
}
else:
entry = {
"ID": parts[0],
"WEIGHT": parts[2],
"SIZE": parts[4] + " " + parts[5], # Combine size and unit
}

result.append(entry)

return result


def check_ceph_osd_df_tree():
"""
Check that the ceph osd df tree output values are correct
Returns:
bool: True, if the ceph osd df tree output values are correct. False, otherwise.
"""
osd_size = float(storage_cluster.get_storage_size()[0:-2])
ceph_output_lines = parse_ceph_osd_df_tree_weight_and_size()

for line in ceph_output_lines:
osd_id = line["ID"]
weight = float(line["WEIGHT"])
units = line["SIZE"].split()[1]
size = float(line["SIZE"].split()[0])
if units.startswith("Gi"):
weight = weight * 1024
elif units.startswith("Mi"):
weight = weight * (1024**2)

# Check if the weight and size are equal ignoring a small diff
diff = size * 0.02
if not (size - diff <= weight <= size + diff):
logger.warning(
f"OSD weight {weight} (converted) does not match the OSD size {size} "
f"for OSD ID {osd_id}. Expected size within [{size - diff}, {size + diff}]"
)
logger.warning(
f"OSD weight {weight} is not equal to the OSD size {size} for the osd id {osd_id}"
)
return False
# If it's a regular OSD entry, check if the expected osd size
# and the current size are equal ignoring a small diff
diff = size * 0.01
if not osd_id.startswith("-") and not (size - diff <= osd_size <= size + diff):
logger.warning(
f"The expected osd size {osd_size} does not match the current OSD size {size} "
f"for OSD ID {osd_id}. Expected size within [{size - diff}, {size + diff}]"
)
return False

return True

0 comments on commit 45222fc

Please sign in to comment.