blob: 268b12bcc82d528a148163983f879c8a444c2240 [file] [log] [blame]
hadik3r237d3f52016-06-27 17:57:49 +02001"""
peustermc89ba382016-07-08 13:46:32 +02002Copyright (c) 2015 SONATA-NFV
3ALL RIGHTS RESERVED.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18nor the names of its contributors may be used to endorse or promote
19products derived from this software without specific prior written
20permission.
21
22This work has been performed in the framework of the SONATA project,
23funded by the European Commission under Grant number 671517 through
24the Horizon 2020 and 5G-PPP programmes. The authors would like to
25acknowledge the contributions of their colleagues of the SONATA
26partner consortium (www.sonata-nfv.eu).
27"""
28
29"""
hadik3r237d3f52016-06-27 17:57:49 +020030Test suite to automatically test emulator REST API endpoints.
31"""
32
33import time
34import unittest
35from emuvim.test.api_base import SimpleTestTopology
36import subprocess
hadik3r895477d2016-06-29 14:38:05 +020037from emuvim.dcemulator.node import EmulatorCompute
38import ast
hadik3r237d3f52016-06-27 17:57:49 +020039
hadik3ra9dd9012016-08-09 10:51:13 +020040
41class testRestApi(SimpleTestTopology):
hadik3r237d3f52016-06-27 17:57:49 +020042 """
43 Tests to check the REST API endpoints of the emulator.
44 """
45
46 def testRestApi(self):
hadik3r237d3f52016-06-27 17:57:49 +020047 # create network
48 self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
hadik3r895477d2016-06-29 14:38:05 +020049
hadik3r237d3f52016-06-27 17:57:49 +020050 # setup links
51 self.net.addLink(self.dc[0], self.h[0])
52 self.net.addLink(self.h[1], self.dc[1])
53 self.net.addLink(self.dc[0], self.dc[1])
hadik3r895477d2016-06-29 14:38:05 +020054
hadik3r237d3f52016-06-27 17:57:49 +020055 # start api
56 self.startApi()
hadik3r895477d2016-06-29 14:38:05 +020057
hadik3r237d3f52016-06-27 17:57:49 +020058 # start Mininet network
59 self.startNet()
hadik3r895477d2016-06-29 14:38:05 +020060
61 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf1 ->>>>>>>>>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +020062 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
63 subprocess.call("son-emu-cli compute start -d datacenter0 -n vnf1", shell=True)
hadik3r895477d2016-06-29 14:38:05 +020064 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf2 ->>>>>>>>>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +020065 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
66 subprocess.call("son-emu-cli compute start -d datacenter0 -n vnf2", shell=True)
hadik3r895477d2016-06-29 14:38:05 +020067 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf3 ->>>>>>>>>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +020068 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
69 subprocess.call("son-emu-cli compute start -d datacenter1 -n vnf3", shell=True)
hadik3r237d3f52016-06-27 17:57:49 +020070 subprocess.call("son-emu-cli compute list", shell=True)
hadik3r895477d2016-06-29 14:38:05 +020071 print('->>>>>>> checking running nodes, compute list, and connectivity >>>>>>>>>>')
72
73 # check number of running nodes
74 self.assertTrue(len(self.getContainernetContainers()) == 3)
75 self.assertTrue(len(self.net.hosts) == 5)
76 self.assertTrue(len(self.net.switches) == 2)
77
78 # check compute list result
79 self.assertTrue(len(self.dc[0].listCompute()) == 2)
80 self.assertTrue(len(self.dc[1].listCompute()) == 1)
81 self.assertTrue(isinstance(self.dc[0].listCompute()[0], EmulatorCompute))
82 self.assertTrue(isinstance(self.dc[0].listCompute()[1], EmulatorCompute))
83 self.assertTrue(isinstance(self.dc[1].listCompute()[0], EmulatorCompute))
84 self.assertTrue(self.dc[0].listCompute()[1].name == "vnf1")
85 self.assertTrue(self.dc[0].listCompute()[0].name == "vnf2")
86 self.assertTrue(self.dc[1].listCompute()[0].name == "vnf3")
87
88 # check connectivity by using ping
89 self.assertTrue(self.net.ping([self.dc[0].listCompute()[1], self.dc[0].listCompute()[0]]) <= 0.0)
90 self.assertTrue(self.net.ping([self.dc[0].listCompute()[0], self.dc[1].listCompute()[0]]) <= 0.0)
91 self.assertTrue(self.net.ping([self.dc[1].listCompute()[0], self.dc[0].listCompute()[1]]) <= 0.0)
stevenvanrossem73efd192016-06-29 01:44:07 +020092
93 print('network add vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
94 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
stevenvanrossemae588012017-06-06 10:33:19 +020095 output = subprocess.check_output("son-emu-cli network add -src vnf1 -dst vnf2 -b -c 10", shell=True)
96 self.assertTrue("add-flow" in output)
97 self.assertTrue("success" in output)
98
stevenvanrossem73efd192016-06-29 01:44:07 +020099 print('network remove vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
100 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
stevenvanrossemae588012017-06-06 10:33:19 +0200101 output = subprocess.check_output("son-emu-cli network remove -src vnf1 -dst vnf2 -b", shell=True)
102 self.assertTrue("del-flows" in output)
103 self.assertTrue("success" in output)
stevenvanrossem73efd192016-06-29 01:44:07 +0200104
hadik3r895477d2016-06-29 14:38:05 +0200105 print('>>>>> checking --> son-emu-cli compute stop -d datacenter0 -n vnf2 ->>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +0200106 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
stevenvanrossemae588012017-06-06 10:33:19 +0200107 output = subprocess.check_output("son-emu-cli compute stop -d datacenter0 -n vnf2", shell=True)
hadik3r895477d2016-06-29 14:38:05 +0200108
109 # check number of running nodes
110 self.assertTrue(len(self.getContainernetContainers()) == 2)
111 self.assertTrue(len(self.net.hosts) == 4)
112 self.assertTrue(len(self.net.switches) == 2)
113 # check compute list result
114 self.assertTrue(len(self.dc[0].listCompute()) == 1)
115 self.assertTrue(len(self.dc[1].listCompute()) == 1)
116
117 print('>>>>> checking --> son-emu-cli compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +0200118 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r895477d2016-06-29 14:38:05 +0200119 output = subprocess.check_output("son-emu-cli compute list", shell=True)
120
121 # check datacenter list result
122 self.assertTrue("datacenter0" in output)
123
124 print('>>>>> checking --> son-emu-cli compute status -d datacenter0 -n vnf1 ->>>>')
hadik3r237d3f52016-06-27 17:57:49 +0200125 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r895477d2016-06-29 14:38:05 +0200126 output = subprocess.check_output("son-emu-cli compute status -d datacenter0 -n vnf1", shell=True)
hadik3ra9dd9012016-08-09 10:51:13 +0200127 output = ast.literal_eval(output)
hadik3r895477d2016-06-29 14:38:05 +0200128
129 # check compute status result
130 self.assertTrue(output["name"] == "vnf1")
131 self.assertTrue(output["state"]["Running"])
132
133 print('>>>>> checking --> son-emu-cli datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +0200134 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r895477d2016-06-29 14:38:05 +0200135 output = subprocess.check_output("son-emu-cli datacenter list", shell=True)
hadik3r895477d2016-06-29 14:38:05 +0200136 # check datacenter list result
hadik3r895477d2016-06-29 14:38:05 +0200137 self.assertTrue("datacenter0" in output)
138
139 print('->>>>> checking --> son-emu-cli datacenter status -d datacenter0 ->>>>>>>>')
hadik3r237d3f52016-06-27 17:57:49 +0200140 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
hadik3r895477d2016-06-29 14:38:05 +0200141 output = subprocess.check_output("son-emu-cli datacenter status -d datacenter0", shell=True)
hadik3r895477d2016-06-29 14:38:05 +0200142 # check datacenter status result
143 self.assertTrue("datacenter0" in output)
144
hadik3r237d3f52016-06-27 17:57:49 +0200145 self.stopNet()
146
147
148if __name__ == '__main__':
149 unittest.main()