2 # -*- coding: utf-8 -*-
5 from nepi.util.constants import STATUS_FINISHED
6 from nepi.testbeds import planetlab
15 class PlanetLabExecuteTestCase(unittest.TestCase):
17 self.root_dir = tempfile.mkdtemp()
20 shutil.rmtree(self.root_dir)
22 def make_instance(self):
23 testbed_version = "01"
24 instance = planetlab.TestbedController(testbed_version)
25 slicename = "inria_nepi12"
26 pl_ssh_key = os.environ.get(
28 "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
29 pl_user, pl_pwd = test_util.pl_auth()
31 instance.defer_configure("homeDirectory", self.root_dir)
32 instance.defer_configure("slice", slicename)
33 instance.defer_configure("sliceSSHKey", pl_ssh_key)
34 instance.defer_configure("authUser", pl_user)
35 instance.defer_configure("authPass", pl_pwd)
39 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
40 def test_simple(self):
41 instance = self.make_instance()
43 instance.defer_create(2, "Node")
44 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
45 instance.defer_create(3, "Node")
46 instance.defer_create_set(3, "hostname", "onelab10.pl.sophia.inria.fr")
47 instance.defer_create(4, "NodeInterface")
48 instance.defer_connect(2, "devs", 4, "node")
49 instance.defer_create(5, "NodeInterface")
50 instance.defer_connect(3, "devs", 5, "node")
51 instance.defer_create(6, "Internet")
52 instance.defer_connect(4, "inet", 6, "devs")
53 instance.defer_connect(5, "inet", 6, "devs")
54 instance.defer_create(7, "Application")
55 instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
56 instance.defer_add_trace(7, "stdout")
57 instance.defer_add_trace(7, "stderr")
58 instance.defer_connect(7, "node", 2, "apps")
60 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
62 --- .* ping statistics ---
63 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
69 instance.do_connect_init()
70 instance.do_connect_compl()
71 instance.do_preconfigure()
73 # Manually replace netref
74 instance.set(7, "command",
75 instance.get(7, "command")
76 .replace("{#[GUID-5].addr[0].[Address]#}",
77 instance.get_address(5, 0, "Address") )
80 instance.do_configure()
83 while instance.status(7) != STATUS_FINISHED:
85 ping_result = instance.trace(7, "stdout") or ""
90 # asserts at the end, to make sure there's proper cleanup
91 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
92 "Unexpected trace:\n" + ping_result)
94 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
95 def test_depends(self):
96 instance = self.make_instance()
98 instance.defer_create(2, "Node")
99 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
100 instance.defer_create(3, "NodeInterface")
101 instance.defer_connect(2, "devs", 3, "node")
102 instance.defer_create(4, "Internet")
103 instance.defer_connect(3, "inet", 4, "devs")
104 instance.defer_create(5, "Application")
105 instance.defer_create_set(5, "command", "gfortran --version")
106 instance.defer_create_set(5, "depends", "gcc-gfortran")
107 instance.defer_add_trace(5, "stdout")
108 instance.defer_add_trace(5, "stderr")
109 instance.defer_connect(5, "node", 2, "apps")
114 instance.do_connect_init()
115 instance.do_connect_compl()
116 instance.do_preconfigure()
117 instance.do_configure()
120 while instance.status(5) != STATUS_FINISHED:
122 ping_result = instance.trace(5, "stdout") or ""
123 comp_result = r".*GNU Fortran \(GCC\).*"
128 # asserts at the end, to make sure there's proper cleanup
129 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
130 "Unexpected trace:\n" + ping_result)
132 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
133 def test_build(self):
134 instance = self.make_instance()
136 instance.defer_create(2, "Node")
137 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
138 instance.defer_create(3, "NodeInterface")
139 instance.defer_connect(2, "devs", 3, "node")
140 instance.defer_create(4, "Internet")
141 instance.defer_connect(3, "inet", 4, "devs")
142 instance.defer_create(10, "Application")
143 instance.defer_create_set(10, "command", "./consts")
144 instance.defer_create_set(10, "buildDepends", "gcc")
145 instance.defer_create_set(10, "build", "gcc ${SOURCES}/consts.c -o consts")
146 instance.defer_create_set(10, "install", "cp consts ${SOURCES}/consts")
147 instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
148 instance.defer_add_trace(10, "stdout")
149 instance.defer_add_trace(10, "stderr")
150 instance.defer_connect(10, "node", 2, "apps")
153 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
154 ETH_P_IP = 0x[0-9a-fA-F]{8}
155 TUNSETIFF = 0x[0-9a-fA-F]{8}
156 IFF_NO_PI = 0x[0-9a-fA-F]{8}
157 IFF_TAP = 0x[0-9a-fA-F]{8}
158 IFF_TUN = 0x[0-9a-fA-F]{8}
159 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
160 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
161 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
162 IFNAMSIZ = 0x[0-9a-fA-F]{8}
163 IFREQ_SZ = 0x[0-9a-fA-F]{8}
164 FIONREAD = 0x[0-9a-fA-F]{8}.*
170 instance.do_connect_init()
171 instance.do_connect_compl()
172 instance.do_preconfigure()
173 instance.do_configure()
176 while instance.status(10) != STATUS_FINISHED:
178 ping_result = instance.trace(10, "stdout") or ""
183 # asserts at the end, to make sure there's proper cleanup
184 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
185 "Unexpected trace:\n" + ping_result)
187 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
188 def test_simple_vsys(self):
189 instance = self.make_instance()
191 instance.defer_create(2, "Node")
192 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
193 instance.defer_create_set(2, "emulation", True) # require emulation
194 instance.defer_create(3, "NodeInterface")
195 instance.defer_connect(2, "devs", 3, "node")
196 instance.defer_create(4, "Internet")
197 instance.defer_connect(3, "inet", 4, "devs")
198 instance.defer_create(5, "TunInterface")
199 instance.defer_add_address(5, "192.168.2.2", 24, False)
200 instance.defer_connect(2, "devs", 5, "node")
201 instance.defer_create(6, "Application")
202 instance.defer_create_set(6, "command", """
204 netconfig help > /dev/null
205 test -e /vsys/vif_up.in > /dev/null
206 test -e /vsys/vif_up.out > /dev/null
207 test -e /vsys/fd_tuntap.control > /dev/null
210 instance.defer_create_set(6, "sudo", True) # only sudo has access to /vsys
211 instance.defer_add_trace(6, "stdout")
212 instance.defer_add_trace(6, "stderr")
213 instance.defer_connect(6, "node", 2, "apps")
218 instance.do_connect_init()
219 instance.do_connect_compl()
220 instance.do_preconfigure()
221 instance.do_configure()
224 while instance.status(6) != STATUS_FINISHED:
226 test_result = (instance.trace(6, "stdout") or "").strip()
227 comp_result = "OKIDOKI"
232 # asserts at the end, to make sure there's proper cleanup
233 self.assertEqual(comp_result, test_result)
235 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
236 def test_emulation(self):
237 instance = self.make_instance()
239 instance.defer_create(2, "Node")
240 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
241 instance.defer_create_set(2, "emulation", True) # require emulation
242 instance.defer_create(3, "NodeInterface")
243 instance.defer_connect(2, "devs", 3, "node")
244 instance.defer_create(4, "Internet")
245 instance.defer_connect(3, "inet", 4, "devs")
246 instance.defer_create(7, "NetPipe")
247 instance.defer_create_set(7, "mode", "CLIENT")
248 instance.defer_create_set(7, "portList", "80")
249 instance.defer_create_set(7, "bwOut", 12.0/1024.0) # 12kbps
250 instance.defer_create_set(7, "bwIn", 64.0/1024.0) # 64kbps
251 instance.defer_create_set(7, "plrOut", 0.01) # 1% plr outbound - high loss
252 instance.defer_create_set(7, "plrIn", 0.001) # 0.1% plr inbound - regular loss
253 instance.defer_create_set(7, "delayOut", int(1500 * 8 / (12.0/1024.0) / 1000)) # tx delay at 12kbps in ms
254 instance.defer_create_set(7, "delayIn", int(1500 * 8 / (64.0/1024.0) / 1000)) # rx delay at 64kbps in ms
255 instance.defer_add_trace(7, "netpipeStats")
256 instance.defer_connect(2, "pipes", 7, "node")
257 instance.defer_create(8, "Application")
258 instance.defer_create_set(8, "command", "time wget -q -O /dev/null http://www.google.com/") # Fetch ~10kb
259 instance.defer_add_trace(8, "stdout")
260 instance.defer_add_trace(8, "stderr")
261 instance.defer_connect(8, "node", 2, "apps")
266 instance.do_connect_init()
267 instance.do_connect_compl()
268 instance.do_preconfigure()
269 instance.do_configure()
272 while instance.status(8) != STATUS_FINISHED:
274 test_result = (instance.trace(8, "stderr") or "").strip()
275 comp_result = r".*real\s*(?P<min>[0-9]+)m(?P<sec>[0-9]+[.][0-9]+)s.*"
276 netpipe_stats = instance.trace(7, "netpipeStats")
282 # asserts at the end, to make sure there's proper cleanup
283 match = re.match(comp_result, test_result, re.MULTILINE)
284 self.assertTrue(match, "Unexpected output: %s" % (test_result,))
286 minutes = int(match.group("min"))
287 seconds = float(match.group("sec"))
288 self.assertTrue((minutes * 60 + seconds) > 1.0, "Emulation not effective: %s" % (test_result,))
290 self.assertTrue(netpipe_stats, "Unavailable netpipe stats")
292 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
293 def test_tun_emulation_requirement(self):
294 instance = self.make_instance()
296 instance.defer_create(2, "Node")
297 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
298 instance.defer_create(3, "NodeInterface")
299 instance.defer_connect(2, "devs", 3, "node")
300 instance.defer_create(4, "Internet")
301 instance.defer_connect(3, "inet", 4, "devs")
302 instance.defer_create(5, "TunInterface")
303 instance.defer_add_address(5, "192.168.2.2", 24, False)
304 instance.defer_connect(2, "devs", 5, "node")
305 instance.defer_create(6, "Application")
306 instance.defer_create_set(6, "command", "false")
307 instance.defer_add_trace(6, "stdout")
308 instance.defer_add_trace(6, "stderr")
309 instance.defer_connect(6, "node", 2, "apps")
314 instance.do_connect_init()
315 instance.do_connect_compl()
316 instance.do_preconfigure()
317 instance.do_configure()
318 self.fail("Usage of TUN without emulation should fail")
322 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
323 def test_tun_ping(self):
324 instance = self.make_instance()
326 instance.defer_create(2, "Node")
327 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
328 instance.defer_create_set(2, "emulation", True) # require emulation
329 instance.defer_create(3, "Node")
330 instance.defer_create_set(3, "hostname", "onelab10.pl.sophia.inria.fr")
331 instance.defer_create_set(3, "emulation", True) # require emulation
332 instance.defer_create(4, "NodeInterface")
333 instance.defer_connect(2, "devs", 4, "node")
334 instance.defer_create(5, "Internet")
335 instance.defer_connect(4, "inet", 5, "devs")
336 instance.defer_create(6, "NodeInterface")
337 instance.defer_connect(3, "devs", 6, "node")
338 instance.defer_connect(6, "inet", 5, "devs")
339 instance.defer_create(7, "TunInterface")
340 instance.defer_add_address(7, "192.168.2.2", 24, False)
341 instance.defer_connect(2, "devs", 7, "node")
342 instance.defer_create(8, "TunInterface")
343 instance.defer_add_address(8, "192.168.2.3", 24, False)
344 instance.defer_connect(3, "devs", 8, "node")
345 instance.defer_connect(7, "tcp", 8, "tcp")
346 instance.defer_create(9, "Application")
347 instance.defer_create_set(9, "command", "ping -qc1 {#[GUID-8].addr[0].[Address]#}")
348 instance.defer_add_trace(9, "stdout")
349 instance.defer_add_trace(9, "stderr")
350 instance.defer_connect(9, "node", 2, "apps")
352 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
354 --- .* ping statistics ---
355 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
361 instance.do_connect_init()
362 instance.do_connect_compl()
363 instance.do_preconfigure()
365 # Manually replace netref
366 instance.set(9, "command",
367 instance.get(9, "command")
368 .replace("{#[GUID-8].addr[0].[Address]#}",
369 instance.get_address(8, 0, "Address") )
372 instance.do_configure()
375 while instance.status(9) != STATUS_FINISHED:
377 ping_result = instance.trace(9, "stdout") or ""
382 # asserts at the end, to make sure there's proper cleanup
383 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
384 "Unexpected trace:\n" + ping_result)
386 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
387 def test_nepi_depends(self):
388 instance = self.make_instance()
390 instance.defer_create(2, "Node")
391 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
392 instance.defer_create(3, "NodeInterface")
393 instance.defer_connect(2, "devs", 3, "node")
394 instance.defer_create(4, "Internet")
395 instance.defer_connect(3, "inet", 4, "devs")
396 instance.defer_create(5, "NepiDependency")
397 instance.defer_connect(5, "node", 2, "deps")
398 instance.defer_create(12, "Application")
399 instance.defer_connect(12, "node", 2, "apps")
400 instance.defer_create_set(12, "command", "python -c 'import nepi'")
401 instance.defer_add_trace(12, "stderr")
406 instance.do_connect_init()
407 instance.do_connect_compl()
408 instance.do_preconfigure()
409 instance.do_configure()
412 while instance.status(12) != STATUS_FINISHED:
414 ping_result = (instance.trace(12, "stderr") or "").strip()
419 # asserts at the end, to make sure there's proper cleanup
420 self.assertEqual(ping_result, "")
423 if __name__ == '__main__':