aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/presentation/input_data_files.py
diff options
context:
space:
mode:
authorTibor Frank <tifrank@cisco.com>2019-04-15 14:17:05 +0200
committerTibor Frank <tifrank@cisco.com>2019-04-17 13:09:43 +0000
commit5aa2e158983f61df6d26129ad566b906051fc5b5 (patch)
tree4bd1da284c080dbfbb43cc95cd504b86c078c7de /resources/tools/presentation/input_data_files.py
parent258f2666143138f20d84665fcfed53475bc88041 (diff)
CSIT-1483: Add processing of output_info.xml as the first choice
Change-Id: I27687ed6dda3a8717538653e75ad0d61c6516c7e Signed-off-by: Tibor Frank <tifrank@cisco.com>
Diffstat (limited to 'resources/tools/presentation/input_data_files.py')
-rw-r--r--resources/tools/presentation/input_data_files.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/resources/tools/presentation/input_data_files.py b/resources/tools/presentation/input_data_files.py
index 262c6a0a63..119a3102e0 100644
--- a/resources/tools/presentation/input_data_files.py
+++ b/resources/tools/presentation/input_data_files.py
@@ -52,46 +52,50 @@ def _download_file(url, file_name, log):
success = False
try:
log.append(("INFO", " Connecting to '{0}' ...".format(url)))
-
response = get(url, stream=True)
code = response.status_code
-
log.append(("INFO", " {0}: {1}".format(code, responses[code])))
if code != codes["OK"]:
- return False
+ url = url.replace("_info", "")
+ log.append(("INFO", " Connecting to '{0}' ...".format(url)))
+ response = get(url, stream=True)
+ code = response.status_code
+ log.append(("INFO", " {0}: {1}".format(code, responses[code])))
+ if code != codes["OK"]:
+ return False, file_name
+ file_name = file_name.replace("_info", "")
log.append(("INFO", " Downloading the file '{0}' to '{1}' ...".
format(url, file_name)))
- file_handle = open(file_name, "wb")
- for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
- if chunk:
- file_handle.write(chunk)
- file_handle.close()
+ with open(file_name, "wb") as file_handle:
+ for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
+ if chunk:
+ file_handle.write(chunk)
success = True
except ConnectionError as err:
log.append(("ERROR", "Not possible to connect to '{0}'.".format(url)))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
except HTTPError as err:
log.append(("ERROR", "Invalid HTTP response from '{0}'.".format(url)))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
except TooManyRedirects as err:
log.append(("ERROR", "Request exceeded the configured number "
"of maximum re-directions."))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
except Timeout as err:
log.append(("ERROR", "Request timed out."))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
except RequestException as err:
log.append(("ERROR", "Unexpected HTTP request exception."))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
except (IOError, ValueError, KeyError) as err:
log.append(("ERROR", "Download failed."))
- log.append(("DEBUG", str(err)))
+ log.append(("DEBUG", repr(err)))
log.append(("INFO", " Download finished."))
- return success
+ return success, file_name
def _unzip_file(spec, build, pid, log):
@@ -169,8 +173,7 @@ def download_and_unzip_data_file(spec, job, build, pid, log):
elif job.startswith("intel-dnv-"):
url = spec.environment["urls"]["URL[VIRL,DNV]"].format(release=job[-4:])
else:
- raise PresentationError("No url defined for the job '{}'.".
- format(job))
+ raise PresentationError("No url defined for the job '{}'.".format(job))
file_name = spec.input["file-name"]
full_name = spec.input["download-path"]. \
format(job=job, build=build["build"], filename=file_name)
@@ -182,7 +185,9 @@ def download_and_unzip_data_file(spec, job, build, pid, log):
name=file_name))
# Download the file from the defined source (Jenkins, logs.fd.io):
- success = _download_file(url, new_name, log)
+ success, downloaded_name = _download_file(url, new_name, log)
+ if success:
+ new_name = downloaded_name
if success and new_name.endswith(".zip"):
if not is_zipfile(new_name):
@@ -205,7 +210,7 @@ def download_and_unzip_data_file(spec, job, build, pid, log):
release=rls,
dir=spec.environment["urls"]["DIR[NEXUS]"],
file=nexus_file_name)
- success = _download_file(url, new_name, log)
+ success, new_name = _download_file(url, new_name, log)
if success:
break