From: chenjiankun <chenjiankun1@huawei.com>
Date: Fri, 15 Sep 2017 03:17:50 +0000 (+0000)
Subject: Read user & password from yardstick.conf in Grafana configuration
X-Git-Tag: opnfv-6.0.0~425^2
X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=d49de4ede216ff24085c4e58dfc1ea970390cb6f;p=yardstick.git

Read user & password from yardstick.conf in Grafana configuration

JIRA: YARDSTICK-812

Currently grafana data source configuration is hardcoding .
It is a risk.
so I read it from yardstick.conf.

Change-Id: I8a9c8afbce6c4534fc43a0bfb5c56d67a8b59db0
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
---

diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py
index 47ea91643..f3c01152b 100644
--- a/api/resources/v1/env.py
+++ b/api/resources/v1/env.py
@@ -101,21 +101,15 @@ class V1Env(ApiResource):
 
     def _create_data_source(self, ip):
         url = 'http://admin:admin@{}:{}/api/datasources'.format(ip, consts.GRAFANA_PORT)
-        influx_conf = utils.parse_ini_file(consts.CONF_FILE)
-
-        try:
-            influx_url = influx_conf['dispatcher_influxdb']['target']
-        except KeyError:
-            LOG.exception('influxdb url not set in yardstick.conf')
-            raise
+        influx_conf = utils.parse_ini_file(consts.CONF_FILE).get('dispatcher_influxdb', {})
 
         data = {
             "name": "yardstick",
             "type": "influxdb",
             "access": "proxy",
-            "url": influx_url,
-            "password": "root",
-            "user": "root",
+            "url": influx_conf.get('target', ''),
+            "password": influx_conf.get('password', ''),
+            "user": influx_conf.get('username', ''),
             "database": "yardstick",
             "basicAuth": True,
             "basicAuthUser": "admin",
diff --git a/api/resources/v2/containers.py b/api/resources/v2/containers.py
index 66dc94120..ee1903901 100644
--- a/api/resources/v2/containers.py
+++ b/api/resources/v2/containers.py
@@ -272,21 +272,15 @@ class V2Containers(ApiResource):
 
     def _create_data_source(self, ip):
         url = 'http://admin:admin@{}:{}/api/datasources'.format(ip, 3000)
-
-        influx_conf = utils.parse_ini_file(consts.CONF_FILE)
-        try:
-            influx_url = influx_conf['dispatcher_influxdb']['target']
-        except KeyError:
-            LOG.exception('influxdb url not set in yardstick.conf')
-            raise
+        influx_conf = utils.parse_ini_file(consts.CONF_FILE).get('dispatcher_influxdb', {})
 
         data = {
             "name": "yardstick",
             "type": "influxdb",
             "access": "proxy",
-            "url": influx_url,
-            "password": "root",
-            "user": "root",
+            "url": influx_conf.get('target', ''),
+            "password": influx_conf.get('password', ''),
+            "user": influx_conf.get('username', ''),
             "database": "yardstick",
             "basicAuth": True,
             "basicAuthUser": "admin",