Merge "Use base attributes with attribute_schema of class"
This commit is contained in:
commit
8ef708b8d0
|
@ -157,7 +157,8 @@ class Attributes(collections.Mapping):
|
|||
:returns: The attributes of the specified resource_class as a template
|
||||
Output map
|
||||
"""
|
||||
schema = resource_class.attributes_schema
|
||||
schema = resource_class.attributes_schema.copy()
|
||||
schema.update(resource_class.base_attributes_schema)
|
||||
attribs = Attributes._make_attributes(schema).items()
|
||||
|
||||
return dict((n, att.as_output(resource_name,
|
||||
|
|
|
@ -230,7 +230,9 @@ class TemplateResource(stack_resource.StackResource):
|
|||
'n': n, 'type': self.type()})
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
for attr in facade_cls.attributes_schema:
|
||||
facade_attrs = facade_cls.attributes_schema.copy()
|
||||
facade_attrs.update(facade_cls.base_attributes_schema)
|
||||
for attr in facade_attrs:
|
||||
if attr not in self.attributes_schema:
|
||||
msg = (_("Attribute %(attr)s for facade %(type)s "
|
||||
"missing in provider") % {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
import collections
|
||||
import datetime
|
||||
import itertools
|
||||
import os
|
||||
import socket
|
||||
import warnings
|
||||
|
@ -1080,7 +1081,9 @@ class EngineService(service.Service):
|
|||
yield name, dict(schema)
|
||||
|
||||
def attributes_schema():
|
||||
for name, schema_data in resource_class.attributes_schema.items():
|
||||
for name, schema_data in itertools.chain(
|
||||
resource_class.attributes_schema.items(),
|
||||
resource_class.base_attributes_schema.items()):
|
||||
schema = attributes.Schema.from_attribute(schema_data)
|
||||
yield name, dict(schema)
|
||||
|
||||
|
|
|
@ -138,6 +138,9 @@ class HeatTestCase(testscenarios.WithScenarios,
|
|||
generic_rsrc.ResourceWithAttributeType)
|
||||
resource._register_class('ResourceWithRequiredProps',
|
||||
generic_rsrc.ResourceWithRequiredProps)
|
||||
resource._register_class(
|
||||
'ResourceWithRequiredPropsAndEmptyAttrs',
|
||||
generic_rsrc.ResourceWithRequiredPropsAndEmptyAttrs)
|
||||
resource._register_class('ResourceWithPropsAndAttrs',
|
||||
generic_rsrc.ResourceWithPropsAndAttrs)
|
||||
resource._register_class('ResWithComplexPropsAndAttrs',
|
||||
|
|
|
@ -143,6 +143,12 @@ class ResourceWithRequiredProps(GenericResource):
|
|||
required=True)}
|
||||
|
||||
|
||||
class ResourceWithRequiredPropsAndEmptyAttrs(GenericResource):
|
||||
properties_schema = {'Foo': properties.Schema(properties.Schema.STRING,
|
||||
required=True)}
|
||||
attributes_schema = {}
|
||||
|
||||
|
||||
class SignalResource(signal_responder.SignalResponder):
|
||||
properties_schema = {
|
||||
'signal_transport': properties.Schema(properties.Schema.STRING,
|
||||
|
|
|
@ -2218,6 +2218,9 @@ class StackServiceTest(common.HeatTestCase):
|
|||
'type': 'string'},
|
||||
'attr2': {'description': 'Another generic attribute',
|
||||
'type': 'map'},
|
||||
'show': {
|
||||
'description': 'Dictionary with resource attributes.',
|
||||
'type': 'map'},
|
||||
},
|
||||
'support_status': {
|
||||
'status': 'SUPPORTED',
|
||||
|
|
|
@ -109,9 +109,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
|
||||
properties_schema = {
|
||||
"Foo": {"Type": "String"},
|
||||
|
@ -198,9 +196,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {}
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
|
||||
|
||||
env = environment.Environment()
|
||||
|
@ -227,9 +223,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {}
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
|
||||
|
||||
env = environment.Environment()
|
||||
|
@ -284,7 +278,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {}
|
||||
attributes_schema = {"Foo": attributes.Schema(
|
||||
|
@ -322,25 +316,19 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.STRING,
|
||||
required=True)}
|
||||
attributes_schema = {}
|
||||
|
||||
env = environment.Environment()
|
||||
resource._register_class('DummyResource', DummyResource)
|
||||
env.load({'resource_registry':
|
||||
{'DummyResource': 'test_resource.template'}})
|
||||
{'ResourceWithRequiredPropsAndEmptyAttrs':
|
||||
'test_resource.template'}})
|
||||
stack = parser.Stack(utils.dummy_context(), 'test_stack',
|
||||
template.Template(empty_template, files=files,
|
||||
env=env),
|
||||
stack_id=str(uuid.uuid4()))
|
||||
|
||||
definition = rsrc_defn.ResourceDefinition('test_t_res',
|
||||
"DummyResource",
|
||||
{"Foo": "bar"})
|
||||
definition = rsrc_defn.ResourceDefinition(
|
||||
'test_t_res',
|
||||
"ResourceWithRequiredPropsAndEmptyAttrs",
|
||||
{"Foo": "bar"})
|
||||
temp_res = template_resource.TemplateResource('test_t_res',
|
||||
definition, stack)
|
||||
self.assertIsNone(temp_res.validate())
|
||||
|
@ -354,24 +342,18 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.STRING,
|
||||
required=True)}
|
||||
attributes_schema = {}
|
||||
|
||||
env = environment.Environment()
|
||||
resource._register_class('DummyResource', DummyResource)
|
||||
env.load({'resource_registry':
|
||||
{'DummyResource': 'test_resource.template'}})
|
||||
{'ResourceWithRequiredPropsAndEmptyAttrs':
|
||||
'test_resource.template'}})
|
||||
stack = parser.Stack(utils.dummy_context(), 'test_stack',
|
||||
template.Template(empty_template, files=files,
|
||||
env=env),
|
||||
stack_id=str(uuid.uuid4()))
|
||||
|
||||
definition = rsrc_defn.ResourceDefinition('test_t_res',
|
||||
"DummyResource")
|
||||
definition = rsrc_defn.ResourceDefinition(
|
||||
'test_t_res',
|
||||
"ResourceWithRequiredPropsAndEmptyAttrs")
|
||||
temp_res = template_resource.TemplateResource('test_t_res',
|
||||
definition, stack)
|
||||
self.assertRaises(exception.StackValidationFailed,
|
||||
|
@ -417,7 +399,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.MAP)}
|
||||
|
@ -453,7 +435,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Length":
|
||||
properties.Schema(properties.Schema.INTEGER)}
|
||||
|
@ -485,7 +467,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
}
|
||||
files = {'test_resource.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.BOOLEAN)}
|
||||
|
@ -518,8 +500,7 @@ class ProviderTemplateTest(common.HeatTestCase):
|
|||
files = {'test_resource.template': json.dumps(provider),
|
||||
'foo.template': json.dumps(provider)}
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
class DummyResource(generic_rsrc.GenericResource):
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.BOOLEAN)}
|
||||
attributes_schema = {}
|
||||
|
@ -882,17 +863,10 @@ class TemplateDataTest(common.HeatTestCase):
|
|||
files = {}
|
||||
self.ctx = utils.dummy_context()
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.STRING,
|
||||
required=True)}
|
||||
attributes_schema = {}
|
||||
|
||||
env = environment.Environment()
|
||||
resource._register_class('DummyResource', DummyResource)
|
||||
env.load({'resource_registry':
|
||||
{'DummyResource': 'test_resource.template'}})
|
||||
{'ResourceWithRequiredPropsAndEmptyAttrs':
|
||||
'test_resource.template'}})
|
||||
|
||||
self.stack = parser.Stack(self.ctx, 'test_stack',
|
||||
template.Template(empty_template,
|
||||
|
@ -900,9 +874,10 @@ class TemplateDataTest(common.HeatTestCase):
|
|||
env=env),
|
||||
stack_id=str(uuid.uuid4()))
|
||||
|
||||
self.defn = rsrc_defn.ResourceDefinition('test_t_res',
|
||||
"DummyResource",
|
||||
{"Foo": "bar"})
|
||||
self.defn = rsrc_defn.ResourceDefinition(
|
||||
'test_t_res',
|
||||
"ResourceWithRequiredPropsAndEmptyAttrs",
|
||||
{"Foo": "bar"})
|
||||
self.res = template_resource.TemplateResource('test_t_res',
|
||||
self.defn, self.stack)
|
||||
|
||||
|
@ -937,26 +912,20 @@ class TemplateResourceCrudTest(common.HeatTestCase):
|
|||
files = {'test_resource.template': json.dumps(self.provider)}
|
||||
self.ctx = utils.dummy_context()
|
||||
|
||||
class DummyResource(object):
|
||||
support_status = support.SupportStatus()
|
||||
properties_schema = {"Foo":
|
||||
properties.Schema(properties.Schema.STRING,
|
||||
required=True)}
|
||||
attributes_schema = {}
|
||||
|
||||
env = environment.Environment()
|
||||
resource._register_class('DummyResource', DummyResource)
|
||||
env.load({'resource_registry':
|
||||
{'DummyResource': 'test_resource.template'}})
|
||||
{'ResourceWithRequiredPropsAndEmptyAttrs':
|
||||
'test_resource.template'}})
|
||||
self.stack = parser.Stack(self.ctx, 'test_stack',
|
||||
template.Template(empty_template,
|
||||
files=files,
|
||||
env=env),
|
||||
stack_id=str(uuid.uuid4()))
|
||||
|
||||
self.defn = rsrc_defn.ResourceDefinition('test_t_res',
|
||||
"DummyResource",
|
||||
{"Foo": "bar"})
|
||||
self.defn = rsrc_defn.ResourceDefinition(
|
||||
'test_t_res',
|
||||
"ResourceWithRequiredPropsAndEmptyAttrs",
|
||||
{"Foo": "bar"})
|
||||
self.res = template_resource.TemplateResource('test_t_res',
|
||||
self.defn, self.stack)
|
||||
self.assertIsNone(self.res.validate())
|
||||
|
|
|
@ -1153,6 +1153,10 @@ class ResourceTest(common.HeatTestCase):
|
|||
'output2': {
|
||||
'Description': 'output2_desc',
|
||||
'Value': '{"Fn::GetAtt": ["TestResource", "output2"]}'
|
||||
},
|
||||
'show': {
|
||||
'Description': u'Dictionary with resource attributes.',
|
||||
'Value': '{"Fn::GetAtt": ["TestResource", "show"]}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1232,6 +1236,10 @@ class ResourceTest(common.HeatTestCase):
|
|||
'output2': {
|
||||
'description': 'output2_desc',
|
||||
'value': '{"get_attr": ["TestResource", "output2"]}'
|
||||
},
|
||||
'show': {
|
||||
'description': u'Dictionary with resource attributes.',
|
||||
'value': '{"get_attr": ["TestResource", "show"]}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue