Re: mirrorlist server selection

Adrian Reber <[email protected]>
Newsgroups gmane.linux.rpm.yum
Message-ID <[email protected]>
On Wed, Mar 17, 2010 at 02:46:35PM -0400, James Antill wrote:
> Adrian Reber <[email protected]> writes:
> 
> > For RPM Fusion's mirrorlist I am also running Matt Domsch's
> > MirrorManager and we have two servers serving the mirrorlist. It is one
> > DNS name which resolves to two IPs. Yum automatically uses the correct
> > mirrorlist server if one of the servers is down (or if nothing answers
> > on port 80).
> 
>  As far as I can see there is no code to do this anywhere, for either
> mirrorlist or metalink yum just has a single URL and requests that
> from urlgrabber (and AFAIK there's nothing in urlgrabber to try all
> IPs for a given host, but maybe there is).
> 
> > I do not know if this is on purpose but if something is
> > answering on the port the mirrorlist is supposed to run with a http
> > status code 500 or 40? would it not also make sense to try another of
> > the available mirrorlist servers? This is especially a problem for RPM
> > Fusion because the mirrorlist infrastructure is not in as good hands as
> > the Fedora infrastructure.
> 
>  Now, in theory, it'd be possible to change _getMetalink() to have a
> list of URLs and try each in turn until we get "something that
> parses". But it's not super easy, and it'd need a lot of testing
> (... patches accepted :).

I am not sure I formulated my problem correctly, so I have written a
patch that does what I want. Maybe this helps to describe my problem
better. To test it I have created a DNS entry (mirrors.lisas.de) which
points to four IPs:

$ host mirrors.lisas.de
mirrors.lisas.de has address 129.143.116.10
mirrors.lisas.de has address 134.108.44.54
mirrors.lisas.de has address 88.198.59.188
mirrors.lisas.de has address 129.143.116.9

Two of those entries are working mirrorlists, one has a webserver which
does know nothing about mirrorlist and returns a 404 (129.143.116.10) and one
does not even have anything running on port 80 (129.143.116.9). I am
using following repo file:

[lisas]
name=test
mirrorlist=http://mirrors.lisas.de/mirrorlist?repo=free-fedora-$releasever&arch=$basearch
enabled=1
metadata_expire=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfusion-free-fedora-$releasever-$basearch

With the attached patch it goes to the next mirrorlist server if it
fails for any reason. It still has some debug code but I would like to
have some feedback if that is something that would be acceptable?

		Adrian

_______________________________________________
Yum mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum
mirrorlist.patch (text/plain, 2.8 KB)
--- yumRepo.py	2009-10-16 22:44:39.000000000 +0200
+++ /tmp/yumRepo.py	2010-03-18 13:32:20.156362252 +0100
@@ -49,6 +49,8 @@
 import errno
 import tempfile
 
+import socket
+
 #  If you want yum to _always_ check the MD .sqlite files then set this to
 # False (this doesn't affect .xml files or .sqilte files derived from them).
 # With this as True yum will only check when a new repomd.xml or
@@ -1626,6 +1628,9 @@
 
         return (returnlist, content)
 
+    def _unique(self, list):
+        return {}.fromkeys(list).keys()
+
     def _getMirrorList(self):
         """retrieve an up2date-style mirrorlist file from our mirrorlist url,
            also save the file to the local repo dir and use that if cache expiry
@@ -1644,14 +1649,36 @@
             url = 'file://' + self.mirrorlist_file # just to keep self._readMirrorList(fo,url) happy
         else:
             url = self.mirrorlist
-            scheme = urlparse.urlparse(url)[0]
+            parsed_url = urlparse.urlparse(url)
+            scheme = parsed_url.scheme
+            hostname = parsed_url.hostname
+            hosts = []
+            for i in socket.getaddrinfo(hostname, None):
+                hosts.append(i[4][0])
+            hosts = sorted(self._unique(hosts))
+            print hosts
             if scheme == '':
                 url = 'file://' + url
-            try:
-                fo = urlgrabber.grabber.urlopen(url, proxies=self.proxy_dict)
-            except urlgrabber.grabber.URLGrabError, e:
-                print "Could not retrieve mirrorlist %s error was\n%s: %s" % (url, e.args[0], misc.to_unicode(e.args[1]))
-                fo = None
+            if (scheme == 'http') or (scheme == 'https'):
+                for host in hosts:
+                    print "----------------> " + host
+                    try:
+                        _url = url
+                        _url = _url.replace(hostname, host)
+                        print _url
+                        fo = urlgrabber.grabber.urlopen(_url, proxies=self.proxy_dict, http_headers = (('Host', hostname),))
+                        break
+                    except urlgrabber.grabber.URLGrabError, e:
+                        if host != hosts[len(hosts) - 1]:
+                            continue
+                        print "Could not retrieve mirrorlist %s error was\n%s: %s" % (url, e.args[0], misc.to_unicode(e.args[1]))
+                        fo = None
+            else:
+                try:
+                    fo = urlgrabber.grabber.urlopen(url, proxies=self.proxy_dict)
+                except urlgrabber.grabber.URLGrabError, e:
+                    print "Could not retrieve mirrorlist %s error was\n%s: %s" % (url, e.args[0], misc.to_unicode(e.args[1]))
+                    fo = None
 
         (returnlist, content) = self._readMirrorList(fo, url)
signature.asc (application/pgp-signature, 828 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIVAwUBS6IikedDuj8+7Mg2AQKtxg//UFVOUOCEzVmkqjDCKTz80qnckhBabgx9
dVdGhjXB4Lo451T7u960l3iD0yguYguKMFFXKUeg1Ca6Qv3hkzW/3YS+IKPJfDJE
Ic24Ca0xYqjUG+6xBb+o+5nlv1+wkmvJxASI7Sqp6f8f2imDamX75VtMzT15hmVK
1JH66oymxRXx0/VZ47aeSjviz0orojAzbluncwu1wOTF+whrPXb8sAseCHl1uNhc
EA2kiQS1x/qUit+aBnL0oG6QWKY0vY9aF/Wuvrue2LfXsAmgLBcxY4AWl3ZTBSol
dRQvssin3g5TCvMIVoPVYL2/ZcFJHtGTm9pBY/nBScIuVtvvu8RAtf4ETm+Q/E68
g+ei5cCMiP604RaRC0MWAdoFQhyQZtUZsG3liyIbg+QH/GT89mtZltkfLO4Z4gVE
cszsq0qFzOHZcbeoFzH5ffmciPW7eJmwgtVIZRmunEE1w46DEy1+eQ+n9Zys06np
/DSLpETHVNEjZTUpyWbNANItXAUg7KW9hKJujqA5vIScs6E4/578GwvpGjk8I0Ko
HoMHS5KT6pv2g9YMGhMdCyM/OYvdP7aDjUSpkkhbcmtx9Y5BPClla6n+ma8cLR8C
SpvLmhd9MRAHQ2bjUJ/nX40i3yYe56pT7TnOYwolQ+UIiEeQn826ZV3yevlNotXM
PRrjjYk2w3A=
=qo1+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.