test_dataDistribution.py 5.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import unittest

from xtreemfs_client import dataDistribution
from xtreemfs_client import osd
from xtreemfs_client import folder

osd_id_prefix = 'osd_'
folder_id_prefix = 'folder_'
osd_capacity_key = 'capacity'


class TestDataDistribution(unittest.TestCase):
    def setUp(self):
        osd_capacity = 100
        capacity_key = 'capacity'
        capacities = {}
        for i in range(0, 2):
            new_osd = osd.OSD('osd' + str(i))
            capacities[new_osd.uuid] = {}
            capacities[new_osd.uuid][capacity_key] = osd_capacity

    def test_totally_random_distribution(self):
        # generate some random distributions and check whether they are different
        max_osd_total_folder_size = 0
        felix_and_farouk_different = False

        num_osds = 3
        osd_capacity = 100
        num_folders = 10
        folder_size = 20

        for i in range(0, 100):
            distribution_felix = dataDistribution.DataDistribution()
            distribution_felix.add_osd_list(create_test_osd_list(num_osds))
            distribution_felix.add_folders(create_test_folder_list(num_folders, folder_size),
                                           osd_information=create_osd_information(num_osds, osd_capacity),
                                           random_osd_assignment=True,
                                           ignore_osd_capacities=True)

            distribution_farouk = dataDistribution.DataDistribution()
            distribution_farouk.add_osd_list(create_test_osd_list(num_osds))
            distribution_farouk.add_folders(create_test_folder_list(num_folders, folder_size),
                                            osd_information=create_osd_information(num_osds, osd_capacity),
                                            random_osd_assignment=True,
                                            ignore_osd_capacities=True)

            osds_felix = distribution_felix.get_osd_list()
Felix Seibert's avatar
Felix Seibert committed
48
            osds_felix_total_folder_sizes = list(map(lambda x: distribution_felix.OSDs[x].total_folder_size, osds_felix))
49
50

            osds_farouk = distribution_farouk.get_osd_list()
Felix Seibert's avatar
Felix Seibert committed
51
            osds_farouk_total_folder_sizes = list(map(lambda x: distribution_farouk.OSDs[x].total_folder_size, osds_farouk))
52
53
54
55
56
57
58
59
60
61
62
63
64
65


            if osds_felix_total_folder_sizes[0] != osds_farouk_total_folder_sizes[0]:
                felix_and_farouk_different = True

            max_felix = max(osds_felix_total_folder_sizes)
            max_farouk = max(osds_farouk_total_folder_sizes)

            max_osd_total_folder_size = max(max_osd_total_folder_size, max_felix, max_farouk)

        self.assertTrue(felix_and_farouk_different)
        self.assertTrue(max_osd_total_folder_size > osd_capacity)

    def test_value_error(self):
Felix Seibert's avatar
Felix Seibert committed
66
67
68
69
70
71
72
73
74
        distribution = dataDistribution.DataDistribution()
        distribution.add_osd_list(create_test_osd_list(1))
        try:
            distribution.add_folders(create_test_folder_list(1, 1),
                                     random_osd_assignment=True,
                                     ignore_osd_capacities=False)
        except ValueError:
            return # expect value error
        self.fail("expect value error!")
75
76

    def test_random_distribution_respecting_capacities(self):
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        # generate some random distributions and check whether they all respect the OSD capacities
        max_osd_total_folder_size = 0
        num_osds = 3
        osd_capacity = 100
        num_folders = 10
        folder_size = 20

        for i in range(0, 100):
            distribution = dataDistribution.DataDistribution()
            distribution.add_osd_list(create_test_osd_list(num_osds))
            distribution.add_folders(create_test_folder_list(num_folders, folder_size),
                                     random_osd_assignment=True,
                                     ignore_osd_capacities=False,
                                     osd_information=create_osd_information(num_osds, osd_capacity),
                                     capacity=osd_capacity_key)

            osds = distribution.get_osd_list()
            total_folder_sizes = list(map(lambda x: distribution.OSDs[x].total_folder_size, osds))
            max_osd_total_folder_size = max(max(total_folder_sizes), max_osd_total_folder_size)

        self.assertTrue(max_osd_total_folder_size <= osd_capacity)
98
99
100
101
102
103
104
105
106
107
108

    def test_round_robin_distribution(self):
        pass

    def test_lpt_distribution(self):
        pass


def create_test_osd_list(num_osds):
    test_osds = []
    for i in range(0, num_osds):
Felix Seibert's avatar
Felix Seibert committed
109
        test_osds.append(osd_id_prefix + str(i))
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    return test_osds


def create_test_folder_list(num_folders, folder_size):
    test_folders = []
    for i in range(0, num_folders):
        new_folder = folder.Folder(folder_id_prefix + str(i), folder_size, None)
        test_folders.append(new_folder)
    return test_folders


def create_osd_information(num_osds, osd_capacity):
    osd_information = {}
    for i in range(0, num_osds):
        osd_uuid = osd_id_prefix + str(i)
        osd_information[osd_uuid] = {}
        osd_information[osd_uuid][osd_capacity_key] = osd_capacity
    return osd_information