blob: 6ed15ab09c5a713693164d45fb5292bc4a220793 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From ffe06c6dd812b604d6482e4353d5564fad78bc90 Mon Sep 17 00:00:00 2001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002From: Hongxu Jia <hongxu.jia@windriver.com>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003Date: Mon, 30 Jul 2018 15:52:21 +0800
Brad Bishopd7bf8c12018-02-25 22:55:05 -05004Subject: [PATCH 4/4] load.py: retry to invoke request with timeout
5
6While networkless, use request to fetch kickstart file from
7network, it failed and wait 300s to break, we should retry
8to invoke request with timeout explicitly. So if it the
9network is up, the fetch works.
10
11Upstream-Status: inappropriate [oe specific]
12
13Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
14---
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015 pykickstart/load.py | 31 +++++++++++++++++++++++++++++++
16 1 file changed, 31 insertions(+)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017
18diff --git a/pykickstart/load.py b/pykickstart/load.py
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080019index ad3bad1..a5cbbc5 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020--- a/pykickstart/load.py
21+++ b/pykickstart/load.py
22@@ -21,6 +21,7 @@ import requests
23 from requests.auth import HTTPDigestAuth
24 from requests.auth import HTTPBasicAuth
25
26+import time
27 import shutil
28 import six
29
30@@ -28,6 +29,9 @@ from pykickstart.errors import KickstartError, KickstartAuthError
31 from pykickstart.i18n import _
32 from requests.exceptions import SSLError, RequestException
33
34+import logging
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080035+log = logging.getLogger("anaconda.main")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036+
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080037 _is_url = lambda location: '://' in location # RFC 3986
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038
39 SSL_VERIFY = False
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080040@@ -73,6 +77,29 @@ def load_to_file(location, destination):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041 _copy_file(location, destination)
42 return destination
43
44+def _access_url(location):
45+ status = False
46+
47+ # Retry 45 times, wait 45s~135s
48+ i = 0
49+ while i < 45:
50+
51+ try:
52+ request = requests.get(location, verify=SSL_VERIFY, timeout=2)
53+ except RequestException as e:
54+ log.info("Try '%s' %d times, %s" % (location, i, str(e)))
55+ status = False
56+ i += 1
57+ time.sleep(1)
58+ continue
59+
60+ else:
61+ status = True
62+ return status
63+
64+ return status
65+
66+
67 def _get_auth(location, user=None, passwd=None):
68
69 auth = None
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070@@ -94,6 +121,10 @@ def _get_auth(location, user=None, passwd=None):
71
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072 def _load_url(location, user=None, passwd=None):
73 '''Load a location (URL or filename) and return contents as string'''
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080074+
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075+ if not _access_url(location):
76+ raise KickstartError(_("Connection %s failed" % location))
77+
78 auth = _get_auth(location, user=user, passwd=passwd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 try:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 request = requests.get(location, verify=SSL_VERIFY, auth=auth)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081--
822.7.4
83