From 59c61d71eb6534dddc4b4f83ba75d14bdd8b6e6a Mon Sep 17 00:00:00 2001 From: Hiroo Kitamura Date: Tue, 26 Nov 2019 16:34:51 +0900 Subject: [PATCH] ETSI-NFV SOL 001 translation: BlockStorage Currently heat-translator supports translation of TOSCA Simple Profile for YAML[1] and TOSCA Simple Profile for NFV[2] only. This commit enables to translation of the follwoing type defined in ETSI NFV-SOL 001[3]. - tosca.nodes.nfv.Vdu.VirtualBlockStorage [1] http://docs.oasis-open.org/tosca/tosca-nfv/v1.0/tosca-nfv-v1.0.html [2] http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.0/TOSCA-Simple-Profile-YAML-v1.0.html [3] https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/001/02.06.01_60/gs_NFV-SOL001v020601p.pdf Change-Id: I026a06de41ed390967e9ef137fa633ecd4fe747f Story: 2006372 Task: 37621 --- .../tosca_nfv_vdu_virtualblockstorage.py | 52 +++++++++++++++++++ .../data/etsi_nfv/tosca_nfv_blockstorage.yaml | 32 ++++++++++++ .../etsi_nfv/hot_nfv_blockstorage.yaml | 11 ++++ .../tests/test_etsi_tosca_hot_translation.py | 9 ++++ .../tests/test_translate_node_template.py | 2 +- 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 translator/hot/tosca/etsi_nfv/tosca_nfv_vdu_virtualblockstorage.py create mode 100644 translator/tests/data/etsi_nfv/tosca_nfv_blockstorage.yaml create mode 100644 translator/tests/data/hot_output/etsi_nfv/hot_nfv_blockstorage.yaml diff --git a/translator/hot/tosca/etsi_nfv/tosca_nfv_vdu_virtualblockstorage.py b/translator/hot/tosca/etsi_nfv/tosca_nfv_vdu_virtualblockstorage.py new file mode 100644 index 00000000..0a6c1264 --- /dev/null +++ b/translator/hot/tosca/etsi_nfv/tosca_nfv_vdu_virtualblockstorage.py @@ -0,0 +1,52 @@ +# +# 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. + +from translator.common.utils import MemoryUnit +from translator.hot.syntax.hot_resource import HotResource + + +# Name used to dynamically load appropriate map class. +TARGET_CLASS_NAME = 'ToscaNfvVduVirtualBlockStorage' + + +class ToscaNfvVduVirtualBlockStorage(HotResource): + """Translate TOSCA node type tosca.nodes.nfv.Vdu.VirtualBlockStorage.""" + + toscatype = 'tosca.nodes.nfv.Vdu.VirtualBlockStorage' + IMAGE = '#ADD_YOUR_IMAGE_HERE' + + def __init__(self, nodetemplate, csar_dir=None): + super(ToscaNfvVduVirtualBlockStorage, self).__init__( + nodetemplate, + type='OS::Cinder::Volume', + csar_dir=csar_dir) + + def handle_properties(self): + tosca_props = self.get_tosca_props() + own_props = {} + + for key, value in tosca_props.items(): + # This image's value is replaced after translation. + if key == 'sw_image_data': + # Users have to add an image ID or name because heat deprecated + # creating an image from a local file. + own_props['image'] = '%s' % ( + self.IMAGE + ) + elif key == 'virtual_block_storage_data': + # Convert to GiB + own_props['size'] = \ + MemoryUnit.convert_unit_size_to_num( + value['size_of_storage'], 'GiB') + + self.properties = own_props diff --git a/translator/tests/data/etsi_nfv/tosca_nfv_blockstorage.yaml b/translator/tests/data/etsi_nfv/tosca_nfv_blockstorage.yaml new file mode 100644 index 00000000..d2a52ee5 --- /dev/null +++ b/translator/tests/data/etsi_nfv/tosca_nfv_blockstorage.yaml @@ -0,0 +1,32 @@ +tosca_definitions_version: tosca_simple_yaml_1_2 + +description: > + Template for deploying one VirtualStorage. + +imports: + - etsi_nfv_sol001_common_types.yaml + - etsi_nfv_sol001_vnfd_types.yaml + +topology_template: + node_templates: + VirtualStorage: + type: tosca.nodes.nfv.Vdu.VirtualBlockStorage + properties: + virtual_block_storage_data: + size_of_storage: 30 GiB + rdma_enabled: true + sw_image_data: + name: VrtualStorage + version: '0.4.0' + checksum: + algorithm: sha-256 + hash: b9c3036539fd7a5f87a1bf38eb05fdde8b556a1a7e664dbeda90ed3cd74b4f9d + container_format: bare + disk_format: qcow2 + min_disk: 2 GiB + min_ram: 8192 MiB + size: 2 GiB + artifacts: + sw_image: + type: tosca.artifacts.nfv.SwImage + file: cirros-0.4.0-x86_64-disk.qcow2 diff --git a/translator/tests/data/hot_output/etsi_nfv/hot_nfv_blockstorage.yaml b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_blockstorage.yaml new file mode 100644 index 00000000..66daf2fd --- /dev/null +++ b/translator/tests/data/hot_output/etsi_nfv/hot_nfv_blockstorage.yaml @@ -0,0 +1,11 @@ +heat_template_version: 2013-05-23 +description: > + Template for deploying one VirtualStorage. +parameters: {} +resources: + VirtualStorage: + type: OS::Cinder::Volume + properties: + size: 30 + image: #ADD_YOUR_IMAGE_HERE +outputs: {} diff --git a/translator/tests/test_etsi_tosca_hot_translation.py b/translator/tests/test_etsi_tosca_hot_translation.py index 81134613..a110e9a2 100644 --- a/translator/tests/test_etsi_tosca_hot_translation.py +++ b/translator/tests/test_etsi_tosca_hot_translation.py @@ -191,3 +191,12 @@ class EtsiToscaHotTranslationTest(TestCase): expected_msg, self.log_fixture.output ) + + def test_hot_translate_etsi_nfv_blockstorage(self): + tosca_file = '../tests/data/etsi_nfv/' \ + 'tosca_nfv_blockstorage.yaml' + hot_files = [ + '../tests/data/hot_output/etsi_nfv/' + 'hot_nfv_blockstorage.yaml', + ] + self._test_successful_translation(tosca_file, hot_files, params={}) diff --git a/translator/tests/test_translate_node_template.py b/translator/tests/test_translate_node_template.py index 42f68ea7..7bddb08b 100644 --- a/translator/tests/test_translate_node_template.py +++ b/translator/tests/test_translate_node_template.py @@ -17,7 +17,6 @@ from translator.tests.base import TestCase class TranslateNodeTemplatesTest(TestCase): def test_generate_type_map(self): - expected_type_list = [ 'tosca.nodes.BlockStorage', 'tosca.nodes.Compute', @@ -37,6 +36,7 @@ class TranslateNodeTemplatesTest(TestCase): 'tosca.policies.Scaling.Cluster', 'tosca.nodes.nfv.VNF', 'tosca.nodes.nfv.Vdu.Compute', + 'tosca.nodes.nfv.Vdu.VirtualBlockStorage', 'tosca.nodes.nfv.VduCp', 'tosca.nodes.nfv.VnfVirtualLink' ]