X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Finput_data_files.py;h=7dae834b4d9dd7c7770fe6362222ab00943138d9;hp=d57d1545eac5a314b81378cbcf67b14c48e3f580;hb=6addc914c636a0dbc1e12a661019cce1715baf77;hpb=fd987b10941ca09a54cf0325c2b097b734bdbc94 diff --git a/resources/tools/presentation/input_data_files.py b/resources/tools/presentation/input_data_files.py index d57d1545ea..7dae834b4d 100644 --- a/resources/tools/presentation/input_data_files.py +++ b/resources/tools/presentation/input_data_files.py @@ -15,6 +15,8 @@ Download all data. """ +import re + import logging from os import rename, remove @@ -34,6 +36,8 @@ CHUNK_SIZE = 512 # Separator used in file names SEPARATOR = "__" +REGEX_RELEASE = re.compile(r'(\D*)(\d{4})(\D*)') + def download_data_files(spec): """Download all data specified in the specification file in the section @@ -59,21 +63,42 @@ def download_data_files(spec): url = "{0}/{1}".format(url, full_name) new_name = join( spec.environment["paths"]["DIR[WORKING,DATA]"], - "{job}{sep}{build}{sep}{name}".format(job=job, sep=SEPARATOR, + "{job}{sep}{build}{sep}{name}".format(job=job, + sep=SEPARATOR, build=build["build"], name=file_name)) - - logging.info("Downloading the file '{0}' to '{1}'.". - format(url, new_name)) + logging.info( + "Downloading the file '{0}' to '{1}' ...".format(url, new_name)) status = "failed" try: response = get(url, stream=True) code = response.status_code if code != codes["OK"]: - logging.error("{0}: {1}".format(code, responses[code])) + logging.warning( + "Jenkins: {0}: {1}.".format(code, responses[code])) + logging.info("Trying to download from Nexus:") spec.set_input_state(job, build["build"], "not found") - continue + if code == codes["not_found"]: + release = re.search(REGEX_RELEASE, job).group(2) + nexus_file_name = "{job}{sep}{build}{sep}{name}".\ + format(job=job, sep=SEPARATOR, build=build["build"], + name=file_name) + url = "{url}/rls{release}/{dir}/{file}".\ + format(url=spec.environment["urls"]["URL[NEXUS]"], + release=release, + dir=spec.environment["urls"]["DIR[NEXUS]"], + file=nexus_file_name) + logging.info("Downloading the file '{0}' to '{1}' ...". + format(url, new_name)) + response = get(url, stream=True) + code = response.status_code + if code != codes["OK"]: + logging.error( + "Nexus: {0}: {1}".format(code, responses[code])) + spec.set_input_state( + job, build["build"], "not found") + continue file_handle = open(new_name, "wb") for chunk in response.iter_content(chunk_size=CHUNK_SIZE):