Log_dir bug fix&Add function of test_ip init 77/28177/5
authorliyin <liyin11@huawei.com>
Tue, 7 Feb 2017 07:29:50 +0000 (15:29 +0800)
committerAce Lee <liyin11@huawei.com>
Thu, 9 Feb 2017 05:10:52 +0000 (05:10 +0000)
JIRA:BOTTLENECK-129

This patch fix the error of log_dir can't be found.
And change several thing:
1.Add if config don't have test_ip, it will use local:8888 as test ip.
2.Fix the bug in setup.py.
3.Add parser init to logger file.

Change-Id: I808c69e2b2ff3c04f271cc7f3e14e1ab406a4d1b
Signed-off-by: liyin <liyin11@huawei.com>
config/__init__.py [new file with mode: 0644]
setup.py
testsuites/posca/__init__.py
testsuites/posca/run_posca.py
testsuites/posca/testcase_script/posca_factor_system_bandwidth.py
utils/logger.py
utils/parser.py

diff --git a/config/__init__.py b/config/__init__.py
new file mode 100644 (file)
index 0000000..b124dfa
--- /dev/null
@@ -0,0 +1,8 @@
+##############################################################################
+# Copyright (c) 2017 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
+##############################################################################
index d9852c9..5e32b23 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -7,38 +7,40 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-'''This file realize the function of how to setup bottlenecks to your environment
-This use setuptools tool to setup'''
+'''This file realize the function of how to setup bottlenecks
+to your environment. This use setuptools tool to setup'''
 
 from setuptools import setup, find_packages
 
 
 setup(
-        name="bottlenecks",
-        version="master",
-        py_modules=['bottlenecks_cli'],
-        packages=find_packages(),
-        include_package_data=True,
-        package_data={
-                    'utils': [
-                                    'utils/infra_setup/heat/*.py',
-                                    'utils/infra_setup/runner/*.py'
-                                ],
-                    'config': [
-                                    '*.yaml'
-                                ],
-                    'testsuites': [
-                                    'posca/testcase_cfg/*',
-                                    'posca/testcase_script/*',
-                                    'posca/testsuite_story/*',
-                                    'posca/testcase_dashboard/*'
-                                ],
-                },
-        url="https://www.opnfv.org",
-        install_requires=["click"],
-        entry_points={
-                    'console_scripts': [
-                                    'bottlenecks=cli.bottlenecks_cli:main'
-                                ],
-                },
+    name="bottlenecks",
+    version="master",
+    py_modules=['bottlenecks_cli'],
+    packages=find_packages(),
+    include_package_data=True,
+    package_data={
+        'utils': [
+            'utils/infra_setup/heat/*.py',
+            'utils/infra_setup/runner/*.py',
+            'utils/*.py'
+        ],
+        'config': [
+            '*.yaml'
+        ],
+        'testsuites': [
+            'posca/testcase_cfg/*',
+            'posca/testcase_script/*',
+            'posca/testsuite_story/*',
+            'posca/testcase_dashboard/*'
+        ],
+    },
+    url="https://www.opnfv.org",
+    install_requires=["click"],
+    entry_points={
+        'console_scripts': [
+            'bottlenecks=cli.bottlenecks_cli:main'
+        ],
+    },
 )
+
index efcda78..b124dfa 100644 (file)
@@ -6,4 +6,3 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-
index fcf35d5..a687e00 100755 (executable)
@@ -39,15 +39,9 @@ def posca_run(test_level, test_name):
     elif test_level == "teststory":
         config = conf_parser.Parser.story_read("posca", test_name)
     for testcase in config:
-        print(config[testcase])
+        LOG.info("Begin to run %s testcase in POSCA testsuite", testcase)
         posca_testcase_run(testcase, config[testcase])
-    if con_dic["dashboard"] == "y":
-        cmd = '/home/opnfv/bottlenecks/testsuites/posca/testcase_dashboard/\
-system_bandwidth.py'
-        pargs = [INTERPRETER, cmd]
-        LOG.info("\nBegin to establish dashboard.")
-        sub_result = subprocess.Popen(pargs)
-        sub_result.wait()
+        LOG.info("End of %s testcase in POSCA testsuite", testcase)
 
 
 def main():
@@ -58,4 +52,3 @@ def main():
 
 if __name__ == '__main__':
     main()
-
index ed4de18..aebfa96 100644 (file)
@@ -16,10 +16,11 @@ import os
 import time
 import utils.logger as log
 import utils.infra_setup.runner.yardstick as Runner
+from utils.parser import Parser as conf_parser
 # --------------------------------------------------
 # logging configuration
 # --------------------------------------------------
-LOG = log.Logger(__name__)
+LOG = log.Logger(__name__).getLogger()
 
 test_dict = {
     "action": "runTestCase",
@@ -41,7 +42,7 @@ def do_test(test_config, con_dic):
     Task_id = Runner.Send_Data(test_dict, con_dic['runner_config'])
     time.sleep(con_dic['test_config']['test_time'])
     Data_Reply = Runner.Get_Reply(con_dic['runner_config'], Task_id)
-    test_date = Data_Reply[con_dic['runner_config']['testcase']][0]
+    test_date = Data_Reply[con_dic['runner_config']['yardstick_testcase']][0]
     return test_date
 
 
@@ -60,6 +61,9 @@ def run(con_dic):
     data_return = {}
     data_max = {}
     data_return["throughput"] = 1
+    if con_dic["runner_config"]["yardstick_test_ip"] is None:
+        con_dic["runner_config"]["yardstick_test_ip"] =\
+            conf_parser.ip_parser("yardstick_test_ip")
     for test_x in data["tx_pkt_sizes"]:
         data_max["throughput"] = 1
         bandwidth_tmp = 1
@@ -88,12 +92,3 @@ def run(con_dic):
         pre_role_result = cur_role_result
     print("date_id is %d,id return success\n" % date_id)
     return data_return
-
-
-def main():
-    run(con_dic)
-
-
-if __name__ == '__main__':
-    main()
-
index 80392f5..5ce6423 100644 (file)
@@ -19,7 +19,8 @@
 import logging
 import os
 
-from utils.parser import Parser as conf
+from utils.parser import Parser as conf_parser
+conf_parser.config_init()
 
 
 class Logger:
@@ -47,7 +48,7 @@ class Logger:
             ch.setLevel(logging.INFO)
         self.logger.addHandler(ch)
 
-        result_path = conf.bottlenecks_config["log_dir"]
+        result_path = conf_parser.bottlenecks_config["log_dir"]
         if not os.path.exists(result_path):
             os.makedirs(result_path)
         result_file = os.path.join(result_path, 'bottlenecks.log')
index 7b1f4e2..a9098a9 100644 (file)
@@ -14,6 +14,7 @@ Second is reading config file.'''
 
 import os
 import yaml
+from pyroute2 import IPDB
 
 
 class Parser():
@@ -82,6 +83,16 @@ class Parser():
         # TO-DO add cli parameters to stack_config.
         return test_cfg, stack_cfg
 
+    @staticmethod
+    def ip_parser(ip_type):
+        with IPDB() as ip:
+            GATEWAY_IP = ip.routes['default'].gateway
+        if ip_type is "dashboard":
+            TEST_IP = GATEWAY_IP + ":9200"
+        elif ip_type is "yardstick_test_ip":
+            TEST_IP = GATEWAY_IP + ":8888"
+        return TEST_IP
+
 
 class HeatTemplate_Parser():
     """parser a Heat template and a method to deploy template to a stack"""
@@ -282,4 +293,3 @@ class HeatTemplate_Parser():
 
     def get_template_date(self):
         return self.heat_date
-