From dfa98d77aa58a5a28fd68f22533e90f78e660882 Mon Sep 17 00:00:00 2001 From: peusterm Date: Wed, 23 Mar 2016 21:21:49 +0100 Subject: [PATCH] Added test that automatically deploys son-demo.son through the dummy GK. Closes #58 --- src/emuvim/api/sonata/README.md | 12 ++-- src/emuvim/api/sonata/dummygatekeeper.py | 1 + .../examples/sonata_y1_demo_topology_1.py | 2 +- .../test/test_sonata_dummy_gatekeeper.py | 61 +++++++++++++++++++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/emuvim/test/test_sonata_dummy_gatekeeper.py diff --git a/src/emuvim/api/sonata/README.md b/src/emuvim/api/sonata/README.md index 5fc1be0..a1708d4 100644 --- a/src/emuvim/api/sonata/README.md +++ b/src/emuvim/api/sonata/README.md @@ -22,20 +22,20 @@ The example starts a small network with two data centers. 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 @@ -59,7 +59,7 @@ _Note: This API should converge to the API of the original GK as much as possibl /api/packages POST - -{file-content} as enctype=multipart/form-data +{file-content} as "content-type": "multipart/form-data" {"service_uuid": "c880aaab-f3b9-43ac-ac6b-3d27b46146b7", size=456, sha1=49ee6468dfa4ecbad440d669b249d523a38651be, error: null} diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index 0c02cab..66a58c0 100644 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -271,6 +271,7 @@ class Packages(fr.Resource): """ try: # get file contents + print request.files son_file = request.files['file'] # generate a uuid to reference this package service_uuid = str(uuid.uuid4()) diff --git a/src/emuvim/examples/sonata_y1_demo_topology_1.py b/src/emuvim/examples/sonata_y1_demo_topology_1.py index 7731fd2..6ea568a 100644 --- a/src/emuvim/examples/sonata_y1_demo_topology_1.py +++ b/src/emuvim/examples/sonata_y1_demo_topology_1.py @@ -30,7 +30,7 @@ def create_topology1(): zapi1.start() # add the SONATA dummy gatekeeper to each DC - sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 8000) + sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) diff --git a/src/emuvim/test/test_sonata_dummy_gatekeeper.py b/src/emuvim/test/test_sonata_dummy_gatekeeper.py new file mode 100644 index 0000000..b2bd36e --- /dev/null +++ b/src/emuvim/test/test_sonata_dummy_gatekeeper.py @@ -0,0 +1,61 @@ +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() + + -- 2.25.1