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.runner import ExperimentRunner
24 from test_utils import skipIfNotAlive, skipInteractive
35 _ping_re = re.compile("[^/]+rtt min/avg/max/mdev = (?P<min>\d\.\d+)/(?P<avg>\d\.\d+)/(?P<max>\d\.\d+)/(?P<mdev>\d\.\d+)[^/]+", re.MULTILINE)
37 class LinuxMultiRunTestCase(unittest.TestCase):
39 self.fedora_host = "nepi2.pl.sophia.inria.fr"
40 self.fedora_user = "inria_nepi"
42 self.ubuntu_host = "roseval.pl.sophia.inria.fr"
43 self.ubuntu_user = "inria_nepi"
45 self.target = "nepi5.pl.sophia.inria.fr"
48 def t_simple_multirun(self, host, user, depends):
50 dirpath = tempfile.mkdtemp()
52 ec = ExperimentController(exp_id = "test-condition-multirun",
55 node = ec.register_resource("LinuxNode")
56 ec.set(node, "hostname", host)
57 ec.set(node, "username", user)
58 ec.set(node, "cleanHome", True)
59 ec.set(node, "cleanProcesses", True)
61 ping = ec.register_resource("LinuxApplication")
62 ec.set(ping, "command", "ping -c10 nepi.inria.fr")
63 ec.register_connection(ping, node)
65 collector = ec.register_resource("Collector")
66 ec.set(collector, "traceName", "stdout")
67 ec.register_connection(ping, collector)
69 def compute_metric_callback(ping, ec, run):
70 stdout = ec.trace(ping, "stdout")
72 m = _ping_re.match(stdout)
76 return float(m.groupdict()["min"])
78 metric_callback = functools.partial(compute_metric_callback, ping)
80 rnr = ExperimentRunner()
81 runs = rnr.run(ec, min_runs = 5,
82 compute_metric_callback = metric_callback,
86 self.assertTrue(runs >= 5)
90 for d in os.listdir(ec.exp_dir):
91 path = os.path.join(ec.exp_dir, d)
92 if os.path.isdir(path):
94 logs = glob.glob(os.path.join(path, "*.stdout"))
95 self.assertEquals(len(logs), 1)
97 self.assertEquals(runs, dircount)
99 shutil.rmtree(dirpath)
101 def test_simple_multirun_fedora(self):
102 self.t_simple_multirun(self.fedora_host, self.fedora_user, "nc")
104 def test_simple_multirun_ubuntu(self):
105 self.t_simple_multirun(self.ubuntu_host, self.ubuntu_user, "netcat")
107 if __name__ == '__main__':