blob: bf5a197230ff4c87f674e9b027f93faf5190ee23 [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From 737e9a7c11233183f48ce6c83d38b504c8ffed12 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
Andrew Geisslereff27472021-10-29 15:35:00 -05004Subject: [PATCH] load.py: retry to invoke request with timeout
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005
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>
Andrew Geisslereff27472021-10-29 15:35:00 -050014
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015---
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080016 pykickstart/load.py | 31 +++++++++++++++++++++++++++++++
17 1 file changed, 31 insertions(+)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018
19diff --git a/pykickstart/load.py b/pykickstart/load.py
Andrew Geisslereff27472021-10-29 15:35:00 -050020index f75fe5d3..a8f3ed1d 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021--- a/pykickstart/load.py
22+++ b/pykickstart/load.py
Andrew Geisslereff27472021-10-29 15:35:00 -050023@@ -21,12 +21,16 @@ import requests
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 from requests.auth import HTTPDigestAuth
25 from requests.auth import HTTPBasicAuth
26
27+import time
28 import shutil
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029
Andrew Geisslereff27472021-10-29 15:35:00 -050030 from pykickstart.errors import KickstartError, KickstartAuthError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031 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
Andrew Geisslereff27472021-10-29 15:35:00 -050040@@ -72,6 +76,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
Andrew Geisslereff27472021-10-29 15:35:00 -050070@@ -93,6 +120,10 @@ def _get_auth(location, user=None, passwd=None):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080071
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)