Add connection cache support in wget checkstatus.
v3 cover Add connection cache support in wget checkstatus.
This v3 fixes proxy setup only use ProxyHandler in urllib when proxies are set into env.
You can also review the changes at,
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=alimon/fetch2-wget-checkstatus
Aníbal Limón (6):
fetch2/__init__.py: Add FetchConnectionCache class
fetch2: Add fetch parameter to checkstatus fetch2/wget.py: Add support of connection cache in checkstatus. tests/fetch.py: Add FetchCheckStatusTest tests. fetch2/wget.py: checkstatus fix using proxy handler tests/fetch.py: FetchCheckStatusTest add cases for ftp and https.
lib/bb/fetch2/__init__.py | 59 ++++++++++++++---- lib/bb/fetch2/git.py | 2 +- lib/bb/fetch2/local.py | 2 +- lib/bb/fetch2/wget.py | 154 ++++++++++++++++++++++++++++++++++++++++++++-- lib/bb/tests/fetch.py | 45 ++++++++++++++ 5 files changed, 244 insertions(+), 18 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/6 fetch2/__init__.py: Add FetchConnectionCache class
FetchConnectionCache class acts as a container for socket connections useful when implement connection cache into fetcher modules.
--- lib/bb/fetch2/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
lib/bb/fetch2/__init__.py +36 -0
@@ -1711,6 +1711,42 @@ class Fetch(object): if ud.lockfile: bb.utils.unlockfile(lf) +class FetchConnectionCache(object): + """ + A class which represents an container for socket connections. + """ + def __init__(self): + self.cache = {} + + def get_connection_name(self, host, port): + return host + ':' + str(port) + + def add_connection(self, host, port, connection): + cn = self.get_connection_name(host, port) + + if cn not in self.cache: + self.cache[cn] = connection + + def get_connection(self, host, port): + connection = None + + cn = self.get_connection_name(host, port) + if cn in self.cache: + connection = self.cache[cn] + + return connection + + def remove_connection(self, host, port): + cn = self.get_connection_name(host, port) + if cn in self.cache: + self.cache[cn].close() + del self.cache[cn] + + def close_connections(self): + for cn in self.cache.keys(): + self.cache[cn].close() + del self.cache[cn] + from . import cvs from . import git from . import gitsm
Signature · 1 line
1.9.1
PATCH v3 2/6 fetch2: Add fetch parameter to checkstatus
In reply to Aníbal LimónIn order to pass connection cache object to checkstatus function add fetch parameter.
--- lib/bb/fetch2/__init__.py | 20 ++++++++++---------- lib/bb/fetch2/git.py | 2 +- lib/bb/fetch2/local.py | 2 +- lib/bb/fetch2/wget.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
lib/bb/fetch2/__init__.py +10 -10
@@ -907,12 +907,12 @@ def rename_bad_checksum(ud, suffix): bb.utils.movefile(ud.localpath, new_localpath) -def try_mirror_url(origud, ud, ld, check = False): +def try_mirror_url(fetch, origud, ud, ld, check = False): # Return of None or a value means we're finished # False means try another url try: if check: - found = ud.method.checkstatus(ud, ld) + found = ud.method.checkstatus(fetch, ud, ld) if found: return found return False
@@ -975,7 +975,7 @@ def try_mirror_url(origud, ud, ld, check = False): pass return False -def try_mirrors(d, origud, mirrors, check = False): +def try_mirrors(fetch, d, origud, mirrors, check = False): """ Try to use a mirrored version of the sources. This method will be automatically called before the fetchers go.
@@ -989,7 +989,7 @@ def try_mirrors(d, origud, mirrors, check = False): uris, uds = build_mirroruris(origud, mirrors, ld) for index, uri in enumerate(uris): - ret = try_mirror_url(origud, uds[index], ld, check) + ret = try_mirror_url(fetch, origud, uds[index], ld, check) if ret != False: return ret return None
@@ -1473,7 +1473,7 @@ class FetchMethod(object): """ return True - def checkstatus(self, urldata, d): + def checkstatus(self, fetch, urldata, d): """ Check the status of a URL Assumes localpath was called first
@@ -1577,7 +1577,7 @@ class Fetch(object): elif m.try_premirror(ud, self.d): logger.debug(1, "Trying PREMIRRORS") mirrors = mirror_from_string(self.d.getVar('PREMIRRORS', True)) - localpath = try_mirrors(self.d, ud, mirrors, False) + localpath = try_mirrors(self, self.d, ud, mirrors, False) if premirroronly: self.d.setVar("BB_NO_NETWORK", "1")
@@ -1616,7 +1616,7 @@ class Fetch(object): m.clean(ud, self.d) logger.debug(1, "Trying MIRRORS") mirrors = mirror_from_string(self.d.getVar('MIRRORS', True)) - localpath = try_mirrors (self.d, ud, mirrors) + localpath = try_mirrors(self, self.d, ud, mirrors) if not localpath or ((not os.path.exists(localpath)) and localpath.find("*") == -1): if firsterr:
@@ -1648,15 +1648,15 @@ class Fetch(object): logger.debug(1, "Testing URL %s", u) # First try checking uri, u, from PREMIRRORS mirrors = mirror_from_string(self.d.getVar('PREMIRRORS', True)) - ret = try_mirrors(self.d, ud, mirrors, True) + ret = try_mirrors(self, self.d, ud, mirrors, True) if not ret: # Next try checking from the original uri, u try: - ret = m.checkstatus(ud, self.d) + ret = m.checkstatus(self, ud, self.d) except: # Finally, try checking uri, u, from MIRRORS mirrors = mirror_from_string(self.d.getVar('MIRRORS', True)) - ret = try_mirrors(self.d, ud, mirrors, True) + ret = try_mirrors(self, self.d, ud, mirrors, True) if not ret: raise FetchError("URL %s doesn't work" % u, u)
lib/bb/fetch2/git.py +1 -1
@@ -423,7 +423,7 @@ class Git(FetchMethod): else: return True, str(rev) - def checkstatus(self, ud, d): + def checkstatus(self, fetch, ud, d): try: self._lsremote(ud, d, "") return True
lib/bb/fetch2/local.py +1 -1
@@ -112,7 +112,7 @@ class Local(FetchMethod): return True - def checkstatus(self, urldata, d): + def checkstatus(self, fetch, urldata, d): """ Check the status of the url """
lib/bb/fetch2/wget.py +1 -1
@@ -100,7 +100,7 @@ class Wget(FetchMethod): return True - def checkstatus(self, ud, d): + def checkstatus(self, fetch, ud, d): uri = ud.url.split(";")[0] fetchcmd = self.basecmd + " --spider '%s'" % uri
Signature · 1 line
1.9.1
PATCH v3 3/6 fetch2/wget.py: Add support of connection cache in checkstatus.
In reply to Aníbal Limónfetch2/__init__.py: Add connection_cache param in Fetch __init__.
In order to pass connection cache object to checkstatus method.
[YOCTO #7796]
--- lib/bb/fetch2/__init__.py | 3 +- lib/bb/fetch2/wget.py | 140 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 138 insertions(+), 5 deletions(-)
lib/bb/fetch2/__init__.py +2 -1
@@ -1505,7 +1505,7 @@ class FetchMethod(object): return "%s-%s" % (key, d.getVar("PN", True) or "") class Fetch(object): - def __init__(self, urls, d, cache = True, localonly = False): + def __init__(self, urls, d, cache = True, localonly = False, connection_cache = None): if localonly and cache: raise Exception("bb.fetch2.Fetch.__init__: cannot set cache and localonly at same time")
@@ -1514,6 +1514,7 @@ class Fetch(object): self.urls = urls self.d = d self.ud = {} + self.connection_cache = connection_cache fn = d.getVar('FILE', True) if cache and fn and fn in urldata_cache:
lib/bb/fetch2/wget.py +136 -4
148 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 4/6 tests/fetch.py: Add FetchCheckStatusTest tests.
In reply to Aníbal LimónAdd tests for checkstatus method using http with/without connection cache.
[YOCTO #7796]
--- lib/bb/tests/fetch.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
lib/bb/tests/fetch.py +39 -0
@@ -710,3 +710,42 @@ class FetchMethodTest(FetcherTest): verstring = ud.method.latest_versionstring(ud, self.d) r = bb.utils.vercmp_string(v, verstring) self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) + + +class FetchCheckStatusTest(FetcherTest): + test_wget_uris = ["http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2", + "http://www.cups.org/software/ipptool/ipptool-20130731-linux-ubuntu-i686.tar.gz", + "http://www.cups.org/", + "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", + "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz", + "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz", + "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz", + "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz"] + + if os.environ.get("BB_SKIP_NETTESTS") == "yes": + print("Unset BB_SKIP_NETTESTS to run network tests") + else: + + def test_wget_checkstatus(self): + fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d) + for u in self.test_wget_uris: + ud = fetch.ud[u] + m = ud.method + ret = m.checkstatus(fetch, ud, self.d) + self.assertTrue(ret, msg="URI %s, can't check status" % (u)) + + + def test_wget_checkstatus_connection_cache(self): + from bb.fetch2 import FetchConnectionCache + + connection_cache = FetchConnectionCache() + fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d, + connection_cache = connection_cache) + + for u in self.test_wget_uris: + ud = fetch.ud[u] + m = ud.method + ret = m.checkstatus(fetch, ud, self.d) + self.assertTrue(ret, msg="URI %s, can't check status" % (u)) + + connection_cache.close_connections()
Signature · 1 line
1.9.1
PATCH v3 5/6 fetch2/wget.py: checkstatus fix using proxy handler
In reply to Aníbal LimónFrom: Aníbal Limón <[email protected]>
Only use ProxyHandler opener when exists proxies in env.
--- lib/bb/fetch2/wget.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
lib/bb/fetch2/wget.py +16 -4
@@ -221,17 +221,29 @@ class Wget(FetchMethod): def export_proxies(d): variables = ['http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY', 'ftp_proxy', 'FTP_PROXY', 'no_proxy', 'NO_PROXY'] + exported = False for v in variables: - if not v in os.environ.keys(): - os.environ[v] = d.getVar(v, True) or '' + if v in os.environ.keys(): + exported = True + else: + v_proxy = d.getVar(v, True) + if v_proxy is not None: + os.environ[v] = v_proxy + exported = True + + return exported def head_method(self): return "HEAD" - export_proxies(d) + exported_proxies = export_proxies(d) + if exported_proxies == True: + opener = urllib2.build_opener(urllib2.ProxyHandler, CacheHTTPHandler) + else: + opener = urllib2.build_opener(CacheHTTPHandler) + urllib2.Request.get_method = head_method - opener = urllib2.build_opener(urllib2.ProxyHandler, CacheHTTPHandler) urllib2.install_opener(opener) uri = ud.url.split(";")[0]
Signature · 1 line
1.9.1
PATCH v3 6/6 tests/fetch.py: FetchCheckStatusTest add cases for ftp and https.
In reply to Aníbal LimónFrom: Aníbal Limón <[email protected]>
--- lib/bb/tests/fetch.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bb/tests/fetch.py +7 -1
@@ -719,8 +719,14 @@ class FetchCheckStatusTest(FetcherTest): "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz", "http://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz", + "https://yoctoproject.org/", + "https://yoctoproject.org/documentation", "http://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz", - "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz"] + "http://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz", + "ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz", + "ftp://ftp.gnu.org/gnu/chess/gnuchess-5.08.tar.gz", + "ftp://ftp.gnu.org/gnu/gmp/gmp-4.0.tar.gz", + ] if os.environ.get("BB_SKIP_NETTESTS") == "yes": print("Unset BB_SKIP_NETTESTS to run network tests")
Signature · 1 line
1.9.1