summaryrefslogtreecommitdiffstats
path: root/utils/functest_utils.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-08-22 18:23:25 +0800
committerMorgan Richomme <morgan.richomme@orange.com>2016-08-23 07:50:23 +0000
commit7e66780a374cd1f10a54a9d47c61b5b663ba058f (patch)
tree4cbdf832ec034d17aee4116834a006c0b7e91c1e /utils/functest_utils.py
parenta9f36b9999ebd62da1e9bfbfb40874c86de3f440 (diff)
refactor push_result_to_db print thing
when Exceptions happen, the print code is too difficult to understand and maintain, modify to make it clear jira: FUNCTEST-425 Change-Id: Ie12af989e711df3791167955642f2edf1164b146 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn> (cherry picked from commit 2588e2af6c2b609ab08957268f8163954cd8eae1)
Diffstat (limited to 'utils/functest_utils.py')
-rw-r--r--utils/functest_utils.py49
1 files changed, 38 insertions, 11 deletions
diff --git a/utils/functest_utils.py b/utils/functest_utils.py
index 807a671a3..4d5004cbe 100644
--- a/utils/functest_utils.py
+++ b/utils/functest_utils.py
@@ -214,24 +214,51 @@ def push_results_to_db(project, case_name, logger,
"build_tag": build_tag, "start_date": test_start,
"stop_date": test_stop, "details": details}
+ error = None
headers = {'Content-Type': 'application/json'}
try:
r = requests.post(url, data=json.dumps(params), headers=headers)
if logger:
logger.debug(r)
r.raise_for_status()
+ except requests.RequestException as exc:
+ if 'r' in locals():
+ error = ("Pushing Result to DB(%s) failed: %s" %
+ (r.url, r.content))
+ else:
+ error = ("Pushing Result to DB(%s) failed: %s" % (url, exc))
+ except Exception as e:
+ error = ("Error [push_results_to_db("
+ "DB: '%(db)s', "
+ "project: '%(project)s', "
+ "case: '%(case)s', "
+ "pod: '%(pod)s', "
+ "version: '%(v)s', "
+ "scenario: '%(s)s', "
+ "criteria: '%(c)s', "
+ "build_tag: '%(t)s', "
+ "details: '%(d)s')]: "
+ "%(error)s" %
+ {
+ 'db': url,
+ 'project': project,
+ 'case': case_name,
+ 'pod': pod_name,
+ 'v': version,
+ 's': scenario,
+ 'c': criteria,
+ 't': build_tag,
+ 'd': details,
+ 'error': e
+ })
+ finally:
+ if error:
+ if logger:
+ logger.error(error)
+ else:
+ print error
+ return False
return True
- except requests.RequestException:
- if logger:
- logger.error("Pushing Result to DB(%s) failed: %s" %
- (r.url, r.content))
- return False
- except Exception, e:
- print("Error [push_results_to_db('%s', '%s', '%s', '%s',"
- "'%s', '%s', '%s', '%s', '%s')]:" %
- (url, project, case_name, pod_name, version,
- scenario, criteria, build_tag, details)), e
- return False
def get_resolvconf_ns():