2 Test suite to automatically test emulator functionalities.
3 Directly interacts with the emulator through the Mininet-like
6 Does not test API endpoints. This is done in separated test suites.
11 from emuvim
.dcemulator
.node
import EmulatorCompute
12 from emuvim
.test
.base
import SimpleTestTopology
15 #@unittest.skip("disabled topology tests for development")
16 class testEmulatorTopology( SimpleTestTopology
):
18 Tests to check the topology API of the emulator.
21 def testSingleDatacenter(self
):
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.
28 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
30 self
.net
.addLink(self
.dc
[0], self
.h
[0])
31 self
.net
.addLink(self
.h
[1], self
.dc
[0])
32 # start Mininet network
34 # check number of running nodes
35 assert(len(self
.getDockernetContainers()) == 0)
36 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
43 @unittest.skip("disabled to test if CI fails because this is the first test.")
44 def testMultipleDatacenterDirect(self
):
46 Create a two data centers and interconnect them.
49 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
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
56 # check number of running nodes
57 assert(len(self
.getDockernetContainers()) == 0)
58 assert(len(self
.net
.hosts
) == 2)
59 assert(len(self
.net
.switches
) == 2)
61 # check connectivity by using ping
62 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
63 # stop Mininet network
66 def testMultipleDatacenterWithIntermediateSwitches(self
):
68 Create a two data centers and interconnect them with additional
69 switches between them.
73 nswitches
=3, ndatacenter
=2, nhosts
=2, ndockers
=0,
74 autolinkswitches
=True)
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
82 # check number of running nodes
83 assert(len(self
.getDockernetContainers()) == 0)
84 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
92 #@unittest.skip("disabled compute tests for development")
93 class testEmulatorCompute( SimpleTestTopology
):
95 Tests to check the emulator's API to add and remove
96 compute resources at runtime.
99 def testAddSingleComputeSingleDC(self
):
101 Adds a single compute instance to
102 a single DC and checks its connectivity with a
106 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
108 self
.net
.addLink(self
.dc
[0], self
.h
[0])
109 # start Mininet network
111 # add compute resources
112 vnf1
= self
.dc
[0].startCompute("vnf1")
113 # check number of running nodes
114 assert(len(self
.getDockernetContainers()) == 1)
115 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
126 def testRemoveSingleComputeSingleDC(self
):
128 Test stop method for compute instances.
129 Check that the instance is really removed.
132 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
134 self
.net
.addLink(self
.dc
[0], self
.h
[0])
135 # start Mininet network
137 # add compute resources
138 vnf1
= self
.dc
[0].startCompute("vnf1")
139 # check number of running nodes
140 assert(len(self
.getDockernetContainers()) == 1)
141 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
150 assert(len(self
.getDockernetContainers()) == 0)
151 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
158 def testGetStatusSingleComputeSingleDC(self
):
160 Check if the getStatus functionality of EmulatorCompute
164 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
166 self
.net
.addLink(self
.dc
[0], self
.h
[0])
167 # start Mininet network
169 # add compute resources
170 vnf1
= self
.dc
[0].startCompute("vnf1")
171 # check number of running nodes
172 assert(len(self
.getDockernetContainers()) == 1)
173 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)
182 s
= self
.dc
[0].containers
.get("vnf1").getStatus()
183 assert(s
["name"] == "vnf1")
184 assert(s
["state"]["Running"])
185 # stop Mininet network
188 def testConnectivityMultiDC(self
):
190 Test if compute instances started in different data centers
191 are able to talk to each other.
195 nswitches
=3, ndatacenter
=2, nhosts
=0, ndockers
=0,
196 autolinkswitches
=True)
198 self
.net
.addLink(self
.dc
[0], self
.s
[0])
199 self
.net
.addLink(self
.dc
[1], self
.s
[2])
200 # start Mininet network
202 # add compute resources
203 vnf1
= self
.dc
[0].startCompute("vnf1")
204 vnf2
= self
.dc
[1].startCompute("vnf2")
205 # check number of running nodes
206 assert(len(self
.getDockernetContainers()) == 2)
207 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
217 def testInterleavedAddRemoveMultiDC(self
):
219 Test multiple, interleaved add and remove operations and ensure
220 that always all expected compute instances are reachable.
224 nswitches
=3, ndatacenter
=2, nhosts
=0, ndockers
=0,
225 autolinkswitches
=True)
227 self
.net
.addLink(self
.dc
[0], self
.s
[0])
228 self
.net
.addLink(self
.dc
[1], self
.s
[2])
229 # start Mininet network
231 # add compute resources
232 vnf1
= self
.dc
[0].startCompute("vnf1")
233 vnf2
= self
.dc
[1].startCompute("vnf2")
234 # check number of running nodes
235 assert(len(self
.getDockernetContainers()) == 2)
236 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
246 assert(len(self
.getDockernetContainers()) == 1)
247 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
270 if __name__
== '__main__':