blob: abe2c87e0030a358b0d2244698b1c127dee91fa0 [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
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060011Upstream-Status: Inappropriate [oe specific]
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
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
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060019index 58faba6..e856c8d 100644
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020--- a/pykickstart/load.py
21+++ b/pykickstart/load.py
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060022@@ -20,12 +20,16 @@
23 import requests
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 from requests.auth import HTTPDigestAuth
25 from requests.auth import HTTPBasicAuth
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026+import time
27 import shutil
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028
Andrew Geisslereff27472021-10-29 15:35:00 -050029 from pykickstart.errors import KickstartError, KickstartAuthError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030 from pykickstart.i18n import _
31 from requests.exceptions import SSLError, RequestException
32
33+import logging
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034+log = logging.getLogger("anaconda.main")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035+
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060036 is_url = lambda location: '://' in location # RFC 3986
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037
38 SSL_VERIFY = False
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060039@@ -71,6 +75,29 @@ def load_to_file(location, destination):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050040 _copy_file(location, destination)
41 return destination
42
43+def _access_url(location):
44+ status = False
45+
46+ # Retry 45 times, wait 45s~135s
47+ i = 0
48+ while i < 45:
49+
50+ try:
51+ request = requests.get(location, verify=SSL_VERIFY, timeout=2)
52+ except RequestException as e:
53+ log.info("Try '%s' %d times, %s" % (location, i, str(e)))
54+ status = False
55+ i += 1
56+ time.sleep(1)
57+ continue
58+
59+ else:
60+ status = True
61+ return status
62+
63+ return status
64+
65+
66 def _get_auth(location, user=None, passwd=None):
67
68 auth = None
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060069@@ -92,6 +119,10 @@ def _get_auth(location, user=None, passwd=None):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 def _load_url(location, user=None, passwd=None):
72 '''Load a location (URL or filename) and return contents as string'''
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080073+
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074+ if not _access_url(location):
75+ raise KickstartError(_("Connection %s failed" % location))
76+
77 auth = _get_auth(location, user=user, passwd=passwd)
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060078
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 try:
Andrew Geissler6aa7eec2023-03-03 12:41:14 -060080--
812.34.1
82