Merge "ETSI-NFV SOL 001 translation: BlockStorage"

This commit is contained in:
Zuul 2020-01-28 20:03:25 +00:00 committed by Gerrit Code Review
commit a299c09d7a
5 changed files with 105 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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: {}

View File

@ -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={})

View File

@ -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'
]