3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
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.
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.
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/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceState, ResourceAction
23 from nepi.execution.trace import TraceAttr
25 from test_utils import skipIfNotAlive, skipInteractive
33 class LinuxSerializationTestCase(unittest.TestCase):
35 self.fedora_host = "nepi2.pl.sophia.inria.fr"
36 self.fedora_user = "inria_nepi"
38 self.ubuntu_host = "roseval.pl.sophia.inria.fr"
39 self.ubuntu_user = "inria_nepi"
41 self.target = "nepi5.pl.sophia.inria.fr"
44 def t_condition_serialize(self, host, user, depends):
46 dirpath = tempfile.mkdtemp()
48 ec = ExperimentController(exp_id="test-condition-serial")
50 node = ec.register_resource("LinuxNode")
51 ec.set(node, "hostname", host)
52 ec.set(node, "username", user)
53 ec.set(node, "cleanHome", True)
54 ec.set(node, "cleanProcesses", True)
56 server = ec.register_resource("LinuxApplication")
57 cmd = "echo 'HOLA' | nc -l 3333"
58 ec.set(server, "command", cmd)
59 ec.set(server, "depends", depends)
60 ec.register_connection(server, node)
62 client = ec.register_resource("LinuxApplication")
63 cmd = "nc 127.0.0.1 3333"
64 ec.set(client, "command", cmd)
65 ec.register_connection(client, node)
67 ec.register_condition(client, ResourceAction.START, server, ResourceState.STARTED)
69 apps = [client, server]
71 filepath = ec.save(dirpath)
75 ec.wait_finished(apps)
77 self.assertTrue(ec.state(node) == ResourceState.STARTED)
78 self.assertTrue(ec.state(server) == ResourceState.STOPPED)
79 self.assertTrue(ec.state(client) == ResourceState.STOPPED)
81 stdout = ec.trace(client, "stdout")
82 self.assertTrue(stdout.strip() == "HOLA")
86 # Load serialized experiment
87 ec2 = ExperimentController.load(filepath)
90 ec2.wait_finished(apps)
92 self.assertEquals(len(ec.resources), len(ec2.resources))
94 self.assertTrue(ec2.state(node) == ResourceState.STARTED)
95 self.assertTrue(ec2.state(server) == ResourceState.STOPPED)
96 self.assertTrue(ec2.state(client) == ResourceState.STOPPED)
98 stdout = ec2.trace(client, "stdout")
100 self.assertTrue(stdout.strip() == "HOLA")
104 shutil.rmtree(dirpath)
106 def test_condition_serialize_fedora(self):
107 self.t_condition_serialize(self.fedora_host, self.fedora_user, "nc")
109 def test_condition_serialize_ubuntu(self):
110 self.t_condition_serialize(self.ubuntu_host, self.ubuntu_user, "netcat")
112 if __name__ == '__main__':