X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fparser.py;h=c0c10721de1df72acb88bd843b76a51b814a91a9;hb=adf6a02bae295455f584ebab762592dd57e2422c;hp=a9098a9873a1e518e2d16ff8cf805a16e49b9c7c;hpb=0a29e9ec59e21dc46db0497187cc9d0de0844b05;p=bottlenecks.git diff --git a/utils/parser.py b/utils/parser.py index a9098a98..c0c10721 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -14,7 +14,10 @@ Second is reading config file.''' import os import yaml +import json +import time from pyroute2 import IPDB +import utils.infra_setup.runner.docker_env as docker_env class Parser(): @@ -39,6 +42,14 @@ class Parser(): cls.bottlenecks_config["fetch_os"] = common_config["fetch_os_file"] cls.bottlenecks_config["log_dir"] = common_config['log_dir'] cls.bottlenecks_config["rc_dir"] = common_config['rc_dir'] + cls.bottlenecks_config["pod_info"] = common_config['pod_info'] + cls.bottlenecks_config["yardstick_rc_dir"] = \ + common_config['yardstick_rc_dir'] + cls.bottlenecks_config["yardstick_image_dir"] = \ + common_config['yardstick_image_dir'] + cls.bottlenecks_config["image_url"] = common_config['image_url'] + cls.bottlenecks_config["yardstick_image_name"] = \ + common_config['yardstick_image_name'] cls.config_dir_check(cls.bottlenecks_config["log_dir"]) @classmethod @@ -47,11 +58,11 @@ class Parser(): cls.test_dir, testcase, 'testsuite_story', - story_name) + story_name + '.yaml') with open(story_dir) as file: story_parser = yaml.load(file) for case_name in story_parser['testcase']: - Parser.testcase_read(cls, testcase, case_name) + Parser.testcase_read(testcase, case_name) return cls.bottlenecks_test @@ -76,6 +87,19 @@ class Parser(): if not os.path.exists(dirname): os.makedirs(dirname) + @classmethod + def testcase_out_dir(cls, testcase): + file_name = os.getenv("OUTPUT_FILE") + if file_name is None: + file_suffix = time.strftime('%H_%M', time.localtime(time.time())) + suffix_name = "_" + str(file_suffix) + out_name = cls.bottlenecks_config["log_dir"] + testcase + outfile_name = out_name + suffix_name + ".out" + else: + out_name = str(file_name) + outfile_name = cls.bottlenecks_config["log_dir"] + out_name + return outfile_name + @staticmethod def config_parser(testcase_cfg, parameters): test_cfg = testcase_cfg['test_config'] @@ -83,6 +107,15 @@ class Parser(): # TO-DO add cli parameters to stack_config. return test_cfg, stack_cfg + @staticmethod + def convert_docker_env(config, ip_type): + if ip_type is "dashboard": + config["contexts"]["dashboard_ip"] = \ + docker_env.ELK_info["ip"] + ":9200" + elif ip_type is "yardstick": + config["contexts"]["yardstick_ip"] = \ + docker_env.yardstick_info["ip"] + ":8888" + @staticmethod def ip_parser(ip_type): with IPDB() as ip: @@ -93,6 +126,21 @@ class Parser(): TEST_IP = GATEWAY_IP + ":8888" return TEST_IP + @staticmethod + def result_to_file(data, file_name): + with open(file_name, "a") as f: + f.write(json.dumps(data, f)) + f.write("\n") + + @staticmethod + def str_to_list(str_org): + try: + data = str_org.split(',') + except AttributeError: + data = [] + data.append(str_org) + return data + class HeatTemplate_Parser(): """parser a Heat template and a method to deploy template to a stack"""