2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 '''This file realize the function of how to parser a config file.
11 This contain Two part:
12 Frist is Init some variables the will be used.
13 Second is reading config file.'''
21 bottlenecks_config = {}
26 cls.code_dir = os.path.dirname(os.path.abspath(__file__))
27 cls.root_dir = os.path.dirname(cls.code_dir)
28 cls.test_dir = os.path.join(cls.root_dir, 'testsuites')
29 config_dir = os.path.join(
34 with open(config_dir) as file:
35 config_info = yaml.load(file)
36 common_config = config_info['common_config']
37 cls.bottlenecks_config["releng_dir"] = common_config["releng_dir"]
38 cls.bottlenecks_config["fetch_os"] = common_config["fetch_os_file"]
39 cls.bottlenecks_config["log_dir"] = common_config['log_dir']
40 cls.bottlenecks_config["rc_dir"] = common_config['rc_dir']
41 cls.config_dir_check(cls.bottlenecks_config["log_dir"])
44 def story_read(cls, testcase, story_name):
45 story_dir = os.path.join(
50 with open(story_dir) as file:
51 story_parser = yaml.load(file)
52 for case_name in story_parser['testcase']:
53 Parser.testcase_read(cls, testcase, case_name)
55 return cls.bottlenecks_test
58 def testcase_read(cls, testcase, testcase_name):
60 testcase_dir = os.path.join(
65 testcase_local = testcase_dir + ".yaml"
66 with open(testcase_local) as f:
67 cls.bottlenecks_test[testcase_name] = yaml.load(f)
69 return cls.bottlenecks_test
72 def config_dir_check(cls, dirname):
75 if not os.path.exists(dirname):
79 def config_parser(testcase_cfg, parameters):
80 test_cfg = testcase_cfg['test_config']
81 stack_cfg = testcase_cfg['stack_config']
82 # TO-DO add cli parameters to stack_config.
83 return test_cfg, stack_cfg