From 61e469b6326b6576e15145d99393c9b7d3fdd4e4 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 29 Apr 2014 16:02:08 -0500 Subject: [PATCH 1/4] Remove unused timeout arg to ResultsReporter init Signed-off-by: Zack Cerza --- teuthology/report.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/teuthology/report.py b/teuthology/report.py index 11d9a9e5de5..73bb702953f 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -174,7 +174,7 @@ class ResultsReporter(object): last_run_file = 'last_successful_run' def __init__(self, archive_base=None, base_uri=None, save=False, - refresh=False, timeout=20, log=None): + refresh=False, log=None): self.log = log or init_logging() self.archive_base = archive_base or config.archive_base self.base_uri = base_uri or config.results_server @@ -183,7 +183,6 @@ class ResultsReporter(object): self.serializer = ResultsSerializer(archive_base, log=self.log) self.save_last_run = save self.refresh = refresh - self.timeout = timeout def report_all_runs(self): """ From ec72137e1bded99a271e072cdb1f5a6703231776 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 29 Apr 2014 16:07:59 -0500 Subject: [PATCH 2/4] Add a requests.Session object to ResultsReporter By default it is set up to retry requests 10 times Signed-off-by: Zack Cerza --- teuthology/report.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/teuthology/report.py b/teuthology/report.py index 73bb702953f..79a0d955686 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -183,6 +183,13 @@ class ResultsReporter(object): self.serializer = ResultsSerializer(archive_base, log=self.log) self.save_last_run = save self.refresh = refresh + self.session = self._make_session() + + def _make_session(self, max_retries=10): + session = requests.Session() + adapter = requests.adapters.HTTPAdapter(max_retries=max_retries) + session.mount('http://', adapter) + return session def report_all_runs(self): """ From ea9c034f3c80d046c3338448c2a04eba41cfb232 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 29 Apr 2014 16:10:51 -0500 Subject: [PATCH 3/4] Use the new ResultsReporter.session object Signed-off-by: Zack Cerza --- teuthology/report.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/teuthology/report.py b/teuthology/report.py index 79a0d955686..3b21874dc2b 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -236,7 +236,7 @@ class ResultsReporter(object): )) if jobs: if not self.refresh: - response = requests.head("{base}/runs/{name}/".format( + response = self.session.head("{base}/runs/{name}/".format( base=self.base_uri, name=run_name)) if response.status_code == 200: self.log.info(" already present; skipped") @@ -275,7 +275,7 @@ class ResultsReporter(object): job_info['status'] = 'dead' job_json = json.dumps(job_info) headers = {'content-type': 'application/json'} - response = requests.post(run_uri, data=job_json, headers=headers) + response = self.session.post(run_uri, data=job_json, headers=headers) if response.status_code == 200: return job_id @@ -294,7 +294,8 @@ class ResultsReporter(object): if msg and msg.endswith('already exists'): job_uri = os.path.join(run_uri, job_id, '') - response = requests.put(job_uri, data=job_json, headers=headers) + response = self.session.put(job_uri, data=job_json, + headers=headers) elif msg: self.log.error( "POST to {uri} failed with status {status}: {msg}".format( @@ -344,7 +345,7 @@ class ResultsReporter(object): if not 'job_id' in fields: fields.append('job_id') uri += "?fields=" + ','.join(fields) - response = requests.get(uri) + response = self.session.get(uri) response.raise_for_status() return response.json() @@ -357,7 +358,7 @@ class ResultsReporter(object): """ uri = "{base}/runs/{name}/jobs/{job_id}/".format( base=self.base_uri, name=run_name, job_id=job_id) - response = requests.delete(uri) + response = self.session.delete(uri) response.raise_for_status() def delete_jobs(self, run_name, job_ids): @@ -378,7 +379,7 @@ class ResultsReporter(object): """ uri = "{base}/runs/{name}/".format( base=self.base_uri, name=run_name) - response = requests.delete(uri) + response = self.session.delete(uri) response.raise_for_status() From adc51e1c69e2e06ed13d0f54f3c3bc8afe67e2d1 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 29 Apr 2014 16:12:49 -0500 Subject: [PATCH 4/4] Drop usage of safe_while Signed-off-by: Zack Cerza --- teuthology/report.py | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/teuthology/report.py b/teuthology/report.py index 3b21874dc2b..2325fadb641 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -9,7 +9,6 @@ from datetime import datetime import teuthology from .config import config -from .contextutil import safe_while def init_logging(): @@ -427,15 +426,13 @@ def try_push_job_info(job_config, extra_info=None): else: job_info = job_config - with safe_while(_raise=False) as proceed: - while proceed(): - try: - log.debug("Pushing job info to %s", config.results_server) - push_job_info(run_name, job_id, job_info) - return - except (requests.exceptions.RequestException, socket.error): - log.exception("Could not report results to %s", - config.results_server) + try: + log.debug("Pushing job info to %s", config.results_server) + push_job_info(run_name, job_id, job_info) + return + except (requests.exceptions.RequestException, socket.error): + log.exception("Could not report results to %s", + config.results_server) def try_delete_jobs(run_name, job_ids, delete_empty_run=True): @@ -468,22 +465,18 @@ def try_delete_jobs(run_name, job_ids, delete_empty_run=True): got_jobs = reporter.get_jobs(run_name, fields=['job_id']) got_job_ids = [j['job_id'] for j in got_jobs] if sorted(got_job_ids) == sorted(job_ids): - with safe_while(_raise=False) as proceed: - while proceed(): - try: - reporter.delete_run(run_name) - return - except (requests.exceptions.RequestException, socket.error): # noqa - log.exception("Run deletion failed") + try: + reporter.delete_run(run_name) + return + except (requests.exceptions.RequestException, socket.error): + log.exception("Run deletion failed") def try_delete_job(job_id): - with safe_while(_raise=False) as proceed: - while proceed(): - try: - reporter.delete_job(run_name, job_id) - return - except (requests.exceptions.RequestException, socket.error): - log.exception("Job deletion failed") + try: + reporter.delete_job(run_name, job_id) + return + except (requests.exceptions.RequestException, socket.error): + log.exception("Job deletion failed") for job_id in job_ids: try_delete_job(job_id)