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 ##############################################################################
12 from yardstick.benchmark.scenarios import base
14 LOG = logging.getLogger(__name__)
17 class Parser(base.Scenario):
18 """running Parser Yang-to-Tosca module as a tool
19 validating output against expected outcome
21 more info https://wiki.opnfv.org/parser
23 __scenario_type__ = "Parser"
25 SETUP_SCRIPT = "parser_setup.sh"
26 TEARDOWN_SCRIPT = "parser_teardown.sh"
27 PARSER_SCRIPT = "parser.sh"
29 def __init__(self, scenario_cfg, context_cfg):
30 self.scenario_cfg = scenario_cfg
31 self.context_cfg = context_cfg
32 self.setup_done = False
36 self.setup_script = pkg_resources.resource_filename(
37 "yardstick.benchmark.scenarios.parser",
39 cmd = "%s" % (self.setup_script)
41 subprocess.call(cmd, shell=True)
43 self.setup_done = True
45 def run(self, result):
46 """execute the translation"""
47 options = self.scenario_cfg['options']
48 yangfile = options.get("yangfile", '~/yardstick/samples/yang.yaml')
49 toscafile = options.get("toscafile", '~/yardstick/samples/tosca.yaml')
51 self.parser_script = pkg_resources.resource_filename(
52 "yardstick.benchmark.scenarios.parser",
55 if not self.setup_done:
58 cmd1 = "%s %s %s" % (self.parser_script, yangfile, toscafile)
59 cmd2 = "chmod 777 %s" % (self.parser_script)
60 subprocess.call(cmd2, shell=True)
61 output = subprocess.call(cmd1, shell=True, stdout=subprocess.PIPE)
62 print "yangtotosca finished"
64 result['yangtotosca'] = "success" if output == 0 else "fail"
67 ''' for scenario teardown remove parser and pyang '''
68 self.teardown_script = pkg_resources.resource_filename(
69 "yardstick.benchmark.scenarios.parser",
70 Parser.TEARDOWN_SCRIPT)
71 subprocess.call(self.teardown_script, shell=True)
72 self.teardown_done = True
76 '''internal test function'''
79 if __name__ == '__main__':