From 406214e5ca40ad57a1c40e4a8454336f6a26cac2 Mon Sep 17 00:00:00 2001 From: shangxdy Date: Sun, 26 Feb 2017 00:49:42 +0800 Subject: Sync upstream code Sync upstream project of tosca-parser Change-Id: Ic707844203ea05007b3c02e9dcadb52389eb3149 JIRA:PARSER-118 Signed-off-by: shangxdy --- .../toscaparser/elements/relationshiptype.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py') diff --git a/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py index 25440ca..8eefbea 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/relationshiptype.py @@ -10,16 +10,25 @@ # License for the specific language governing permissions and limitations # under the License. +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError from toscaparser.elements.statefulentitytype import StatefulEntityType class RelationshipType(StatefulEntityType): '''TOSCA built-in relationship type.''' + SECTIONS = (DERIVED_FROM, VALID_TARGET_TYPES, INTERFACES, + ATTRIBUTES, PROPERTIES, DESCRIPTION, VERSION, + CREDENTIAL) = ('derived_from', 'valid_target_types', + 'interfaces', 'attributes', 'properties', + 'description', 'version', 'credential') + def __init__(self, type, capability_name=None, custom_def=None): super(RelationshipType, self).__init__(type, self.RELATIONSHIP_PREFIX, custom_def) self.capability_name = capability_name self.custom_def = custom_def + self._validate_keys() @property def parent_type(self): @@ -31,3 +40,10 @@ class RelationshipType(StatefulEntityType): @property def valid_target_types(self): return self.entity_value(self.defs, 'valid_target_types') + + def _validate_keys(self): + for key in self.defs.keys(): + if key not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Relationshiptype "%s"' % self.type, + field=key)) -- cgit 1.2.3-korg