Bottlenecks frame support parser config 95/26795/2
authorliyin <liyin11@huawei.com>
Mon, 9 Jan 2017 10:28:35 +0000 (18:28 +0800)
committerAce Lee <liyin11@huawei.com>
Tue, 10 Jan 2017 08:59:26 +0000 (08:59 +0000)
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 <liyin11@huawei.com>
config/config.yaml [new file with mode: 0644]
utils/parser.py [new file with mode: 0644]

diff --git a/config/config.yaml b/config/config.yaml
new file mode 100644 (file)
index 0000000..cf380e2
--- /dev/null
@@ -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 (file)
index 0000000..7ddf02a
--- /dev/null
@@ -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