Bottlenecks frame support parser config
[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 from logger import Logger
11 import os
12 import yaml
13
14
15 class Parser():
16     def __init__(self):
17         self.code_dir = os.path.dirname(os.path.abspath(__file__))
18         self.root_dir = os.path.dirname(self.code_dir)
19         self.test_dir = os.path.join(self.root_dir, 'testsuites')
20         config_dir = os.path.join(
21             self.root_dir,
22             'config',
23             'config.yaml')
24         with open(config_dir) as file:
25             log_info = yaml.load(file)
26             self.logdir = log_info['common_config']
27         self.LOG = Logger(__name__).getLogger()
28
29     def config_read(self, testcase, story_name):
30         self.LOG.info("begin to parser config file!")
31         testcase_parser = {}
32         self.story_dir = os.path.join(
33             self.test_dir,
34             testcase,
35             'testsuite_story',
36             story_name)
37         with open(self.story_dir) as file:
38             self.LOG.info('testsuite:' + testcase + 'story:' + story_name)
39             story_parser = yaml.load(file)
40         for case_name in story_parser['testcase']:
41             testcase_dir = os.path.join(
42                 self.test_dir,
43                 testcase,
44                 'testcase_cfg',
45                 case_name)
46             with open(testcase_dir) as f:
47                 self.LOG.info('story: %s, testcase: %s' % (story_name, case_name))
48                 testcase_parser[case_name] = yaml.load(f)
49
50         return testcase_parser
51
52     def config_parser(self, testcase_cfg, parameters):
53         test_cfg = testcase_cfg['test_config']
54         stack_cfg = testcase_cfg['stack_config']
55         # TO-DO add cli parameters to stack_config.
56         return test_cfg, stack_cfg