Bottlenecks POSCA testing code reconstruction
[bottlenecks.git] / testsuites / posca / run_posca.py
index e5e11e9..fcf35d5 100755 (executable)
@@ -1,44 +1,61 @@
-#!/usr/bin/env python\r
-##############################################################################\r
-# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.\r
-#\r
-# All rights reserved. This program and the accompanying materials\r
-# are made available under the terms of the Apache License, Version 2.0\r
-# which accompanies this distribution, and is available at\r
-# http://www.apache.org/licenses/LICENSE-2.0\r
-##############################################################################\r
-\r
-import sys\r
-import subprocess\r
-\r
-INTERPRETER = "/usr/bin/python"\r
-# ------------------------------------------------------\r
-# run posca testcase\r
-# ------------------------------------------------------\r
-\r
-\r
-def posca_run(arg):\r
-    print("========== run posca ==========")\r
-    print(arg)\r
-    if(arg == "posca_factor_system_bandwidth"):\r
-        print("========== run posca_system_bandwidth ===========")\r
-        cmd = '/home/opnfv/bottlenecks/testsuites/posca/testcase_script/\\r
-posca_factor_system_bandwidth.py'\r
-        pargs = [INTERPRETER, cmd]\r
-        sub_result = subprocess.Popen(pargs)\r
-        sub_result.wait()\r
-\r
-\r
-def posca_env_check():\r
-    print("========== posca env check ===========")\r
-\r
-\r
-def main():\r
-    # para_testname = sys.argv[0]\r
-    para_test_arg = sys.argv[2]\r
-    posca_env_check()\r
-    posca_run(para_test_arg)\r
-    sys.exit(0)\r
-\r
-if __name__ == '__main__':\r
-    main()\r
+#!/usr/bin/env python
+##############################################################################
+# 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
+##############################################################################
+'''This file realize the function of how to run posca.
+In this file, The first thing is to read testcase config
+for example: you could run this by use
+posca_run('testcase', "Which testcase you will run")
+posca_run('teststory', "Which story you will run")
+and if you run "python run_posca", this will run testcase,
+posca_factor_system_bandwidth by default.'''
+
+import importlib
+import utils.parser as conf_parser
+import utils.logger as log
+INTERPRETER = "/usr/bin/python"
+
+LOG = log.Logger(__name__).getLogger()
+# ------------------------------------------------------
+# run posca testcase
+# ------------------------------------------------------
+
+
+def posca_testcase_run(testcase_script, test_config):
+
+    module_string = "testsuites.posca.testcase_script.%s" % (testcase_script)
+    module = importlib.import_module(module_string)
+    module.run(test_config)
+
+
+def posca_run(test_level, test_name):
+    if test_level == "testcase":
+        config = conf_parser.Parser.testcase_read("posca", test_name)
+    elif test_level == "teststory":
+        config = conf_parser.Parser.story_read("posca", test_name)
+    for testcase in config:
+        print(config[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()
+
+
+def main():
+    test_level = "testcase"
+    test_name = "posca_factor_system_bandwidth"
+    posca_run(test_level, test_name)
+
+
+if __name__ == '__main__':
+    main()
+