f5ed7be4172a73288531635b3bc8f95fde8c6ba9
[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 from nepi.util.sshfuncs import RUNNING, FINISHED
28
29 from test_utils import skipIfNotAlive
30
31 import os
32 import time
33 import tempfile
34 import unittest
35
36 class LinuxInterfaceTestCase(unittest.TestCase):
37     def setUp(self):
38         self.fedora_host = 'nepi2.pl.sophia.inria.fr'
39         self.fedora_user = 'inria_nepi'
40
41         self.ubuntu_host = 'roseval.pl.sophia.inria.fr'
42         self.ubuntu_user = 'alina'
43
44     @skipIfNotAlive
45     def t_deploy(self, host, user):
46         from nepi.execution.resource import ResourceFactory
47         
48         ResourceFactory.register_type(LinuxNode)
49         ResourceFactory.register_type(LinuxInterface)
50         ResourceFactory.register_type(LinuxChannel)
51
52         ec = ExperimentController()
53         
54         node = ec.register_resource("LinuxNode")
55         ec.set(node, "hostname", host)
56         ec.set(node, "username", user)
57
58         iface = ec.register_resource("LinuxInterface")
59         chan = ec.register_resource("LinuxChannel")
60
61         ec.register_connection(iface, node)
62         ec.register_connection(iface, chan)
63
64         ec.deploy()
65
66         while not all([ ec.state(guid) == ResourceState.STARTED \
67                 for guid in [node, iface]]) and not ec.finished:
68             time.sleep(0.5)
69
70         self.assertTrue(ec.state(node) == ResourceState.STARTED)
71         self.assertTrue(ec.state(iface) == ResourceState.STARTED)
72         self.assertTrue(ec.get(iface, "deviceName") == "eth0")
73
74         ec.shutdown()
75
76     def test_deploy_fedora(self):
77         self.t_deploy(self.fedora_host, self.fedora_user)
78
79     def test_deploy_ubuntu(self):
80         self.t_deploy(self.ubuntu_host, self.ubuntu_user)
81
82
83 if __name__ == '__main__':
84     unittest.main()
85