diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 363: import attachment support for client implementations

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

Commit Message

Andy Doan Aug. 2, 2012, 11:09 p.m. UTC
Merge authors:
  Andy Doan (doanac)
Related merge proposals:
  https://code.launchpad.net/~doanac/lava-dispatcher/attchments/+merge/117522
  proposed by: Andy Doan (doanac)
  review: Approve - Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 363 [merge]
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-dispatcher
timestamp: Thu 2012-08-02 18:05:53 -0500
message:
  import attachment support for client implementations
modified:
  lava_dispatcher/actions/launch_control.py
  lava_dispatcher/client/base.py
  lava_dispatcher/client/fastmodel.py
  lava_dispatcher/test_data.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/actions/launch_control.py'
--- lava_dispatcher/actions/launch_control.py	2012-07-24 04:01:01 +0000
+++ lava_dispatcher/actions/launch_control.py	2012-07-31 20:20:02 +0000
@@ -168,8 +168,8 @@ 
             for bundle in all_bundles:
                 test_runs += bundle['test_runs']
 
-        self.context.test_data.add_seriallog(
-            self.context.client.get_seriallog())
+        attachments = self.client.get_test_data_attachments()
+        self.context.test_data.add_attachments(attachments)
 
         main_bundle['test_runs'].append(self.context.test_data.get_test_run())
 

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2012-08-01 17:52:55 +0000
+++ lava_dispatcher/client/base.py	2012-08-02 23:05:53 +0000
@@ -33,6 +33,8 @@ 
 from cStringIO import StringIO
 from tempfile import mkdtemp
 
+from lava_dispatcher.test_data import create_attachment
+
 
 class CommandRunner(object):
     """A convenient way to run a shell command and wait for a shell prompt.
@@ -424,9 +426,6 @@ 
         self.setup_proxy(self.tester_str)
         logging.info("System is in test image now")
 
-    def get_seriallog(self):
-        return self.sio.getvalue()
-
     def get_www_scratch_dir(self):
         ''' returns a temporary directory available for downloads that's gets
         deleted when the process exits '''
@@ -436,6 +435,10 @@ 
         os.chmod(d, 0755)
         return d
 
+    def get_test_data_attachments(self):
+        '''returns attachments to go in the "lava_results" test run'''
+        return [ create_attachment('serial.log', self.sio.getvalue()) ]
+
     # Android stuff
 
     def get_android_adb_interface(self):

=== modified file 'lava_dispatcher/client/fastmodel.py'
--- lava_dispatcher/client/fastmodel.py	2012-08-01 17:52:55 +0000
+++ lava_dispatcher/client/fastmodel.py	2012-08-02 23:05:53 +0000
@@ -19,7 +19,9 @@ 
 # with this program; if not, see <http://www.gnu.org/licenses>.
 
 import atexit
+import codecs
 import contextlib
+import cStringIO
 import logging
 import os
 import pexpect
@@ -40,6 +42,9 @@ 
 from lava_dispatcher.downloader import (
     download_image,
     )
+from lava_dispatcher.test_data import (
+    create_attachment,
+    )
 from lava_dispatcher.utils import (
     logging_spawn,
     logging_system,
@@ -192,6 +197,17 @@ 
         if self._sim_proc is not None:
             self._sim_proc.close()
 
+    def _drain_sim_proc(self):
+        '''pexpect will continue to get data for the simproc process. We need
+        to keep this pipe drained so that it won't get full and then stop block
+        the process from continuing to execute'''
+
+        # NOTE: the RTSM binary uses the windows code page(cp1252), but the
+        # dashboard needs this with a utf-8 encoding
+        f = cStringIO.StringIO()
+        self._sim_proc.logfile = codecs.EncodedFile(f, 'cp1252', 'utf-8')
+        _pexpect_drain(self._sim_proc).start()
+
     def _boot_linaro_image(self):
         self._stop()
 
@@ -215,7 +231,7 @@ 
         if match == 0:
             raise RuntimeError("fast model license check failed")
 
-        _pexpect_drain(self._sim_proc).start()
+        self._drain_sim_proc()
 
         logging.info('simulator is started connecting to serial port')
         self.proc = logging_spawn(
@@ -242,6 +258,16 @@ 
                     tarfile, mnt, self.context.lava_result_dir))
         return 'pass', '', tarfile
 
+    def get_test_data_attachments(self):
+        '''returns attachments to go in the "lava_results" test run'''
+        a = super(LavaFastModelClient, self).get_test_data_attachments()
+
+        # if the simulator never got started we won't even get to a logfile
+        if getattr(self._sim_proc, 'logfile', None) is not None:
+            content = self._sim_proc.logfile.getvalue()
+            a.append( create_attachment('rtsm.log', content) )
+        return a
+
 class _pexpect_drain(threading.Thread):
     ''' The simulator process can dump a lot of information to its console. If
     don't actively read from it, the pipe will get full and the process will
@@ -254,5 +280,4 @@ 
     def run(self):
         # change simproc's stdout so it doesn't overlap the stdout from our
         # serial console logging
-        self.proc.logfile = open('/dev/null', 'w')
         self.proc.drain()

=== modified file 'lava_dispatcher/test_data.py'
--- lava_dispatcher/test_data.py	2012-05-08 18:05:52 +0000
+++ lava_dispatcher/test_data.py	2012-07-31 20:20:02 +0000
@@ -22,6 +22,14 @@ 
 from uuid import uuid1
 import base64
 
+
+def create_attachment(pathname, content, mime_type='text/plain'):
+    return {
+        'pathname': pathname,
+        'mime_type': mime_type,
+        'content': base64.b64encode(content),
+    }
+
 class LavaTestData(object):
     def __init__(self, test_id='lava'):
         self.job_status = 'pass'
@@ -48,8 +56,8 @@ 
             }
         self._test_run['test_results'].append(result_data)
 
-    def add_attachment(self, attachment):
-        self._test_run['attachments'].append(attachment)
+    def add_attachments(self, attachments):
+        self._test_run['attachments'].extend(attachments)
 
     def add_tag(self, tag):
         self._test_run['tags'].append(tag)
@@ -68,13 +76,3 @@ 
         self.add_result('job_complete', self.job_status)
         return self._test_run
 
-    def add_seriallog(self, serial_log):
-        """
-        Add serial log to the "attachments" field, it aligns bundle 1.2 format
-        """
-        serial_log_base64 = base64.b64encode(serial_log)
-        attachment = {
-                "pathname": "serial.log",
-                "mime_type": "text/plain",
-                "content": serial_log_base64 }
-        self.add_attachment(attachment)