diff options
Diffstat (limited to 'meta-python/recipes-extended/python-pykickstart/files/0004-load.py-retry-to-invoke-request-with-timeout.patch')
| -rw-r--r-- | meta-python/recipes-extended/python-pykickstart/files/0004-load.py-retry-to-invoke-request-with-timeout.patch | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/meta-python/recipes-extended/python-pykickstart/files/0004-load.py-retry-to-invoke-request-with-timeout.patch b/meta-python/recipes-extended/python-pykickstart/files/0004-load.py-retry-to-invoke-request-with-timeout.patch new file mode 100644 index 0000000000..70254f6fda --- /dev/null +++ b/meta-python/recipes-extended/python-pykickstart/files/0004-load.py-retry-to-invoke-request-with-timeout.patch | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | From c0e63f0d3c09bdabb0ad2c88b7cc73e7618dd86a Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Hongxu Jia <hongxu.jia@windriver.com> | ||
| 3 | Date: Thu, 15 Jun 2017 17:35:33 +0800 | ||
| 4 | Subject: [PATCH 4/4] load.py: retry to invoke request with timeout | ||
| 5 | |||
| 6 | While networkless, use request to fetch kickstart file from | ||
| 7 | network, it failed and wait 300s to break, we should retry | ||
| 8 | to invoke request with timeout explicitly. So if it the | ||
| 9 | network is up, the fetch works. | ||
| 10 | |||
| 11 | Upstream-Status: inappropriate [oe specific] | ||
| 12 | |||
| 13 | Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> | ||
| 14 | --- | ||
| 15 | pykickstart/load.py | 30 ++++++++++++++++++++++++++++++ | ||
| 16 | 1 file changed, 30 insertions(+) | ||
| 17 | |||
| 18 | diff --git a/pykickstart/load.py b/pykickstart/load.py | ||
| 19 | index 48c8276..74b266b 100644 | ||
| 20 | --- 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 | ||
| 35 | +log = logging.getLogger("anaconda") | ||
| 36 | + | ||
| 37 | _is_url = lambda location: '://' in location # RFC 3986 | ||
| 38 | |||
| 39 | SSL_VERIFY = False | ||
| 40 | @@ -74,6 +78,29 @@ def load_to_file(location, destination): | ||
| 41 | _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 | ||
| 70 | @@ -96,6 +123,9 @@ def _get_auth(location, user=None, passwd=None): | ||
| 71 | def _load_url(location, user=None, passwd=None): | ||
| 72 | '''Load a location (URL or filename) and return contents as string''' | ||
| 73 | |||
| 74 | + if not _access_url(location): | ||
| 75 | + raise KickstartError(_("Connection %s failed" % location)) | ||
| 76 | + | ||
| 77 | auth = _get_auth(location, user=user, passwd=passwd) | ||
| 78 | |||
| 79 | try: | ||
| 80 | -- | ||
| 81 | 2.7.4 | ||
| 82 | |||
