From a5eb10b2f291d4c6c3693dcbb561203d49b51fe2 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Fri, 17 Jun 2016 13:35:47 +0530 Subject: [PATCH] VNF scaling: TOSCA definitions and sample template implements blueprint: #vnf-scaling Change-Id: I315e5d4df9217b499c537ae31ca80cfe212a55b5 --- .../vnfd/tosca-vnfd-scale.yaml | 63 +++++++++++++++ .../vm/test_tosca_templates_under_samples.py | 76 +++++++++++++++++++ tacker/vm/tosca/lib/tacker_defs.yaml | 34 ++++++++- 3 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 samples/tosca-templates/vnfd/tosca-vnfd-scale.yaml create mode 100644 tacker/tests/unit/vm/test_tosca_templates_under_samples.py diff --git a/samples/tosca-templates/vnfd/tosca-vnfd-scale.yaml b/samples/tosca-templates/vnfd/tosca-vnfd-scale.yaml new file mode 100644 index 000000000..bfed6f4ad --- /dev/null +++ b/samples/tosca-templates/vnfd/tosca-vnfd-scale.yaml @@ -0,0 +1,63 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +description: sample-tosca-vnfd-scaling + +metadata: + template_name: sample-tosca-vnfd-scaling + +topology_template: + node_templates: + VDU1: + type: tosca.nodes.nfv.VDU.Tacker + properties: + image: cirros-0.3.4-x86_64-uec + mgmt_driver: noop + availability_zone: nova + flavor: m1.tiny + + CP1: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: true + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU1 + + VDU2: + type: tosca.nodes.nfv.VDU.Tacker + properties: + image: cirros-0.3.4-x86_64-uec + mgmt_driver: noop + availability_zone: nova + flavor: m1.tiny + + CP2: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: true + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU2 + + VL1: + type: tosca.nodes.nfv.VL + properties: + network_name: private + vendor: Tacker + + policies: + - SP1: + type: tosca.policy.tacker.Scaling + properties: + increment: 1 + cooldown: 120 + min_instances: 1 + max_instances: 3 + default_instances: 2 + targets: [VDU1, VDU2] diff --git a/tacker/tests/unit/vm/test_tosca_templates_under_samples.py b/tacker/tests/unit/vm/test_tosca_templates_under_samples.py new file mode 100644 index 000000000..460e45589 --- /dev/null +++ b/tacker/tests/unit/vm/test_tosca_templates_under_samples.py @@ -0,0 +1,76 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import testtools + +from toscaparser import tosca_template +from toscaparser.utils import yamlparser + +from tacker.vm.tosca import utils +from translator.hot import tosca_translator + + +# TODO(kanagaraj-manickam) Update it for including other samples also +def get_list_of_samples(): + base_path = (os.path.dirname(os.path.abspath(__file__)) + + '/../../../../samples/tosca-templates/vnfd/') + return [base_path + 'tosca-vnfd-scale.yaml'] + + +class TestSamples(testtools.TestCase): + """Sample tosca validation. + + Helps to validate the tosca templates provided in the samples folder + to make sure whether its valid YAML, valid TOSCA and + possible to translate into HOT template. + """ + + def test_samples(self): + for f in get_list_of_samples(): + with open(f, 'r') as _f: + yaml_dict = None + try: + yaml_dict = yamlparser.simple_ordered_parse(_f.read()) + except: # noqa + pass + + self.assertIsNotNone( + yaml_dict, + "Yaml parser failed to parse %s" % f) + + utils.updateimports(yaml_dict) + + tosca = None + try: + tosca = tosca_template.ToscaTemplate( + a_file=False, + yaml_dict_tpl=yaml_dict) + except: # noqa + pass + + self.assertIsNotNone( + tosca, + "Tosca parser failed to parse %s" % f) + + hot = None + try: + hot = tosca_translator.TOSCATranslator(tosca, + {}).translate() + except: # noqa + pass + + self.assertIsNotNone( + hot, + "Heat-translator failed to translate %s" % f) diff --git a/tacker/vm/tosca/lib/tacker_defs.yaml b/tacker/vm/tosca/lib/tacker_defs.yaml index 06c669a6d..0c58e73da 100644 --- a/tacker/vm/tosca/lib/tacker_defs.yaml +++ b/tacker/vm/tosca/lib/tacker_defs.yaml @@ -125,6 +125,34 @@ policy_types: properties: name: http-ping -group_types: - tosca.groups.tacker.VDU: - derived_from: tosca.groups.Root + tosca.policies.tacker.Scaling: + derived_from: tosca.policies.Scaling + description: Defines policy for scaling the given targets. + properties: + increment: + type: integer + required: true + description: Number of nodes to add or remove during the scale out/in. + targets: + type: list + entry_schema: + type: string + required: true + description: List of Scaling nodes. + min_instances: + type: integer + required: true + description: Minimum number of instances to scale in. + max_instances: + type: integer + required: true + description: Maximum number of instances to scale out. + default_instances: + type: integer + required: true + description: Initial number of instances. + cooldown: + type: integer + required: false + default: 120 + description: Wait time (in seconds) between consecutive scaling operations. During the cooldown period, scaling action will be ignored