From d93f6ca5bf0d4f22ec0fd90eac1bf8b9c09db820 Mon Sep 17 00:00:00 2001 From: kubi Date: Tue, 29 Dec 2015 11:04:20 +0800 Subject: running Parser Yang-to-Tosca module as a tool with jnon and fatih's help, new docker image has been uploaded so this part is about parser verify validating output against expected outcome. Change-Id: If50d241a5338888f14fd11a752dc72678e0c569b JIRA:YARDSTICK-224 Signed-off-by: kubi --- README.rst | 2 +- samples/parser.yaml | 21 + samples/tosca.yaml | 149 +++++ samples/yang.yaml | 687 +++++++++++++++++++++ setup.py | 2 + tests/unit/benchmark/scenarios/parser/__init__.py | 0 .../unit/benchmark/scenarios/parser/test_parser.py | 58 ++ yardstick/benchmark/scenarios/parser/__init__.py | 0 yardstick/benchmark/scenarios/parser/parser.py | 80 +++ yardstick/benchmark/scenarios/parser/parser.sh | 51 ++ .../benchmark/scenarios/parser/parser_setup.sh | 16 + .../benchmark/scenarios/parser/parser_teardown.sh | 13 + 12 files changed, 1078 insertions(+), 1 deletion(-) create mode 100644 samples/parser.yaml create mode 100644 samples/tosca.yaml create mode 100644 samples/yang.yaml create mode 100644 tests/unit/benchmark/scenarios/parser/__init__.py create mode 100644 tests/unit/benchmark/scenarios/parser/test_parser.py create mode 100644 yardstick/benchmark/scenarios/parser/__init__.py create mode 100644 yardstick/benchmark/scenarios/parser/parser.py create mode 100755 yardstick/benchmark/scenarios/parser/parser.sh create mode 100755 yardstick/benchmark/scenarios/parser/parser_setup.sh create mode 100755 yardstick/benchmark/scenarios/parser/parser_teardown.sh diff --git a/README.rst b/README.rst index 8cb360040..582622264 100644 --- a/README.rst +++ b/README.rst @@ -80,7 +80,7 @@ Example setup known to work for development and test: - Cloud: Mirantis OpenStack 6.0 deployed using Virtualbox Install dependencies: -$ sudo apt-get install python-virtualenv python-dev libffi-dev libssl-dev +$ sudo apt-get install python-virtualenv python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev $ sudo easy_install -U setuptools Create a virtual environment: diff --git a/samples/parser.yaml b/samples/parser.yaml new file mode 100644 index 000000000..32d9abed1 --- /dev/null +++ b/samples/parser.yaml @@ -0,0 +1,21 @@ +--- +# Sample task config file +# running Parser Yang-to-Tosca module as a tool +# validating output against expected outcome + +schema: "yardstick:task:0.1" + +scenarios: +- + type: Parser + options: + yangfile: /root/yardstick/samples/yang.yaml + toscafile: /root/yardstick/samples/tosca.yaml + + runner: + type: Iteration + iterations: 1 + interval: 1 + +context: + type: Dummy diff --git a/samples/tosca.yaml b/samples/tosca.yaml new file mode 100644 index 000000000..4472f7ef8 --- /dev/null +++ b/samples/tosca.yaml @@ -0,0 +1,149 @@ +tosca_definitions_version:tosca_simple_yaml_1_0_0 +description: + This module defines a VNF Deployment Unit. +import: + + +metadata: + ID:clearwater + Vendor:HP +dsl_definitions: + compute_props_host_ellis:&compute_props_host_ellis + num_cpu:4 + mem_size:4096 + compute_props_host_bono:&compute_props_host_bono + num_cpu:3 + mem_size:2048 +node_types: + tosca.nodes.compute.ellis: + derived_from:tosca.nodes.compute + + tosca.nodes.compute.bono: + derived_from:tosca.nodes.compute + +topology_template: + # a description of the topology template + description:> + Vdus used in a vnfd + inputs: + storage_size: + type:scalar-unit.size + default:2048 + description:The required storage resource + storage_location: + type:string + description:> + Block storage mount point (filesystem path). + node_templates: + ellis: + type:tosca.nodes.Compute + capabilities: + os: + properties: + architecture: + type: + distribution: + version: + host: + properties:*compute_props_host_ellis + scalable: + properties: + min_instances:1 + default_instances:1 + requirements: + - local_storage: + node:ellis_BlockStorage + relationship: + type:AttachesTo + properties: + location:{ get_input:storage_location } + interfaces: + Standard: + start: + implementation:start.sh + delete: + implementaion:stop.sh + stop: + implementaion:shutdown.sh + ellis_BlockStorage: + type:tosca.nodes.BlockStorage + properties: + size:{ get_input:storage_size } + bono: + type:tosca.nodes.Compute + capabilities: + os: + properties: + architecture: + type: + distribution: + version: + host: + properties:*compute_props_host_bono + scalable: + properties: + min_instances:3 + default_instances:3 + requirements: + - local_storage: + node:bono_BlockStorage + relationship: + type:AttachesTo + properties: + location:{ get_input:storage_location } + interfaces: + Standard: + start: + implementation:start.sh + delete: + implementaion:stop.sh + stop: + implementaion:shutdown.sh + bono_BlockStorage: + type:tosca.nodes.BlockStorage + properties: + size:{ get_input:storage_size } + clearwater_network1: + type:tosca.nodes.network.Network + properties: + ip_version:4 + ellis_port1: + type:tosca.nodes.network.Port + requirements: + - binding: + node:ellis + - link: + node:clearwater_network1 + clearwater_network2: + type:tosca.nodes.network.Network + properties: + ip_version:4 + ellis_port2: + type:tosca.nodes.network.Port + requirements: + - binding: + node:ellis + - link: + node:clearwater_network2 + clearwater_network1: + type:tosca.nodes.network.Network + properties: + ip_version:4 + bono_port1: + type:tosca.nodes.network.Port + requirements: + - binding: + node:bono + - link: + node:clearwater_network1 + clearwater_network2: + type:tosca.nodes.network.Network + properties: + ip_version:4 + bono_port2: + type:tosca.nodes.network.Port + requirements: + - binding: + node:bono + - link: + node:clearwater_network2 \ No newline at end of file diff --git a/samples/yang.yaml b/samples/yang.yaml new file mode 100644 index 000000000..86b7b2f31 --- /dev/null +++ b/samples/yang.yaml @@ -0,0 +1,687 @@ + module clearwater { + + namespace "http://localhost/ietf-inet-types.yang"; + + prefix "yang"; + + organization "HP"; + + contact "TBD"; + + description "This module defines a VNF Deployment Unit."; + revision "2014-05-18" { + + description + + "Initial version"; + + reference + + "RFC XXXX"; + + } + container clearwater { + + description + + "Vdus used in a vnfd"; + + list ellis { + key id; + leaf id{ + type string; + description "key ID for vdu1"; + } + description + + "Vdu key"; + + + + leaf instance-num { + + type uint16{ + range 1..6;} + default 1; + + + description + + "Number of instances of the said VDU which shall be + instantiated"; + + } + + leaf vm-image { + + type string; + reference "uri"; + + + description + + "Reference to a VM image"; + + } + container resource { + description + + "The required resource"; + + container cpu { + + description + + "The required computation resource"; + + + + leaf vCPU_num { + + type uint32{ + range 4; + } + + description + + "The number of virtual CPU units"; + + } + + + + list vCPU-spec { + + key "name"; + + + + description + + "Processor characteristics for the VDU"; + + + + leaf name { + + type string; + + description + + "Name of vCPU-spec"; + + } + leaf description { + + type string; + + description + + "Description of vCPU-spec"; + + } + + leaf value { + + type uint32; + + description + + "Value of vCPU-spec"; + + } + + } + + } + + container memory { + + description + + "The required memory resource"; + + leaf memory_size { + + type uint32{ + range 4096; + } + + description + + "Memory size, unit:MBytes"; + + } + + list memory-spec { + + key name; + + + + description + + "Memory characteristics for the VDU"; + + + + leaf name { + + type string; + + description + + "Name of memory-spec"; + + } + + + + leaf description { + + type string; + + description + + "Description of memory-spec"; + + } + + + + leaf value { + + type uint32; + + description + + "Value of memory-spec"; + + } + + } + + } + + + + container disk { + + description + + "The required storage resource"; + + + + leaf disk-size { + + type uint32{ + range 2048; + } + description + + "Virtual storage size, unit:MBytes"; + } + + + + list disk-KQI { + + key name; + + + + description + + "Storage characteristics in the VDU"; + + + + leaf name { + + type string; + + description + + "Name of disk-KQI"; + + } + leaf description { + + type string; + + description + + "Description of disk-KQI"; + + } + + + + leaf value { + + type uint32; + + description + + "Value of disk-KQI"; + + } + + } + + } + + + + container vnic { + + description + + "Virtual network interface card (vnic) resource"; + + + + leaf vnic-num { + + type uint32{ + range 2; + } + + description + + "The total number of virtual vnic"; + + } + } + + } + + + + container workflow-script { + + description + + "VDU workflow script"; + + + + leaf init { + + type string; + default "start.sh"; + + + description + + "VDU initialization script"; + } + + + + leaf terminate { + + type string; + default "stop.sh"; + + + description + + "VDU termination script"; + } + + leaf graceful-shutdown { + + type string; + default "shutdown.sh"; + + + description + + "VDU graceful shutdown script"; + + } + + } + + } + list bono { + key id; + leaf id{ + type string; + description "key ID for vdu2"; + } + description + + "Vdu key"; + + + + leaf instance-num { + + type uint16; + default 3; + + + description + + "Number of instances of the said VDU which shall be + instantiated"; + + } + + + + leaf vm-image { + + type string; + reference "URI"; + + + description + + "Reference to a VM image"; + + } + + + + container resource { + description + + "The required resource"; + + + + container cpu { + + description + + "The required computation resource"; + + + + leaf vCPU_num { + + type uint32{ + range 3; + } + + description + + "The number of virtual CPU units"; + + } + + + + list vCPU-spec { + + key "name"; + + + + description + + "Processor characteristics for the VDU"; + + + + leaf name { + + type string; + + description + + "Name of vCPU-spec"; + + } + leaf description { + + type string; + + description + + "Description of vCPU-spec"; + + } + + + + leaf value { + + type uint32; + + description + + "Value of vCPU-spec"; + + } + + } + + } + + + + container memory { + + description + + "The required memory resource"; + + + + leaf memory_size { + + type uint32{ + range 2048; + } + + description + + "Memory size, unit:MBytes"; + + } + + list memory-spec { + + key name; + + description + + "Memory characteristics for the VDU"; + + + + leaf name { + + type string; + + description + + "Name of memory-spec"; + + } + + + + leaf description { + + type string; + + description + + "Description of memory-spec"; + + } + + + + leaf value { + + type uint32; + + description + + "Value of memory-spec"; + + } + + } + + } + + + + container disk { + + description + + "The required storage resource"; + + + + leaf disk-size { + + type uint32{ + range 3000; + } + + description + + "Virtual storage size, unit:MBytes"; + + } + + + + list disk-KQI { + + key name; + + + + description + + "Storage characteristics in the VDU"; + + + + leaf name { + + type string; + + description + + "Name of disk-KQI"; + + } + leaf description { + + type string; + + description + + "Description of disk-KQI"; + + } + + + + leaf value { + + type uint32; + + description + + "Value of disk-KQI"; + + } + + } + + } + + + + container vnic { + + description + + "Virtual network interface card (vnic) resource"; + + + + leaf vnic-num { + + type uint32{ + range 2; + } + + description + + "The total number of virtual vnic"; + + } + } + + } + + + + container workflow-script { + + description + + "VDU workflow script"; + + + + leaf init { + + type string; + default "start.sh"; + + + description + + "VDU initialization script"; + + } + + + + leaf terminate { + + type string; + default "stop.sh"; + + + description + + "VDU termination script"; + + } + + leaf graceful-shutdown { + + type string; + default "shutdown.sh"; + + + description + + "VDU graceful shutdown script"; + + } + + } + + } + + } + + } + diff --git a/setup.py b/setup.py index 872760ae5..e923b23c5 100755 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ setup( 'benchmark/scenarios/compute/*.bash', 'benchmark/scenarios/networking/*.bash', 'benchmark/scenarios/networking/*.txt', + 'benchmark/scenarios/parser/*.sh', 'benchmark/scenarios/storage/*.bash', 'resources/files/*' ] @@ -22,6 +23,7 @@ setup( "coverage>=3.6", "flake8", "Jinja2>=2.6", + "lxml", "PyYAML>=3.10", "pbr<2.0,>=1.3", "python-glanceclient>=0.12.0", diff --git a/tests/unit/benchmark/scenarios/parser/__init__.py b/tests/unit/benchmark/scenarios/parser/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/benchmark/scenarios/parser/test_parser.py b/tests/unit/benchmark/scenarios/parser/test_parser.py new file mode 100644 index 000000000..d11a6d5c8 --- /dev/null +++ b/tests/unit/benchmark/scenarios/parser/test_parser.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other. +# +# 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 +############################################################################## + +# Unittest for yardstick.benchmark.scenarios.parser.Parser + +import mock +import unittest +import json + +from yardstick.benchmark.scenarios.parser import parser + +@mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess') +class ParserTestCase(unittest.TestCase): + + def setUp(self): + pass + + def test_parser_successful_setup(self, mock_subprocess): + + p = parser.Parser({}, {}) + mock_subprocess.call().return_value = 0 + p.setup() + self.assertEqual(p.setup_done, True) + + def test_parser_successful(self, mock_subprocess): + args = { + 'options': {'yangfile':'/root/yardstick/samples/yang.yaml', + 'toscafile':'/root/yardstick/samples/tosca.yaml'}, + } + p = parser.Parser(args, {}) + result = {} + mock_subprocess.call().return_value = 0 + sample_output = '{"yangtotosca": "success"}' + + p.run(result) + expected_result = json.loads(sample_output) + + def test_parser_teardown_successful(self, mock_subprocess): + + p = parser.Parser({}, {}) + mock_subprocess.call().return_value = 0 + p.teardown() + self.assertEqual(p.teardown_done, True) + + +def main(): + unittest.main() + +if __name__ == '__main__': + main() diff --git a/yardstick/benchmark/scenarios/parser/__init__.py b/yardstick/benchmark/scenarios/parser/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/benchmark/scenarios/parser/parser.py b/yardstick/benchmark/scenarios/parser/parser.py new file mode 100644 index 000000000..006258d05 --- /dev/null +++ b/yardstick/benchmark/scenarios/parser/parser.py @@ -0,0 +1,80 @@ +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other. +# +# 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 +############################################################################## +import pkg_resources +import logging +import subprocess +from yardstick.benchmark.scenarios import base + +LOG = logging.getLogger(__name__) + + +class Parser(base.Scenario): + """running Parser Yang-to-Tosca module as a tool + validating output against expected outcome + + more info https://wiki.opnfv.org/parser + """ + __scenario_type__ = "Parser" + + SETUP_SCRIPT = "parser_setup.sh" + TEARDOWN_SCRIPT = "parser_teardown.sh" + PARSER_SCRIPT = "parser.sh" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.setup_done = False + + def setup(self): + """scenario setup""" + self.setup_script = pkg_resources.resource_filename( + "yardstick.benchmark.scenarios.parser", + Parser.SETUP_SCRIPT) + cmd = "%s" % (self.setup_script) + + subprocess.call(cmd, shell=True) + + self.setup_done = True + + def run(self, result): + """execute the translation""" + options = self.scenario_cfg['options'] + yangfile = options.get("yangfile", '~/yardstick/samples/yang.yaml') + toscafile = options.get("toscafile", '~/yardstick/samples/tosca.yaml') + + self.parser_script = pkg_resources.resource_filename( + "yardstick.benchmark.scenarios.parser", + Parser.PARSER_SCRIPT) + + if not self.setup_done: + self.setup() + + cmd1 = "%s %s %s" % (self.parser_script, yangfile, toscafile) + cmd2 = "chmod 777 %s" % (self.parser_script) + subprocess.call(cmd2, shell=True) + output = subprocess.call(cmd1, shell=True, stdout=subprocess.PIPE) + print "yangtotosca finished" + + result['yangtotosca'] = "success" if output == 0 else "fail" + + def teardown(self): + ''' for scenario teardown remove parser and pyang ''' + self.teardown_script = pkg_resources.resource_filename( + "yardstick.benchmark.scenarios.parser", + Parser.TEARDOWN_SCRIPT) + subprocess.call(self.teardown_script, shell=True) + self.teardown_done = True + + +def _test(): + '''internal test function''' + pass + +if __name__ == '__main__': + _test() diff --git a/yardstick/benchmark/scenarios/parser/parser.sh b/yardstick/benchmark/scenarios/parser/parser.sh new file mode 100755 index 000000000..4408e637c --- /dev/null +++ b/yardstick/benchmark/scenarios/parser/parser.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +############################################################################## +# Copyright (c) 2015 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 +############################################################################## + +set -e + +# Commandline arguments +yangfile=$1 +base_dir=$(dirname $yangfile) +shift +toscafile=$1 +OUTPUT_FILE=/tmp/parser-out.log + +# run parser test +run_parser() +{ + cd /tmp/parser/yang2tosca + python tosca_translator.py --filename $yangfile> $OUTPUT_FILE +} + +# write the result to stdout in json format +check_result() +{ + + if (diff -q $toscafile ${yangfile%'.yaml'}"_tosca.yaml" >> $OUTPUT_FILE); + then + exit 0 + else + exit 1 + fi + +} + +# main entry +main() +{ + # run the test + run_parser + + # output result + check_result +} + +main diff --git a/yardstick/benchmark/scenarios/parser/parser_setup.sh b/yardstick/benchmark/scenarios/parser/parser_setup.sh new file mode 100755 index 000000000..44356447d --- /dev/null +++ b/yardstick/benchmark/scenarios/parser/parser_setup.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +############################################################################## +# Copyright (c) 2015 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 +############################################################################## + +git clone https://github.com/mbj4668/pyang.git /tmp/pyang +cd /tmp/pyang +python setup.py install +git clone https://gerrit.opnfv.org/gerrit/parser /tmp/parser + diff --git a/yardstick/benchmark/scenarios/parser/parser_teardown.sh b/yardstick/benchmark/scenarios/parser/parser_teardown.sh new file mode 100755 index 000000000..727e9decd --- /dev/null +++ b/yardstick/benchmark/scenarios/parser/parser_teardown.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +############################################################################## +# Copyright (c) 2015 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 +############################################################################## + +rm -rf /tmp/pyang +rm -rf /tmp/parser -- cgit 1.2.3-korg