1 # Copyright (c) 2015 SONATA-NFV and Paderborn University
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Neither the name of the SONATA-NFV, Paderborn University
17 # nor the names of its contributors may be used to endorse or promote
18 # products derived from this software without specific prior written
21 # This work has been performed in the framework of the SONATA project,
22 # funded by the European Commission under Grant number 671517 through
23 # the Horizon 2020 and 5G-PPP programmes. The authors would like to
24 # acknowledge the contributions of their colleagues of the SONATA
25 # partner consortium (www.sonata-nfv.eu).
27 from emuvim
.test
.api_base
import SimpleTestTopology
29 from emuvim
.dcemulator
.node
import EmulatorCompute
33 class testRestApi(SimpleTestTopology
):
35 Tests to check the REST API endpoints of the emulator.
38 def testRestApi(self
):
40 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
43 self
.net
.addLink(self
.dc
[0], self
.h
[0])
44 self
.net
.addLink(self
.h
[1], self
.dc
[1])
45 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
50 # start Mininet network
53 print('->>>>>>> vim-emu compute start -d datacenter0 -n vnf1 ->>>>>>>>>>>>>>>')
54 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
56 "vim-emu compute start -d datacenter0 -n vnf1", shell
=True)
57 print('->>>>>>> vim-emu compute start -d datacenter0 -n vnf2 ->>>>>>>>>>>>>>>')
58 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
60 "vim-emu compute start -d datacenter0 -n vnf2", shell
=True)
61 print('->>>>>>> vim-emu compute start -d datacenter0 -n vnf3 ->>>>>>>>>>>>>>>')
62 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
64 "vim-emu compute start -d datacenter1 -n vnf3", shell
=True)
65 subprocess
.call("vim-emu compute list", shell
=True)
66 print('->>>>>>> checking running nodes, compute list, and connectivity >>>>>>>>>>')
68 # check number of running nodes
69 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
70 self
.assertTrue(len(self
.net
.hosts
) == 5)
71 self
.assertTrue(len(self
.net
.switches
) == 2)
73 # check compute list result
74 self
.assertTrue(len(self
.dc
[0].listCompute()) == 2)
75 self
.assertTrue(len(self
.dc
[1].listCompute()) == 1)
76 self
.assertTrue(isinstance(
77 self
.dc
[0].listCompute()[0], EmulatorCompute
))
78 self
.assertTrue(isinstance(
79 self
.dc
[0].listCompute()[1], EmulatorCompute
))
80 self
.assertTrue(isinstance(
81 self
.dc
[1].listCompute()[0], EmulatorCompute
))
82 self
.assertTrue(self
.dc
[0].listCompute()[1].name
== "vnf1")
83 self
.assertTrue(self
.dc
[0].listCompute()[0].name
== "vnf2")
84 self
.assertTrue(self
.dc
[1].listCompute()[0].name
== "vnf3")
86 # check connectivity by using ping
87 self
.assertTrue(self
.net
.ping(
88 [self
.dc
[0].listCompute()[1], self
.dc
[0].listCompute()[0]]) <= 0.0)
89 self
.assertTrue(self
.net
.ping(
90 [self
.dc
[0].listCompute()[0], self
.dc
[1].listCompute()[0]]) <= 0.0)
91 self
.assertTrue(self
.net
.ping(
92 [self
.dc
[1].listCompute()[0], self
.dc
[0].listCompute()[1]]) <= 0.0)
94 print('network add vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
95 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
96 output
= subprocess
.check_output(
97 "vim-emu network add -src vnf1 -dst vnf2 -b -c 10", shell
=True)
98 self
.assertTrue("add-flow" in output
)
99 self
.assertTrue("success" in output
)
101 print('network remove vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
102 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
103 output
= subprocess
.check_output(
104 "vim-emu network remove -src vnf1 -dst vnf2 -b", shell
=True)
105 self
.assertTrue("del-flows" in output
)
106 self
.assertTrue("success" in output
)
108 print('>>>>> checking --> vim-emu compute stop -d datacenter0 -n vnf2 ->>>>>>')
109 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
110 output
= subprocess
.check_output(
111 "vim-emu compute stop -d datacenter0 -n vnf2", shell
=True)
113 # check number of running nodes
114 self
.assertTrue(len(self
.getContainernetContainers()) == 2)
115 self
.assertTrue(len(self
.net
.hosts
) == 4)
116 self
.assertTrue(len(self
.net
.switches
) == 2)
117 # check compute list result
118 self
.assertTrue(len(self
.dc
[0].listCompute()) == 1)
119 self
.assertTrue(len(self
.dc
[1].listCompute()) == 1)
121 print('>>>>> checking --> vim-emu compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
122 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
123 output
= subprocess
.check_output("vim-emu compute list", shell
=True)
125 # check datacenter list result
126 self
.assertTrue("datacenter0" in output
)
128 print('>>>>> checking --> vim-emu compute status -d datacenter0 -n vnf1 ->>>>')
129 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
130 output
= subprocess
.check_output(
131 "vim-emu compute status -d datacenter0 -n vnf1", shell
=True)
132 output
= ast
.literal_eval(output
)
134 # check compute status result
135 self
.assertTrue(output
["name"] == "vnf1")
136 self
.assertTrue(output
["state"]["Running"])
138 print('>>>>> checking --> vim-emu datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
139 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
140 output
= subprocess
.check_output("vim-emu datacenter list", shell
=True)
141 # check datacenter list result
142 self
.assertTrue("datacenter0" in output
)
144 print('->>>>> checking --> vim-emu datacenter status -d datacenter0 ->>>>>>>>')
145 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
146 output
= subprocess
.check_output(
147 "vim-emu datacenter status -d datacenter0", shell
=True)
148 # check datacenter status result
149 self
.assertTrue("datacenter0" in output
)
154 if __name__
== '__main__':