summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBian Naimeng <biannm@cn.fujitsu.com>2015-08-28 16:37:38 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-29 14:03:51 +0100
commit8e1f080c0453de681e1dbc1b36e2781d552e9f79 (patch)
treebb5a361f08a6bbf0e99a106bbd73a14c0a4c1039
parentce2a82708626b8f542fad769d2988ca16ea6dd2b (diff)
downloadpoky-8e1f080c0453de681e1dbc1b36e2781d552e9f79.tar.gz
bitbake: toaster: Support environments which have proxies set
In an environment with a proxy which requires authentication, e.g. with $http_proxy = 'http://user:password@ip:port', the following error occurs when running Toaster: EE: Using proxy http://user:password@ip:port EE: could not connect to 'url', skipping update: 'error message' This prevents Toaster from fetching layer, recipe and machine information from remote repositories. This patch allows Toaster to use the proxy settings from the environment for HTTP/HTTPS requests. (Bitbake rev: e7a85031fd05a46ef60b380883da4cc372acf89b) Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/toaster/orm/models.py36
1 files changed, 7 insertions, 29 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 92fcaa7adf..58f76a8342 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -817,42 +817,20 @@ class LayerIndexLayerSource(LayerSource):
817 assert self.apiurl is not None 817 assert self.apiurl is not None
818 from django.db import transaction, connection 818 from django.db import transaction, connection
819 819
820 import httplib, urlparse, json 820 import urllib2, urlparse, json
821 import os 821 import os
822 proxy_settings = os.environ.get("http_proxy", None) 822 proxy_settings = os.environ.get("http_proxy", None)
823 823
824 def _get_json_response(apiurl = self.apiurl): 824 def _get_json_response(apiurl = self.apiurl):
825 conn = None
826 _parsedurl = urlparse.urlparse(apiurl) 825 _parsedurl = urlparse.urlparse(apiurl)
827 path = _parsedurl.path 826 path = _parsedurl.path
828 query = _parsedurl.query
829 def parse_url(url):
830 parsedurl = urlparse.urlparse(url)
831 try:
832 (host, port) = parsedurl.netloc.split(":")
833 except ValueError:
834 host = parsedurl.netloc
835 port = None
836
837 if port is None:
838 port = 80
839 else:
840 port = int(port)
841 return (host, port)
842 827
843 if proxy_settings is None: 828 try:
844 host, port = parse_url(apiurl) 829 res = urllib2.urlopen(apiurl)
845 conn = httplib.HTTPConnection(host, port) 830 except urllib2.URLError as e:
846 conn.request("GET", path + "?" + query) 831 raise Exception("Failed to read %s: %s" % (path, e.reason))
847 else: 832
848 host, port = parse_url(proxy_settings) 833 return json.loads(res.read())
849 conn = httplib.HTTPConnection(host, port)
850 conn.request("GET", apiurl)
851
852 r = conn.getresponse()
853 if r.status != 200:
854 raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason))
855 return json.loads(r.read())
856 834
857 # verify we can get the basic api 835 # verify we can get the basic api
858 try: 836 try: