Adding custom datatypes support in properties of capabilities

Currently if there is costum datatype definition in capability, the
parser will be error, the patch support custom datatype definition
in property for capability.

Change-Id: Ic899fd125840f817b06b05aacf0829aa2d82ffa0
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
This commit is contained in:
shangxdy 2017-08-10 21:26:10 +08:00
parent 3f5476e442
commit 2394b580ca
5 changed files with 57 additions and 3 deletions

View File

@ -16,10 +16,11 @@ from toscaparser.properties import Property
class Capability(object): class Capability(object):
'''TOSCA built-in capabilities type.''' '''TOSCA built-in capabilities type.'''
def __init__(self, name, properties, definition): def __init__(self, name, properties, definition, custom_def=None):
self.name = name self.name = name
self._properties = properties self._properties = properties
self.definition = definition self.definition = definition
self.custom_def = custom_def
def get_properties_objects(self): def get_properties_objects(self):
'''Return a list of property objects.''' '''Return a list of property objects.'''
@ -30,7 +31,8 @@ class Capability(object):
props_def = self.definition.get_properties_def() props_def = self.definition.get_properties_def()
if props_def and name in props_def: if props_def and name in props_def:
properties.append(Property(name, value, properties.append(Property(name, value,
props_def[name].schema)) props_def[name].schema,
self.custom_def))
return properties return properties
def get_properties(self): def get_properties(self):

View File

@ -164,7 +164,7 @@ class EntityTemplate(object):
if 'properties' in props and props['properties']: if 'properties' in props and props['properties']:
properties.update(props['properties']) properties.update(props['properties'])
cap = Capability(name, properties, c) cap = Capability(name, properties, c, self.custom_def)
capability.append(cap) capability.append(cap)
return capability return capability

View File

@ -0,0 +1,27 @@
tosca_definitions_version: tosca_simple_yaml_1_0
node_types:
tosca.nodes.SomeNode:
derived_from: tosca.nodes.Root
capabilities:
cap1:
type: tosca.capabilities.SomeCap
capability_types:
tosca.capabilities.SomeCap:
derived_from: tosca.capabilities.Root
properties:
data:
type: tosca.datatypes.SomeData
data_types:
tosca.datatypes.SomeData:
derived_from: tosca.datatypes.Root
properties:
name:
type: string
required: true
value:
type: integer
required: false
default: 100

View File

@ -0,0 +1,19 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: TOSCA simple profile to test a custom defined capability with custom datatype
imports:
- custom_types/custom_cap_with_datatype.yaml
topology_template:
node_templates:
TestNode:
type: tosca.nodes.SomeNode
capabilities:
cap1:
properties:
data:
name: test
value: 1

View File

@ -779,6 +779,12 @@ class ToscaTemplateTest(TestCase):
"data/test_custom_caps_def.yaml") "data/test_custom_caps_def.yaml")
ToscaTemplate(tosca_tpl) ToscaTemplate(tosca_tpl)
def test_custom_caps_with_custom_datatype(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/test_custom_caps_with_datatype.yaml")
ToscaTemplate(tosca_tpl)
def test_custom_rel_with_script(self): def test_custom_rel_with_script(self):
tosca_tpl = os.path.join( tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),