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 def testBaseResourceModelApi(self
):
11 r
= BaseResourceModel()
12 # check if default flavors are there
13 assert(len(r
._flavors
) == 5)
14 # check addFlavor functionality
15 f
= ResourceFlavor("test", {"testmetric": 42})
17 assert("test" in r
._flavors
)
18 assert(r
._flavors
.get("test").get("testmetric") == 42)
19 # test if allocate and free runs through
20 assert(len(r
.allocate("testc", "tiny")) == 3) # expected: 3tuple
21 assert(r
.free("testc"))
23 def testAddRmToDc(self
):
25 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
27 self
.net
.addLink(self
.dc
[0], self
.h
[0])
28 self
.net
.addLink(self
.h
[1], self
.dc
[0])
30 r
= BaseResourceModel()
31 self
.dc
[0].assignResourceModel(r
)
32 # start Mininet network
34 # check number of running nodes
35 assert(len(self
.getDockernetContainers()) == 0)
36 assert(len(self
.net
.hosts
) == 2)
37 assert(len(self
.net
.switches
) == 1)
38 # check resource model and resource model registrar
39 assert(self
.dc
[0]._resource
_model
is not None)
40 assert(len(self
.net
.rm_registrar
.resource_models
) == 1)
42 # check if alloc was called during startCompute
43 assert(len(r
.allocated_compute_instances
) == 0)
44 self
.dc
[0].startCompute("tc1")
46 assert(len(r
.allocated_compute_instances
) == 1)
47 # check if free was called during stopCompute
48 self
.dc
[0].stopCompute("tc1")
49 assert(len(r
.allocated_compute_instances
) == 0)
50 # check connectivity by using ping
51 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
52 # stop Mininet network
56 class testUpbSimpleCloudDcRM(SimpleTestTopology
):
58 Test the UpbSimpleCloudDc resource model.
60 def testAllocation(self
):
64 # create dummy resource model environment
65 reg
= ResourceModelRegistrar(dc_emulation_max_cpu
=1.0)
66 rm
= UpbSimpleCloudDcRM(max_cu
=100, max_mu
=100)
67 reg
.register("test_dc", rm
)
69 res
= rm
.allocate("c1", "tiny") # calculate allocation
70 assert(res
[0] == E_CPU
/ MAX_CU
* 1) # validate compute result
71 assert(res
[1] < 0) # validate memory result
72 assert(res
[2] < 0) # validate disk result
74 res
= rm
.allocate("c2", "small") # calculate allocation
75 assert(res
[0] == E_CPU
/ MAX_CU
* 4) # validate compute result
76 assert(res
[1] < 0) # validate memory result
77 assert(res
[2] < 0) # validate disk result
79 res
= rm
.allocate("c3", "medium") # calculate allocation
80 assert(res
[0] == E_CPU
/ MAX_CU
* 8) # validate compute result
81 assert(res
[1] < 0) # validate memory result
82 assert(res
[2] < 0) # validate disk result
84 res
= rm
.allocate("c4", "large") # calculate allocation
85 assert(res
[0] == E_CPU
/ MAX_CU
* 16) # validate compute result
86 assert(res
[1] < 0) # validate memory result
87 assert(res
[2] < 0) # validate disk result
89 res
= rm
.allocate("c5", "xlarge") # calculate allocation
90 assert(res
[0] == E_CPU
/ MAX_CU
* 32) # validate compute result
91 assert(res
[1] < 0) # validate memory result
92 assert(res
[2] < 0) # validate disk result
94 # test over provisioning exeption
97 rm
.allocate("c6", "xlarge") # calculate allocation
98 rm
.allocate("c7", "xlarge") # calculate allocation
99 rm
.allocate("c8", "xlarge") # calculate allocation
100 rm
.allocate("c9", "xlarge") # calculate allocation
101 except Exception as e
:
102 assert("Not enough compute" in e
.message
)
110 # create dummy resource model environment
111 reg
= ResourceModelRegistrar(dc_emulation_max_cpu
=1.0)
112 rm
= UpbSimpleCloudDcRM(max_cu
=100, max_mu
=100)
113 reg
.register("test_dc", rm
)
114 rm
.allocate("c1", "tiny") # calculate allocation
115 assert(rm
.dc_alloc_cu
== 1)
117 assert(rm
.dc_alloc_cu
== 0)