diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 333: support linaro-android-media-create in fastmodel client

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

Commit Message

Andy Doan June 26, 2012, 3:52 p.m. UTC
Merge authors:
  Andy Doan (doanac)
Related merge proposals:
  https://code.launchpad.net/~doanac/lava-dispatcher/linaro-android-media-create/+merge/111998
  proposed by: Andy Doan (doanac)
------------------------------------------------------------
revno: 333 [merge]
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-dispatcher
timestamp: Tue 2012-06-26 10:50:46 -0500
message:
  support linaro-android-media-create in fastmodel client
modified:
  lava_dispatcher/actions/android_deploy.py
  lava_dispatcher/client/fastmodel.py
  lava_dispatcher/client/lmc_utils.py
  lava_dispatcher/downloader.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/android_deploy.py'
--- lava_dispatcher/actions/android_deploy.py	2012-06-15 20:36:11 +0000
+++ lava_dispatcher/actions/android_deploy.py	2012-06-25 21:36:11 +0000
@@ -20,6 +20,7 @@ 
 # along with this program; if not, see <http://www.gnu.org/licenses>.
 
 from lava_dispatcher.actions import BaseAction
+from lava_dispatcher.client.fastmodel import LavaFastModelClient
 from lava_dispatcher.client.master import LavaMasterImageClient
 
 
@@ -39,6 +40,7 @@ 
         }
 
     def run(self, boot, system, data, pkg=None, use_cache=True, rootfstype='ext4'):
-        if not isinstance(self.client, LavaMasterImageClient):
+        if not isinstance(self.client, LavaMasterImageClient) and \
+            not isinstance(self.client, LavaFastModelClient):
             raise RuntimeError("Invalid LavaClient for this action")
         self.client.deploy_linaro_android(boot, system, data, pkg, use_cache, rootfstype)

=== modified file 'lava_dispatcher/client/fastmodel.py'
--- lava_dispatcher/client/fastmodel.py	2012-06-22 16:18:50 +0000
+++ lava_dispatcher/client/fastmodel.py	2012-06-25 21:36:11 +0000
@@ -23,6 +23,7 @@ 
 import logging
 import os
 import pexpect
+import shutil
 import threading
 
 from lava_dispatcher.client.base import (
@@ -31,6 +32,7 @@ 
     )
 from lava_dispatcher.client.lmc_utils import (
     image_partition_mounted,
+    generate_android_image,
     get_partition_offset,
     )
 from lava_dispatcher.downloader import (
@@ -91,6 +93,28 @@ 
         else:
             self._customize_ubuntu()
 
+    def deploy_linaro_android(self, boot, system, data, pkg=None,
+                                use_cache=True, rootfstype='ext4'):
+        logging.info("Deploying Android on %s" % self.hostname)
+
+        self._boot = download_image(boot, self.context, decompress=False)
+        self._data = download_image(data, self.context, decompress=False)
+        self._system = download_image(system, self.context, decompress=False)
+
+        self._sd_image = '%s/android.img' % os.path.dirname(self._system)
+
+        generate_android_image(
+            'vexpress-a9', self._boot, self._data, self._system, self._sd_image)
+
+        # now grab the axf file from the boot partition
+        with image_partition_mounted(self._sd_image, self.boot_part) as mntdir:
+            src = '%s/linux-system-ISW.axf' % mntdir
+            self._axf = \
+                '%s/%s' % (os.path.dirname(self._system),os.path.split(src)[1])
+            shutil.copyfile(src, self._axf)
+
+        self._customize_android()
+
     def _close_sim_proc(self):
         self._sim_proc.close(True)
 

=== modified file 'lava_dispatcher/client/lmc_utils.py'
--- lava_dispatcher/client/lmc_utils.py	2012-04-10 15:29:26 +0000
+++ lava_dispatcher/client/lmc_utils.py	2012-06-26 03:59:26 +0000
@@ -115,6 +115,14 @@ 
         raise
     return image_file
 
+def generate_android_image(device, boot, data, system, ofile, size="2000M"):
+    cmd = ("flock /var/lock/lava-lmc.lck sudo linaro-android-media-create "
+           "--dev %s --image_file %s --image_size %s "
+           "--boot %s --userdata %s --system %s" %
+            (device, ofile, size, boot, data,system) )
+    logging.info("Generating android image with: %s" % cmd)
+    _run_linaro_media_create(cmd)
+
 def get_partition_offset(image, partno):
     cmd = 'parted %s -m -s unit b print' % image
     part_data = getoutput(cmd)

=== modified file 'lava_dispatcher/downloader.py'
--- lava_dispatcher/downloader.py	2012-06-15 20:35:05 +0000
+++ lava_dispatcher/downloader.py	2012-06-25 20:45:16 +0000
@@ -75,15 +75,15 @@ 
             fd.close()
 
 @contextlib.contextmanager
-def _decompressor_stream(url, imgdir):
+def _decompressor_stream(url, imgdir, decompress):
     fd = None
     decompressor = None
 
     fname,suffix = _url_to_fname_suffix(url, imgdir)
 
-    if suffix == 'gz':
+    if suffix == 'gz' and decompress:
         decompressor = zlib.decompressobj(16+zlib.MAX_WBITS)
-    elif suffix == 'bz2':
+    elif suffix == 'bz2' and decompress:
         decompressor = bz2.BZ2Decompressor()
     else:
         fname = '%s.%s' % (fname, suffix) #don't remove the file's real suffix
@@ -107,9 +107,10 @@ 
     filename = os.path.join(path, '.'.join(parts[:-1]))
     return (filename, suffix)
 
-def download_image(url, context, imgdir=None, delete_on_exit=True):
+def download_image(url, context, imgdir=None,
+                    delete_on_exit=True, decompress=True):
     '''downloads a image that's been compressed as .bz2 or .gz and
-    decompresses it on the file to the cache directory
+    optionally decompresses it on the file to the cache directory
     '''
     logging.info("Downloading image: %s" % url)
     if not imgdir:
@@ -129,7 +130,7 @@ 
         raise Exception("Unsupported url protocol scheme: %s" % url.scheme)
 
     with reader(url, context.lava_proxy, context.lava_cookies) as r:
-        with _decompressor_stream(url, imgdir) as (writer, fname):
+        with _decompressor_stream(url, imgdir, decompress) as (writer, fname):
             bsize = 32768
             buff = r.read(bsize)
             while buff: