Fixing wrong license
[nepi.git] / test / resources / linux / interface.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 version 2 as
8 #    published by the Free Software Foundation;
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 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20
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
27 from test_utils import skipIfNotAlive
28
29 import os
30 import time
31 import tempfile
32 import unittest
33
34 class LinuxInterfaceTestCase(unittest.TestCase):
35     def setUp(self):
36         self.fedora_host = "nepi2.pl.sophia.inria.fr"
37         self.fedora_user = "inria_nepi"
38
39         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
40         self.ubuntu_user = "alina"
41
42     @skipIfNotAlive
43     def t_deploy(self, host, user):
44         from nepi.execution.resource import ResourceFactory
45         
46         ResourceFactory.register_type(LinuxNode)
47         ResourceFactory.register_type(LinuxInterface)
48         ResourceFactory.register_type(LinuxChannel)
49
50         ec = ExperimentController()
51         
52         node = ec.register_resource("linux::Node")
53         ec.set(node, "hostname", host)
54         ec.set(node, "username", user)
55
56         iface = ec.register_resource("linux::Interface")
57         chan = ec.register_resource("linux::Channel")
58
59         ec.register_connection(iface, node)
60         ec.register_connection(iface, chan)
61
62         ec.deploy()
63
64         while not all([ ec.state(guid) == ResourceState.STARTED \
65                 for guid in [node, iface]]):
66             time.sleep(0.5)
67
68         self.assertTrue(ec.state(node) == ResourceState.STARTED)
69         self.assertTrue(ec.state(iface) == ResourceState.STARTED)
70         self.assertTrue(ec.get(iface, "deviceName") == "eth0")
71
72         ec.shutdown()
73
74     def test_deploy_fedora(self):
75         self.t_deploy(self.fedora_host, self.fedora_user)
76
77     def test_deploy_ubuntu(self):
78         self.t_deploy(self.ubuntu_host, self.ubuntu_user)
79
80
81 if __name__ == '__main__':
82     unittest.main()
83