diff options
author | QiLiang <liangqi1@huawei.com> | 2015-09-29 14:50:12 +0800 |
---|---|---|
committer | qi liang <liangqi1@huawei.com> | 2015-10-15 01:17:39 +0000 |
commit | cd809cb6b8bd4bd5002538d107aea1fb8adb0584 (patch) | |
tree | 65b5b96f3f51628f519415e82c6b103fadff700a /yardstick/dispatcher | |
parent | a1378b700a9234e7fcbf77c7890030b306bc65ea (diff) |
Support general configuration file
Use openstack library oslo_config for parsing configuration options
from the command line and configuration files.
Refer http://docs.openstack.org/developer/oslo.config/ or rally
source code for more info on oslo_config library usage.
This patch is initially for test result dispatcher configuration,
but it is very general to use.
Usage:
0) install yardstick
1) mkdir /etc/yardstick
2) cp <repo_root_dir>/etc/yardstick/yardstick.conf.sample \
/etc/yardstick/yardstick.conf
3) edit /etc/yardstick/yardstick.conf
4) run `yardstick task start xxx` cmd
JIRA: YARDSTICK-61
Change-Id: I01677ef6e9ab7c1975aa193799195e850da73478
Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'yardstick/dispatcher')
-rw-r--r-- | yardstick/dispatcher/__init__.py | 10 | ||||
-rw-r--r-- | yardstick/dispatcher/file.py | 33 | ||||
-rw-r--r-- | yardstick/dispatcher/http.py | 28 |
3 files changed, 50 insertions, 21 deletions
diff --git a/yardstick/dispatcher/__init__.py b/yardstick/dispatcher/__init__.py index 44278c1d2..b519efc7a 100644 --- a/yardstick/dispatcher/__init__.py +++ b/yardstick/dispatcher/__init__.py @@ -7,6 +7,16 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from oslo_config import cfg + import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.dispatcher") + +CONF = cfg.CONF +OPTS = [ + cfg.StrOpt('dispatcher', + default='file', + help='Dispatcher to store data.'), +] +CONF.register_opts(OPTS) diff --git a/yardstick/dispatcher/file.py b/yardstick/dispatcher/file.py index dc39f152e..b6130005f 100644 --- a/yardstick/dispatcher/file.py +++ b/yardstick/dispatcher/file.py @@ -10,8 +10,25 @@ import logging import json +from oslo_config import cfg + from yardstick.dispatcher.base import Base as DispatchBase +CONF = cfg.CONF +OPTS = [ + cfg.StrOpt('file_path', + default='/tmp/yardstick.out', + help='Name and the location of the file to record ' + 'data.'), + cfg.IntOpt('max_bytes', + default=0, + help='The max size of the file.'), + cfg.IntOpt('backup_count', + default=0, + help='The max number of the files to keep.'), +] +CONF.register_opts(OPTS, group="dispatcher_file") + class FileDispatcher(DispatchBase): """Dispatcher class for recording data to a file. @@ -19,27 +36,19 @@ class FileDispatcher(DispatchBase): __dispatcher_type__ = "File" - # TODO: make parameters below configurable, currently just hard coded - # Path of the file to record the data - file_path = "/tmp/yardstick.out" - # The max size of the file - max_bytes = 0 - # The max number of the files to keep - backup_count = 0 - def __init__(self, conf): super(FileDispatcher, self).__init__(conf) self.log = None # if the directory and path are configured, then log to the file - if self.file_path: + if CONF.dispatcher_file.file_path: dispatcher_logger = logging.Logger('dispatcher.file') dispatcher_logger.setLevel(logging.INFO) # create rotating file handler which logs result rfh = logging.handlers.RotatingFileHandler( - self.conf.get('file_path', self.file_path), - maxBytes=self.max_bytes, - backupCount=self.backup_count, + self.conf.get('file_path', CONF.dispatcher_file.file_path), + maxBytes=CONF.dispatcher_file.max_bytes, + backupCount=CONF.dispatcher_file.backup_count, encoding='utf8') rfh.setLevel(logging.INFO) diff --git a/yardstick/dispatcher/http.py b/yardstick/dispatcher/http.py index c3230adb2..703cfca62 100644 --- a/yardstick/dispatcher/http.py +++ b/yardstick/dispatcher/http.py @@ -9,13 +9,29 @@ import json import logging - import requests +from oslo_config import cfg + from yardstick.dispatcher.base import Base as DispatchBase LOG = logging.getLogger(__name__) +CONF = cfg.CONF +http_dispatcher_opts = [ + cfg.StrOpt('target', + default='http://127.0.0.1:8000/results', + help='The target where the http request will be sent. ' + 'If this is not set, no data will be posted. For ' + 'example: target = http://hostname:1234/path'), + cfg.IntOpt('timeout', + default=5, + help='The max time in seconds to wait for a request to ' + 'timeout.'), +] + +CONF.register_opts(http_dispatcher_opts, group="dispatcher_http") + class HttpDispatcher(DispatchBase): """Dispatcher class for posting data into a http target. @@ -23,17 +39,11 @@ class HttpDispatcher(DispatchBase): __dispatcher_type__ = "Http" - # TODO: make parameters below configurable, currently just hard coded - # The target where the http request will be sent. - target = "http://127.0.0.1:8000/results" - # The max time in seconds to wait for a request to timeout. - timeout = 5 - def __init__(self, conf): super(HttpDispatcher, self).__init__(conf) self.headers = {'Content-type': 'application/json'} - self.timeout = self.timeout - self.target = self.target + self.timeout = CONF.dispatcher_http.timeout + self.target = CONF.dispatcher_http.target def record_result_data(self, data): if self.target == '': |