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.runner import ExperimentRunner
23 from test_utils import skipIfNotAlive, skipInteractive
34 _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)
36 class LinuxMultiRunTestCase(unittest.TestCase):
38 self.fedora_host = "nepi2.pl.sophia.inria.fr"
39 self.fedora_user = "inria_nepi"
41 self.ubuntu_host = "roseval.pl.sophia.inria.fr"
42 self.ubuntu_user = "inria_nepi"
44 self.target = "nepi5.pl.sophia.inria.fr"
47 def t_simple_multirun(self, host, user, depends):
49 dirpath = tempfile.mkdtemp()
51 ec = ExperimentController(exp_id = "test-condition-multirun",
54 node = ec.register_resource("linux::Node")
55 ec.set(node, "hostname", host)
56 ec.set(node, "username", user)
57 ec.set(node, "cleanExperiment", True)
58 ec.set(node, "cleanProcesses", True)
60 ping = ec.register_resource("linux::Application")
61 ec.set(ping, "command", "ping -c10 nepi.inria.fr")
62 ec.register_connection(ping, node)
64 collector = ec.register_resource("Collector")
65 ec.set(collector, "traceName", "stdout")
66 ec.register_connection(ping, collector)
68 def compute_metric_callback(ping, ec, run):
69 stdout = ec.trace(ping, "stdout")
71 m = _ping_re.match(stdout)
75 return float(m.groupdict()["min"])
77 metric_callback = functools.partial(compute_metric_callback, ping)
79 rnr = ExperimentRunner()
80 runs = rnr.run(ec, min_runs = 5,
81 compute_metric_callback = metric_callback,
85 self.assertTrue(runs >= 5)
89 for d in os.listdir(ec.exp_dir):
90 path = os.path.join(ec.exp_dir, d)
91 if os.path.isdir(path):
93 logs = glob.glob(os.path.join(path, "*.stdout"))
94 self.assertEquals(len(logs), 1)
96 self.assertEquals(runs, dircount)
98 shutil.rmtree(dirpath)
100 def test_simple_multirun_fedora(self):
101 self.t_simple_multirun(self.fedora_host, self.fedora_user, "nc")
103 def test_simple_multirun_ubuntu(self):
104 self.t_simple_multirun(self.ubuntu_host, self.ubuntu_user, "netcat")
106 if __name__ == '__main__':