1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class Parser(base.Scenario):
20 """running Parser Yang-to-Tosca module as a tool
21 validating output against expected outcome
23 more info https://wiki.opnfv.org/parser
25 __scenario_type__ = "Parser"
27 SETUP_SCRIPT = "parser_setup.sh"
28 TEARDOWN_SCRIPT = "parser_teardown.sh"
29 PARSER_SCRIPT = "parser.sh"
31 def __init__(self, scenario_cfg, context_cfg):
32 self.scenario_cfg = scenario_cfg
33 self.context_cfg = context_cfg
34 self.setup_done = False
38 self.setup_script = pkg_resources.resource_filename(
39 "yardstick.benchmark.scenarios.parser",
41 cmd = "%s" % (self.setup_script)
43 subprocess.call(cmd, shell=True)
45 self.setup_done = True
47 def run(self, result):
48 """execute the translation"""
49 options = self.scenario_cfg['options']
50 yangfile = options.get("yangfile", '~/yardstick/samples/yang.yaml')
51 toscafile = options.get("toscafile", '~/yardstick/samples/tosca.yaml')
53 self.parser_script = pkg_resources.resource_filename(
54 "yardstick.benchmark.scenarios.parser",
57 if not self.setup_done:
60 cmd1 = "%s %s %s" % (self.parser_script, yangfile, toscafile)
61 cmd2 = "chmod 777 %s" % (self.parser_script)
62 subprocess.call(cmd2, shell=True)
63 p = subprocess.Popen(cmd1, shell=True, stdout=subprocess.PIPE,
64 stderr=subprocess.PIPE)
66 LOG.info("yangtotosca finished")
68 result['yangtotosca'] = "success" if p.returncode == 0 else "fail"
71 """ for scenario teardown remove parser and pyang """
72 self.teardown_script = pkg_resources.resource_filename(
73 "yardstick.benchmark.scenarios.parser",
74 Parser.TEARDOWN_SCRIPT)
75 subprocess.call(self.teardown_script, shell=True)
76 self.teardown_done = True
80 """internal test function"""
84 if __name__ == '__main__':