aboutsummaryrefslogtreecommitdiffstats
path: root/hdv/redfish/test_api.py
diff options
context:
space:
mode:
authorShubham Mishra <shivam828787@gmail.com>2020-07-22 15:56:25 +0530
committerShubham Mishra <shivam828787@gmail.com>2020-08-25 21:54:25 +0530
commitdcdd46fe975c13c56a246ba0a6c79516a6afda77 (patch)
tree3a45f7cdf9a8b14c4c1dba63058ea108d9d48dc1 /hdv/redfish/test_api.py
parent1bf4bd7a74febb5f837f606940a17c48530eebbd (diff)
add pytest for main engine and integrated testapi
Change-Id: I9fffd0e04758ddbd0fd05a6358dd4e162c9c8e05 Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Diffstat (limited to 'hdv/redfish/test_api.py')
-rw-r--r--hdv/redfish/test_api.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/hdv/redfish/test_api.py b/hdv/redfish/test_api.py
new file mode 100644
index 0000000..7d0eeec
--- /dev/null
+++ b/hdv/redfish/test_api.py
@@ -0,0 +1,58 @@
+from datetime import datetime as dt
+import requests
+
+OPNFV_URL = "http://testresults.opnfv.org/test/api/v1"
+POD_NAME = 'intel-pod10'
+INSTALLER = 'none'
+BUILD_TAG = "none"
+PKG_LIST = 'package-list.mk'
+START_TIME = dt.now().strftime('%Y-%m-%d %H:%M:%S')
+STOP_TIME = dt.now().strftime('%Y-%m-%d %H:%M:%S')
+TC_NAME = 'HDV_Redfish_Basic'
+VERSION = '1.0'
+CRITERIA = 'PASS'
+
+class PushResults():
+ """ Push results to opnfv test api """
+ def __init__(self, results, logger):
+ """ constructor """
+ # store external values
+ self.results = results
+ self.logger = logger
+ # initialize internal values
+ self.push_vals = dict()
+ # call functions
+ self.generate_response()
+ self.push_results()
+
+ def generate_response(self):
+ """ generate json output to be pushed """
+ # Build body
+ body = {
+ "project_name": "cirv",
+ "scenario": "none",
+ "start_date": START_TIME,
+ "stop_date": STOP_TIME,
+ "case_name": TC_NAME,
+ "pod_name": POD_NAME,
+ "installer": INSTALLER,
+ "version": VERSION,
+ "build_tag": BUILD_TAG,
+ "criteria": CRITERIA,
+ "details": self.results
+ }
+
+ self.logger.debug("The generated json response to be pushed:%s", body)
+ # store this value in the class variable
+ self.push_vals = body
+
+ def push_results(self):
+ """ push results to testapi """
+ url = OPNFV_URL + "/results"
+ print(self.push_vals)
+ try:
+ response = requests.post(url, json=self.push_vals)
+ self.logger.info("testapi push response:%s", response)
+ except ConnectionError:
+ self.logger.exception("error while pushing results to testapi")
+ self.logger.error("failed to push results")