Added test that automatically deploys son-demo.son through the dummy GK. Closes #58
[osm/vim-emu.git] / src / emuvim / test / test_sonata_dummy_gatekeeper.py
1 import time
2 import requests
3 from emuvim.test.base import SimpleTestTopology
4 from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
5
6
7
8 class testSonataDummyGatekeeper(SimpleTestTopology):
9
10 def testAPI(self):
11 # create network
12 self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
13 # setup links
14 self.net.addLink(self.dc[0], self.h[0])
15 self.net.addLink(self.dc[0], self.dc[1])
16 self.net.addLink(self.h[1], self.dc[1])
17 # connect dummy GK to data centers
18 sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
19 sdkg1.connectDatacenter(self.dc[0])
20 sdkg1.connectDatacenter(self.dc[1])
21 # run the dummy gatekeeper (in another thread, don't block)
22 sdkg1.start()
23 # start Mininet network
24 self.startNet()
25 time.sleep(1)
26
27 # TODO download original son package
28
29 # board package
30 files = {"file": open("/home/manuel/Desktop/sonata-demo.son", "rb")}
31 r = requests.post("http://127.0.0.1:5000/api/packages", files=files)
32 self.assertEqual(r.status_code, 200)
33 self.assertTrue(r.json().get("service_uuid") is not None)
34
35 # instantiate service
36 service_uuid = r.json().get("service_uuid")
37 r2 = requests.post("http://127.0.0.1:5000/api/instantiations", json={"service_uuid": service_uuid})
38 self.assertEqual(r2.status_code, 200)
39
40 # give the emulator some time to instantiate everything
41 time.sleep(2)
42
43 # check get request APIs
44 r3 = requests.get("http://127.0.0.1:5000/api/packages")
45 self.assertEqual(len(r3.json().get("service_uuid_list")), 1)
46 r4 = requests.get("http://127.0.0.1:5000/api/instantiations")
47 self.assertEqual(len(r4.json().get("service_instance_list")), 1)
48
49 # check number of running nodes
50 assert(len(self.getDockernetContainers()) == 3)
51 assert(len(self.net.hosts) == 5)
52 assert(len(self.net.switches) == 2)
53 # check compute list result
54 assert(len(self.dc[0].listCompute()) == 3)
55 # check connectivity by using ping
56 for vnf in self.dc[0].listCompute():
57 assert(self.net.ping([self.h[0], vnf]) <= 0.0)
58 # stop Mininet network
59 self.stopNet()
60
61