diff options
-rwxr-xr-x | yardstick/benchmark/runners/base.py | 1 | ||||
-rw-r--r-- | yardstick/dispatcher/base.py | 4 | ||||
-rw-r--r-- | yardstick/dispatcher/file.py | 3 | ||||
-rw-r--r-- | yardstick/dispatcher/http.py | 53 |
4 files changed, 45 insertions, 16 deletions
diff --git a/yardstick/benchmark/runners/base.py b/yardstick/benchmark/runners/base.py index c3fe6b104..cc8c93cb6 100755 --- a/yardstick/benchmark/runners/base.py +++ b/yardstick/benchmark/runners/base.py @@ -39,6 +39,7 @@ def _output_serializer_main(filename, queue): # blocks until data becomes available record = queue.get() if record == '_TERMINATE_': + dispatcher.flush_result_data() break else: dispatcher.record_result_data(record) diff --git a/yardstick/dispatcher/base.py b/yardstick/dispatcher/base.py index 28c4c1ae6..fe635b9d4 100644 --- a/yardstick/dispatcher/base.py +++ b/yardstick/dispatcher/base.py @@ -36,3 +36,7 @@ class Base(object): @abc.abstractmethod def record_result_data(self, data): """Recording result data interface.""" + + @abc.abstractmethod + def flush_result_data(self): + """Flush result data into permanent storage media interface.""" diff --git a/yardstick/dispatcher/file.py b/yardstick/dispatcher/file.py index b6130005f..50414b969 100644 --- a/yardstick/dispatcher/file.py +++ b/yardstick/dispatcher/file.py @@ -61,3 +61,6 @@ class FileDispatcher(DispatchBase): def record_result_data(self, data): if self.log: self.log.info(json.dumps(data)) + + def flush_result_data(self): + pass diff --git a/yardstick/dispatcher/http.py b/yardstick/dispatcher/http.py index 703cfca62..af9ace469 100644 --- a/yardstick/dispatcher/http.py +++ b/yardstick/dispatcher/http.py @@ -44,27 +44,48 @@ class HttpDispatcher(DispatchBase): self.headers = {'Content-type': 'application/json'} self.timeout = CONF.dispatcher_http.timeout self.target = CONF.dispatcher_http.target + self.raw_result = [] + # TODO set pod_name, installer, version based on pod info + self.result = { + "project_name": "yardstick", + "description": "yardstick test cases result", + "pod_name": "opnfv-jump-2", + "installer": "compass", + "version": "Brahmaputra-dev" + } def record_result_data(self, data): + self.raw_result.append(data) + + def flush_result_data(self): if self.target == '': # if the target was not set, do not do anything LOG.error('Dispatcher target was not set, no data will' 'be posted.') return - # We may have receive only one counter on the wire - if not isinstance(data, list): - data = [data] - - for result in data: - try: - LOG.debug('Message : %s' % result) - res = requests.post(self.target, - data=json.dumps(result), - headers=self.headers, - timeout=self.timeout) - LOG.debug('Message posting finished with status code' - '%d.' % res.status_code) - except Exception as err: - LOG.exception('Failed to record result data: %s', - err) + self.result["details"] = self.raw_result + + case_name = "" + for v in self.raw_result: + if isinstance(v, dict) and "scenario_cfg" in v: + case_name = v["scenario_cfg"]["type"] + break + if case_name == "": + LOG.error('Test result : %s' % json.dumps(self.result)) + LOG.error('The case_name cannot be found, no data will be posted.') + return + + self.result["case_name"] = case_name + + try: + LOG.debug('Test result : %s' % json.dumps(self.result)) + res = requests.post(self.target, + data=json.dumps(self.result), + headers=self.headers, + timeout=self.timeout) + LOG.debug('Test result posting finished with status code' + ' %d.' % res.status_code) + except Exception as err: + LOG.exception('Failed to record result data: %s', + err) |