aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakhilbatra898 <akhil.batra@research.iiit.ac.in>2017-04-10 19:36:05 +0530
committerakhilbatra898 <akhil.batra@research.iiit.ac.in>2017-04-12 17:12:00 +0530
commita68d7f591a85f5d6eb0113b2a692d2aaa0ddfb4f (patch)
tree98e01865c3dcee86a27930cb5947ccde9547d394
parenta4878f6c98855f5392324e0e72df3e2711022dd9 (diff)
Consume OPNFV TestAPI to push results
push_results will be triggered after a benchmark run is completed. - Added Validation before the information to be sent to testapi - A validator is added as a decorator for this Change-Id: I1149133fc41668f6c8dab042e59673be2b46d09d Signed-off-by: akhilbatra898 <akhil.batra@research.iiit.ac.in>
-rw-r--r--qtip/reporter/testapi.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/qtip/reporter/testapi.py b/qtip/reporter/testapi.py
new file mode 100644
index 00000000..a0be5379
--- /dev/null
+++ b/qtip/reporter/testapi.py
@@ -0,0 +1,68 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import requests
+
+
+payload_template = {'project_name',
+ 'case_name',
+ 'pod_name',
+ 'installer',
+ 'version',
+ 'scenario',
+ 'criteria',
+ 'build_tag',
+ 'start_date',
+ 'stop_date',
+ 'details'}
+
+
+def validate_payload():
+ def _decorator(func):
+ def _execute(testapi_url, payload):
+ if set(payload.keys()) != payload_template:
+ missing_parameters = list(payload_template -
+ set(payload.keys()))
+ print "Missing Parameters -- {}".\
+ format(",".join(missing_parameters))
+ raise MissingParamsError("push_results", missing_parameters)
+ invalid_params = []
+ for key in payload:
+ if (payload[key] == "") or (payload[key] is None):
+ invalid_params.append(key)
+ if len(invalid_params) > 0:
+ print "Invalid or missing values of parameters -- `{}`".\
+ format(",".join(invalid_params))
+ raise InvalidParamsError("push_results", invalid_params)
+ return func(testapi_url, payload)
+ return _execute
+ return _decorator
+
+
+class InvalidParamsError(Exception):
+ def __init__(self, method, params):
+ self.method = method
+ self.params = params
+
+
+class MissingParamsError(Exception):
+ def __init__(self, method, params):
+ self.method = method
+ self.params = params
+
+
+@validate_payload()
+def push_results(testapi_url, payload):
+ """ push results to OPNFV TestAPI """
+
+ response = requests.post(testapi_url + '/results', json=payload)
+ if response.status_code == requests.codes.ok:
+ return response.json()
+ else:
+ response.raise_for_status()