[Yum-devel] [PATCH] Reuse mirrors when max_retries > len(mirrors). BZ 765598

Zdenek Pavlas zpavlas at redhat.com
Fri Apr 12 14:33:56 UTC 2013


When there's less mirrors than the retry limit, we should
reuse mirrors.  A wrapper around the mirror failure callback
implements this.

This needs a recent python-urlgrabber that sends the 'tries'
counter to the callback.
---
 yum/yumRepo.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index b9bf1fe..f0eabb7 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -628,8 +628,23 @@ class YumRepository(Repository, config.RepoConf):
         if self.metalink:
             urls = map(add_mc, urls)
 
+        def mirror_failure(obj):
+            action = {}
+
+            # if max_retries > len(mirrors), set remove=False
+            # for first few attempts to allow mirror reuse.
+            if hasattr(obj, 'tries'):
+                action['remove'] = obj.tries > self.retries - len(self.urls)
+
+            # No known user of this callback, but just in case...
+            cb = self.mirror_failure_obj
+            if cb:
+                fun, arg, karg = callable(cb) and (cb, (), {}) or cb
+                action.update(fun(obj, *arg, **karg))
+            return action
+
         self._grab = mgclass(self._grabfunc, urls,
-                             failure_callback=self.mirror_failure_obj)
+                             failure_callback=mirror_failure)
 
     def _default_grabopts(self, cache=True):
         opts = { 'keepalive': self.keepalive,
-- 
1.7.11.7



More information about the Yum-devel mailing list