diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 321: download code fixes for proxy and cookies

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

Commit Message

Andy Doan June 11, 2012, 8:08 p.m. UTC
Merge authors:
  Andy Doan (doanac)
Related merge proposals:
  https://code.launchpad.net/~doanac/lava-dispatcher/download-fixes/+merge/109255
  proposed by: Andy Doan (doanac)
  review: Approve - Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 321 [merge]
committer: Andy Doan <andy.doan@linaro.org>
branch nick: lava-dispatcher
timestamp: Mon 2012-06-11 14:54:52 -0500
message:
  download code fixes for proxy and cookies
modified:
  lava_dispatcher/client/master.py
  lava_dispatcher/context.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/master.py'
--- lava_dispatcher/client/master.py	2012-06-08 06:22:05 +0000
+++ lava_dispatcher/client/master.py	2012-06-11 19:54:52 +0000
@@ -35,7 +35,6 @@ 
 
 from lava_dispatcher.utils import (
     download,
-    download_with_cache,
     logging_spawn,
     logging_system,
     string_to_list,
@@ -439,6 +438,11 @@ 
         if os.path.exists(path):
             shutil.rmtree(path)
 
+    def _download(self, url, directory):
+        lava_proxy = self.context.lava_proxy
+        lava_cookies = self.context.lava_cookies
+        return download(url, directory, lava_proxy, lava_cookies)
+
     def deploy_linaro(self, hwpack=None, rootfs=None, image=None,
                       kernel_matrix=None, use_cache=True, rootfstype='ext3'):
         LAVA_IMAGE_TMPDIR = self.context.lava_image_tmpdir
@@ -473,14 +477,13 @@ 
                         # get the lock directory. The rest will skip the caching if _about_to_cache_tarballs
                         # return false.
                         should_cache = self._about_to_cache_tarballs(image, lava_cachedir)
-                        image_file = download_with_cache(image, tarball_dir, lava_cachedir)
+                        image_file = self._download(image, tarball_dir)
                         image_file = self.decompress(image_file)
                         boot_tgz, root_tgz = self._generate_tarballs(image_file)
                         if should_cache:
                             self._cache_tarballs(image, boot_tgz, root_tgz, lava_cachedir)
                 else:
-                    lava_proxy = self.context.lava_proxy
-                    image_file = download(image, tarball_dir, lava_proxy)
+                    image_file = self._download(image, tarball_dir)
                     image_file = self.decompress(image_file)
                     boot_tgz, root_tgz = self._generate_tarballs(image_file)
                     # remove the cached tarballs

=== modified file 'lava_dispatcher/context.py'
--- lava_dispatcher/context.py	2012-05-08 05:37:59 +0000
+++ lava_dispatcher/context.py	2012-06-07 23:38:28 +0000
@@ -63,6 +63,10 @@ 
         return proxy
 
     @property
+    def lava_cookies(self):
+        return self.config.get("LAVA_COOKIES", None)
+
+    @property
     def lava_image_tmpdir(self):
         return self.config.get("LAVA_IMAGE_TMPDIR")
 

=== modified file 'lava_dispatcher/utils.py'
--- lava_dispatcher/utils.py	2012-05-08 05:56:59 +0000
+++ lava_dispatcher/utils.py	2012-06-07 23:38:28 +0000
@@ -29,8 +29,7 @@ 
 
 import pexpect
 
-
-def download(url, path="", proxy=None, verbose_failure=1):
+def download(url, path="", proxy=None, cookies=None, verbose_failure=1):
     urlpath = urlparse.urlsplit(url).path
     filename = os.path.basename(urlpath)
     if path:
@@ -42,6 +41,8 @@ 
         else:
             handlers = []
         opener = urllib2.build_opener(*handlers)
+        if cookies:
+            opener.addheaders.append(('Cookie', cookies))
         response = opener.open(urllib2.quote(url, safe=":/"), timeout=30)
         fd = open(filename, 'wb')
         shutil.copyfileobj(response, fd, 0x10000)
@@ -74,20 +75,6 @@ 
     shutil.copy(src, dest)
 
 
-# XXX: duplication, we have similar code in lava-test, we need to move that to
-# lava.utils -> namespace as standalone package
-def download_with_cache(url, path="", cachedir=""):
-    cache_loc = url_to_cache(url, cachedir)
-    if os.path.exists(cache_loc):
-        filename = os.path.basename(cache_loc)
-        file_location = os.path.join(path, filename)
-        link_or_copy_file(cache_loc, file_location)
-    else:
-        file_location = download(url, path)
-        copy_file(file_location, cache_loc)
-    return file_location
-
-
 def url_to_cache(url, cachedir):
     url_parts = urlparse.urlsplit(url)
     path = os.path.join(cachedir, url_parts.netloc,