3 from emuvim
.test
.base
import SimpleTestTopology
4 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
8 class testSonataDummyGatekeeper(SimpleTestTopology
):
12 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
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)
23 # start Mininet network
27 # TODO download original son 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)
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)
40 # give the emulator some time to instantiate everything
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)
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