diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 642: Make sure power_off() is always called at the end of a job

Message ID 20130725021926.2458.40850.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Antonio Terceiro July 25, 2013, 2:19 a.m. UTC
------------------------------------------------------------
revno: 642
committer: Antonio Terceiro <antonio.terceiro@linaro.org>
branch nick: kill-fastmodel-process
timestamp: Wed 2013-07-24 13:56:18 -0300
message:
  Make sure power_off() is always called at the end of a job
  
  This way all device objects can always clean up after themselves. Previously
  power_off was only called by TargetBasedClient#retrieve_results, i.e. the
  device's power_off() was only called when the job contained a submit_results
  action.
modified:
  lava_dispatcher/client/base.py
  lava_dispatcher/client/targetdevice.py
  lava_dispatcher/context.py
  lava_dispatcher/job.py
  lava_dispatcher/utils.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2013-07-16 16:02:15 +0000
+++ lava_dispatcher/client/base.py	2013-07-24 16:56:18 +0000
@@ -475,6 +475,9 @@ 
     def retrieve_results(self, result_disk):
         raise NotImplementedError(self.retrieve_results)
 
+    def finish(self):
+        pass
+
     # Android stuff
 
     def get_android_adb_interface(self):

=== modified file 'lava_dispatcher/client/targetdevice.py'
--- lava_dispatcher/client/targetdevice.py	2013-07-16 16:01:28 +0000
+++ lava_dispatcher/client/targetdevice.py	2013-07-24 16:56:18 +0000
@@ -67,7 +67,7 @@ 
     def _boot_linaro_image(self):
         if self.proc:
             logging.warning('device already powered on, powering off first')
-            self.target_device.power_off(self.proc)
+            self._power_off_device()
         self.proc = self.target_device.power_on()
 
     def _boot_linaro_android_image(self):
@@ -85,9 +85,9 @@ 
         return self.tester_session()
 
     def retrieve_results(self, result_disk):
+        self._power_off_device()
+
         td = self.target_device
-        td.power_off(self.proc)
-
         tar = os.path.join(td.scratch_dir, 'lava_results.tgz')
         result_dir = self.context.config.lava_result_dir
         with td.file_system(td.config.root_part, result_dir) as mnt:
@@ -99,3 +99,18 @@ 
         a = super(TargetBasedClient, self).get_test_data_attachments()
         a.extend(self.target_device.get_test_data_attachments())
         return a
+
+    def finish(self):
+        self._power_off_device()
+
+    def _power_off_device(self):
+        """
+        Powers the associated device off by calling its power_off() method.
+
+        Can be called multiple times, but only the first will be effective, all
+        the others will be no-ops (unless the device is powered on again by
+        calling one of the _boot* methods).
+        """
+        if self.proc:
+            self.target_device.power_off(self.proc)
+            self.proc = None

=== modified file 'lava_dispatcher/context.py'
--- lava_dispatcher/context.py	2013-07-16 16:07:31 +0000
+++ lava_dispatcher/context.py	2013-07-24 16:56:18 +0000
@@ -148,3 +148,6 @@ 
         logging.debug("Executing on host : '%r'" % command)
         return subprocess.check_output(command) 
 
+    def finish(self):
+        self.client.finish()
+

=== modified file 'lava_dispatcher/job.py'
--- lava_dispatcher/job.py	2013-07-16 16:08:07 +0000
+++ lava_dispatcher/job.py	2013-07-24 16:56:18 +0000
@@ -268,6 +268,7 @@ 
                 except Exception as err:
                     logging.error("Failed to submit the test result. Error = %s", err)
                     raise
+            self.context.finish()
 
     def _set_logging_level(self):
         # set logging level is optional

=== modified file 'lava_dispatcher/utils.py'
--- lava_dispatcher/utils.py	2013-07-24 14:04:25 +0000
+++ lava_dispatcher/utils.py	2013-07-24 16:56:18 +0000
@@ -272,7 +272,7 @@ 
                 time=datetime.datetime.utcnow().timetuple())
 
 def finalize_process(proc):
-    print("*** finalize_process ***")
     if proc:
+        logging.debug("Finalizing child proccess with PID %d" % proc.pid)
         proc.kill(9)
         proc.close()