From: Alina Quereilhac Date: Tue, 16 Jul 2013 15:39:43 +0000 (-0700) Subject: Fixing UdpTunnel not cleaning up processes X-Git-Tag: nepi-3.0.0~70 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0f1f8b4831f892fa82407dd7d1ab07b3927cd92c;p=nepi.git Fixing UdpTunnel not cleaning up processes --- diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index 645d6678..7ee7a470 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -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. diff --git a/src/nepi/resources/planetlab/tap.py b/src/nepi/resources/planetlab/tap.py index 9fdd5f08..01e7b144 100644 --- a/src/nepi/resources/planetlab/tap.py +++ b/src/nepi/resources/planetlab/tap.py @@ -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