From e1a54d34819563946d1ff1ec673d1d261b826ad8 Mon Sep 17 00:00:00 2001 From: liyin Date: Mon, 9 Jan 2017 18:28:35 +0800 Subject: [PATCH] Bottlenecks frame support parser config JIRA: BOTTLENECK-123 This code is for Bottlenecks to have a common way to parser config. those config are divided into three part: common config, test config and stack config. those function could build a frame of config read. we will modify it after a few times. Change-Id: I7d3ddc2c8af3043dc9cd89b519e506eca6a03514 Signed-off-by: liyin --- config/config.yaml | 2 ++ utils/parser.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 config/config.yaml create mode 100644 utils/parser.py diff --git a/config/config.yaml b/config/config.yaml new file mode 100644 index 00000000..cf380e27 --- /dev/null +++ b/config/config.yaml @@ -0,0 +1,2 @@ +common_config: + log_dir: '/tmp/bottlenecks_POSCA.log' \ No newline at end of file diff --git a/utils/parser.py b/utils/parser.py new file mode 100644 index 00000000..7ddf02a2 --- /dev/null +++ b/utils/parser.py @@ -0,0 +1,56 @@ +#!/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 +############################################################################## +from logger import Logger +import os +import yaml + + +class Parser(): + def __init__(self): + self.code_dir = os.path.dirname(os.path.abspath(__file__)) + self.root_dir = os.path.dirname(self.code_dir) + self.test_dir = os.path.join(self.root_dir, 'testsuites') + config_dir = os.path.join( + self.root_dir, + 'config', + 'config.yaml') + with open(config_dir) as file: + log_info = yaml.load(file) + self.logdir = log_info['common_config'] + self.LOG = Logger(__name__).getLogger() + + def config_read(self, testcase, story_name): + self.LOG.info("begin to parser config file!") + testcase_parser = {} + self.story_dir = os.path.join( + self.test_dir, + testcase, + 'testsuite_story', + story_name) + with open(self.story_dir) as file: + self.LOG.info('testsuite:' + testcase + 'story:' + story_name) + story_parser = yaml.load(file) + for case_name in story_parser['testcase']: + testcase_dir = os.path.join( + self.test_dir, + testcase, + 'testcase_cfg', + case_name) + with open(testcase_dir) as f: + self.LOG.info('story: %s, testcase: %s' % (story_name, case_name)) + testcase_parser[case_name] = yaml.load(f) + + return testcase_parser + + def config_parser(self, 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 \ No newline at end of file -- 2.16.6