enhance proxy support in attachment retrieve
authorGui Chen <gui.chen@intel.com>
Fri, 15 Jun 2012 10:33:18 +0000 (18:33 +0800)
committerGui Chen <gui.chen@intel.com>
Fri, 15 Jun 2012 11:27:59 +0000 (19:27 +0800)
fix the issue that proxy in '--repo' is not available in attachment retrieving

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/imager/baseimager.py
plugins/backend/yumpkgmgr.py
plugins/backend/zypppkgmgr.py

index af12d8e..10f972a 100644 (file)
@@ -32,7 +32,7 @@ import rpm
 from mic import kickstart
 from mic import msger
 from mic.utils.errors import CreatorError, Abort
-from mic.utils import misc, rpmmisc, runner, proxy, fs_related as fs
+from mic.utils import misc, rpmmisc, runner, fs_related as fs
 
 class BaseImageCreator(object):
     """Installs a system to a chroot directory.
@@ -839,6 +839,7 @@ class BaseImageCreator(object):
                 for fpath in glob.glob(fpaths):
                     self._attachment.append(fpath)
                 continue
+
             filelist = pkg_manager.getFilelist(item)
             if filelist:
                 # found rpm in rootfs
@@ -848,14 +849,10 @@ class BaseImageCreator(object):
                 continue
 
             # try to retrieve rpm file
-            url = pkg_manager.package_url(item)
+            (url, proxies) = pkg_manager.package_url(item)
             if not url:
                 msger.warning("Can't get url from repo for %s" % item)
                 continue
-            proxies = None
-            aproxy = proxy.get_proxy_for(url)
-            if aproxy:
-                proxies = {url.split(':')[0]: aproxy}
             fpath = os.path.join(self.cachedir, os.path.basename(url))
             if not os.path.exists(fpath):
                 # download pkgs
index 8911c05..d677428 100644 (file)
@@ -28,6 +28,7 @@ import yum
 from mic import msger
 from mic.kickstart import ksparser
 from mic.utils import misc, rpmmisc
+from mic.utils.proxy import get_proxy_for
 from mic.utils.errors import CreatorError
 from mic.imager.baseimager import BaseImageCreator
 
@@ -447,9 +448,22 @@ class Yum(BackendPlugin, yum.YumBase):
             return None
         return pkg[0].po.filelist
 
-    def package_url(self, pkg):
-        pkgs = self.pkgSack.searchNevra(name=pkg)
+    def package_url(self, pkgname):
+        pkgs = self.pkgSack.searchNevra(name=pkgname)
         if pkgs:
-            return pkgs[0].remote_url
-        else:
-            return None
+            proxy = None
+            proxies = None
+            url = pkgs[0].remote_url
+            repoid = pkgs[0].repoid
+            repos = filter(lambda r: r.id == repoid, self.repos.listEnabled())
+
+            if repos:
+                proxy = repos[0].proxy
+            if not proxy:
+                proxy = get_proxy_for(url)
+            if proxy:
+                proxies = {str(url.split(':')[0]): str(proxy)}
+
+            return (url, proxies)
+
+        return (None, None)
index 1be9e07..ac1fa5d 100755 (executable)
@@ -838,7 +838,7 @@ class Zypp(BackendPlugin):
 
         return os.path.join(baseurl, location)
 
-    def package_url(self, pkg):
+    def package_url(self, pkgname):
 
         def cmpEVR(ed1, ed2):
             (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
@@ -851,12 +851,14 @@ class Zypp(BackendPlugin):
         q = zypp.PoolQuery()
         q.addKind(zypp.ResKind.package)
         q.setMatchExact()
-        q.addAttribute(zypp.SolvAttr.name,pkg)
+        q.addAttribute(zypp.SolvAttr.name, pkgname)
         items = sorted(q.queryResults(self.Z.pool()),
                        cmp=lambda x,y: cmpEVR(x.edition(), y.edition()),
                        reverse=True)
 
         if items:
-            return self.get_url(items[0])
+            url = self.get_url(items[0])
+            proxies = self.get_proxies(items[0])
+            return (url, proxies)
 
-        return None
+        return (None, None)