summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-25 02:43:26 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-25 02:43:26 +0000
commitd29df23ae5057fe0ccded6f8d8f3e36a084a78b3 (patch)
treee3cf9338e708edbbcb66bf776ee529615989e982
parenta513db6bb8f5887f975a1b0152818b682fb67095 (diff)
parentf49a1f22f8ba1bfa7a9942f7a9f084d2c9c81378 (diff)
Merge "yardstick env influxdb/grafana cmd support centos"
-rw-r--r--api/resources/v1/env.py52
-rw-r--r--yardstick/benchmark/core/task.py7
-rw-r--r--yardstick/common/constants.py2
-rw-r--r--yardstick/common/utils.py10
4 files changed, 52 insertions, 19 deletions
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py
index 4632f15fe..8943db3d1 100644
--- a/api/resources/v1/env.py
+++ b/api/resources/v1/env.py
@@ -65,16 +65,20 @@ class V1Env(ApiResource):
client.pull(consts.GRAFANA_IMAGE, consts.GRAFANA_TAG)
LOG.info('Createing grafana container')
- self._create_grafana_container(client)
+ container = self._create_grafana_container(client)
LOG.info('Grafana container is created')
time.sleep(5)
+ container = client.inspect_container(container['Id'])
+ ip = container['NetworkSettings']['Networks']['bridge']['IPAddress']
+ LOG.debug('container ip is: %s', ip)
+
LOG.info('Creating data source for grafana')
- self._create_data_source()
+ self._create_data_source(ip)
LOG.info('Creating dashboard for grafana')
- self._create_dashboard()
+ self._create_dashboard(ip)
self._update_task_status(task_id)
LOG.info('Finished')
@@ -82,8 +86,8 @@ class V1Env(ApiResource):
self._update_task_error(task_id, str(e))
LOG.exception('Create grafana failed')
- def _create_dashboard(self):
- url = 'http://admin:admin@%s:3000/api/dashboards/db' % consts.GRAFANA_IP
+ def _create_dashboard(self, ip):
+ url = 'http://admin:admin@{}:{}/api/dashboards/db'.format(ip, consts.GRAFANA_PORT)
path = os.path.join(consts.REPOS_DIR, 'dashboard', '*dashboard.json')
for i in sorted(glob.iglob(path)):
@@ -95,13 +99,21 @@ class V1Env(ApiResource):
LOG.exception('Create dashboard %s failed', i)
raise
- def _create_data_source(self):
- url = 'http://admin:admin@%s:3000/api/datasources' % consts.GRAFANA_IP
+ 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
+
data = {
"name": "yardstick",
"type": "influxdb",
"access": "proxy",
- "url": "http://%s:8086" % consts.INFLUXDB_IP,
+ "url": influx_url,
"password": "root",
"user": "root",
"database": "yardstick",
@@ -117,8 +129,8 @@ class V1Env(ApiResource):
raise
def _create_grafana_container(self, client):
- ports = [3000]
- port_bindings = {k: k for k in ports}
+ ports = [consts.GRAFANA_PORT]
+ port_bindings = {consts.GRAFANA_PORT: consts.GRAFANA_MAPPING_PORT}
restart_policy = {"MaximumRetryCount": 0, "Name": "always"}
host_config = client.create_host_config(port_bindings=port_bindings,
restart_policy=restart_policy)
@@ -133,6 +145,7 @@ class V1Env(ApiResource):
host_config=host_config)
LOG.info('Starting container')
client.start(container)
+ return container
def _check_image_exist(self, client, t):
return any(t in a['RepoTags'][0]
@@ -152,9 +165,6 @@ class V1Env(ApiResource):
client = Client(base_url=consts.DOCKER_URL)
try:
- LOG.info('Changing output to influxdb')
- self._change_output_to_influxdb()
-
LOG.info('Checking if influxdb image exist')
if not self._check_image_exist(client, '%s:%s' %
(consts.INFLUXDB_IMAGE,
@@ -163,11 +173,18 @@ class V1Env(ApiResource):
client.pull(consts.INFLUXDB_IMAGE, tag=consts.INFLUXDB_TAG)
LOG.info('Createing influxdb container')
- self._create_influxdb_container(client)
+ container = self._create_influxdb_container(client)
LOG.info('Influxdb container is created')
time.sleep(5)
+ container = client.inspect_container(container['Id'])
+ ip = container['NetworkSettings']['Networks']['bridge']['IPAddress']
+ LOG.debug('container ip is: %s', ip)
+
+ LOG.info('Changing output to influxdb')
+ self._change_output_to_influxdb(ip)
+
LOG.info('Config influxdb')
self._config_influxdb()
@@ -180,7 +197,7 @@ class V1Env(ApiResource):
def _create_influxdb_container(self, client):
- ports = [8083, 8086]
+ ports = [consts.INFLUXDB_DASHBOARD_PORT, consts.INFLUXDB_PORT]
port_bindings = {k: k for k in ports}
restart_policy = {"MaximumRetryCount": 0, "Name": "always"}
host_config = client.create_host_config(port_bindings=port_bindings,
@@ -196,6 +213,7 @@ class V1Env(ApiResource):
host_config=host_config)
LOG.info('Starting container')
client.start(container)
+ return container
def _config_influxdb(self):
try:
@@ -208,7 +226,7 @@ class V1Env(ApiResource):
except Exception:
LOG.exception('Config influxdb failed')
- def _change_output_to_influxdb(self):
+ def _change_output_to_influxdb(self, ip):
utils.makedirs(consts.CONF_DIR)
parser = configparser.ConfigParser()
@@ -218,7 +236,7 @@ class V1Env(ApiResource):
LOG.info('Set dispatcher to influxdb')
parser.set('DEFAULT', 'dispatcher', 'influxdb')
parser.set('dispatcher_influxdb', 'target',
- 'http://%s:8086' % consts.INFLUXDB_IP)
+ 'http://{}:{}'.format(ip, consts.INFLUXDB_PORT))
LOG.info('Writing to %s', consts.CONF_FILE)
with open(consts.CONF_FILE, 'w') as f:
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index b53d6446e..ede14b1c0 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -58,7 +58,12 @@ class Task(object): # pragma: no cover
check_environment()
- output_config = utils.parse_ini_file(config_file)
+ try:
+ output_config = utils.parse_ini_file(config_file)
+ except Exception:
+ # all error will be ignore, the default value is {}
+ output_config = {}
+
self._init_output_config(output_config)
self._set_output_config(output_config, args.output_file)
LOG.debug('Output configuration is: %s', output_config)
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index 69485a4e4..8e8114fbb 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -77,6 +77,7 @@ INFLUXDB_PASS = get_param('influxdb.password', 'root')
INFLUXDB_DB_NAME = get_param('influxdb.db_name', 'yardstick')
INFLUXDB_IMAGE = get_param('influxdb.image', 'tutum/influxdb')
INFLUXDB_TAG = get_param('influxdb.tag', '0.13')
+INFLUXDB_DASHBOARD_PORT = 8083
# grafana
GRAFANA_IP = get_param('grafana.ip', SERVER_IP)
@@ -85,6 +86,7 @@ GRAFANA_USER = get_param('grafana.username', 'admin')
GRAFANA_PASS = get_param('grafana.password', 'admin')
GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
GRAFANA_TAG = get_param('grafana.tag', '3.1.1')
+GRAFANA_MAPPING_PORT = 1948
# api
API_PORT = 5000
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index 92bb7b7d3..7a64b8ca2 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -172,7 +172,15 @@ def write_file(path, data, mode='w'):
def parse_ini_file(path):
parser = configparser.ConfigParser()
- parser.read(path)
+
+ try:
+ files = parser.read(path)
+ except configparser.MissingSectionHeaderError:
+ logger.exception('invalid file type')
+ raise
+ else:
+ if not files:
+ raise RuntimeError('file not exist')
try:
default = {k: v for k, v in parser.items('DEFAULT')}