Use result_collection_api to store test result 11/2411/5
authorQiLiang <liangqi1@huawei.com>
Sat, 10 Oct 2015 09:39:22 +0000 (17:39 +0800)
committerHou Jingwen <houjingwen@huawei.com>
Fri, 16 Oct 2015 04:01:02 +0000 (04:01 +0000)
Execute a sample task file from Yardstick, push the test results
to MongodB provided by Releng using the common result api
provided by Functest.

Usage:

0) install yardstick

1) config yardstick
mkdir /etc/yardstick
cat << EOF >> /etc/yardstick/yardstick.conf
[DEFAULT]
debug = True
dispatcher = http

[dispatcher_http]
timeout = 5
target = http://213.77.62.197/results
EOF

2) run test
yardstick task start sample/fio.yaml

3) fetch result from remote result_collection_api
curl "http://213.77.62.197/results?case=Fio&installer=compass"

JIRA: YARDSTICK-132

Change-Id: I0996c6487c1900704380feb895555057a3f184e9
Signed-off-by: QiLiang <liangqi1@huawei.com>
yardstick/benchmark/runners/base.py
yardstick/dispatcher/base.py
yardstick/dispatcher/file.py
yardstick/dispatcher/http.py

index c3fe6b1..cc8c93c 100755 (executable)
@@ -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)
index 28c4c1a..fe635b9 100644 (file)
@@ -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."""
index b613000..50414b9 100644 (file)
@@ -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
index 703cfca..af9ace4 100644 (file)
@@ -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)