1 # Copyright 2013 IBM Corp
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # ceilometer/ceilometer/dispatcher/http.py
24 from oslo_config import cfg
26 from yardstick.dispatcher.base import Base as DispatchBase
28 LOG = logging.getLogger(__name__)
31 http_dispatcher_opts = [
33 default='http://127.0.0.1:8000/results',
34 help='The target where the http request will be sent. '
35 'If this is not set, no data will be posted. For '
36 'example: target = http://hostname:1234/path'),
39 help='The max time in seconds to wait for a request to '
43 CONF.register_opts(http_dispatcher_opts, group="dispatcher_http")
46 class HttpDispatcher(DispatchBase):
47 """Dispatcher class for posting data into a http target.
50 __dispatcher_type__ = "Http"
52 def __init__(self, conf):
53 super(HttpDispatcher, self).__init__(conf)
54 self.headers = {'Content-type': 'application/json'}
55 self.timeout = CONF.dispatcher_http.timeout
56 self.target = CONF.dispatcher_http.target
59 "project_name": "yardstick",
60 "description": "yardstick test cases result",
61 "pod_name": os.environ.get('NODE_NAME', 'unknown'),
62 "installer": os.environ.get('INSTALLER_TYPE', 'unknown'),
63 "version": os.environ.get('YARDSTICK_VERSION', 'unknown')
66 def record_result_data(self, data):
67 self.raw_result.append(data)
69 def flush_result_data(self):
71 # if the target was not set, do not do anything
72 LOG.error('Dispatcher target was not set, no data will'
76 self.result["details"] = self.raw_result
79 for v in self.raw_result:
80 if isinstance(v, dict) and "scenario_cfg" in v:
81 case_name = v["scenario_cfg"]["tc"]
84 LOG.error('Test result : %s' % json.dumps(self.result))
85 LOG.error('The case_name cannot be found, no data will be posted.')
88 self.result["case_name"] = case_name
91 LOG.debug('Test result : %s' % json.dumps(self.result))
92 res = requests.post(self.target,
93 data=json.dumps(self.result),
96 LOG.debug('Test result posting finished with status code'
97 ' %d.' % res.status_code)
98 except Exception as err:
99 LOG.exception('Failed to record result data: %s',