379f92e7ef57fb24f22d96b99c8eed44bdbf96d5
[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 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
22 from nepi.execution.ec import ExperimentController 
23 from nepi.execution.resource import ResourceState
24 from nepi.resources.linux.node import LinuxNode
25 from nepi.resources.linux.interface import LinuxInterface
26 from nepi.resources.linux.channel import LinuxChannel
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]]):
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