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
36 from emuvim
.api
.sonata
.dummygatekeeper
import initialize_GK
39 PACKAGE_PATH
= "misc/sonata-demo-service.son"
42 class testSonataDummyGatekeeper(SimpleTestTopology
):
44 # @unittest.skip("disabled")
45 def test_GK_Api_start_service(self
):
47 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
49 self
.net
.addLink(self
.dc
[0], self
.h
[0])
50 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
51 self
.net
.addLink(self
.h
[1], self
.dc
[1])
52 # connect dummy GK to data centers
53 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
54 sdkg1
.connectDatacenter(self
.dc
[0])
55 sdkg1
.connectDatacenter(self
.dc
[1])
56 # run the dummy gatekeeper (in another thread, don't block)
58 # start Mininet network
62 print "starting tests"
64 files
= {"package": open(PACKAGE_PATH
, "rb")}
65 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
66 self
.assertEqual(r
.status_code
, 201)
67 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
70 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
71 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
72 self
.assertEqual(r2
.status_code
, 201)
74 # give the emulator some time to instantiate everything
77 # check get request APIs
78 r3
= requests
.get("http://127.0.0.1:5000/packages")
79 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
80 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
81 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
83 # check number of running nodes
84 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
85 self
.assertTrue(len(self
.net
.hosts
) == 5)
86 self
.assertTrue(len(self
.net
.switches
) == 2)
87 # check compute list result
88 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
89 # check connectivity by using ping
90 for vnf
in self
.dc
[0].listCompute():
91 p
= self
.net
.ping([self
.h
[0], vnf
])
92 self
.assertTrue(p
<= 50.0)
93 # stop Mininet network
97 # @unittest.skip("disabled")
98 def test_GK_Api_stop_service(self
):
100 self
.createNet(ndatacenter
=2, nhosts
=2)
102 self
.net
.addLink(self
.dc
[0], self
.h
[0])
103 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
104 self
.net
.addLink(self
.h
[1], self
.dc
[1])
105 # connect dummy GK to data centers
106 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
107 sdkg1
.connectDatacenter(self
.dc
[0])
108 sdkg1
.connectDatacenter(self
.dc
[1])
109 # run the dummy gatekeeper (in another thread, don't block)
111 # start Mininet network
115 print "starting tests"
117 files
= {"package": open(PACKAGE_PATH
, "rb")}
118 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
119 self
.assertEqual(r
.status_code
, 201)
120 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
122 # instantiate service
123 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
124 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
125 self
.assertEqual(r2
.status_code
, 201)
127 # give the emulator some time to instantiate everything
130 # check get request APIs
131 r3
= requests
.get("http://127.0.0.1:5000/packages")
132 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
133 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
134 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
136 # check number of running nodes
137 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
138 self
.assertTrue(len(self
.net
.hosts
) == 5)
139 self
.assertTrue(len(self
.net
.switches
) == 2)
140 # check compute list result
141 self
.assertEqual(len(self
.dc
[0].listCompute()), 2)
144 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
145 self
.assertTrue(service_instance_uuid
is not None)
146 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
148 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
149 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
151 # stop Mininet network
155 def test_GK_stress_service(self
):
157 self
.createNet(ndatacenter
=2, nhosts
=2)
158 # connect dummy GK to data centers
159 sdkg1
= SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
160 sdkg1
.connectDatacenter(self
.dc
[0])
161 sdkg1
.connectDatacenter(self
.dc
[1])
162 # run the dummy gatekeeper (in another thread, don't block)
164 # start Mininet network
168 print "starting tests"
170 files
= {"package": open("misc/sonata-stress-service.son", "rb")}
171 r
= requests
.post("http://127.0.0.1:5000/packages", files
=files
)
172 self
.assertEqual(r
.status_code
, 201)
173 self
.assertTrue(json
.loads(r
.text
).get("service_uuid") is not None)
175 # instantiate service
176 self
.service_uuid
= json
.loads(r
.text
).get("service_uuid")
177 r2
= requests
.post("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
}))
178 self
.assertEqual(r2
.status_code
, 201)
180 # give the emulator some time to instantiate everything
183 # check get request APIs
184 r3
= requests
.get("http://127.0.0.1:5000/packages")
185 self
.assertEqual(len(json
.loads(r3
.text
).get("service_uuid_list")), 1)
186 r4
= requests
.get("http://127.0.0.1:5000/instantiations")
187 self
.assertEqual(len(json
.loads(r4
.text
).get("service_instantiations_list")), 1)
190 service_instance_uuid
= json
.loads(r2
.text
).get("service_instance_uuid")
191 self
.assertTrue(service_instance_uuid
is not None)
192 requests
.delete("http://127.0.0.1:5000/instantiations", data
=json
.dumps({"service_uuid": self
.service_uuid
, "service_instance_uuid":service_instance_uuid
}))
194 r5
= requests
.get("http://127.0.0.1:5000/instantiations")
195 self
.assertTrue(len(json
.loads(r5
.text
).get("service_instantiations_list")), 0) # note that there was 1 instance before
197 # stop Mininet network