Revert "Support attributes with dynamic scheme"

This code was never used for anything, as the rest of the patch series
never landed and was abandoned.

This reverts commit 15e52ff5e9.

Change-Id: I7d1a22753e8de1d3adf127c14516ebd667513bfa
This commit is contained in:
Zane Bitter 2017-06-21 16:38:40 +00:00
parent 608b35eaef
commit dc957bc2a6
6 changed files with 7 additions and 95 deletions

View File

@ -259,34 +259,6 @@ class Attributes(collections.Mapping):
'\n\t'.join(six.itervalues(self))) '\n\t'.join(six.itervalues(self)))
class DynamicSchemeAttributes(Attributes):
"""The collection of attributes for resources without static attr scheme.
The class defines collection of attributes for such entities as Resource
Group, Software Deployment and so on that doesn't have static attribute
scheme. The attribute scheme for such kind of resources can contain
attribute from attribute scheme (like other resources) and dynamic
attributes (nested stack attrs or API response attrs).
"""
def __getitem__(self, key):
try:
# check if the value can be resolved with attributes
# in attributes schema (static attributes)
return super(DynamicSchemeAttributes, self).__getitem__(key)
except KeyError:
# ok, the attribute is not present in attribute scheme
# try to check the attributes dynamically
if key in self._resolved_values:
return self._resolved_values[key]
value = self._resolver(key)
if value is not None:
self._resolved_values[key] = value
return value
def select_from_attribute(attribute_value, path): def select_from_attribute(attribute_value, path):
"""Select an element from an attribute value. """Select an element from an attribute value.

View File

@ -197,18 +197,6 @@ class Resource(status.ResourceStatus):
LOG.info(six.text_type(ex)) LOG.info(six.text_type(ex))
raise ex raise ex
def _init_attributes(self):
"""The method that defines attribute initialization for a resource.
Some resource requires different initialization of resource attributes.
So they must override this method and return the initialized
attributes to the resource.
:return: resource attributes
"""
return attributes.Attributes(self.name,
self.attributes_schema,
self._make_resolver(weakref.ref(self)))
def __init__(self, name, definition, stack): def __init__(self, name, definition, stack):
def _validate_name(res_name): def _validate_name(res_name):
@ -227,7 +215,10 @@ class Resource(status.ResourceStatus):
self._update_allowed_properties = self.calc_update_allowed( self._update_allowed_properties = self.calc_update_allowed(
self.properties) self.properties)
self.attributes_schema.update(self.base_attributes_schema) self.attributes_schema.update(self.base_attributes_schema)
self.attributes = self._init_attributes() self.attributes = attributes.Attributes(self.name,
self.attributes_schema,
self._make_resolver(
weakref.ref(self)))
self.abandon_in_progress = False self.abandon_in_progress = False

View File

@ -189,8 +189,6 @@ class HeatTestCase(testscenarios.WithScenarios,
generic_rsrc.StackResourceType) generic_rsrc.StackResourceType)
resource._register_class('ResourceWithRestoreType', resource._register_class('ResourceWithRestoreType',
generic_rsrc.ResourceWithRestoreType) generic_rsrc.ResourceWithRestoreType)
resource._register_class('DynamicSchemaResource',
generic_rsrc.DynamicSchemaResource)
resource._register_class('ResourceTypeUnSupportedLiberty', resource._register_class('ResourceTypeUnSupportedLiberty',
generic_rsrc.ResourceTypeUnSupportedLiberty) generic_rsrc.ResourceTypeUnSupportedLiberty)
resource._register_class('ResourceTypeSupportedKilo', resource._register_class('ResourceTypeSupportedKilo',

View File

@ -379,30 +379,6 @@ class ResourceWithRestoreType(ResWithComplexPropsAndAttrs):
return defn.freeze(properties=props) return defn.freeze(properties=props)
class DynamicSchemaResource(resource.Resource):
"""Resource with an attribute not registered in the attribute schema."""
properties_schema = {}
attributes_schema = {
'stat_attr': attributes.Schema('A generic static attribute',
type=attributes.Schema.STRING),
}
def _init_attributes(self):
# software deployment scheme is not static
# so return dynamic attributes for it
return attributes.DynamicSchemeAttributes(
self.name, self.attributes_schema, self._resolve_attribute)
def _resolve_attribute(self, name):
if name == 'stat_attr':
return "static_attribute"
elif name == 'dynamic_attr':
return "dynamic_attribute"
else:
raise KeyError()
class ResourceTypeUnSupportedLiberty(GenericResource): class ResourceTypeUnSupportedLiberty(GenericResource):
support_status = support.SupportStatus( support_status = support.SupportStatus(
version='5.0.0', version='5.0.0',

View File

@ -98,7 +98,9 @@ class NeutronTest(common.HeatTestCase):
res = self._get_some_neutron_resource() res = self._get_some_neutron_resource()
res.attributes_schema.update( res.attributes_schema.update(
{'attr2': attributes.Schema(type=attributes.Schema.STRING)}) {'attr2': attributes.Schema(type=attributes.Schema.STRING)})
res.attributes = res._init_attributes() res.attributes = attributes.Attributes(res.name,
res.attributes_schema,
res._resolve_all_attributes)
side_effect = [{'attr1': 'val1', 'attr2': 'val2'}, side_effect = [{'attr1': 'val1', 'attr2': 'val2'},
{'attr1': 'val1', 'attr2': 'val2'}, {'attr1': 'val1', 'attr2': 'val2'},
{'attr1': 'val1', 'attr2': 'val2'}, {'attr1': 'val1', 'attr2': 'val2'},

View File

@ -16,13 +16,8 @@ import six
from heat.engine import attributes from heat.engine import attributes
from heat.engine import resources from heat.engine import resources
from heat.engine import rsrc_defn
from heat.engine import stack
from heat.engine import support from heat.engine import support
from heat.engine import template
from heat.tests import common from heat.tests import common
from heat.tests import generic_resource
from heat.tests import utils
class AttributeSchemaTest(common.HeatTestCase): class AttributeSchemaTest(common.HeatTestCase):
@ -298,25 +293,3 @@ class AttributesTypeTest(common.HeatTestCase):
self.assertNotIn(msg, self.LOG.output) self.assertNotIn(msg, self.LOG.output)
attribs._validate_type(attr, self.invalid_value) attribs._validate_type(attr, self.invalid_value)
self.assertIn(msg, self.LOG.output) self.assertIn(msg, self.LOG.output)
class DynamicSchemeAttributeTest(common.HeatTestCase):
def setUp(self):
super(DynamicSchemeAttributeTest, self).setUp()
test_stack = stack.Stack(
utils.dummy_context(), 'test_stack',
template.Template.create_empty_template())
snippet = rsrc_defn.ResourceDefinition('test_resource',
'DynamicSchemaResource')
test_res = generic_resource.DynamicSchemaResource(
'aresource', snippet, test_stack)
self.attrs = test_res.attributes
def test_get_static_attribute(self):
self.assertEqual("static_attribute", self.attrs["stat_attr"])
def test_get_dynamic_attribute(self):
self.assertEqual("dynamic_attribute", self.attrs["dynamic_attr"])
def test_get_non_existing_attribute(self):
self.assertRaises(KeyError, self.attrs.__getitem__, "non_existing")