2 from emuvim
.test
.base
import SimpleTestTopology
3 from emuvim
.dcemulator
.resourcemodel
import BaseResourceModel
, ResourceFlavor
4 from emuvim
.dcemulator
.resourcemodel
.upb
.simple
import UpbSimpleCloudDcRM
5 from emuvim
.dcemulator
.resourcemodel
import ResourceModelRegistrar
8 class testResourceModel(SimpleTestTopology
):
10 Test the general resource model API and functionality.
13 def testBaseResourceModelApi(self
):
15 Tast bare API without real resource madel.
18 r
= BaseResourceModel()
19 # check if default flavors are there
20 self
.assertTrue(len(r
._flavors
) == 5)
21 # check addFlavor functionality
22 f
= ResourceFlavor("test", {"testmetric": 42})
24 self
.assertTrue("test" in r
._flavors
)
25 self
.assertTrue(r
._flavors
.get("test").get("testmetric") == 42)
26 # test if allocate and free runs through
27 self
.assertTrue(len(r
.allocate("testc", "tiny")) == 3) # expected: 3tuple
28 self
.assertTrue(r
.free("testc"))
30 def testAddRmToDc(self
):
32 Test is allocate/free is called when a RM is added to a DC.
36 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
38 self
.net
.addLink(self
.dc
[0], self
.h
[0])
39 self
.net
.addLink(self
.h
[1], self
.dc
[0])
41 r
= BaseResourceModel()
42 self
.dc
[0].assignResourceModel(r
)
43 # start Mininet network
45 # check number of running nodes
46 self
.assertTrue(len(self
.getDockernetContainers()) == 0)
47 self
.assertTrue(len(self
.net
.hosts
) == 2)
48 self
.assertTrue(len(self
.net
.switches
) == 1)
49 # check resource model and resource model registrar
50 self
.assertTrue(self
.dc
[0]._resource
_model
is not None)
51 self
.assertTrue(len(self
.net
.rm_registrar
.resource_models
) == 1)
53 # check if alloc was called during startCompute
54 self
.assertTrue(len(r
.allocated_compute_instances
) == 0)
55 self
.dc
[0].startCompute("tc1")
57 self
.assertTrue(len(r
.allocated_compute_instances
) == 1)
58 # check if free was called during stopCompute
59 self
.dc
[0].stopCompute("tc1")
60 self
.assertTrue(len(r
.allocated_compute_instances
) == 0)
61 # check connectivity by using ping
62 self
.assertTrue(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
63 # stop Mininet network
67 class testUpbSimpleCloudDcRM(SimpleTestTopology
):
69 Test the UpbSimpleCloudDc resource model.
72 def testAllocation(self
):
74 Test the allocation procedures and correct calculations.
80 # create dummy resource model environment
81 reg
= ResourceModelRegistrar(dc_emulation_max_cpu
=1.0)
82 rm
= UpbSimpleCloudDcRM(max_cu
=100, max_mu
=100)
83 reg
.register("test_dc", rm
)
85 res
= rm
.allocate("c1", "tiny") # calculate allocation
86 self
.assertTrue(res
[0] == E_CPU
/ MAX_CU
* 1) # validate compute result
87 self
.assertTrue(res
[1] < 0) # validate memory result
88 self
.assertTrue(res
[2] < 0) # validate disk result
90 res
= rm
.allocate("c2", "small") # calculate allocation
91 self
.assertTrue(res
[0] == E_CPU
/ MAX_CU
* 4) # validate compute result
92 self
.assertTrue(res
[1] < 0) # validate memory result
93 self
.assertTrue(res
[2] < 0) # validate disk result
95 res
= rm
.allocate("c3", "medium") # calculate allocation
96 self
.assertTrue(res
[0] == E_CPU
/ MAX_CU
* 8) # validate compute result
97 self
.assertTrue(res
[1] < 0) # validate memory result
98 self
.assertTrue(res
[2] < 0) # validate disk result
100 res
= rm
.allocate("c4", "large") # calculate allocation
101 self
.assertTrue(res
[0] == E_CPU
/ MAX_CU
* 16) # validate compute result
102 self
.assertTrue(res
[1] < 0) # validate memory result
103 self
.assertTrue(res
[2] < 0) # validate disk result
105 res
= rm
.allocate("c5", "xlarge") # calculate allocation
106 self
.assertTrue(res
[0] == E_CPU
/ MAX_CU
* 32) # validate compute result
107 self
.assertTrue(res
[1] < 0) # validate memory result
108 self
.assertTrue(res
[2] < 0) # validate disk result
110 # test over provisioning exeption
113 rm
.allocate("c6", "xlarge") # calculate allocation
114 rm
.allocate("c7", "xlarge") # calculate allocation
115 rm
.allocate("c8", "xlarge") # calculate allocation
116 rm
.allocate("c9", "xlarge") # calculate allocation
117 except Exception as e
:
118 self
.assertTrue("Not enough compute" in e
.message
)
120 self
.assertTrue(exception
)
124 Test the free procedure.
130 # create dummy resource model environment
131 reg
= ResourceModelRegistrar(dc_emulation_max_cpu
=1.0)
132 rm
= UpbSimpleCloudDcRM(max_cu
=100, max_mu
=100)
133 reg
.register("test_dc", rm
)
134 rm
.allocate("c1", "tiny") # calculate allocation
135 self
.assertTrue(rm
.dc_alloc_cu
== 1)
137 self
.assertTrue(rm
.dc_alloc_cu
== 0)
139 def testInRealTopo(self
):
141 Start a real container and check if limitations are really passed down to Dockernet.
145 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
147 self
.net
.addLink(self
.dc
[0], self
.h
[0])
148 self
.net
.addLink(self
.h
[1], self
.dc
[0])
150 r
= UpbSimpleCloudDcRM(max_cu
=100, max_mu
=100)
151 self
.dc
[0].assignResourceModel(r
)
152 # start Mininet network
154 # check number of running nodes
155 self
.assertTrue(len(self
.getDockernetContainers()) == 0)
156 self
.assertTrue(len(self
.net
.hosts
) == 2)
157 self
.assertTrue(len(self
.net
.switches
) == 1)
158 # check resource model and resource model registrar
159 self
.assertTrue(self
.dc
[0]._resource
_model
is not None)
160 self
.assertTrue(len(self
.net
.rm_registrar
.resource_models
) == 1)
162 # check if alloc was called during startCompute
163 self
.assertTrue(len(r
.allocated_compute_instances
) == 0)
164 tc1
= self
.dc
[0].startCompute("tc1", flavor_name
="tiny")
166 self
.assertTrue(len(r
.allocated_compute_instances
) == 1)
168 # check if there is a real limitation set for containers cgroup
169 self
.assertEqual(tc1
.cpu_period
/tc1
.cpu_quota
, 100)
171 # check if free was called during stopCompute
172 self
.dc
[0].stopCompute("tc1")
173 self
.assertTrue(len(r
.allocated_compute_instances
) == 0)
174 # check connectivity by using ping
175 self
.assertTrue(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
176 # stop Mininet network