Add full path for Property

Add full path field for Property class. Now
properties with sub-schemas should contain properties
with path, where their parent specified. For example,
if there is schema:
        "a": type map:
               schema:
                 "b": type string,
                 "c": type string

Then property "a" has path == 'a', "b" has path == 'a.b',
"c" has path == 'a.c'.

Change-Id: I6d0ba022f34b925d47142669d6076ebd63a2acdc
Related-bug: #1620859
changes/15/420015/5
Peter Razumovsky 6 years ago
parent bf8e3fd7ea
commit 74a7c8c38a

@ -213,10 +213,11 @@ def schemata(schema_dicts):
class Property(object):
def __init__(self, schema, name=None, context=None):
def __init__(self, schema, name=None, context=None, path=None):
self.schema = Schema.from_legacy(schema)
self.name = name
self.context = context
self.path = self.make_path(name, path)
def required(self):
return self.schema.required
@ -242,6 +243,18 @@ class Property(object):
def support_status(self):
return self.schema.support_status
def make_path(self, name, path=None):
if path is None:
path = ''
if name is None:
name = ''
if isinstance(name, int) or name.isdigit():
name = str(name)
delim = '' if not path or path.endswith('.') else '.'
return delim.join([path, name])
def _get_integer(self, value):
if value is None:
value = self.has_default() and self.default() or 0
@ -274,7 +287,7 @@ class Property(object):
schemata = dict((k, self.schema.schema[k]) for k in keys)
properties = Properties(schemata, dict(child_values),
context=self.context,
parent_name=self.name)
parent_name=self.path)
if validate:
properties.validate()
@ -361,7 +374,7 @@ class Properties(collections.Mapping):
def __init__(self, schema, data, resolver=lambda d: d, parent_name=None,
context=None, section=None):
self.props = dict((k, Property(s, k, context))
self.props = dict((k, Property(s, k, context, path=parent_name))
for k, s in schema.items())
self.resolve = resolver
self.data = data

@ -914,6 +914,14 @@ class PropertyTest(common.HeatTestCase):
self.assertEqual(['foo', 'bar'], p.get_value('foo,bar'))
self.assertEqual(['foo'], p.get_value('foo'))
def test_map_path(self):
p = properties.Property({'Type': 'Map'}, name='test', path='parent')
self.assertEqual('parent.test', p.path)
def test_list_path(self):
p = properties.Property({'Type': 'List'}, name='0', path='parent')
self.assertEqual('parent.0', p.path)
def test_list_maxlength_good(self):
schema = {'Type': 'List',
'MaxLength': '3'}

Loading…
Cancel
Save