1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env python
##############################################################################
# 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
##############################################################################
import os
import yaml
class Parser():
bottlenecks_config = {}
@classmethod
def config_init(cls):
cls.code_dir = os.path.dirname(os.path.abspath(__file__))
cls.root_dir = os.path.dirname(cls.code_dir)
cls.test_dir = os.path.join(cls.root_dir, 'testsuites')
config_dir = os.path.join(
cls.root_dir,
'config',
'config.yaml')
with open(config_dir) as file:
config_info = yaml.load(file)
common_config = config_info['common_config']
cls.bottlenecks_config["releng_dir"] = common_config["releng_dir"]
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.config_dir_check(cls.bottlenecks_config["log_dir"])
@classmethod
def config_read(cls, testcase, story_name):
story_dir = os.path.join(
cls.test_dir,
testcase,
'testsuite_story',
story_name)
with open(story_dir) as file:
story_parser = yaml.load(file)
for case_name in story_parser['testcase']:
testcase_dir = os.path.join(
cls.test_dir,
testcase,
'testcase_cfg',
case_name)
with open(testcase_dir) as f:
cls.bottlenecks_config[case_name] = yaml.load(f)
return cls.bottlenecks_config
@classmethod
def config_dir_check(cls, dirname):
if dirname is None:
dirname = '/tmp/'
if not os.path.exists(dirname):
os.makedirs(dirname)
@staticmethod
def config_parser(testcase_cfg, parameters):
test_cfg = testcase_cfg['test_config']
stack_cfg = testcase_cfg['stack_config']
# TO-DO add cli parameters to stack_config.
return test_cfg, stack_cfg
|