Commit 0f8f79d0 authored by Felix Seibert's avatar Felix Seibert
Browse files

add get_average_osd_load method and test

parent 9afa6268
......@@ -158,6 +158,22 @@ class TestDataDistribution(unittest.TestCase):
total_folder_sizes = list(map(lambda x: distribution.OSDs[x].total_folder_size, osds))
self.assertTrue(2 * min(total_folder_sizes) == max(total_folder_sizes))
def test_average_osd_load(self):
folder_sizes = [49, 123, 1, 7]
num_folders = 2
num_osds = 4
osd_capacities = [100, 150]
distribution = dataDistribution.DataDistribution()
distribution.add_osd_list(create_test_osd_list(num_osds, osd_capacities))
distribution.add_folders(create_test_folder_list(num_folders, folder_sizes),
create_osd_information(num_osds, osd_capacities),
osd_capacity_key)
average = (sum(folder_sizes) * num_folders) / (sum(osd_capacities * num_osds))
self.assertEqual(average, distribution.get_average_osd_load(create_osd_information(num_osds, osd_capacities),
osd_capacity_key))
def create_test_osd_list(num_osds, osd_capacities):
test_osds = []
......
......@@ -86,6 +86,18 @@ class DataDistribution(object):
return 0
return total_size / total_number_of_folders
def get_average_osd_load(self, osd_information, capacity):
"""
calculate the average OSD load, that is,
the ratio between the sum of all folder sizes and the total OSD capacity.
"""
total_folder_size = 0
total_osd_capacity = 0
for osd_uuid in self.OSDs.keys():
total_folder_size += self.OSDs[osd_uuid].total_folder_size
total_osd_capacity += osd_information[osd_uuid][capacity]
return total_folder_size / total_osd_capacity
def add_folders(self, folders,
osd_information=None, ratio_parameter='', capacity='',
ignore_osd_capacities=True,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment