Fixing UdpTunnel not cleaning up processes
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 16 Jul 2013 15:39:43 +0000 (08:39 -0700)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 16 Jul 2013 15:39:43 +0000 (08:39 -0700)
src/nepi/execution/ec.py
src/nepi/resources/planetlab/tap.py

index 645d667..7ee7a47 100644 (file)
@@ -197,6 +197,18 @@ class ExperimentController(object):
             ResourceState.FAILED,
             ResourceState.FINISHED])
 
+    def wait_released(self, guids):
+        """ Blocking method that wait until all the RM from the 'guid' list 
+            reached the state RELEASED
+
+        :param guids: List of guids
+        :type guids: list
+        """
+        return self.wait(guids, states = [ResourceState.RELEASED,
+            ResourceState.STOPPED,
+            ResourceState.FAILED,
+            ResourceState.FINISHED])
+
     def wait(self, guids, states = [ResourceState.FINISHED, 
             ResourceState.FAILED,
             ResourceState.STOPPED]):
@@ -623,20 +635,11 @@ class ExperimentController(object):
         if not group:
             group = self.resources
 
-        threads = []
         for guid in group:
             rm = self.get_resource(guid)
-            thread = threading.Thread(target=rm.release)
-            threads.append(thread)
-            thread.setDaemon(True)
-            thread.start()
-
-        while list(threads) and not self.finished:
-            thread = threads[0]
-            # Time out after 5 seconds to check EC not terminated
-            thread.join(5)
-            if not thread.is_alive():
-                threads.remove(thread)
+            self.schedule("0s", rm.release)
+
+        self.wait_released(group)
         
     def shutdown(self):
         """ Shutdown the Experiment Controller. 
index 9fdd5f0..01e7b14 100644 (file)
@@ -142,7 +142,7 @@ class PlanetlabTap(LinuxApplication):
         self._run_in_background()
         
         # Retrive if_name
-        if_name = self._wait_if_name()
+        if_name = self.wait_if_name()
         self.set("deviceName", if_name) 
 
     def deploy(self):
@@ -214,7 +214,19 @@ class PlanetlabTap(LinuxApplication):
 
         return self._state
 
-    def _wait_if_name(self):
+    def release(self):
+        # Node needs to wait until all associated RMs are released
+        # to be released
+        from nepi.resources.linux.udptunnel import UdpTunnel
+        rms = self.get_connected(UdpTunnel.rtype())
+        for rm in rms:
+            if rm.state < ResourceState.STOPPED:
+                self.ec.schedule(reschedule_delay, self.release)
+                return 
+
+        super(PlanetlabTap, self).release()
+
+    def wait_if_name(self):
         """ Waits until the if_name file for the command is generated, 
             and returns the if_name for the device """
         if_name = None