Skip to content

Commit

Permalink
Factor Schema out of properties.py for re-use
Browse files Browse the repository at this point in the history
There is currently some function duplication in Heat for schema
validation. There is properties.Schema and a ParamSchema class which
do mostly the same, but each with their own code.
It would be good to have a common implementation for property and
parameter validation with only property or parameter specific code
implemented in sub-classes.
The current Schema class in properties.py cannot be used in
parameters.py due to cyclic import dependencies that would arise.

This patch factors the Schema class and Constraint classes into their
own file which can then be imported by both properties.py and
parameters.py. For property schema specific code, a class
PropertySchema is introduced as derived from the common Schema class.

The code of the Schema and Constraint classes is unchanged except for
absolutely  refactoring work.

In a subsequent patch, I plan to provide the code to base ParamSchema
on the common Schema class.

Change-Id: I833edd8fad316220f56d6727fe1e3409f8fda6ee
Partial-Bug: #1230229
  • Loading branch information
Thomas Spatzier committed Dec 2, 2013
1 parent e726c53 commit eae9a2a
Show file tree
Hide file tree
Showing 11 changed files with 802 additions and 643 deletions.
8 changes: 4 additions & 4 deletions doc/source/ext/resources.py
Expand Up @@ -69,12 +69,12 @@ def _section(self, parent, title, id_pattern):
def _prop_syntax_example(self, prop):
if not prop:
return 'Value'
if prop.type == properties.LIST:
if prop.type == properties.Schema.LIST:
schema = lambda i: prop.schema[i] if prop.schema else None
sub_type = [self._prop_syntax_example(schema(i))
for i in range(2)]
return '[%s, %s, ...]' % tuple(sub_type)
elif prop.type == properties.MAP:
elif prop.type == properties.Schema.MAP:
def sub_props():
for sub_key, sub_value in prop.schema.items():
if sub_value.implemented:
Expand Down Expand Up @@ -193,12 +193,12 @@ def contribute_property(self, prop_list, prop_key, prop):
definition.append(para)

sub_schema = None
if prop.schema and prop.type == properties.MAP:
if prop.schema and prop.type == properties.Schema.MAP:
para = nodes.emphasis('', _('Map properties:'))
definition.append(para)
sub_schema = prop.schema

elif prop.schema and prop.type == properties.LIST:
elif prop.schema and prop.type == properties.Schema.LIST:
para = nodes.emphasis(
'', _('List contents:'))
definition.append(para)
Expand Down

0 comments on commit eae9a2a

Please sign in to comment.