summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2022-06-24 10:17:03 -0700
committerMatt Clay <matt@mystile.com>2022-06-24 12:23:51 -0700
commit99217ca2b68909455b783811836d66589bd991d8 (patch)
treea6f8971c45374d389e7498140555f2ee17f5836b /test
parenta2022a37db7c29fd04a31fc33a430a6ce989de1f (diff)
downloadansible-99217ca2b68909455b783811836d66589bd991d8.tar.gz
[stable-2.13] ansible-test - Improve pip bootstrap download.
(cherry picked from commit b9d13d222cfe4ebd9675d5bbf529e929daaded6f) Co-authored-by: Matt Clay <matt@mystile.com>
Diffstat (limited to 'test')
-rw-r--r--test/lib/ansible_test/_util/target/setup/requirements.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/lib/ansible_test/_util/target/setup/requirements.py b/test/lib/ansible_test/_util/target/setup/requirements.py
index 0a29429b87..ac71f24008 100644
--- a/test/lib/ansible_test/_util/target/setup/requirements.py
+++ b/test/lib/ansible_test/_util/target/setup/requirements.py
@@ -18,6 +18,7 @@ if DESIRED_RLIMIT_NOFILE < CURRENT_RLIMIT_NOFILE:
CURRENT_RLIMIT_NOFILE = DESIRED_RLIMIT_NOFILE
import base64
+import contextlib
import errno
import io
import json
@@ -41,10 +42,10 @@ except ImportError:
try:
from urllib.request import urlopen
except ImportError:
- from urllib import urlopen
+ # noinspection PyCompatibility,PyUnresolvedReferences
+ from urllib2 import urlopen # pylint: disable=ansible-bad-import-from
ENCODING = 'utf-8'
-PAYLOAD = b'{payload}' # base-64 encoded JSON payload which will be populated before this script is executed
Text = type(u'')
@@ -91,7 +92,20 @@ def bootstrap(pip, options): # type: (str, t.Dict[str, t.Any]) -> None
log('Downloading pip %s bootstrap script: %s' % (pip_version, url))
make_dirs(os.path.dirname(cache_path))
- download_file(url, temp_path)
+
+ try:
+ download_file(url, temp_path)
+ except Exception as ex:
+ raise ApplicationError(('''
+Download failed: %s
+
+The bootstrap script can be manually downloaded and saved to: %s
+
+If you're behind a proxy, consider commenting on the following GitHub issue:
+
+https://github.com/ansible/ansible/issues/77304
+''' % (ex, cache_path)).strip())
+
shutil.move(temp_path, cache_path)
log('Cached pip %s bootstrap script: %s' % (pip_version, cache_path))
@@ -196,8 +210,8 @@ def devnull(): # type: () -> t.IO[bytes]
def download_file(url, path): # type: (str, str) -> None
"""Download the given URL to the specified file path."""
with open(to_bytes(path), 'wb') as saved_file:
- download = urlopen(url)
- shutil.copyfileobj(download, saved_file)
+ with contextlib.closing(urlopen(url)) as download:
+ shutil.copyfileobj(download, saved_file)
class ApplicationError(Exception):
@@ -317,5 +331,7 @@ def to_text(value, errors='strict'): # type: (t.AnyStr, str) -> t.Text
raise Exception('value is not bytes or text: %s' % type(value))
+PAYLOAD = b'{payload}' # base-64 encoded JSON payload which will be populated before this script is executed
+
if __name__ == '__main__':
main()