blob: d552f1f8b5a25810c7daeb68e2a2f3a3e47f1f06 [file] [log] [blame]
peusterm94f53ae2016-01-15 12:32:53 +01001"""
2Test suite to automatically test emulator functionalities.
3Directly interacts with the emulator through the Mininet-like
4Python API.
5
6Does not test API endpoints. This is done in separated test suites.
7"""
8
peustermef070042016-03-14 16:12:37 +01009import time
peusterm94f53ae2016-01-15 12:32:53 +010010import unittest
cgeoffroy9524ad32016-03-03 18:24:15 +010011from emuvim.dcemulator.node import EmulatorCompute
peusterm41006b72016-03-12 12:13:06 +010012from emuvim.test.base import SimpleTestTopology
peusterm94f53ae2016-01-15 12:32:53 +010013
14
15#@unittest.skip("disabled topology tests for development")
peusterm41006b72016-03-12 12:13:06 +010016class testEmulatorTopology( SimpleTestTopology ):
peusterm94f53ae2016-01-15 12:32:53 +010017 """
18 Tests to check the topology API of the emulator.
19 """
20
21 def testSingleDatacenter(self):
22 """
23 Create a single data center and add check if its switch is up
24 by using manually added hosts. Tests especially the
25 data center specific addLink method.
26 """
27 # create network
28 self.createNet(nswitches=0, ndatacenter=1, nhosts=2, ndockers=0)
29 # setup links
30 self.net.addLink(self.dc[0], self.h[0])
31 self.net.addLink(self.h[1], self.dc[0])
32 # start Mininet network
33 self.startNet()
34 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +010035 assert(len(self.getDockernetContainers()) == 0)
peusterm94f53ae2016-01-15 12:32:53 +010036 assert(len(self.net.hosts) == 2)
37 assert(len(self.net.switches) == 1)
38 # check connectivity by using ping
39 assert(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
40 # stop Mininet network
41 self.stopNet()
42
peusterm0ca5d0e2016-03-14 16:46:01 +010043 @unittest.skip("disabled to test if CI fails because this is the first test.")
peusterm94f53ae2016-01-15 12:32:53 +010044 def testMultipleDatacenterDirect(self):
45 """
46 Create a two data centers and interconnect them.
47 """
48 # create network
49 self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
50 # 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])
54 # start Mininet network
55 self.startNet()
56 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +010057 assert(len(self.getDockernetContainers()) == 0)
peusterm94f53ae2016-01-15 12:32:53 +010058 assert(len(self.net.hosts) == 2)
59 assert(len(self.net.switches) == 2)
peustermef070042016-03-14 16:12:37 +010060 time.sleep(5)
peusterm94f53ae2016-01-15 12:32:53 +010061 # check connectivity by using ping
62 assert(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
63 # stop Mininet network
64 self.stopNet()
65
66 def testMultipleDatacenterWithIntermediateSwitches(self):
67 """
68 Create a two data centers and interconnect them with additional
69 switches between them.
70 """
71 # create network
72 self.createNet(
73 nswitches=3, ndatacenter=2, nhosts=2, ndockers=0,
74 autolinkswitches=True)
75 # setup links
76 self.net.addLink(self.dc[0], self.h[0])
77 self.net.addLink(self.h[1], self.dc[1])
78 self.net.addLink(self.dc[0], self.s[0])
79 self.net.addLink(self.s[2], self.dc[1])
80 # start Mininet network
81 self.startNet()
82 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +010083 assert(len(self.getDockernetContainers()) == 0)
peusterm94f53ae2016-01-15 12:32:53 +010084 assert(len(self.net.hosts) == 2)
85 assert(len(self.net.switches) == 5)
86 # check connectivity by using ping
87 assert(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
88 # stop Mininet network
89 self.stopNet()
90
91
92#@unittest.skip("disabled compute tests for development")
peusterm41006b72016-03-12 12:13:06 +010093class testEmulatorCompute( SimpleTestTopology ):
peusterm94f53ae2016-01-15 12:32:53 +010094 """
95 Tests to check the emulator's API to add and remove
96 compute resources at runtime.
97 """
98
99 def testAddSingleComputeSingleDC(self):
100 """
101 Adds a single compute instance to
102 a single DC and checks its connectivity with a
103 manually added host.
104 """
105 # create network
106 self.createNet(nswitches=0, ndatacenter=1, nhosts=1, ndockers=0)
107 # setup links
108 self.net.addLink(self.dc[0], self.h[0])
109 # start Mininet network
110 self.startNet()
111 # add compute resources
112 vnf1 = self.dc[0].startCompute("vnf1")
113 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100114 assert(len(self.getDockernetContainers()) == 1)
peusterm94f53ae2016-01-15 12:32:53 +0100115 assert(len(self.net.hosts) == 2)
116 assert(len(self.net.switches) == 1)
117 # check compute list result
118 assert(len(self.dc[0].listCompute()) == 1)
119 assert(isinstance(self.dc[0].listCompute()[0], EmulatorCompute))
120 assert(self.dc[0].listCompute()[0].name == "vnf1")
121 # check connectivity by using ping
122 assert(self.net.ping([self.h[0], vnf1]) <= 0.0)
123 # stop Mininet network
124 self.stopNet()
125
126 def testRemoveSingleComputeSingleDC(self):
127 """
128 Test stop method for compute instances.
129 Check that the instance is really removed.
130 """
131 # create network
132 self.createNet(nswitches=0, ndatacenter=1, nhosts=1, ndockers=0)
133 # setup links
134 self.net.addLink(self.dc[0], self.h[0])
135 # start Mininet network
136 self.startNet()
137 # add compute resources
138 vnf1 = self.dc[0].startCompute("vnf1")
139 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100140 assert(len(self.getDockernetContainers()) == 1)
peusterm94f53ae2016-01-15 12:32:53 +0100141 assert(len(self.net.hosts) == 2)
142 assert(len(self.net.switches) == 1)
143 # check compute list result
144 assert(len(self.dc[0].listCompute()) == 1)
145 # check connectivity by using ping
146 assert(self.net.ping([self.h[0], vnf1]) <= 0.0)
147 # remove compute resources
148 self.dc[0].stopCompute("vnf1")
149 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100150 assert(len(self.getDockernetContainers()) == 0)
peusterm94f53ae2016-01-15 12:32:53 +0100151 assert(len(self.net.hosts) == 1)
152 assert(len(self.net.switches) == 1)
153 # check compute list result
154 assert(len(self.dc[0].listCompute()) == 0)
155 # stop Mininet network
156 self.stopNet()
157
158 def testGetStatusSingleComputeSingleDC(self):
159 """
160 Check if the getStatus functionality of EmulatorCompute
161 objects works well.
162 """
163 # create network
164 self.createNet(nswitches=0, ndatacenter=1, nhosts=1, ndockers=0)
165 # setup links
166 self.net.addLink(self.dc[0], self.h[0])
167 # start Mininet network
168 self.startNet()
169 # add compute resources
170 vnf1 = self.dc[0].startCompute("vnf1")
171 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100172 assert(len(self.getDockernetContainers()) == 1)
peusterm94f53ae2016-01-15 12:32:53 +0100173 assert(len(self.net.hosts) == 2)
174 assert(len(self.net.switches) == 1)
175 # check compute list result
176 assert(len(self.dc[0].listCompute()) == 1)
177 assert(isinstance(self.dc[0].listCompute()[0], EmulatorCompute))
178 assert(self.dc[0].listCompute()[0].name == "vnf1")
179 # check connectivity by using ping
180 assert(self.net.ping([self.h[0], vnf1]) <= 0.0)
181 # check get status
182 s = self.dc[0].containers.get("vnf1").getStatus()
183 assert(s["name"] == "vnf1")
184 assert(s["state"]["Running"])
185 # stop Mininet network
186 self.stopNet()
187
188 def testConnectivityMultiDC(self):
189 """
190 Test if compute instances started in different data centers
191 are able to talk to each other.
192 """
193 # create network
194 self.createNet(
195 nswitches=3, ndatacenter=2, nhosts=0, ndockers=0,
196 autolinkswitches=True)
197 # setup links
198 self.net.addLink(self.dc[0], self.s[0])
199 self.net.addLink(self.dc[1], self.s[2])
200 # start Mininet network
201 self.startNet()
202 # add compute resources
203 vnf1 = self.dc[0].startCompute("vnf1")
204 vnf2 = self.dc[1].startCompute("vnf2")
205 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100206 assert(len(self.getDockernetContainers()) == 2)
peusterm94f53ae2016-01-15 12:32:53 +0100207 assert(len(self.net.hosts) == 2)
208 assert(len(self.net.switches) == 5)
209 # check compute list result
210 assert(len(self.dc[0].listCompute()) == 1)
211 assert(len(self.dc[1].listCompute()) == 1)
212 # check connectivity by using ping
213 assert(self.net.ping([vnf1, vnf2]) <= 0.0)
214 # stop Mininet network
215 self.stopNet()
216
217 def testInterleavedAddRemoveMultiDC(self):
218 """
219 Test multiple, interleaved add and remove operations and ensure
220 that always all expected compute instances are reachable.
221 """
222 # create network
223 self.createNet(
224 nswitches=3, ndatacenter=2, nhosts=0, ndockers=0,
225 autolinkswitches=True)
226 # setup links
227 self.net.addLink(self.dc[0], self.s[0])
228 self.net.addLink(self.dc[1], self.s[2])
229 # start Mininet network
230 self.startNet()
231 # add compute resources
232 vnf1 = self.dc[0].startCompute("vnf1")
233 vnf2 = self.dc[1].startCompute("vnf2")
234 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100235 assert(len(self.getDockernetContainers()) == 2)
peusterm94f53ae2016-01-15 12:32:53 +0100236 assert(len(self.net.hosts) == 2)
237 assert(len(self.net.switches) == 5)
238 # check compute list result
239 assert(len(self.dc[0].listCompute()) == 1)
240 assert(len(self.dc[1].listCompute()) == 1)
241 # check connectivity by using ping
242 assert(self.net.ping([vnf1, vnf2]) <= 0.0)
243 # remove compute resources
244 self.dc[0].stopCompute("vnf1")
245 # check number of running nodes
cgeoffroycf350382016-03-02 16:39:58 +0100246 assert(len(self.getDockernetContainers()) == 1)
peusterm94f53ae2016-01-15 12:32:53 +0100247 assert(len(self.net.hosts) == 1)
248 assert(len(self.net.switches) == 5)
249 # check compute list result
250 assert(len(self.dc[0].listCompute()) == 0)
251 assert(len(self.dc[1].listCompute()) == 1)
252 # add compute resources
253 vnf3 = self.dc[0].startCompute("vnf3")
254 vnf4 = self.dc[0].startCompute("vnf4")
255 # check compute list result
256 assert(len(self.dc[0].listCompute()) == 2)
257 assert(len(self.dc[1].listCompute()) == 1)
258 assert(self.net.ping([vnf3, vnf2]) <= 0.0)
259 assert(self.net.ping([vnf4, vnf2]) <= 0.0)
260 # remove compute resources
261 self.dc[0].stopCompute("vnf3")
262 self.dc[0].stopCompute("vnf4")
263 self.dc[1].stopCompute("vnf2")
264 # check compute list result
265 assert(len(self.dc[0].listCompute()) == 0)
266 assert(len(self.dc[1].listCompute()) == 0)
267 # stop Mininet network
268 self.stopNet()
269
270if __name__ == '__main__':
271 unittest.main()