diff options
author | not4win <ashwinnayak111@gmail.com> | 2020-08-18 21:20:37 +0530 |
---|---|---|
committer | not4win <ashwinnayak111@gmail.com> | 2020-09-10 00:16:17 +0530 |
commit | b189119586d1d3cf176c31402daa4b34830ec48b (patch) | |
tree | 93edc86b5d4c06df38d7c3ace74a13f7ba5fda2b /sdv/docker/sdvconfig/testapi | |
parent | 69f4c631e49c359338cff5c9f5b2c96c6fe6b280 (diff) |
sdv-prevalidation: added src, mapping, documentation, Dockerfile, and server files
Signed-off-by: Ashwin Nayak<ashwinnayak111@gmail.com>
Change-Id: I81ae24169a5f8ff79d2c129f30daf5c9f04e5da9
Diffstat (limited to 'sdv/docker/sdvconfig/testapi')
-rw-r--r-- | sdv/docker/sdvconfig/testapi/__init__.py | 19 | ||||
-rw-r--r-- | sdv/docker/sdvconfig/testapi/testapi.py | 77 |
2 files changed, 96 insertions, 0 deletions
diff --git a/sdv/docker/sdvconfig/testapi/__init__.py b/sdv/docker/sdvconfig/testapi/__init__.py new file mode 100644 index 0000000..acd5868 --- /dev/null +++ b/sdv/docker/sdvconfig/testapi/__init__.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" test-api package """ + +from .testapi import PushResults diff --git a/sdv/docker/sdvconfig/testapi/testapi.py b/sdv/docker/sdvconfig/testapi/testapi.py new file mode 100644 index 0000000..5546ee9 --- /dev/null +++ b/sdv/docker/sdvconfig/testapi/testapi.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +# Copyright (C) 2020 Ashwin Nayak +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" testapi class to push results to opnfv testapi """ + +from datetime import datetime as dt +import requests + +OPNFV_URL = "http://testresults.opnfv.org/test/api/v1" +POD_NAME = 'intel-pod10' +INSTALLER = 'Airship' +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 = 'SDV_config_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": "sdv", + "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" + + 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") |