2 Copyright (c) 2015 SONATA-NFV
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
34 from emuvim
.test
.base
import SimpleTestTopology
35 from emuvim
.api
.sonata
import SonataDummyGatekeeperEndpoint
37 PACKAGE_PATH
= "misc/sonata-demo-docker.son"
40 class testSonataDummyGatekeeper(SimpleTestTopology
):
42 @unittest.skip("disabled")
45 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
47 self
.net
.addLink(self
.dc
[0], self
.h
[0])
48 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
49 self
.net
.addLink(self
.h
[1], self
.dc
[1])
50 # connect dummy GK to data centers
51 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
52 sdkg1
.connectDatacenter(self
.dc
[0])
53 sdkg1
.connectDatacenter(self
.dc
[1])
54 # run the dummy gatekeeper (in another thread, don't block)
56 # start Mininet network
60 print "starting tests"
62 files
= {"package": open(PACKAGE_PATH
, "rb")}
63 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
64 self
.assertEqual(r
.status_code
, 200)
65 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
68 service_uuid
= json
.loads(r
.text
).get("service_uuid")
69 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": service_uuid
}))
70 self
.assertEqual(r2
.status_code
, 200)
72 # give the emulator some time to instantiate everything
75 # check get request APIs
76 r3
= requests
.get("http://127.0.0.1:5000/packages")
77 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
78 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
79 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instance_list")), 1)
81 # check number of running nodes
82 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
83 self
.assertTrue(len(self
.net
.hosts
) == 5)
84 self
.assertTrue(len(self
.net
.switches
) == 2)
85 # check compute list result
86 self
.assertTrue(len(self
.dc
[0].listCompute()) == 3)
87 # check connectivity by using ping
88 for vnf
in self
.dc
[0].listCompute():
89 self
.assertTrue(self
.net
.ping([self
.h
[0], vnf
]) <= 0.0)
90 # stop Mininet network