PlanetlabTap reads STOP from unix socket
[nepi.git] / test / resources / planetlab / tap.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21 from nepi.execution.ec import ExperimentController 
22
23 from test_utils import skipIfNotAlive, skipInteractive
24
25 import os
26 import time
27 import unittest
28
29 class PlanetlabTapTestCase(unittest.TestCase):
30     def setUp(self):
31         self.host = "nepi2.pl.sophia.inria.fr"
32         self.user = "inria_nepi"
33
34     @skipIfNotAlive
35     def t_tap_create(self, host, user):
36
37         ec = ExperimentController(exp_id = "test-tap-create")
38         
39         node = ec.register_resource("PlanetlabNode")
40         ec.set(node, "hostname", host)
41         ec.set(node, "username", user)
42         ec.set(node, "cleanHome", True)
43         ec.set(node, "cleanProcesses", True)
44
45         tap = ec.register_resource("PlanetlabTap")
46         ec.set(tap, "ip4", "192.168.1.1")
47         ec.set(tap, "prefix4", 24)
48         ec.register_connection(tap, node)
49
50         app = ec.register_resource("LinuxApplication")
51         cmd = "ping -c3 192.168.1.1"
52         ec.set(app, "command", cmd)
53         ec.register_connection(app, node)
54
55         ec.deploy()
56
57         ec.wait_finished(app)
58
59         ping = ec.trace(app, 'stdout')
60         expected = """3 packets transmitted, 3 received, 0% packet loss"""
61         self.assertTrue(ping.find(expected) > -1)
62         
63         if_name = ec.get(tap, "deviceName")
64         self.assertTrue(if_name.startswith("tap"))
65
66         ec.shutdown()
67
68     def test_tap_create(self):
69         self.t_tap_create(self.host, self.user)
70
71 if __name__ == '__main__':
72     unittest.main()
73