Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 8126FE00C1B; Thu, 27 Aug 2015 19:18:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE autolearn=no version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS Received: from heian.cn.fujitsu.com (unknown [59.151.112.132]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 1AD25E00A3C for ; Thu, 27 Aug 2015 19:18:24 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100109501" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 Aug 2015 10:21:30 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t7S2IFoi004441 for ; Fri, 28 Aug 2015 10:18:15 +0800 Received: from localhost.localdomain (10.167.226.31) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 28 Aug 2015 10:18:21 +0800 From: Bian Naimeng To: Date: Fri, 28 Aug 2015 10:18:05 +0800 Message-ID: <1440728285-10514-1-git-send-email-biannm@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] Subject: [RFC PATCH v2] toaster: support authentication required proxy connection X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2015 02:18:32 -0000 Content-Type: text/plain At authentication required proxy environment, such as setting $http_proxy to 'http://user:password@ip:port', the following error will be caught. EE: Using proxy http://user:password@ip:port EE: could not connect to 'url', skipping update: 'error message' It means toaster can not fetche layer, recipe and machine information from remote repository at authentication required proxy environment. What this patch tries to fix is that make toaster support authentication required proxy connection. I have did some tests after applying this patch. 1. Proxy with authentication # export http_proxy="http://user:password@ip:port" # bitbake/bin/toaster Result: OK 2. Proxy without authentication # export http_proxy="http://ip:port" # bitbake/bin/toaster Result: OK 3. Directly # bitbake/bin/toaster Result: Unknow, Not yet tested Signed-off-by: Bian Naimeng --- lib/toaster/orm/models.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py index 92fcaa7..ffd435b 100644 --- a/lib/toaster/orm/models.py +++ b/lib/toaster/orm/models.py @@ -817,42 +817,20 @@ class LayerIndexLayerSource(LayerSource): assert self.apiurl is not None from django.db import transaction, connection - import httplib, urlparse, json + import urllib2, urlparse, json import os proxy_settings = os.environ.get("http_proxy", None) def _get_json_response(apiurl = self.apiurl): - conn = None _parsedurl = urlparse.urlparse(apiurl) path = _parsedurl.path - query = _parsedurl.query - def parse_url(url): - parsedurl = urlparse.urlparse(url) - try: - (host, port) = parsedurl.netloc.split(":") - except ValueError: - host = parsedurl.netloc - port = None - - if port is None: - port = 80 - else: - port = int(port) - return (host, port) - if proxy_settings is None: - host, port = parse_url(apiurl) - conn = httplib.HTTPConnection(host, port) - conn.request("GET", path + "?" + query) - else: - host, port = parse_url(proxy_settings) - conn = httplib.HTTPConnection(host, port) - conn.request("GET", apiurl) - - r = conn.getresponse() - if r.status != 200: - raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason)) - return json.loads(r.read()) + try: + res = urllib2.urlopen(apiurl); + except urllib2.URLError,e: + raise Exception("Failed to read " + path + ": %d %s" % (e.code, e.reason)) + + return json.loads(res.read()) # verify we can get the basic api try: -- 1.9.1