Use ConfigParser to write yardstick.conf 03/26003/6
authorchenjiankun <chenjiankun1@huawei.com>
Thu, 15 Dec 2016 02:31:43 +0000 (02:31 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Mon, 26 Dec 2016 17:40:50 +0000 (17:40 +0000)
JIRA: YARDSTICK-474

Currently, I use file.write() method to write config in yardstick.conf.
But it is not recommended.
So I change to use ConfigParser to write config in yardstick.conf

Change-Id: Ia789cf09296afd5d1507bcf99f165378bf87c591
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/resources/env_action.py
etc/yardstick/yardstick.conf.sample
setup.py
yardstick/common/constants.py

index c2c93f1..59a1692 100644 (file)
@@ -13,6 +13,7 @@ import time
 import json
 import os
 import errno
+import ConfigParser
 
 from docker import Client
 
@@ -104,7 +105,7 @@ def _create_influxdb():
     client = Client(base_url=config.DOCKER_URL)
 
     try:
-        _config_output_file()
+        _change_output_to_influxdb()
 
         if not _check_image_exist(client, '%s:%s' % (config.INFLUXDB_IMAGE,
                                                      config.INFLUXDB_TAG)):
@@ -144,29 +145,18 @@ def _config_influxdb():
         logger.debug('Failed to config influxDB: %s', e)
 
 
-def _config_output_file():
+def _change_output_to_influxdb():
     yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)
+
+    parser = ConfigParser.ConfigParser()
+    parser.read(config.YARDSTICK_CONFIG_SAMPLE_FILE)
+
+    parser.set('DEFAULT', 'dispatcher', 'influxdb')
+    parser.set('dispatcher_influxdb', 'target',
+               'http://%s:8086' % api_conf.GATEWAY_IP)
+
     with open(config.YARDSTICK_CONFIG_FILE, 'w') as f:
-        f.write("""\
-[DEFAULT]
-debug = False
-dispatcher = influxdb
-
-[dispatcher_file]
-file_path = /tmp/yardstick.out
-
-[dispatcher_http]
-timeout = 5
-# target = http://127.0.0.1:8000/results
-
-[dispatcher_influxdb]
-timeout = 5
-target = http://%s:8086
-db_name = yardstick
-username = root
-password = root
-"""
-                % api_conf.GATEWAY_IP)
+        parser.write(f)
 
 
 def prepareYardstickEnv(args):
index f4eff05..70cf71a 100644 (file)
@@ -8,22 +8,21 @@
 ##############################################################################
 
 [DEFAULT]
-# verbose = True
-# debug = True
-# dispatcher = http
+debug = False
+dispatcher = http
 
 [dispatcher_http]
-timeout = 5
-target = http://127.0.0.1:8000/results
+timeout = 5
+target = http://127.0.0.1:8000/results
 
 [dispatcher_file]
-file_path = /tmp/yardstick.out
-max_bytes = 0
-backup_count = 0
+file_path = /tmp/yardstick.out
+max_bytes = 0
+backup_count = 0
 
 [dispatcher_influxdb]
-timeout = 5
-target = http://127.0.0.1:8086
-db_name = yardstick
-username = root
-password = root
+timeout = 5
+target = http://127.0.0.1:8086
+db_name = yardstick
+username = root
+password = root
index 54595b6..0100b46 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,8 @@ setup(
             'resources/scripts/remove/*.bash'
         ],
         'etc': [
-            'yardstick/nodes/*/*.yaml'
+            'yardstick/nodes/*/*.yaml',
+            'yardstick/*.sample'
         ],
         'tests': [
             'opnfv/*/*.yaml',
index 6993c41..705e1ad 100644 (file)
@@ -1,3 +1,11 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
 import os
 
 DOCKER_URL = 'unix://var/run/docker.sock'
@@ -15,6 +23,7 @@ GRAFANA_TAGS = '3.1.1'
 
 dirname = os.path.dirname
 abspath = os.path.abspath
+join = os.path.join
 sep = os.path.sep
 
 INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
@@ -25,7 +34,12 @@ YARDSTICK_REPOS_DIR = '/home/opnfv/repos/yardstick'
 
 YARDSTICK_CONFIG_DIR = '/etc/yardstick/'
 
-YARDSTICK_CONFIG_FILE = os.path.join(YARDSTICK_CONFIG_DIR, 'yardstick.conf')
+YARDSTICK_CONFIG_FILE = join(YARDSTICK_CONFIG_DIR, 'yardstick.conf')
+
+YARDSTICK_CONFIG_SAMPLE_DIR = join(YARDSTICK_ROOT_PATH, 'etc/yardstick/')
+
+YARDSTICK_CONFIG_SAMPLE_FILE = join(YARDSTICK_CONFIG_SAMPLE_DIR,
+                                    'yardstick.conf.sample')
 
 RELENG_DIR = '/home/opnfv/repos/releng'
 
@@ -35,6 +49,6 @@ CLEAN_IMAGES_SCRIPT = 'tests/ci/clean_images.sh'
 
 LOAD_IMAGES_SCRIPT = 'tests/ci/load_images.sh'
 
-OPENSTACK_RC_FILE = os.path.join(YARDSTICK_CONFIG_DIR, 'openstack.creds')
+OPENSTACK_RC_FILE = join(YARDSTICK_CONFIG_DIR, 'openstack.creds')
 
 YARDSTICK_ENV_ACTION_API = 'http://localhost:5000/yardstick/env/action'