-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
105 lines (88 loc) · 3.54 KB
/
test.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import unittest
from engine.g5k_engine import G5kEngine, check_nodes, ROLE_DISTRIBUTION_MODE_STRICT
from execo.host import Host
class TestBuildRoles(unittest.TestCase):
def setUp(self):
self.engine = G5kEngine()
self.engine.config = {
"resources": {
"a": {
"controller": 1,
"compute" : 2,
"network" : 1,
"storage" : 1,
"util" : 1
}
}
}
def test_not_enough_nodes(self):
self.engine.deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4"])
with self.assertRaises(Exception):
roles = self.engine.build_roles()
def test_build_roles_same_number_of_nodes(self):
self.engine.deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5", "a-6"])
roles = self.engine.build_roles()
self.assertEquals(1, len(roles["controller"]))
self.assertEquals(1, len(roles["storage"]))
self.assertEquals(2, len(roles["compute"]))
self.assertEquals(1, len(roles["network"]))
self.assertEquals(1, len(roles["util"]))
def test_build_roles_less_deployed_nodes(self):
self.engine.deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5"])
roles = self.engine.build_roles()
self.assertEquals(1, len(roles["controller"]))
self.assertEquals(1, len(roles["storage"]))
self.assertEquals(1, len(roles["compute"]))
self.assertEquals(1, len(roles["network"]))
self.assertEquals(1, len(roles["util"]))
def test_build_roles_with_multiple_clusters(self):
self.engine.config = {
"resources": {
"a": {
"controller": 1,
"compute" : 2,
"network" : 1,
"storage" : 1,
"util" : 1
},
"b": {
"compute": 2
}
}
}
self.engine.deployed_nodes = map(lambda x: Host(x), ["a-1", "a-2", "a-3", "a-4", "a-5", "a-6", "b-1", "b-2"])
roles = self.engine.build_roles()
self.assertEquals(1, len(roles["controller"]))
self.assertEquals(1, len(roles["storage"]))
self.assertEquals(4, len(roles["compute"]))
self.assertEquals(1, len(roles["network"]))
self.assertEquals(1, len(roles["util"]))
class TestCheckNodes(unittest.TestCase):
def setUp(self):
self.roles = {
"a": {
"controller": 1,
"compute" : 1,
"network" : 1,
"storage" : 1,
"util" : 1
},
"b": {
"compute": 2
}
}
def test_enough_nodes_strict(self):
nodes = [1, 2, 3, 4, 5, 6, 7]
self.assertTrue(check_nodes(nodes, self.roles, ROLE_DISTRIBUTION_MODE_STRICT))
def test_enough_nodes_not_strict(self):
nodes = [1, 2, 3, 4, 5, 6, 7]
self.assertTrue(check_nodes(nodes, self.roles, ""))
def test_not_enough_nodes_strict(self):
nodes = [1, 2, 3, 4, 5, 6]
with self.assertRaises(Exception):
check_nodes(nodes, self.roles, ROLE_DISTRIBUTION_MODE_STRICT)
def test_not_enough_nodes_not_strict(self):
nodes = [1, 2, 3, 4, 5]
self.assertTrue(check_nodes(nodes, self.roles, ""))
if __name__ == '__main__':
unittest.main()