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 version 2 as
8 # published by the Free Software Foundation;
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.ec import ExperimentController
21 from nepi.execution.resource import ResourceState, ResourceAction
22 from nepi.execution.trace import TraceAttr
24 from test_utils import skipIfNotAlive, skipInteractive
32 class LinuxSerializationTestCase(unittest.TestCase):
34 self.fedora_host = "nepi2.pl.sophia.inria.fr"
35 self.fedora_user = "inria_nepi"
37 self.ubuntu_host = "roseval.pl.sophia.inria.fr"
38 self.ubuntu_user = "inria_nepi"
40 self.target = "nepi5.pl.sophia.inria.fr"
43 def t_condition_serialize(self, host, user, depends):
45 dirpath = tempfile.mkdtemp()
47 ec = ExperimentController(exp_id="test-condition-serial")
49 node = ec.register_resource("linux::Node")
50 ec.set(node, "hostname", host)
51 ec.set(node, "username", user)
52 ec.set(node, "cleanExperiment", True)
53 ec.set(node, "cleanProcesses", True)
55 server = ec.register_resource("linux::Application")
56 cmd = "echo 'HOLA' | nc -l 3333"
57 ec.set(server, "command", cmd)
58 ec.set(server, "depends", depends)
59 ec.register_connection(server, node)
61 client = ec.register_resource("linux::Application")
62 cmd = "nc 127.0.0.1 3333"
63 ec.set(client, "command", cmd)
64 ec.register_connection(client, node)
66 ec.register_condition(client, ResourceAction.START, server, ResourceState.STARTED)
68 apps = [client, server]
70 filepath = ec.save(dirpath)
74 ec.wait_finished(apps)
76 self.assertTrue(ec.state(node) == ResourceState.STARTED)
77 self.assertTrue(ec.state(server) == ResourceState.STOPPED)
78 self.assertTrue(ec.state(client) == ResourceState.STOPPED)
80 stdout = ec.trace(client, "stdout")
81 self.assertTrue(stdout.strip() == "HOLA")
85 # Load serialized experiment
86 ec2 = ExperimentController.load(filepath)
89 ec2.wait_finished(apps)
91 self.assertEqual(len(ec.resources), len(ec2.resources))
93 self.assertTrue(ec2.state(node) == ResourceState.STARTED)
94 self.assertTrue(ec2.state(server) == ResourceState.STOPPED)
95 self.assertTrue(ec2.state(client) == ResourceState.STOPPED)
97 stdout = ec2.trace(client, "stdout")
99 self.assertTrue(stdout.strip() == "HOLA")
103 shutil.rmtree(dirpath)
105 def test_condition_serialize_fedora(self):
106 self.t_condition_serialize(self.fedora_host, self.fedora_user, "nc")
108 def test_condition_serialize_ubuntu(self):
109 self.t_condition_serialize(self.ubuntu_host, self.ubuntu_user, "netcat")
111 if __name__ == '__main__':