s/dedicatedSlice/cleanProc/g
[nepi.git] / test / testbeds / planetlab / execute.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import getpass
5 from nepi.util.constants import ApplicationStatus as AS
6 from nepi.testbeds import planetlab
7 import os
8 import re
9 import shutil
10 import sys
11 import tempfile
12 import test_util
13 import time
14 import unittest
15
16 class PlanetLabExecuteTestCase(unittest.TestCase):
17     testbed_id = "planetlab"
18     slicename = "inria_nepi"
19     plchost = "nepiplc.pl.sophia.inria.fr"
20     
21     host1 = "nepi1.pl.sophia.inria.fr"
22     host2 = "nepi2.pl.sophia.inria.fr"
23     
24     port_base = 2000 + (os.getpid() % 1000) * 13
25     
26     PLR50_PY = os.path.join(
27         os.path.dirname(planetlab.__file__), 
28         'scripts',
29         'plr50.py')
30     PLR50_C = os.path.join(
31         os.path.dirname(planetlab.__file__), 
32         'scripts',
33         'plr50.c')
34     TOS_PY = os.path.join(
35         os.path.dirname(planetlab.__file__), 
36         'scripts',
37         'tosqueue.py')
38     CLS_PY = os.path.join(
39         os.path.dirname(planetlab.__file__), 
40         'scripts',
41         'classqueue.py')
42     
43     def setUp(self):
44         self.root_dir = tempfile.mkdtemp()
45         self.__class__.port_base = self.port_base + 100
46         
47     def tearDown(self):
48         try:
49             shutil.rmtree(self.root_dir)
50         except:
51             # retry
52             time.sleep(0.1)
53             shutil.rmtree(self.root_dir)
54
55     def make_instance(self):
56         testbed_id = self.testbed_id
57         slicename = self.slicename
58         plchost = self.plchost
59         
60         instance = planetlab.TestbedController()
61         pl_ssh_key = os.environ.get(
62             "PL_SSH_KEY",
63             "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
64         slicename = os.environ.get(
65             "PL_SLICE",
66             slicename)
67         pl_user, pl_pwd = test_util.pl_auth()
68         
69         instance.defer_configure("homeDirectory", self.root_dir)
70         instance.defer_configure("slice", slicename)
71         instance.defer_configure("sliceSSHKey", pl_ssh_key)
72         instance.defer_configure("authUser", pl_user)
73         instance.defer_configure("authPass", pl_pwd)
74         instance.defer_configure("plcHost", plchost)
75         instance.defer_configure("tapPortBase", self.port_base)
76         instance.defer_configure("p2pDeployment", False) # it's interactive, we don't want it in tests
77         instance.defer_configure("cleanProc", True)
78         
79         # Hack, but we need vsys_vnet
80         instance.do_setup()
81         vnet = instance.vsys_vnet
82         self.net_prefix = vnet.rsplit('.',1)[0]
83         
84         return instance
85
86     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
87     def test_simple(self):
88         instance = self.make_instance()
89         
90         instance.defer_create(2, "Node")
91         instance.defer_create_set(2, "hostname", self.host1)
92         instance.defer_create(3, "Node")
93         instance.defer_create_set(3, "hostname", self.host2)
94         instance.defer_create(4, "NodeInterface")
95         instance.defer_connect(2, "devs", 4, "node")
96         instance.defer_create(5, "NodeInterface")
97         instance.defer_connect(3, "devs", 5, "node")
98         instance.defer_create(6, "Internet")
99         instance.defer_connect(4, "inet", 6, "devs")
100         instance.defer_connect(5, "inet", 6, "devs")
101         instance.defer_create(7, "Application")
102         instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
103         instance.defer_add_trace(7, "stdout")
104         instance.defer_add_trace(7, "stderr")
105         instance.defer_connect(7, "node", 2, "apps")
106
107         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
108
109 --- .* ping statistics ---
110 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
111 """
112
113         try:
114             instance.do_setup()
115             instance.do_create()
116             instance.do_connect_init()
117             instance.do_connect_compl()
118             instance.do_preconfigure()
119             
120             # Manually replace netref
121             instance.set(7, "command",
122                 instance.get(7, "command")
123                     .replace("{#[GUID-5].addr[0].[Address]#}", 
124                         instance.get_address(5, 0, "Address") )
125             )
126
127             instance.do_configure()
128             
129             instance.do_prestart()
130             instance.start()
131             while instance.status(7) != AS.STATUS_FINISHED:
132                 time.sleep(0.5)
133             ping_result = instance.trace(7, "stdout") or ""
134             instance.stop()
135         finally:
136             try:
137                 instance.shutdown()
138             except:
139                 pass
140
141         # asserts at the end, to make sure there's proper cleanup
142         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
143             "Unexpected trace:\n" + ping_result)
144         
145     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
146     def test_depends(self):
147         instance = self.make_instance()
148         
149         instance.defer_create(2, "Node")
150         instance.defer_create_set(2, "hostname", self.host1)
151         instance.defer_create(3, "NodeInterface")
152         instance.defer_connect(2, "devs", 3, "node")
153         instance.defer_create(4, "Internet")
154         instance.defer_connect(3, "inet", 4, "devs")
155         instance.defer_create(5, "Application")
156         instance.defer_create_set(5, "command", "gfortran --version")
157         instance.defer_create_set(5, "depends", "gcc-gfortran")
158         instance.defer_add_trace(5, "stdout")
159         instance.defer_add_trace(5, "stderr")
160         instance.defer_connect(5, "node", 2, "apps")
161
162         try:
163             instance.do_setup()
164             instance.do_create()
165             instance.do_connect_init()
166             instance.do_connect_compl()
167             instance.do_preconfigure()
168             instance.do_configure()
169             
170             instance.do_prestart()
171             instance.start()
172             while instance.status(5) != AS.STATUS_FINISHED:
173                 time.sleep(0.5)
174             ping_result = instance.trace(5, "stdout") or ""
175             comp_result = r".*GNU Fortran \(GCC\).*"
176             instance.stop()
177         finally:
178             try:
179                 instance.shutdown()
180             except:
181                 pass
182
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)
186         
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_build(self):
189         instance = self.make_instance()
190         
191         instance.defer_create(2, "Node")
192         instance.defer_create_set(2, "hostname", self.host1)
193         instance.defer_create(3, "NodeInterface")
194         instance.defer_connect(2, "devs", 3, "node")
195         instance.defer_create(4, "Internet")
196         instance.defer_connect(3, "inet", 4, "devs")
197         instance.defer_create(10, "Application")
198         instance.defer_create_set(10, "command", "./consts")
199         instance.defer_create_set(10, "buildDepends", "gcc")
200         instance.defer_create_set(10, "build", "gcc ${SOURCES}/consts.c -o consts")
201         instance.defer_create_set(10, "install", "cp consts ${SOURCES}/consts")
202         instance.defer_create_set(10, "sources", os.path.join(os.path.dirname(planetlab.__file__),'scripts','consts.c'))
203         instance.defer_add_trace(10, "stdout")
204         instance.defer_add_trace(10, "stderr")
205         instance.defer_connect(10, "node", 2, "apps")
206
207         comp_result = \
208 r""".*ETH_P_ALL = 0x[0-9a-fA-F]{8}
209 ETH_P_IP = 0x[0-9a-fA-F]{8}
210 TUNGETIFF = 0x[0-9a-fA-F]{8}
211 TUNSETIFF = 0x[0-9a-fA-F]{8}
212 IFF_NO_PI = 0x[0-9a-fA-F]{8}
213 IFF_TAP = 0x[0-9a-fA-F]{8}
214 IFF_TUN = 0x[0-9a-fA-F]{8}
215 IFF_VNET_HDR = 0x[0-9a-fA-F]{8}
216 TUN_PKT_STRIP = 0x[0-9a-fA-F]{8}
217 IFHWADDRLEN = 0x[0-9a-fA-F]{8}
218 IFNAMSIZ = 0x[0-9a-fA-F]{8}
219 IFREQ_SZ = 0x[0-9a-fA-F]{8}
220 FIONREAD = 0x[0-9a-fA-F]{8}.*
221 """
222
223         try:
224             instance.do_setup()
225             instance.do_create()
226             instance.do_connect_init()
227             instance.do_connect_compl()
228             instance.do_preconfigure()
229             instance.do_configure()
230             
231             instance.do_prestart()
232             instance.start()
233             while instance.status(10) != AS.STATUS_FINISHED:
234                 time.sleep(0.5)
235             ping_result = instance.trace(10, "stdout") or ""
236             instance.stop()
237         finally:
238             try:
239                 instance.shutdown()
240             except:
241                 pass
242
243         # asserts at the end, to make sure there's proper cleanup
244         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
245             "Unexpected trace:\n" + ping_result)
246         
247     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
248     def test_simple_vsys(self):
249         instance = self.make_instance()
250         
251         instance.defer_create(2, "Node")
252         instance.defer_create_set(2, "hostname", self.host1)
253         instance.defer_create(3, "NodeInterface")
254         instance.defer_connect(2, "devs", 3, "node")
255         instance.defer_create(4, "Internet")
256         instance.defer_connect(3, "inet", 4, "devs")
257         instance.defer_create(5, "TunInterface")
258         instance.defer_add_address(5, self.net_prefix+".2", 24, False)
259         instance.defer_connect(2, "devs", 5, "node")
260         instance.defer_create(6, "Application")
261         instance.defer_create_set(6, "command", """
262 set -e
263 netconfig help > /dev/null
264 test -e /vsys/vif_up.in > /dev/null
265 test -e /vsys/vif_up.out > /dev/null
266 test -e /vsys/fd_tuntap.control > /dev/null
267 echo 'OKIDOKI'
268 """)
269         instance.defer_create_set(6, "sudo", True) # only sudo has access to /vsys
270         instance.defer_add_trace(6, "stdout")
271         instance.defer_add_trace(6, "stderr")
272         instance.defer_connect(6, "node", 2, "apps")
273
274         try:
275             instance.do_setup()
276             instance.do_create()
277             instance.do_connect_init()
278             instance.do_connect_compl()
279             instance.do_preconfigure()
280             instance.do_configure()
281             
282             instance.do_prestart()
283             instance.start()
284             while instance.status(6) != AS.STATUS_FINISHED:
285                 time.sleep(0.5)
286             test_result = (instance.trace(6, "stdout") or "").strip()
287             comp_result = "OKIDOKI"
288             instance.stop()
289         finally:
290             try:
291                 instance.shutdown()
292             except:
293                 pass
294
295         # asserts at the end, to make sure there's proper cleanup
296         self.assertEqual(comp_result, test_result)
297
298     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
299     def test_emulation(self):
300         instance = self.make_instance()
301         
302         instance.defer_create(2, "Node")
303         instance.defer_create_set(2, "hostname", self.host1)
304         instance.defer_create(3, "NodeInterface")
305         instance.defer_connect(2, "devs", 3, "node")
306         instance.defer_create(4, "Internet")
307         instance.defer_connect(3, "inet", 4, "devs")
308         instance.defer_create(7, "NetPipe")
309         instance.defer_create_set(7, "mode", "CLIENT")
310         instance.defer_create_set(7, "portList", "80")
311         instance.defer_create_set(7, "bwOut", 12.0/1024.0) # 12kbps
312         instance.defer_create_set(7, "bwIn", 64.0/1024.0) # 64kbps
313         instance.defer_create_set(7, "plrOut", 0.01) # 1% plr outbound - high loss
314         instance.defer_create_set(7, "plrIn", 0.001) # 0.1% plr inbound - regular loss
315         instance.defer_create_set(7, "delayOut", int(1500 * 8 / (12.0/1024.0) / 1000)) # tx delay at 12kbps in ms
316         instance.defer_create_set(7, "delayIn", int(1500 * 8 / (64.0/1024.0) / 1000)) # rx delay at 64kbps in ms
317         instance.defer_add_trace(7, "netpipeStats")
318         instance.defer_connect(2, "pipes", 7, "node")
319         instance.defer_create(8, "Application")
320         instance.defer_create_set(8, "command", "time wget -q -O /dev/null http://www.google.com/") # Fetch ~10kb
321         instance.defer_add_trace(8, "stdout")
322         instance.defer_add_trace(8, "stderr")
323         instance.defer_connect(8, "node", 2, "apps")
324
325         try:
326             instance.do_setup()
327             instance.do_create()
328             instance.do_connect_init()
329             instance.do_connect_compl()
330             instance.do_preconfigure()
331             instance.do_configure()
332             
333             instance.do_prestart()
334             instance.start()
335             while instance.status(8) != AS.STATUS_FINISHED:
336                 time.sleep(0.5)
337             test_result = (instance.trace(8, "stderr") or "").strip()
338             comp_result = r".*real\s*(?P<min>[0-9]+)m(?P<sec>[0-9]+[.][0-9]+)s.*"
339             netpipe_stats = instance.trace(7, "netpipeStats")
340             
341             instance.stop()
342         finally:
343             try:
344                 instance.shutdown()
345             except:
346                 pass
347
348         # asserts at the end, to make sure there's proper cleanup
349         match = re.match(comp_result, test_result, re.MULTILINE)
350         self.assertTrue(match, "Unexpected output: %s" % (test_result,))
351         
352         minutes = int(match.group("min"))
353         seconds = float(match.group("sec"))
354         self.assertTrue((minutes * 60 + seconds) > 1.0, "Emulation not effective: %s" % (test_result,))
355
356         self.assertTrue(netpipe_stats, "Unavailable netpipe stats")
357
358     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
359     def _pingtest(self, TunClass, ConnectionProto, Cipher, Filter1=None, Filter2=None, Filter1args=None, Filter2args=None, PLREX=None, flood=False):
360         instance = self.make_instance()
361         
362         instance.defer_create(2, "Node")
363         instance.defer_create_set(2, "hostname", self.host1)
364         instance.defer_create(3, "Node")
365         instance.defer_create_set(3, "hostname", self.host2)
366         instance.defer_create(4, "NodeInterface")
367         instance.defer_connect(2, "devs", 4, "node")
368         instance.defer_create(5, "Internet")
369         instance.defer_connect(4, "inet", 5, "devs")
370         instance.defer_create(6, "NodeInterface")
371         instance.defer_connect(3, "devs", 6, "node")
372         instance.defer_connect(6, "inet", 5, "devs")
373         instance.defer_create(7, TunClass)
374         instance.defer_create_set(7, "tun_cipher", Cipher)
375         instance.defer_add_trace(7, "packets")
376         instance.defer_add_address(7, self.net_prefix+".2", 24, False)
377         if flood:
378             instance.defer_create_set(7, "bwlimit", 128)
379         instance.defer_connect(2, "devs", 7, "node")
380         instance.defer_create(8, TunClass)
381         instance.defer_create_set(8, "tun_cipher", Cipher)
382         instance.defer_add_trace(8, "packets")
383         instance.defer_add_address(8, self.net_prefix+".3", 24, False)
384         instance.defer_connect(3, "devs", 8, "node")
385         instance.defer_create(9, "Application")
386         if flood:
387             instance.defer_create_set(9, "command", "sudo -S ping -s 1000 -l 1000 -qfc1000 {#[GUID-8].addr[0].[Address]#} ; sleep 20 ; ping -qc10 {#[GUID-8].addr[0].[Address]#}")
388         else:
389             instance.defer_create_set(9, "command", "ping -qc10 {#[GUID-8].addr[0].[Address]#}")
390         instance.defer_add_trace(9, "stdout")
391         instance.defer_add_trace(9, "stderr")
392         instance.defer_connect(9, "node", 2, "apps")
393         
394         if Filter1:
395             instance.defer_create(10, "TunFilter")
396             instance.defer_create_set(10, "module", Filter1)
397             if Filter1args:
398                 instance.defer_create_set(10, "args", Filter1args)
399             instance.defer_connect(7, "fd->", 10, "->fd")
400             
401         if Filter2:
402             instance.defer_create(11, "TunFilter")
403             instance.defer_create_set(11, "module", Filter2)
404             if Filter2args:
405                 instance.defer_create_set(11, "args", Filter2args)
406             instance.defer_connect(8, "fd->", 11, "->fd")
407
408         if PLREX is None:
409             if Filter1 and Filter2:
410                 plr = "[5-9][0-9]"
411             elif Filter1 or Filter2:
412                 plr = "[3-9][0-9]"
413             else:
414                 plr = "0"
415         else:
416             plr = PLREX
417        
418         instance.defer_connect(
419             (10 if Filter1 else 7), ConnectionProto, 
420             (11 if Filter2 else 8), ConnectionProto)
421
422         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
423
424 --- .* ping statistics ---
425 10 packets transmitted, [0-9]+ received,.* %s%% packet loss, time \d*ms.*
426 """ % (plr,)
427         if flood:
428             comp_result = ".*" + comp_result
429
430         try:
431             instance.do_setup()
432             instance.do_create()
433             instance.do_connect_init()
434             instance.do_connect_compl()
435             instance.do_preconfigure()
436             
437             # Manually replace netref
438             instance.set(9, "command",
439                 instance.get(9, "command")
440                     .replace("{#[GUID-8].addr[0].[Address]#}", 
441                         instance.get_address(8, 0, "Address") )
442             )
443             
444             instance.do_configure()
445             
446             instance.do_prestart()
447             instance.start()
448             while instance.status(9) != AS.STATUS_FINISHED:
449                 time.sleep(0.5)
450             ping_result = instance.trace(9, "stdout") or ""
451             packets1 = instance.trace(7, "packets") or ""
452             packets2 = instance.trace(8, "packets") or ""
453             instance.stop()
454         finally:
455             try:
456                 instance.shutdown()
457             except:
458                 pass
459
460         # asserts at the end, to make sure there's proper cleanup
461         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE|re.DOTALL),
462             "Unexpected trace:\n%s\nPackets @ source:\n%s\nPackets @ target:\n%s" % (
463                 ping_result,
464                 packets1,
465                 packets2))
466
467     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
468     def test_tun_ping(self):
469         self._pingtest("TunInterface", "tcp", "AES")
470
471     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
472     def test_tun_ping_udp(self):
473         self._pingtest("TunInterface", "udp", "AES")
474
475     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
476     def test_tun_ping_gre(self):
477         self._pingtest("TunInterface", "gre", "PLAIN")
478
479     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
480     def test_tun_ping_flood(self):
481         self._pingtest("TunInterface", "tcp", "PLAIN", flood = True)
482
483     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
484     def test_tun_ping_flood_udp(self):
485         self._pingtest("TunInterface", "udp", "PLAIN", flood = True)
486
487     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
488     def test_tap_ping(self):
489         self._pingtest("TapInterface", "tcp", "AES")
490
491     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
492     def test_tap_ping_udp(self):
493         self._pingtest("TapInterface", "udp", "AES")
494
495     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
496     def test_tap_ping_gre(self):
497         self._pingtest("TapInterface", "gre", "PLAIN")
498
499     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
500     def test_tap_ping_udp_loss1_py(self):
501         self._pingtest("TapInterface", "udp", "AES", self.PLR50_PY, None, "plr=50")
502
503     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
504     def test_tap_ping_udp_loss2_py(self):
505         self._pingtest("TapInterface", "udp", "AES", self.PLR50_PY, self.PLR50_PY, "plr=40", "plr=40")
506
507     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
508     def test_tap_ping_udp_loss1_c(self):
509         self._pingtest("TapInterface", "udp", "AES", self.PLR50_C, None, "plr=50")
510
511     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
512     def test_tap_ping_udp_loss2_c(self):
513         self._pingtest("TapInterface", "udp", "AES", self.PLR50_C, self.PLR50_C, "plr=40", "plr=40")
514
515     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
516     def test_tun_ping_udp_tos(self):
517         self._pingtest("TunInterface", "udp", "AES", self.TOS_PY, self.TOS_PY, "size=1000", "size=1000", "0")
518
519     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
520     def test_tun_ping_udp_class(self):
521         self._pingtest("TunInterface", "udp", "AES", self.CLS_PY, self.CLS_PY, "size=10", "size=10", "0")
522
523     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
524     def test_nepi_depends(self):
525         instance = self.make_instance()
526         
527         instance.defer_create(2, "Node")
528         instance.defer_create_set(2, "hostname", self.host1)
529         instance.defer_create(3, "NodeInterface")
530         instance.defer_connect(2, "devs", 3, "node")
531         instance.defer_create(4, "Internet")
532         instance.defer_connect(3, "inet", 4, "devs")
533         instance.defer_create(5, "NepiDependency")
534         instance.defer_connect(5, "node", 2, "deps")
535         instance.defer_create(12, "Application")
536         instance.defer_connect(12, "node", 2, "apps")
537         instance.defer_create_set(12, "command", "python -c 'import nepi'")
538         instance.defer_add_trace(12, "stderr")
539
540         try:
541             instance.do_setup()
542             instance.do_create()
543             instance.do_connect_init()
544             instance.do_connect_compl()
545             instance.do_preconfigure()
546             instance.do_configure()
547             
548             instance.do_prestart()
549             instance.start()
550             while instance.status(12) != AS.STATUS_FINISHED:
551                 time.sleep(0.5)
552             ping_result = (instance.trace(12, "stderr") or "").strip()
553             instance.stop()
554         finally:
555             try:
556                 instance.shutdown()
557             except:
558                 pass
559         
560         # asserts at the end, to make sure there's proper cleanup
561         self.assertEqual(ping_result, "")
562
563     @test_util.skipUnless(test_util.pl_auth() is not None, 
564         "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
565     @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
566         "Test is expensive, requires NEPI_FULL_TESTS=yes")
567     def test_ns3_depends(self):
568         instance = self.make_instance()
569         
570         instance.defer_create(2, "Node")
571         instance.defer_create_set(2, "hostname", self.host1)
572         instance.defer_create(3, "NodeInterface")
573         instance.defer_connect(2, "devs", 3, "node")
574         instance.defer_create(4, "Internet")
575         instance.defer_connect(3, "inet", 4, "devs")
576         instance.defer_create(5, "NepiDependency")
577         instance.defer_connect(5, "node", 2, "deps")
578         instance.defer_create(6, "NS3Dependency")
579         instance.defer_connect(6, "node", 2, "deps")
580         instance.defer_create(12, "Application")
581         instance.defer_connect(12, "node", 2, "apps")
582         instance.defer_create_set(12, "command", "python -c 'import nepi.testbeds.ns3.execute ; tb = nepi.testbeds.ns3.execute.TestbedController() ; mod = tb._configure_ns3_module()'")
583         instance.defer_add_trace(12, "stderr")
584
585         try:
586             instance.do_setup()
587             instance.do_create()
588             instance.do_connect_init()
589             instance.do_connect_compl()
590             instance.do_preconfigure()
591             instance.do_configure()
592             
593             instance.do_prestart()
594             instance.start()
595             while instance.status(12) != AS.STATUS_FINISHED:
596                 time.sleep(0.5)
597             ping_result = (instance.trace(12, "stderr") or "").strip()
598             instance.stop()
599         finally:
600             try:
601                 instance.shutdown()
602             except:
603                 pass
604         
605         # asserts at the end, to make sure there's proper cleanup
606         self.assertEqual(ping_result, "")
607
608     @test_util.skipUnless(test_util.pl_auth() is not None, "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
609     def test_discovery(self):
610         instance = self.make_instance()
611         
612         instance.defer_create(2, "Node")
613         instance.defer_create_set(2, "operatingSystem", "f12")
614         instance.defer_create(3, "Node")
615         instance.defer_create_set(3, "operatingSystem", "f12")
616         instance.defer_create(4, "NodeInterface")
617         instance.defer_connect(2, "devs", 4, "node")
618         instance.defer_create(5, "NodeInterface")
619         instance.defer_connect(3, "devs", 5, "node")
620         instance.defer_create(6, "Internet")
621         instance.defer_connect(4, "inet", 6, "devs")
622         instance.defer_connect(5, "inet", 6, "devs")
623         instance.defer_create(7, "Application")
624         instance.defer_create_set(7, "command", "ping -qc1 {#[GUID-5].addr[0].[Address]#}")
625         instance.defer_add_trace(7, "stdout")
626         instance.defer_add_trace(7, "stderr")
627         instance.defer_connect(7, "node", 2, "apps")
628
629         comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
630
631 --- .* ping statistics ---
632 1 packets transmitted, 1 received, 0% packet loss, time \d*ms.*
633 """
634
635         try:
636             instance.do_setup()
637             instance.do_create()
638             instance.do_connect_init()
639             instance.do_connect_compl()
640             instance.do_preconfigure()
641             
642             # Manually replace netref
643             instance.set(7, "command",
644                 instance.get(7, "command")
645                     .replace("{#[GUID-5].addr[0].[Address]#}", 
646                         instance.get_address(5, 0, "Address") )
647             )
648
649             instance.do_configure()
650             
651             instance.do_prestart()
652             instance.start()
653             while instance.status(7) != AS.STATUS_FINISHED:
654                 time.sleep(0.5)
655             ping_result = instance.trace(7, "stdout") or ""
656             instance.stop()
657         finally:
658             try:
659                 instance.shutdown()
660             except:
661                 pass
662
663         # asserts at the end, to make sure there's proper cleanup
664         self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
665             "Unexpected trace:\n" + ping_result)
666         
667         
668
669 if __name__ == '__main__':
670     unittest.main()
671