- for job, builds in spec.builds.items():
- for build in builds:
- if job.startswith("csit-"):
- if spec.input["file-name"].endswith(".zip"):
- url = spec.environment["urls"]["URL[JENKINS,CSIT]"]
- elif spec.input["file-name"].endswith(".gz"):
- url = spec.environment["urls"]["URL[NEXUS,LOG]"]
- else:
- logging.error("Not supported file format.")
- continue
- elif job.startswith("hc2vpp-"):
- url = spec.environment["urls"]["URL[JENKINS,HC]"]
- else:
- 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)
- 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,
- build=build["build"],
- name=file_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
- # temporary workaround, remove when output.log.xml is not needed
- if code != codes["OK"] and \
- spec.input["file-name"].endswith(".gz"):
- url = '.'.join(url.split('.')[:-1]) + ".log.gz"
- response = get(url, stream=True)
- code = response.status_code
-
- if code != codes["OK"]:
- 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")
- 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")
+ def requests_retry_session(retries=3,
+ backoff_factor=0.3,
+ status_forcelist=(500, 502, 504)):
+ """
+
+ :param retries: Total number of retries to allow.
+ :param backoff_factor: A backoff factor to apply between attempts after
+ the second try.
+ :param status_forcelist: A set of integer HTTP status codes that are
+ forced to retry.
+ :type retries: int
+ :type backoff_factor: float
+ :type status_forcelist: iterable
+ :returns: Session object.
+ :rtype: requests.Session
+ """
+
+ retry = Retry(
+ total=retries,
+ read=retries,
+ connect=retries,
+ backoff_factor=backoff_factor,
+ status_forcelist=status_forcelist,
+ )
+ adapter = HTTPAdapter(max_retries=retry)
+ session = requests.Session()
+ session.mount(u"http://", adapter)
+ session.mount(u"https://", adapter)
+ return session
+
+ success = False
+ while repeat:
+ repeat -= 1
+ session = None
+ try:
+ logging.info(f" Connecting to {url} ...")
+ session = requests_retry_session()
+ response = session.get(url, stream=True, verify=verify)
+ code = response.status_code
+ logging.info(f" {code}: {responses[code]}")
+
+ if code != codes[u"OK"]:
+ if session:
+ session.close()
+ return False, file_name
+
+ dst_file_name = file_name.replace(u".gz", u"")
+ logging.info(f" Downloading the file {url} to {dst_file_name}")
+ with open(dst_file_name, u"wb") as file_handle: