Merge "Imported templates are not fully validated"
This commit is contained in:
commit
cdf530fd19
@ -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))
|
||||
|
@ -32,3 +32,7 @@ policy_types:
|
||||
type: map
|
||||
entry_schema:
|
||||
type: string
|
||||
relationship_types1:
|
||||
relationship_types:
|
||||
test.relation.connects:
|
||||
derived_from4: tosca.relationships.ConnectsTo
|
||||
|
@ -37,3 +37,9 @@ topology_template:
|
||||
metadata:
|
||||
user1: 1001
|
||||
user2: 1003
|
||||
relationship_templates:
|
||||
my_custom_rel:
|
||||
type: test.relation.connects
|
||||
interfaces:
|
||||
Configure:
|
||||
pre_configure_source: scripts/wp_db_configure.sh
|
||||
|
@ -97,6 +97,11 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
_('Policy "mycompany.mytypes.myScalingPolicy" contains unknown '
|
||||
'field "derived1_from". Refer to the definition to '
|
||||
'verify valid values.'))
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError,
|
||||
_('Relationshiptype "test.relation.connects" contains unknown '
|
||||
'field "derived_from4". Refer to the definition to '
|
||||
'verify valid values.'))
|
||||
|
||||
def test_unsupported_type(self):
|
||||
tpl_snippet = '''
|
||||
|
Loading…
x
Reference in New Issue
Block a user