Added LICENSE
[nepi.git] / test / resources / linux / interface.py
1 """
2     NEPI, a framework to manage network experiments
3     Copyright (C) 2013 INRIA
4
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 """
19
20 #!/usr/bin/env python
21 from nepi.execution.ec import ExperimentController 
22 from nepi.execution.resource import ResourceState
23 from nepi.resources.linux.node import LinuxNode
24 from nepi.resources.linux.interface import LinuxInterface
25 from nepi.resources.linux.channel import LinuxChannel
26 from nepi.util.sshfuncs import RUNNING, FINISHED
27
28 from test_utils import skipIfNotAlive
29
30 import os
31 import time
32 import tempfile
33 import unittest
34
35 class LinuxInterfaceTestCase(unittest.TestCase):
36     def setUp(self):
37         self.fedora_host = 'nepi2.pl.sophia.inria.fr'
38         self.fedora_user = 'inria_nepi'
39
40         self.ubuntu_host = 'roseval.pl.sophia.inria.fr'
41         self.ubuntu_user = 'alina'
42
43     @skipIfNotAlive
44     def t_deploy(self, host, user):
45         from nepi.execution.resource import ResourceFactory
46         
47         ResourceFactory.register_type(LinuxNode)
48         ResourceFactory.register_type(LinuxInterface)
49         ResourceFactory.register_type(LinuxChannel)
50
51         ec = ExperimentController()
52         
53         node = ec.register_resource("LinuxNode")
54         ec.set(node, "hostname", host)
55         ec.set(node, "username", user)
56
57         iface = ec.register_resource("LinuxInterface")
58         chan = ec.register_resource("LinuxChannel")
59
60         ec.register_connection(iface, node)
61         ec.register_connection(iface, chan)
62
63         ec.deploy()
64
65         while not all([ ec.state(guid) == ResourceState.STARTED \
66                 for guid in [node, iface]]) and not ec.finished:
67             time.sleep(0.5)
68
69         self.assertTrue(ec.state(node) == ResourceState.STARTED)
70         self.assertTrue(ec.state(iface) == ResourceState.STARTED)
71         self.assertTrue(ec.get(iface, "deviceName") == "eth0")
72
73         ec.shutdown()
74
75     def test_deploy_fedora(self):
76         self.t_deploy(self.fedora_host, self.fedora_user)
77
78     def test_deploy_ubuntu(self):
79         self.t_deploy(self.ubuntu_host, self.ubuntu_user)
80
81
82 if __name__ == '__main__':
83     unittest.main()
84