diff options
author | Rex Lee <limingjiang@huawei.com> | 2017-01-10 08:54:16 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-01-10 08:54:16 +0000 |
commit | ceebb672c85c5dbce6df17f0c263375d17adcc05 (patch) | |
tree | 807b3fbdcef0025eb56d2c8b093e7f7d24ed3a9a /api/utils/influx.py | |
parent | 45db0fdabb4585b96756a390650181a3c46facf7 (diff) | |
parent | 254414758828a12a353e0670704faa5bcb792cae (diff) |
Merge "Record test case names when run a task using API"
Diffstat (limited to 'api/utils/influx.py')
-rw-r--r-- | api/utils/influx.py | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/api/utils/influx.py b/api/utils/influx.py index 9366ed3e9..d4b070fb4 100644 --- a/api/utils/influx.py +++ b/api/utils/influx.py @@ -7,10 +7,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import logging +import ConfigParser from urlparse import urlsplit from influxdb import InfluxDBClient -import ConfigParser from api import conf @@ -21,46 +21,26 @@ def get_data_db_client(): parser = ConfigParser.ConfigParser() try: parser.read(conf.OUTPUT_CONFIG_FILE_PATH) - dispatcher = parser.get('DEFAULT', 'dispatcher') - if 'influxdb' != dispatcher: + if 'influxdb' != parser.get('DEFAULT', 'dispatcher'): raise RuntimeError - ip = _get_ip(parser.get('dispatcher_influxdb', 'target')) - username = parser.get('dispatcher_influxdb', 'username') - password = parser.get('dispatcher_influxdb', 'password') - db_name = parser.get('dispatcher_influxdb', 'db_name') - return InfluxDBClient(ip, conf.PORT, username, password, db_name) + return _get_client(parser) except ConfigParser.NoOptionError: logger.error('can not find the key') raise -def _get_ip(url): - return urlsplit(url).hostname +def _get_client(parser): + ip = _get_ip(parser.get('dispatcher_influxdb', 'target')) + username = parser.get('dispatcher_influxdb', 'username') + password = parser.get('dispatcher_influxdb', 'password') + db_name = parser.get('dispatcher_influxdb', 'db_name') + return InfluxDBClient(ip, conf.PORT, username, password, db_name) -def _write_data(measurement, field, timestamp, tags): - point = { - 'measurement': measurement, - 'fields': field, - 'time': timestamp, - 'tags': tags - } - - try: - client = get_data_db_client() - - logger.debug('Start to write data: %s', point) - client.write_points([point]) - except RuntimeError: - logger.debug('dispatcher is not influxdb') - - -def write_data_tasklist(task_id, timestamp, status, error=''): - field = {'status': status, 'error': error} - tags = {'task_id': task_id} - _write_data('tasklist', field, timestamp, tags) +def _get_ip(url): + return urlsplit(url).hostname def query(query_sql): |