Added Support for Unsupported Types

Checks for the unsupported type in the template.
Raises an error if a type is a valid TOSCA type but
mappting to HOT is not yet provided in the translator.

Co-Authored-By: Sahdev Zala <spzala@us.ibm.com>

Change-Id: If6e821b1b2db4f01dd302ff068f3d4f0b73661b2
Partially-Implements: blueprint unsupported-type-validation
This commit is contained in:
Nandini 2016-07-15 16:21:40 +05:30 committed by Sahdev Zala
parent 537fd33902
commit 13adc548fa
4 changed files with 40 additions and 0 deletions

View File

@ -43,6 +43,11 @@ class ToscaClassImportError(TOSCAException):
'exists and has no language definition errors.') 'exists and has no language definition errors.')
class UnsupportedTypeError(TOSCAException):
msg_fmt = _('Type "%(type)s" is valid TOSCA type but translation '
'support is not yet available.')
class ToscaClassAttributeError(TOSCAException): class ToscaClassAttributeError(TOSCAException):
msg_fmt = _('Class attribute referenced not found. ' msg_fmt = _('Class attribute referenced not found. '
'%(message)s. Check to see that it is defined.') '%(message)s. Check to see that it is defined.')

View File

@ -27,6 +27,7 @@ from toscaparser.utils.gettextutils import _
from translator.common.exception import ToscaClassAttributeError from translator.common.exception import ToscaClassAttributeError
from translator.common.exception import ToscaClassImportError from translator.common.exception import ToscaClassImportError
from translator.common.exception import ToscaModImportError from translator.common.exception import ToscaModImportError
from translator.common.exception import UnsupportedTypeError
from translator.common import utils from translator.common import utils
from translator.conf.config import ConfigProvider as translatorConfig from translator.conf.config import ConfigProvider as translatorConfig
from translator.hot.syntax.hot_resource import HotResource from translator.hot.syntax.hot_resource import HotResource
@ -180,6 +181,8 @@ class TranslateNodeTemplates(object):
# Copy the TOSCA graph: nodetemplate # Copy the TOSCA graph: nodetemplate
for node in self.nodetemplates: for node in self.nodetemplates:
base_type = HotResource.get_base_type_str(node.type_definition) base_type = HotResource.get_base_type_str(node.type_definition)
if base_type not in TOSCA_TO_HOT_TYPE:
raise UnsupportedTypeError(type=_('%s') % base_type)
hot_node = TOSCA_TO_HOT_TYPE[base_type](node) hot_node = TOSCA_TO_HOT_TYPE[base_type](node)
self.hot_resources.append(hot_node) self.hot_resources.append(hot_node)
self.hot_lookup[node] = hot_node self.hot_lookup[node] = hot_node
@ -220,6 +223,8 @@ class TranslateNodeTemplates(object):
for policy in self.policies: for policy in self.policies:
policy_type = policy.type_definition policy_type = policy.type_definition
if policy_type.type not in TOSCA_TO_HOT_TYPE:
raise UnsupportedTypeError(type=_('%s') % policy_type.type)
policy_node = TOSCA_TO_HOT_TYPE[policy_type.type](policy) policy_node = TOSCA_TO_HOT_TYPE[policy_type.type](policy)
self.hot_resources.append(policy_node) self.hot_resources.append(policy_node)

View File

@ -0,0 +1,15 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: Template to test unsupported translation. Load Balancer is a
> valid TOSCA type but not supported in translator yet.
topology_template:
node_templates:
simple_load_balancer:
type: tosca.nodes.LoadBalancer
capabilities:
client:
properties:
network_name: PUBLIC
floating: true
dns_name: http://mycompany.com/

View File

@ -16,8 +16,11 @@ import os
from toscaparser.common.exception import ExceptionCollector from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import URLException from toscaparser.common.exception import URLException
from toscaparser.common.exception import ValidationError from toscaparser.common.exception import ValidationError
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.utils.gettextutils import _ from toscaparser.utils.gettextutils import _
from translator.common.exception import UnsupportedTypeError
from translator.common.utils import TranslationUtils from translator.common.utils import TranslationUtils
from translator.hot.tosca_translator import TOSCATranslator
from translator.tests.base import TestCase from translator.tests.base import TestCase
@ -495,3 +498,15 @@ class ToscaHotTranslationTest(TestCase):
hot_file = '../tests/data/hot_output/hot_autoscaling.yaml' hot_file = '../tests/data/hot_output/hot_autoscaling.yaml'
params = {} params = {}
self._test_successful_translation(tosca_file, hot_file, params) self._test_successful_translation(tosca_file, hot_file, params)
def test_translate_unsupported_tosca_type(self):
tosca_file = '../tests/data/test_tosca_unsupported_type.yaml'
tosca_tpl = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), tosca_file))
params = {}
expected_msg = _('Type "tosca.nodes.LoadBalancer" is valid TOSCA '
'type but translation support is not yet available.')
tosca = ToscaTemplate(tosca_tpl, params, True)
err = self.assertRaises(UnsupportedTypeError,
TOSCATranslator(tosca, params).translate)
self.assertEqual(expected_msg, err.__str__())