Adding LinuxTraceroute RM
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 17 Jul 2013 23:57:23 +0000 (16:57 -0700)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Wed, 17 Jul 2013 23:57:23 +0000 (16:57 -0700)
src/nepi/resources/linux/traceroute.py [new file with mode: 0644]
test/resources/linux/traceroute.py [new file with mode: 0755]

diff --git a/src/nepi/resources/linux/traceroute.py b/src/nepi/resources/linux/traceroute.py
new file mode 100644 (file)
index 0000000..80ca3b9
--- /dev/null
@@ -0,0 +1,85 @@
+#
+#    NEPI, a framework to manage network experiments
+#    Copyright (C) 2013 INRIA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.attribute import Attribute, Flags, Types
+from nepi.execution.resource import clsinit_copy 
+from nepi.resources.linux.application import LinuxApplication
+from nepi.util.timefuncs import tnow
+
+import os
+
+@clsinit_copy
+class LinuxTraceroute(LinuxApplication):
+    _rtype = "LinuxTraceroute"
+
+    @classmethod
+    def _register_attributes(cls):
+        countinuous = Attribute("continuous",
+            "Run traceroute in a while loop",
+            type = Types.Bool,
+            default = False,
+            flags = Flags.ExecReadOnly)
+
+        print_timestamp = Attribute("printTimestamp",
+            "Print timestamp before running traceroute",
+            type = Types.Bool,
+            default = False,
+            flags = Flags.ExecReadOnly)
+
+        target = Attribute("target",
+            "Traceroute target host (host that will be pinged)",
+            flags = Flags.ExecReadOnly)
+
+        cls._register_attribute(countinuous)
+        cls._register_attribute(print_timestamp)
+        cls._register_attribute(target)
+
+    def __init__(self, ec, guid):
+        super(LinuxTraceroute, self).__init__(ec, guid)
+        self._home = "traceroute-%s" % self.guid
+
+    def deploy(self):
+        if not self.get("command"):
+            self.set("command", self._start_command)
+
+        if not self.get("depends"):
+            self.set("depends", "traceroute")
+
+        super(LinuxTraceroute, self).deploy()
+
+    @property
+    def _start_command(self):
+        args = []
+        if self.get("continuous") == True:
+            args.append("while true; do ")
+        if self.get("printTimestamp") == True:
+            args.append("""echo "`date +'%Y%m%d%H%M%S'`";""")
+        args.append("traceroute")
+        args.append(self.get("target"))
+        if self.get("continuous") == True:
+            args.append("; done ")
+
+        command = " ".join(args)
+
+        return command
+
+    def valid_connection(self, guid):
+        # TODO: Validate!
+        return True
+
diff --git a/test/resources/linux/traceroute.py b/test/resources/linux/traceroute.py
new file mode 100755 (executable)
index 0000000..996472e
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+#    NEPI, a framework to manage network experiments
+#    Copyright (C) 2013 INRIA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.ec import ExperimentController 
+from test_utils import skipIfNotAlive, skipInteractive
+
+import os
+import time
+import tempfile
+import unittest
+
+class LinuxTracerouteTestCase(unittest.TestCase):
+    def setUp(self):
+        self.fedora_host = "nepi2.pl.sophia.inria.fr"
+        self.fedora_user = "inria_nepi"
+
+        self.ubuntu_host = "roseval.pl.sophia.inria.fr"
+        self.ubuntu_user = "alina"
+        
+        self.target = "nepi5.pl.sophia.inria.fr"
+
+    @skipIfNotAlive
+    def t_traceroute(self, host, user):
+
+        ec = ExperimentController(exp_id = "test-traceroute")
+        
+        node = ec.register_resource("LinuxNode")
+        ec.set(node, "hostname", host)
+        ec.set(node, "username", user)
+        ec.set(node, "cleanHome", True)
+        ec.set(node, "cleanProcesses", True)
+
+        app = ec.register_resource("LinuxTraceroute")
+        ec.set(app, "target", self.target)
+        ec.register_connection(app, node)
+
+        ec.deploy()
+
+        ec.wait_finished(app)
+
+        stdout = ec.trace(app, "stdout")
+        self.assertTrue(stdout.find("traceroute to") > -1)
+
+        ec.shutdown()
+
+    def test_traceroute_fedora(self):
+        self.t_traceroute(self.fedora_host, self.fedora_user)
+
+    def test_traceroute_ubuntu(self):
+        self.t_traceroute(self.ubuntu_host, self.ubuntu_user)
+
+if __name__ == '__main__':
+    unittest.main()
+