Bug fixing Netns emulation
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 28 Dec 2014 13:39:58 +0000 (14:39 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 28 Dec 2014 13:39:58 +0000 (14:39 +0100)
src/nepi/resources/linux/netns/netnsemulation.py
src/nepi/resources/netns/netnsapplication.py
src/nepi/resources/netns/netnsbase.py
src/nepi/resources/netns/netnsserver.py
src/nepi/resources/netns/netnswrapper.py
test/resources/linux/netns/netnsclient.py [changed mode: 0644->0755]
test/resources/linux/netns/netnsemulation.py [changed mode: 0644->0755]

index 5d6aae4..4ad8062 100644 (file)
@@ -32,7 +32,7 @@ import threading
 
 @clsinit_copy
 class LinuxNetNSEmulation(LinuxApplication, NetNSEmulation):
-    _rtype = "LinuxNetNSEmulation"
+    _rtype = "linux::netns::Emulation"
 
     @classmethod
     def _register_attributes(cls):
@@ -174,6 +174,26 @@ class LinuxNetNSEmulation(LinuxApplication, NetNSEmulation):
 
             self.set_ready()
 
+    def do_start(self):
+        """ Starts  execution execution
+
+        """
+        self.info("Starting")
+
+        if self.state == ResourceState.READY:
+            self.set_started()
+        else:
+            msg = " Failed to execute command '%s'" % command
+            self.error(msg, out, err)
+            raise RuntimeError, msg
+
+    def do_stop(self):
+        """ Stops simulation execution
+
+        """
+        if self.state == ResourceState.STARTED:
+            self.set_stopped()
+
     def do_release(self):
         self.info("Releasing resource")
 
index 5ffff92..2ed1363 100644 (file)
@@ -57,7 +57,7 @@ class NetNSApplication(NetNSBase):
         return [self.node]
 
     def do_start(self):
-        if self.simulation.state < ResourceState.STARTED:
+        if self.emulation.state < ResourceState.STARTED:
             self.debug("---- RESCHEDULING START ----" )
             self.ec.schedule(self.reschedule_delay, self.start)
         else:
@@ -74,8 +74,8 @@ class NetNSApplication(NetNSBase):
             self._start_time = self.emulation.start_time
 
     def _configure_traces(self):
-        stdout = "%s/%d.stdout " % (self.emulation.run_home, self.pid)
-        stderr = "%s/%d.stderr " % (self.emulation.run_home, self.pid)
+        stdout = "%s/%d.stdout" % (self.emulation.run_home, self.guid)
+        stderr = "%s/%d.stderr" % (self.emulation.run_home, self.guid)
         self._trace_filename["stdout"] = stdout 
         self._trace_filename["stderr"] = stderr
         self._traces["stdout"] = self.emulation.create("open", stdout, "w")
@@ -86,8 +86,8 @@ class NetNSApplication(NetNSBase):
         if self._state == ResourceState.STARTED:
             retcode = self.emulation.invoke(self.uuid, "poll")
    
-            if retcode:
-                if ret == 0:
+            if retcode is not None:
+                if retcode == 0:
                     self.set_stopped()
                 else:
                     out = ""
index 8dddc75..285cff7 100644 (file)
@@ -94,7 +94,7 @@ class NetNSBase(ResourceManager):
 
     def do_start(self):
         if self.state == ResourceState.READY:
-            # No need to do anything, simulation.Run() will start every object
+            # No need to do anything, emulation.Run() will start every object
             self.info("Starting")
             self.set_started()
         else:
@@ -104,7 +104,7 @@ class NetNSBase(ResourceManager):
 
     def do_stop(self):
         if self.state == ResourceState.STARTED:
-            # No need to do anything, simulation.Destroy() will stop every object
+            # No need to do anything, emulation.Destroy() will stop every object
             self.set_stopped()
     
     @property
@@ -119,14 +119,13 @@ class NetNSBase(ResourceManager):
             return self.emulation.emu_get(self.uuid, name)
         
         value = super(NetNSBase, self).get(name)
-        if name != "critical":
-            print name, value, "lalal"
         return value
 
     def set(self, name, value):
-        #flags = Flags.NoWrite | Flags.NoRead | Flags.Design
         flags = Flags.Design
-        if self.has_flag(name, flags):
+        if (self.state > ResourceState.NEW and \
+                self.has_flag(name, Flags.Design)) or \
+                self.has_flag(name, Flags.NoWrite):
             out = err = ""
             msg = " Cannot change Design only attribue %s" % name
             self.error(msg, out, err)
@@ -136,8 +135,6 @@ class NetNSBase(ResourceManager):
             self.emulation.emu_set(self.uuid, name, value)
         
         value = super(NetNSBase, self).set(name, value)
-        if name != "critical":
-            print name, value, "IEEEEEEEE:"
 
         return value
 
index 85853a1..4458b66 100644 (file)
@@ -154,6 +154,10 @@ def run_server(socket_name, level = logging.INFO,
         enable_dump = False):
 
     ###### wrapper instantiation
+    if level == logging.DEBUG:
+        from syslog import LOG_DEBUG
+        import netns
+        netns.environ.set_log_level(LOG_DEBUG)
 
     wrapper = NetNSWrapper(loglevel=level, enable_dump = enable_dump)
     
@@ -205,7 +209,7 @@ if __name__ == '__main__':
     ## configure logging
     FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
     level = logging.DEBUG if verbose else logging.INFO
-
+    
     logging.basicConfig(format = FORMAT, level = level)
 
     ## Run the server
index 712df34..74bd69a 100644 (file)
@@ -23,11 +23,6 @@ import os
 import sys
 import uuid
 
-try:
-    import netns
-except ImportError:
-    pass
-
 class NetNSWrapper(object):
     def __init__(self, loglevel = logging.INFO, enable_dump = False):
         super(NetNSWrapper, self).__init__()
old mode 100644 (file)
new mode 100755 (executable)
index 4f1bdf8..8fb7c0f
@@ -26,6 +26,7 @@ from nepi.resources.linux.netns.netnsclient import LinuxNetNSClient
 
 from test_utils import skipIf
 
+import logging
 import os
 import threading
 import time
@@ -52,7 +53,7 @@ class LinuxNetNSClientTest(unittest.TestCase):
     @skipIf(os.getuid() != 0, "Test requires root privileges")
     def test_run_ping_routing(self):
         thread = threading.Thread(target = run_server,
-                args = [self.socket_name])
+                args = [self.socket_name], kwargs={"level":logging.DEBUG})
 
         thread.setDaemon(True)
         thread.start()
