blob: f31f3e4e5cba7247e1940463eb1e35508e2a20b2 [file] [log] [blame]
peusterm43485a22016-03-14 11:18:37 +01001import time
peusterm5c6475c2016-03-13 12:54:11 +01002from emuvim.test.base import SimpleTestTopology
peusterm43485a22016-03-14 11:18:37 +01003from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor
peusterm5c6475c2016-03-13 12:54:11 +01004
5
6class testResourceModel(SimpleTestTopology):
7
8 def testBaseResourceModelApi(self):
peusterm43485a22016-03-14 11:18:37 +01009 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})
14 r.addFlavour(f)
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"))
peusterm5c6475c2016-03-13 12:54:11 +010020
21 def testAddRmToDc(self):
22 # create network
23 self.createNet(nswitches=0, ndatacenter=1, nhosts=2, ndockers=0)
24 # setup links
25 self.net.addLink(self.dc[0], self.h[0])
26 self.net.addLink(self.h[1], self.dc[0])
27 # add resource model
28 r = BaseResourceModel()
29 self.dc[0].assignResourceModel(r)
30 # start Mininet network
31 self.startNet()
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(self.net.rm_registrar.num_models == 1)
peusterm43485a22016-03-14 11:18:37 +010039
40 # check if alloc was called during startCompute
41 assert(len(r.allocated_compute_instances) == 0)
42 self.dc[0].startCompute("tc1")
43 time.sleep(1)
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)
peusterm5c6475c2016-03-13 12:54:11 +010048 # check connectivity by using ping
49 assert(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
50 # stop Mininet network
51 self.stopNet()