2 from emuvim
.test
.base
import SimpleTestTopology
3 from emuvim
.dcemulator
.resourcemodel
import BaseResourceModel
, ResourceFlavor
6 class testResourceModel(SimpleTestTopology
):
8 def testBaseResourceModelApi(self
):
9 r
= BaseResourceModel()
10 # check if default flavors are there
11 assert(len(r
._flavors
) == 5)
12 # check addFlavor functionality
13 f
= ResourceFlavor("test", {"testmetric": 42})
15 assert("test" in r
._flavors
)
16 assert(r
._flavors
.get("test").get("testmetric") == 42)
17 # test if allocate and free runs through
18 assert(len(r
.allocate("testc", "tiny")) == 3) # expected: 3tuple
19 assert(r
.free("testc"))
21 def testAddRmToDc(self
):
23 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
25 self
.net
.addLink(self
.dc
[0], self
.h
[0])
26 self
.net
.addLink(self
.h
[1], self
.dc
[0])
28 r
= BaseResourceModel()
29 self
.dc
[0].assignResourceModel(r
)
30 # start Mininet network
32 # check number of running nodes
33 assert(len(self
.getDockernetContainers()) == 0)
34 assert(len(self
.net
.hosts
) == 2)
35 assert(len(self
.net
.switches
) == 1)
36 # check resource model and resource model registrar
37 assert(self
.dc
[0]._resource
_model
is not None)
38 assert(len(self
.net
.rm_registrar
.resource_models
) == 1)
40 # check if alloc was called during startCompute
41 assert(len(r
.allocated_compute_instances
) == 0)
42 self
.dc
[0].startCompute("tc1")
44 assert(len(r
.allocated_compute_instances
) == 1)
45 # check if free was called during stopCompute
46 self
.dc
[0].stopCompute("tc1")
47 assert(len(r
.allocated_compute_instances
) == 0)
48 # check connectivity by using ping
49 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
50 # stop Mininet network