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