diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 408: fix health check regression for master images

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

Commit Message

Andy Doan Oct. 18, 2012, 3:11 p.m. UTC
------------------------------------------------------------
revno: 408
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-dispatcher
timestamp: Thu 2012-10-18 10:10:06 -0500
message:
  fix health check regression for master images
  
  Target implementations must now always set self.deployment_data. We
  were missing logic to set this when we find cached tarballs for health
  jobs. This commit does two things:
  
  1. Add "data" to the tuple that gets cached. This data is flexible, but
  in practice is just "oe" or "ubuntu" to tell us which deployment_data
  is needed.
  
  2. Make tarballcache more resilient. This changes how tarballcache is
  set up. So current installations not including this new "data" file will
  need to re-generate their tarballs. While I was at it, I also fixed
  logic so that accidental deletion of say "boot.tgz" can be managed
  properly (ie - it will clear the cache and regenerate)
modified:
  lava_dispatcher/device/master.py
  lava_dispatcher/tarballcache.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/device/master.py'
--- lava_dispatcher/device/master.py	2012-10-17 16:52:05 +0000
+++ lava_dispatcher/device/master.py	2012-10-18 15:10:06 +0000
@@ -65,6 +65,14 @@ 
         Target.android_deployment_data['boot_cmds'] = 'boot_cmds_android'
         Target.ubuntu_deployment_data['boot_cmds'] = 'boot_cmds'
 
+        # used for tarballcache logic to get proper boot_cmds
+        Target.ubuntu_deployment_data['data_type'] = 'ubuntu'
+        Target.oe_deployment_data['data_type'] = 'oe'
+        self.target_map = {
+            'ubuntu': Target.ubuntu_deployment_data,
+            'oe': Target.oe_deployment_data,
+            }
+
         self.master_ip = None
 
         if config.pre_connect_command:
@@ -124,8 +132,9 @@ 
         self.boot_master_image()
 
         if self.context.job_data.get('health_check', False):
-            (boot_tgz, root_tgz) = tarballcache.get_tarballs(
+            (boot_tgz, root_tgz, data) = tarballcache.get_tarballs(
                 self.context, image, self.scratch_dir, self._generate_tarballs)
+            self.deployment_data = self.target_map[data]
         else:
             image_file = download_image(image, self.context, self.scratch_dir)
             boot_tgz, root_tgz = self._generate_tarballs(image_file)
@@ -171,7 +180,11 @@ 
             tb = traceback.format_exc()
             self.sio.write(tb)
             raise
-        return boot_tgz, root_tgz
+
+        # we need to associate the deployment data with these so that we
+        # can provide the proper boot_cmds later on in the job
+        data = self.deployment_data['data_type']
+        return boot_tgz, root_tgz, data
 
     def target_extract(self, runner, tar_url, dest, timeout=-1, num_retry=5):
         decompression_char = ''

=== modified file 'lava_dispatcher/tarballcache.py'
--- lava_dispatcher/tarballcache.py	2012-09-30 17:01:37 +0000
+++ lava_dispatcher/tarballcache.py	2012-10-18 15:10:06 +0000
@@ -47,18 +47,25 @@ 
     with _cache_locked(image_url, context.config.lava_cachedir) as cachedir:
         boot_tgz = os.path.join(cachedir, 'boot.tgz')
         root_tgz = os.path.join(cachedir, 'root.tgz')
+        data_file = os.path.join(cachedir, 'data')
 
         if os.path.exists(boot_tgz) and os.path.exists(root_tgz):
-            logging.info('returning cached copies')
-            (boot_tgz, root_tgz) = _link(boot_tgz, root_tgz, scratch_dir)
-            return (boot_tgz, root_tgz)
+            data = _get_data(cachedir, data_file)
+            if data is not None:
+                logging.info('returning cached copies')
+                (boot_tgz, root_tgz) = _link(boot_tgz, root_tgz, scratch_dir)
+                return (boot_tgz, root_tgz, data)
+        else:
+            logging.info('no cache found for %s' % image_url)
 
-        logging.info('no cache found for %s' % image_url)
+        _clear_cache(boot_tgz, root_tgz, data_file)
         image = download_image(image_url, context, cachedir)
-        (boot_tgz, root_tgz) = generator(image)
+        (boot_tgz, root_tgz, data) = generator(image)
+        with open(data_file, 'w') as f:
+            f.write(data)
         _link(boot_tgz, root_tgz, cachedir)
         os.unlink(image)
-        return (boot_tgz, root_tgz)
+        return (boot_tgz, root_tgz, data)
 
 
 def _link(boot_tgz, root_tgz, destdir):
@@ -69,6 +76,25 @@ 
     return (dboot_tgz, droot_tgz)
 
 
+def _clear_cache(boot_tgz, root_tgz, data):
+    logging.info('Clearing cache contents')
+    if os.path.exists(boot_tgz):
+        os.unlink(boot_tgz)
+    if os.path.exists(root_tgz):
+        os.unlink(root_tgz)
+    if os.path.exists(data):
+        os.unlink(data)
+
+
+def _get_data(cachedir, data_file):
+    try:
+        with open(data_file, 'r') as f:
+            return f.read()
+    except IOError:
+        logging.warn('No data found for cached tarballs in %s' % cachedir)
+    return None
+
+
 @contextlib.contextmanager
 def _cache_locked(image_url, cachedir):
     cachedir = utils.url_to_cache(image_url, cachedir).replace('.', '-')