summaryrefslogtreecommitdiffstats
path: root/scripts/parser.py
diff options
context:
space:
mode:
authorLeo Wang <grakiss.wanglei@huawei.com>2016-09-22 21:56:54 -0400
committerLeo Wang <grakiss.wanglei@huawei.com>2016-09-30 05:30:22 -0400
commit39942dc9c5bc152a6ed20534755cc0dc38d85ede (patch)
tree8d4a980e7454b26cd97216a8e91de6c947692e9a /scripts/parser.py
parentc554b6951f8ee8298d3f8ae8f53ba468dbf4c164 (diff)
Use template to unify commands in functest/yardstick
JIRA: DOVETAIL-19 1. use jinja2 to unify commands in config files 2. it simplify the process of test execution, put the dissimilarity in config 3. add precondition/postcondition for functest/yardstick config Change-Id: Ib996b11ea065b61910b34b78191bb7b1ffd92e59 Signed-off-by: Leo Wang <grakiss.wanglei@huawei.com>
Diffstat (limited to 'scripts/parser.py')
-rw-r--r--scripts/parser.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/parser.py b/scripts/parser.py
index c0b18e13..1c0c0450 100644
--- a/scripts/parser.py
+++ b/scripts/parser.py
@@ -7,3 +7,34 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
+import jinja2
+
+
+import utils.dovetail_logger as dt_logger
+import utils.dovetail_utils as dt_utils
+
+logger = dt_logger.Logger('parser.py').getLogger()
+
+from conf.dovetail_config import *
+
+class Parser:
+ '''preprocess configuration files'''
+
+ @classmethod
+ def parse_cmd(cls, cmd, testcase):
+ cmd_lines = None
+ try:
+ template = jinja2.Template(cmd, undefined=jinja2.StrictUndefined)
+ kwargs = {}
+ for arg in dovetail_config['parameters']:
+ path = eval(arg['path'])
+ logger.debug('name: %s, eval path: %s ' % (arg['name'], path))
+ kwargs[arg['name']] = dt_utils.get_obj_by_path(testcase.testcase,path)
+
+ logger.debug('kwargs: %s' % kwargs)
+ cmd_lines = template.render(**kwargs)
+ except Exception as e:
+ logger.error('failed to parse cmd %s, exception:%s' % (cmd, e))
+ return None
+
+ return cmd_lines