905b1c6014da70bc33413627da2accd326d3e27c
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.
10 from emuvim
.dcemulator
.node
import EmulatorCompute
11 from emuvim
.test
.base
import SimpleTestTopology
14 #@unittest.skip("disabled topology tests for development")
15 class testEmulatorTopology( SimpleTestTopology
):
17 Tests to check the topology API of the emulator.
20 def testSingleDatacenter(self
):
22 Create a single data center and add check if its switch is up
23 by using manually added hosts. Tests especially the
24 data center specific addLink method.
27 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=2, ndockers
=0)
29 self
.net
.addLink(self
.dc
[0], self
.h
[0])
30 self
.net
.addLink(self
.h
[1], self
.dc
[0])
31 # start Mininet network
33 # check number of running nodes
34 assert(len(self
.getDockernetContainers()) == 0)
35 assert(len(self
.net
.hosts
) == 2)
36 assert(len(self
.net
.switches
) == 1)
37 # check connectivity by using ping
38 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
39 # stop Mininet network
42 def testMultipleDatacenterDirect(self
):
44 Create a two data centers and interconnect them.
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
.h
[1], self
.dc
[1])
51 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
52 # start Mininet network
54 # check number of running nodes
55 assert(len(self
.getDockernetContainers()) == 0)
56 assert(len(self
.net
.hosts
) == 2)
57 assert(len(self
.net
.switches
) == 2)
58 # check connectivity by using ping
59 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
60 # stop Mininet network
63 def testMultipleDatacenterWithIntermediateSwitches(self
):
65 Create a two data centers and interconnect them with additional
66 switches between them.
70 nswitches
=3, ndatacenter
=2, nhosts
=2, ndockers
=0,
71 autolinkswitches
=True)
73 self
.net
.addLink(self
.dc
[0], self
.h
[0])
74 self
.net
.addLink(self
.h
[1], self
.dc
[1])
75 self
.net
.addLink(self
.dc
[0], self
.s
[0])
76 self
.net
.addLink(self
.s
[2], self
.dc
[1])
77 # start Mininet network
79 # check number of running nodes
80 assert(len(self
.getDockernetContainers()) == 0)
81 assert(len(self
.net
.hosts
) == 2)
82 assert(len(self
.net
.switches
) == 5)
83 # check connectivity by using ping
84 assert(self
.net
.ping([self
.h
[0], self
.h
[1]]) <= 0.0)
85 # stop Mininet network
89 #@unittest.skip("disabled compute tests for development")
90 class testEmulatorCompute( SimpleTestTopology
):
92 Tests to check the emulator's API to add and remove
93 compute resources at runtime.
96 def testAddSingleComputeSingleDC(self
):
98 Adds a single compute instance to
99 a single DC and checks its connectivity with a
103 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
105 self
.net
.addLink(self
.dc
[0], self
.h
[0])
106 # start Mininet network
108 # add compute resources
109 vnf1
= self
.dc
[0].startCompute("vnf1")
110 # check number of running nodes
111 assert(len(self
.getDockernetContainers()) == 1)
112 assert(len(self
.net
.hosts
) == 2)
113 assert(len(self
.net
.switches
) == 1)
114 # check compute list result
115 assert(len(self
.dc
[0].listCompute()) == 1)
116 assert(isinstance(self
.dc
[0].listCompute()[0], EmulatorCompute
))
117 assert(self
.dc
[0].listCompute()[0].name
== "vnf1")
118 # check connectivity by using ping
119 assert(self
.net
.ping([self
.h
[0], vnf1
]) <= 0.0)
120 # stop Mininet network
123 def testRemoveSingleComputeSingleDC(self
):
125 Test stop method for compute instances.
126 Check that the instance is really removed.
129 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
131 self
.net
.addLink(self
.dc
[0], self
.h
[0])
132 # start Mininet network
134 # add compute resources
135 vnf1
= self
.dc
[0].startCompute("vnf1")
136 # check number of running nodes
137 assert(len(self
.getDockernetContainers()) == 1)
138 assert(len(self
.net
.hosts
) == 2)
139 assert(len(self
.net
.switches
) == 1)
140 # check compute list result
141 assert(len(self
.dc
[0].listCompute()) == 1)
142 # check connectivity by using ping
143 assert(self
.net
.ping([self
.h
[0], vnf1
]) <= 0.0)
144 # remove compute resources
145 self
.dc
[0].stopCompute("vnf1")
146 # check number of running nodes
147 assert(len(self
.getDockernetContainers()) == 0)
148 assert(len(self
.net
.hosts
) == 1)
149 assert(len(self
.net
.switches
) == 1)
150 # check compute list result
151 assert(len(self
.dc
[0].listCompute()) == 0)
152 # stop Mininet network
155 def testGetStatusSingleComputeSingleDC(self
):
157 Check if the getStatus functionality of EmulatorCompute
161 self
.createNet(nswitches
=0, ndatacenter
=1, nhosts
=1, ndockers
=0)
163 self
.net
.addLink(self
.dc
[0], self
.h
[0])
164 # start Mininet network
166 # add compute resources
167 vnf1
= self
.dc
[0].startCompute("vnf1")
168 # check number of running nodes
169 assert(len(self
.getDockernetContainers()) == 1)
170 assert(len(self
.net
.hosts
) == 2)
171 assert(len(self
.net
.switches
) == 1)
172 # check compute list result
173 assert(len(self
.dc
[0].listCompute()) == 1)
174 assert(isinstance(self
.dc
[0].listCompute()[0], EmulatorCompute
))
175 assert(self
.dc
[0].listCompute()[0].name
== "vnf1")
176 # check connectivity by using ping
177 assert(self
.net
.ping([self
.h
[0], vnf1
]) <= 0.0)
179 s
= self
.dc
[0].containers
.get("vnf1").getStatus()
180 assert(s
["name"] == "vnf1")
181 assert(s
["state"]["Running"])
182 # stop Mininet network
185 def testConnectivityMultiDC(self
):
187 Test if compute instances started in different data centers
188 are able to talk to each other.
192 nswitches
=3, ndatacenter
=2, nhosts
=0, ndockers
=0,
193 autolinkswitches
=True)
195 self
.net
.addLink(self
.dc
[0], self
.s
[0])
196 self
.net
.addLink(self
.dc
[1], self
.s
[2])
197 # start Mininet network
199 # add compute resources
200 vnf1
= self
.dc
[0].startCompute("vnf1")
201 vnf2
= self
.dc
[1].startCompute("vnf2")
202 # check number of running nodes
203 assert(len(self
.getDockernetContainers()) == 2)
204 assert(len(self
.net
.hosts
) == 2)
205 assert(len(self
.net
.switches
) == 5)
206 # check compute list result
207 assert(len(self
.dc
[0].listCompute()) == 1)
208 assert(len(self
.dc
[1].listCompute()) == 1)
209 # check connectivity by using ping
210 assert(self
.net
.ping([vnf1
, vnf2
]) <= 0.0)
211 # stop Mininet network
214 def testInterleavedAddRemoveMultiDC(self
):
216 Test multiple, interleaved add and remove operations and ensure
217 that always all expected compute instances are reachable.
221 nswitches
=3, ndatacenter
=2, nhosts
=0, ndockers
=0,
222 autolinkswitches
=True)
224 self
.net
.addLink(self
.dc
[0], self
.s
[0])
225 self
.net
.addLink(self
.dc
[1], self
.s
[2])
226 # start Mininet network
228 # add compute resources
229 vnf1
= self
.dc
[0].startCompute("vnf1")
230 vnf2
= self
.dc
[1].startCompute("vnf2")
231 # check number of running nodes
232 assert(len(self
.getDockernetContainers()) == 2)
233 assert(len(self
.net
.hosts
) == 2)
234 assert(len(self
.net
.switches
) == 5)
235 # check compute list result
236 assert(len(self
.dc
[0].listCompute()) == 1)
237 assert(len(self
.dc
[1].listCompute()) == 1)
238 # check connectivity by using ping
239 assert(self
.net
.ping([vnf1
, vnf2
]) <= 0.0)
240 # remove compute resources
241 self
.dc
[0].stopCompute("vnf1")
242 # check number of running nodes
243 assert(len(self
.getDockernetContainers()) == 1)
244 assert(len(self
.net
.hosts
) == 1)
245 assert(len(self
.net
.switches
) == 5)
246 # check compute list result
247 assert(len(self
.dc
[0].listCompute()) == 0)
248 assert(len(self
.dc
[1].listCompute()) == 1)
249 # add compute resources
250 vnf3
= self
.dc
[0].startCompute("vnf3")
251 vnf4
= self
.dc
[0].startCompute("vnf4")
252 # check compute list result
253 assert(len(self
.dc
[0].listCompute()) == 2)
254 assert(len(self
.dc
[1].listCompute()) == 1)
255 assert(self
.net
.ping([vnf3
, vnf2
]) <= 0.0)
256 assert(self
.net
.ping([vnf4
, vnf2
]) <= 0.0)
257 # remove compute resources
258 self
.dc
[0].stopCompute("vnf3")
259 self
.dc
[0].stopCompute("vnf4")
260 self
.dc
[1].stopCompute("vnf2")
261 # check compute list result
262 assert(len(self
.dc
[0].listCompute()) == 0)
263 assert(len(self
.dc
[1].listCompute()) == 0)
264 # stop Mininet network
267 if __name__
== '__main__':