Imported templates are not fully validated

Validated First level sections of imported templates,First level
sub-sections of relationship_types and added testcases for the same

Change-Id: I21e8deffa5b3013624bfac62cddc491ebd135b14
Partially-Implements: #1516177
This commit is contained in:
Santhosh64 2016-07-04 14:30:48 +05:30
parent 3743a40b89
commit 8fb4f7d8e1
4 changed files with 31 additions and 0 deletions

View File

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

View File

@ -32,3 +32,7 @@ policy_types:
type: map
entry_schema:
type: string
relationship_types1:
relationship_types:
test.relation.connects:
derived_from4: tosca.relationships.ConnectsTo

View File

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

View File

@ -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_inputs(self):
tpl_snippet = '''