Added unit tests for linux application
[nepi.git] / test / resources / linux / interface.py
1 #!/usr/bin/env python
2 from neco.execution.ec import ExperimentController 
3 from neco.execution.resource import ResourceState
4 from neco.resources.linux.node import LinuxNode
5 from neco.resources.linux.interface import LinuxInterface
6 from neco.resources.linux.channel import LinuxChannel
7 from neco.util.sshfuncs import RUNNING, FINISHED
8
9 from test_utils import skipIfNotAlive
10
11 import os
12 import time
13 import tempfile
14 import unittest
15
16 class LinuxInterfaceTestCase(unittest.TestCase):
17     def setUp(self):
18         self.fedora_host = 'nepi2.pl.sophia.inria.fr'
19         self.fedora_user = 'inria_nepi'
20
21         self.ubuntu_host = 'roseval.pl.sophia.inria.fr'
22         self.ubuntu_user = 'alina'
23
24     @skipIfNotAlive
25     def t_deploy(self, host, user):
26         from neco.execution.resource import ResourceFactory
27         
28         ResourceFactory.register_type(LinuxNode)
29         ResourceFactory.register_type(LinuxInterface)
30         ResourceFactory.register_type(LinuxChannel)
31
32         ec = ExperimentController()
33         
34         node = ec.register_resource("LinuxNode")
35         ec.set(node, "hostname", host)
36         ec.set(node, "username", user)
37
38         iface = ec.register_resource("LinuxInterface")
39         chan = ec.register_resource("LinuxChannel")
40
41         ec.register_connection(iface, node)
42         ec.register_connection(iface, chan)
43
44         ec.deploy()
45
46         while not all([ ec.state(guid) == ResourceState.STARTED \
47                 for guid in [node, iface]]) and not ec.finished:
48             time.sleep(0.5)
49
50         self.assertTrue(ec.state(node) == ResourceState.STARTED)
51         self.assertTrue(ec.state(iface) == ResourceState.STARTED)
52         self.assertTrue(ec.get(iface, "deviceName") == "eth0")
53
54         ec.shutdown()
55
56     def test_deploy_fedora(self):
57         self.t_deploy(self.fedora_host, self.fedora_user)
58
59     def test_deploy_ubuntu(self):
60         self.t_deploy(self.ubuntu_host, self.ubuntu_user)
61
62
63 if __name__ == '__main__':
64     unittest.main()
65