Commit 4ad8c91f authored by Felix Seibert's avatar Felix Seibert
Browse files

test for two step rebalancing; use random seed for reproducible test results

parent 12109caa
......@@ -20,6 +20,8 @@ class TestDataDistribution(unittest.TestCase):
capacities[new_osd.uuid] = {}
capacities[new_osd.uuid][capacity_key] = osd_capacity
random.seed(9234)
def test_totally_random_distribution(self):
# generate some random distributions and check whether they are different
max_osd_total_folder_size = 0
......@@ -247,6 +249,43 @@ class TestDataDistribution(unittest.TestCase):
self.assertEqual(0, min(total_folder_sizes))
self.assertEqual(2, max(total_folder_sizes))
def test_rebalance_two_steps(self):
folder_sizes = [1]
num_folders = 12
osd_bandwidths = [10]
num_osds = 4
distribution = dataDistribution.DataDistribution()
distribution.add_osd_list(create_test_osd_list(num_osds, osd_bandwidths))
distribution.add_folders(create_test_folder_list(num_folders, folder_sizes), random_osd_assignment=True)
distribution.rebalance_two_steps()
osds = distribution.get_osd_list()
total_folder_sizes = list(map(lambda x: distribution.OSDs[x].total_folder_size, osds))
# 12 unit size folders on 4 OSD => each should have 3 files
self.assertEqual(3, min(total_folder_sizes))
self.assertEqual(3, max(total_folder_sizes))
self.assertEqual(12, sum(total_folder_sizes))
# same test with one more folder size
folder_sizes = [1, 2]
distribution = dataDistribution.DataDistribution()
distribution.add_osd_list(create_test_osd_list(num_osds, osd_bandwidths))
distribution.add_folders(create_test_folder_list(num_folders, folder_sizes), random_osd_assignment=True)
distribution.rebalance_two_steps()
osds = distribution.get_osd_list()
total_folder_sizes = list(map(lambda x: distribution.OSDs[x].total_folder_size, osds))
self.assertEqual(9, min(total_folder_sizes))
self.assertEqual(9, max(total_folder_sizes))
self.assertEqual(36, sum(total_folder_sizes))
def create_test_osd_list(num_osds, osd_capacities):
test_osds = []
for i in range(0, num_osds):
......
Markdown is supported
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