To upload the file `sonata-demo.son` (from son-schema repo) do:
-* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:8000/api/packages`
+* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:5000/api/packages`
To list all uploaded packages do:
-* `curl http://127.0.0.1:8000/api/packages`
+* `curl http://127.0.0.1:5000/api/packages`
To instantiate (start) a service do:
-* Specific service: `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
-* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{}"`
+* Specific service: `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
+* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{}"`
To list all running services do:
-* `curl http://127.0.0.1:8000/api/instantiations`
+* `curl http://127.0.0.1:5000/api/instantiations`
## API definition
<td>/api/packages</td>
<td>POST</td>
<td>-</td>
-<td>{file-content} as enctype=multipart/form-data</td>
+<td>{file-content} as "content-type": "multipart/form-data"</td>
<td>{"service_uuid": "c880aaab-f3b9-43ac-ac6b-3d27b46146b7", size=456, sha1=49ee6468dfa4ecbad440d669b249d523a38651be, error: null}</td>
</tr>
<tr>
--- /dev/null
+import time
+import requests
+from emuvim.test.base import SimpleTestTopology
+from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
+
+
+
+class testSonataDummyGatekeeper(SimpleTestTopology):
+
+ def testAPI(self):
+ # create network
+ self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
+ # setup links
+ self.net.addLink(self.dc[0], self.h[0])
+ self.net.addLink(self.dc[0], self.dc[1])
+ self.net.addLink(self.h[1], self.dc[1])
+ # connect dummy GK to data centers
+ sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
+ sdkg1.connectDatacenter(self.dc[0])
+ sdkg1.connectDatacenter(self.dc[1])
+ # run the dummy gatekeeper (in another thread, don't block)
+ sdkg1.start()
+ # start Mininet network
+ self.startNet()
+ time.sleep(1)
+
+ # TODO download original son package
+
+ # board package
+ files = {"file": open("/home/manuel/Desktop/sonata-demo.son", "rb")}
+ r = requests.post("http://127.0.0.1:5000/api/packages", files=files)
+ self.assertEqual(r.status_code, 200)
+ self.assertTrue(r.json().get("service_uuid") is not None)
+
+ # instantiate service
+ service_uuid = r.json().get("service_uuid")
+ r2 = requests.post("http://127.0.0.1:5000/api/instantiations", json={"service_uuid": service_uuid})
+ self.assertEqual(r2.status_code, 200)
+
+ # give the emulator some time to instantiate everything
+ time.sleep(2)
+
+ # check get request APIs
+ r3 = requests.get("http://127.0.0.1:5000/api/packages")
+ self.assertEqual(len(r3.json().get("service_uuid_list")), 1)
+ r4 = requests.get("http://127.0.0.1:5000/api/instantiations")
+ self.assertEqual(len(r4.json().get("service_instance_list")), 1)
+
+ # check number of running nodes
+ assert(len(self.getDockernetContainers()) == 3)
+ assert(len(self.net.hosts) == 5)
+ assert(len(self.net.switches) == 2)
+ # check compute list result
+ assert(len(self.dc[0].listCompute()) == 3)
+ # check connectivity by using ping
+ for vnf in self.dc[0].listCompute():
+ assert(self.net.ping([self.h[0], vnf]) <= 0.0)
+ # stop Mininet network
+ self.stopNet()
+
+