@@ -131,7 +132,7 @@ class LinuxNetNSClientTest(unittest.TestCase):
         #        nexthop = '10.0.1.1')
         client.invoke(n1, "add_route", prefix="10.0.1.0", prefix_len=24,
                 nexthop="10.0.0.2")
-        client.invoke(n3, "add_route", prefix "10.0.0.0", prefix_len=24,
+        client.invoke(n3, "add_route", prefix="10.0.0.0", prefix_len=24,
                 nexthop="10.0.1.1")
 
         ## launch pings
old mode 100644 (file)
new mode 100755 (executable)
index d6d0b44..faa5838
@@ -21,7 +21,7 @@
 from nepi.execution.ec import ExperimentController 
 from nepi.execution.trace import TraceAttr
 
-from test_utils import skipIfNotAlive
+from test_utils import skipIfNotAlive, skipIf
 
 import os
 import time
@@ -51,10 +51,11 @@ class LinuxNetNSEmulationTest(unittest.TestCase):
         self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
 
     @skipIfNotAlive
+    @skipIf(os.getuid() != 0, "Test requires root privileges")
     def t_ping(self, host, user = None, identity = None):
         ec = ExperimentController(exp_id = "test-netns-p2p-ping")
         
-        node = ec.register_resource("LinuxNode")
+        node = ec.register_resource("linux::Node")
         if host == "localhost":
             ec.set(node, "hostname", "localhost")
         else:
@@ -65,7 +66,7 @@ class LinuxNetNSEmulationTest(unittest.TestCase):
         ec.set(node, "cleanProcesses", True)
         #ec.set(node, "cleanHome", True)
 
-        emu = ec.register_resource("LinuxNetNSEmulation")
+        emu = ec.register_resource("linux::netns::Emulation")
         ec.set(emu, "verbose", True)
         ec.register_connection(emu, node)
 
@@ -77,7 +78,7 @@ class LinuxNetNSEmulationTest(unittest.TestCase):
         ec.register_connection(iface2, switch)
  
         ping = ec.register_resource("netns::Application")
-        ec.set(ping, "command", "10.0.0.2")
+        ec.set(ping, "command", "ping -c20 10.0.0.2")
         ec.register_connection(ping, netnode1)
 
         ec.deploy()