Fix a bug that raise AttributeError.
authorHuang Hao <hao.h.huang@intel.com>
Tue, 14 Jan 2014 04:43:14 +0000 (12:43 +0800)
committerGui Chen <gui.chen@intel.com>
Thu, 16 Jan 2014 06:01:26 +0000 (08:01 +0200)
When download attachment packages by using yum pkgmgr, the url
variable below is a unicode instead of SafeURL object.

Traceback (most recent call last):
......
  File "/home/huanghao/workspace/mic/plugins/imager/loop_plugin.py", line 127, in do_create
    creator.install()
  File "/usr/local/lib/python2.7/dist-packages/mic/imager/baseimager.py", line 1051, in install
    self.__attachment_packages(pkg_manager)
  File "/usr/local/lib/python2.7/dist-packages/mic/imager/baseimager.py", line 966, in __attachment_packages
    fpath = grabber.myurlgrab(url.full, fpath, proxies, None)
AttributeError: 'unicode' object has no attribute 'full'

Change-Id: Ib5c03ef053b8cf22f1b8ef1868ad244427df7cc6

plugins/backend/yumpkgmgr.py

index 93c54cb5636cabbb63a63d97a38d819a16c36fef..6884551c98745556deb09c538f3734189b0f8bb1 100644 (file)
@@ -31,8 +31,10 @@ from mic.utils import misc, rpmmisc
 from mic.utils.grabber import TextProgress
 from mic.utils.proxy import get_proxy_for
 from mic.utils.errors import CreatorError
+from mic.utils.safeurl import SafeURL
 from mic.imager.baseimager import BaseImageCreator
 
+
 YUMCONF_TEMP = """[main]
 installroot=$installroot
 cachedir=/var/cache/yum
@@ -471,18 +473,18 @@ class Yum(BackendPlugin, yum.YumBase):
     def package_url(self, pkgname):
         pkgs = self.pkgSack.searchNevra(name=pkgname)
         if pkgs:
-            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
+            pkg = pkgs[0]
+
+            repo = pkg.repo
+            url = SafeURL(repo.baseurl[0]).join(pkg.remote_path)
+
+            proxy = repo.proxy
             if not proxy:
                 proxy = get_proxy_for(url)
             if proxy:
                 proxies = {str(url.split(':')[0]): str(proxy)}
+            else:
+                proxies = None
 
             return (url, proxies)