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()
21 shutil.rmtree(self.root_dir)
25 shutil.rmtree(self.root_dir)
27 def make_instance(self):
28 testbed_version = "01"
29 instance = planetlab.TestbedController(testbed_version)
30 slicename = "inria_nepi12"
31 pl_ssh_key = os.environ.get(
33 "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
34 pl_user, pl_pwd = test_util.pl_auth()
36 instance.defer_configure("homeDirectory", self.root_dir)
37 instance.defer_configure("slice", slicename)
38 instance.defer_configure("sliceSSHKey", pl_ssh_key)
39 instance.defer_configure("authUser", pl_user)
40 instance.defer_configure("authPass", pl_pwd)
44 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
45 def test_simple(self):
46 instance = self.make_instance()
48 instance.defer_create(2, "Node")
49 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
50 instance.defer_create(3, "Node")
51 instance.defer_create_set(3, "hostname", "onelab10.pl.sophia.inria.fr")
52 instance.defer_create(4, "NodeInterface")
53 instance.defer_connect(2, "devs", 4, "node")
54 instance.defer_create(5, "NodeInterface")
55 instance.defer_connect(3, "devs", 5, "node")
56 instance.defer_create(6, "Internet")
57 instance.defer_connect(4, "inet", 6, "devs")
58 instance.defer_connect(5, "inet", 6, "devs")
59 instance.defer_create(7, "Application")
60 instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
61 instance.defer_add_trace(7, "stdout")
62 instance.defer_add_trace(7, "stderr")
63 instance.defer_connect(7, "node", 2, "apps")
65 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
67 --- .* ping statistics ---
68 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
74 instance.do_connect_init()
75 instance.do_connect_compl()
76 instance.do_preconfigure()
78 # Manually replace netref
79 instance.set(7, "command",
80 instance.get(7, "command")
81 .replace("{#[GUID-5].addr[0].[Address]#}",
82 instance.get_address(5, 0, "Address") )
85 instance.do_configure()
88 while instance.status(7) != STATUS_FINISHED:
90 ping_result = instance.trace(7, "stdout") or ""
95 # asserts at the end, to make sure there's proper cleanup
96 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
97 "Unexpected trace:\n" + ping_result)
99 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
100 def test_depends(self):
101 instance = self.make_instance()
103 instance.defer_create(2, "Node")
104 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
105 instance.defer_create(3, "NodeInterface")
106 instance.defer_connect(2, "devs", 3, "node")
107 instance.defer_create(4, "Internet")
108 instance.defer_connect(3, "inet", 4, "devs")
109 instance.defer_create(5, "Application")
110 instance.defer_create_set(5, "command", "gfortran --version")
111 instance.defer_create_set(5, "depends", "gcc-gfortran")
112 instance.defer_add_trace(5, "stdout")
113 instance.defer_add_trace(5, "stderr")
114 instance.defer_connect(5, "node", 2, "apps")
119 instance.do_connect_init()
120 instance.do_connect_compl()
121 instance.do_preconfigure()
122 instance.do_configure()
125 while instance.status(5) != STATUS_FINISHED:
127 ping_result = instance.trace(5, "stdout") or ""
128 comp_result = r".*GNU Fortran \(GCC\).*"
133 # asserts at the end, to make sure there's proper cleanup
134 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
135 "Unexpected trace:\n" + ping_result)
137 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
138 def test_build(self):
139 instance = self.make_instance()
141 instance.defer_create(2, "Node")
142 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
143 instance.defer_create(3, "NodeInterface")
144 instance.defer_connect(2, "devs", 3, "node")
145 instance.defer_create(4, "Internet")
146 instance.defer_connect(3, "inet", 4, "devs")
147 instance.defer_create(10, "Application")
148 instance.defer_create_set(10, "command", "./consts")
149 instance.defer_create_set(10, "buildDepends", "gcc")
150 instance.defer_create_set(10, "build", "gcc ${SOURCES}/consts.c -o consts")
151 instance.defer_create_set(10, "install", "cp consts ${SOURCES}/consts")
152 instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
153 instance.defer_add_trace(10, "stdout")
154 instance.defer_add_trace(10, "stderr")
155 instance.defer_connect(10, "node", 2, "apps")
158 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
159 ETH_P_IP = 0x[0-9a-fA-F]{8}
160 TUNSETIFF = 0x[0-9a-fA-F]{8}
161 IFF_NO_PI = 0x[0-9a-fA-F]{8}
162 IFF_TAP = 0x[0-9a-fA-F]{8}
163 IFF_TUN = 0x[0-9a-fA-F]{8}
164 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
165 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
166 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
167 IFNAMSIZ = 0x[0-9a-fA-F]{8}
168 IFREQ_SZ = 0x[0-9a-fA-F]{8}
169 FIONREAD = 0x[0-9a-fA-F]{8}.*
175 instance.do_connect_init()
176 instance.do_connect_compl()
177 instance.do_preconfigure()
178 instance.do_configure()
181 while instance.status(10) != STATUS_FINISHED:
183 ping_result = instance.trace(10, "stdout") or ""
188 # asserts at the end, to make sure there's proper cleanup
189 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
190 "Unexpected trace:\n" + ping_result)
192 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
193 def test_simple_vsys(self):
194 instance = self.make_instance()
196 instance.defer_create(2, "Node")
197 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
198 instance.defer_create_set(2, "emulation", True) # require emulation
199 instance.defer_create(3, "NodeInterface")
200 instance.defer_connect(2, "devs", 3, "node")
201 instance.defer_create(4, "Internet")
202 instance.defer_connect(3, "inet", 4, "devs")
203 instance.defer_create(5, "TunInterface")
204 instance.defer_add_address(5, "192.168.2.2", 24, False)
205 instance.defer_connect(2, "devs", 5, "node")
206 instance.defer_create(6, "Application")
207 instance.defer_create_set(6, "command", """
209 netconfig help > /dev/null
210 test -e /vsys/vif_up.in > /dev/null
211 test -e /vsys/vif_up.out > /dev/null
212 test -e /vsys/fd_tuntap.control > /dev/null
215 instance.defer_create_set(6, "sudo", True) # only sudo has access to /vsys
216 instance.defer_add_trace(6, "stdout")
217 instance.defer_add_trace(6, "stderr")
218 instance.defer_connect(6, "node", 2, "apps")
223 instance.do_connect_init()
224 instance.do_connect_compl()
225 instance.do_preconfigure()
226 instance.do_configure()
229 while instance.status(6) != STATUS_FINISHED:
231 test_result = (instance.trace(6, "stdout") or "").strip()
232 comp_result = "OKIDOKI"
237 # asserts at the end, to make sure there's proper cleanup
238 self.assertEqual(comp_result, test_result)
240 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
241 def test_emulation(self):
242 instance = self.make_instance()
244 instance.defer_create(2, "Node")
245 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
246 instance.defer_create_set(2, "emulation", True) # require emulation
247 instance.defer_create(3, "NodeInterface")
248 instance.defer_connect(2, "devs", 3, "node")
249 instance.defer_create(4, "Internet")
250 instance.defer_connect(3, "inet", 4, "devs")
251 instance.defer_create(7, "NetPipe")
252 instance.defer_create_set(7, "mode", "CLIENT")
253 instance.defer_create_set(7, "portList", "80")
254 instance.defer_create_set(7, "bwOut", 12.0/1024.0) # 12kbps
255 instance.defer_create_set(7, "bwIn", 64.0/1024.0) # 64kbps
256 instance.defer_create_set(7, "plrOut", 0.01) # 1% plr outbound - high loss
257 instance.defer_create_set(7, "plrIn", 0.001) # 0.1% plr inbound - regular loss
258 instance.defer_create_set(7, "delayOut", int(1500 * 8 / (12.0/1024.0) / 1000)) # tx delay at 12kbps in ms
259 instance.defer_create_set(7, "delayIn", int(1500 * 8 / (64.0/1024.0) / 1000)) # rx delay at 64kbps in ms
260 instance.defer_add_trace(7, "netpipeStats")
261 instance.defer_connect(2, "pipes", 7, "node")
262 instance.defer_create(8, "Application")
263 instance.defer_create_set(8, "command", "time wget -q -O /dev/null http://www.google.com/") # Fetch ~10kb
264 instance.defer_add_trace(8, "stdout")
265 instance.defer_add_trace(8, "stderr")
266 instance.defer_connect(8, "node", 2, "apps")
271 instance.do_connect_init()
272 instance.do_connect_compl()
273 instance.do_preconfigure()
274 instance.do_configure()
277 while instance.status(8) != STATUS_FINISHED:
279 test_result = (instance.trace(8, "stderr") or "").strip()
280 comp_result = r".*real\s*(?P<min>[0-9]+)m(?P<sec>[0-9]+[.][0-9]+)s.*"
281 netpipe_stats = instance.trace(7, "netpipeStats")
287 # asserts at the end, to make sure there's proper cleanup
288 match = re.match(comp_result, test_result, re.MULTILINE)
289 self.assertTrue(match, "Unexpected output: %s" % (test_result,))
291 minutes = int(match.group("min"))
292 seconds = float(match.group("sec"))
293 self.assertTrue((minutes * 60 + seconds) > 1.0, "Emulation not effective: %s" % (test_result,))
295 self.assertTrue(netpipe_stats, "Unavailable netpipe stats")
297 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
298 def test_tun_emulation_requirement(self):
299 instance = self.make_instance()
301 instance.defer_create(2, "Node")
302 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
303 instance.defer_create(3, "NodeInterface")
304 instance.defer_connect(2, "devs", 3, "node")
305 instance.defer_create(4, "Internet")
306 instance.defer_connect(3, "inet", 4, "devs")
307 instance.defer_create(5, "TunInterface")
308 instance.defer_add_address(5, "192.168.2.2", 24, False)
309 instance.defer_connect(2, "devs", 5, "node")
310 instance.defer_create(6, "Application")
311 instance.defer_create_set(6, "command", "false")
312 instance.defer_add_trace(6, "stdout")
313 instance.defer_add_trace(6, "stderr")
314 instance.defer_connect(6, "node", 2, "apps")
319 instance.do_connect_init()
320 instance.do_connect_compl()
321 instance.do_preconfigure()
322 instance.do_configure()
323 self.fail("Usage of TUN without emulation should fail")
327 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
328 def _pingtest(self, TunClass, ConnectionProto):
329 instance = self.make_instance()
331 instance.defer_create(2, "Node")
332 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
333 instance.defer_create_set(2, "emulation", True) # require emulation
334 instance.defer_create(3, "Node")
335 instance.defer_create_set(3, "hostname", "onelab10.pl.sophia.inria.fr")
336 instance.defer_create_set(3, "emulation", True) # require emulation
337 instance.defer_create(4, "NodeInterface")
338 instance.defer_connect(2, "devs", 4, "node")
339 instance.defer_create(5, "Internet")
340 instance.defer_connect(4, "inet", 5, "devs")
341 instance.defer_create(6, "NodeInterface")
342 instance.defer_connect(3, "devs", 6, "node")
343 instance.defer_connect(6, "inet", 5, "devs")
344 instance.defer_create(7, TunClass)
345 instance.defer_add_address(7, "192.168.2.2", 24, False)
346 instance.defer_connect(2, "devs", 7, "node")
347 instance.defer_create(8, TunClass)
348 instance.defer_add_address(8, "192.168.2.3", 24, False)
349 instance.defer_connect(3, "devs", 8, "node")
350 instance.defer_connect(7, ConnectionProto, 8, ConnectionProto)
351 instance.defer_create(9, "Application")
352 instance.defer_create_set(9, "command", "ping -qc1 {#[GUID-8].addr[0].[Address]#}")
353 instance.defer_add_trace(9, "stdout")
354 instance.defer_add_trace(9, "stderr")
355 instance.defer_connect(9, "node", 2, "apps")
357 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
359 --- .* ping statistics ---
360 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
366 instance.do_connect_init()
367 instance.do_connect_compl()
368 instance.do_preconfigure()
370 # Manually replace netref
371 instance.set(9, "command",
372 instance.get(9, "command")
373 .replace("{#[GUID-8].addr[0].[Address]#}",
374 instance.get_address(8, 0, "Address") )
377 instance.do_configure()
380 while instance.status(9) != STATUS_FINISHED:
382 ping_result = instance.trace(9, "stdout") or ""
387 # asserts at the end, to make sure there's proper cleanup
388 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
389 "Unexpected trace:\n" + ping_result)
391 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
392 def test_tun_ping(self):
393 self._pingtest("TunInterface", "tcp")
395 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
396 def test_tun_ping_udp(self):
397 self._pingtest("TunInterface", "udp")
399 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
400 def test_tap_ping(self):
401 self._pingtest("TapInterface", "tcp")
403 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
404 def test_tap_ping_udp(self):
405 self._pingtest("TapInterface", "udp")
407 @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
408 def test_nepi_depends(self):
409 instance = self.make_instance()
411 instance.defer_create(2, "Node")
412 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
413 instance.defer_create(3, "NodeInterface")
414 instance.defer_connect(2, "devs", 3, "node")
415 instance.defer_create(4, "Internet")
416 instance.defer_connect(3, "inet", 4, "devs")
417 instance.defer_create(5, "NepiDependency")
418 instance.defer_connect(5, "node", 2, "deps")
419 instance.defer_create(12, "Application")
420 instance.defer_connect(12, "node", 2, "apps")
421 instance.defer_create_set(12, "command", "python -c 'import nepi'")
422 instance.defer_add_trace(12, "stderr")
427 instance.do_connect_init()
428 instance.do_connect_compl()
429 instance.do_preconfigure()
430 instance.do_configure()
433 while instance.status(12) != STATUS_FINISHED:
435 ping_result = (instance.trace(12, "stderr") or "").strip()
440 # asserts at the end, to make sure there's proper cleanup
441 self.assertEqual(ping_result, "")
443 @test_util.skipUnless(test_util.pl_auth() is not None,
444 "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
445 @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
446 "Test is expensive, requires NEPI_FULL_TESTS=yes")
447 def test_ns3_depends(self):
448 instance = self.make_instance()
450 instance.defer_create(2, "Node")
451 instance.defer_create_set(2, "hostname", "onelab11.pl.sophia.inria.fr")
452 instance.defer_create(3, "NodeInterface")
453 instance.defer_connect(2, "devs", 3, "node")
454 instance.defer_create(4, "Internet")
455 instance.defer_connect(3, "inet", 4, "devs")
456 instance.defer_create(5, "NepiDependency")
457 instance.defer_connect(5, "node", 2, "deps")
458 instance.defer_create(6, "NS3Dependency")
459 instance.defer_connect(6, "node", 2, "deps")
460 instance.defer_create(12, "Application")
461 instance.defer_connect(12, "node", 2, "apps")
462 instance.defer_create_set(12, "command", "python -c 'import nepi.testbeds.ns3.execute ; tb = nepi.testbeds.ns3.execute.TestbedController(\"3_9_RC3\") ; mod = tb._load_ns3_module()'")
463 instance.defer_add_trace(12, "stderr")
468 instance.do_connect_init()
469 instance.do_connect_compl()
470 instance.do_preconfigure()
471 instance.do_configure()
474 while instance.status(12) != STATUS_FINISHED:
476 ping_result = (instance.trace(12, "stderr") or "").strip()
481 # asserts at the end, to make sure there's proper cleanup
482 self.assertEqual(ping_result, "")
485 if __name__ == '__main__':