diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 6e2a4099bc..074364c287 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.py @@ -259,34 +259,6 @@ class Attributes(collections.Mapping): '\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): """Select an element from an attribute value. diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 46849cec74..d58343d425 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -197,18 +197,6 @@ class Resource(status.ResourceStatus): LOG.info(six.text_type(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 _validate_name(res_name): @@ -227,7 +215,10 @@ class Resource(status.ResourceStatus): self._update_allowed_properties = self.calc_update_allowed( self.properties) 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 diff --git a/heat/tests/common.py b/heat/tests/common.py index 16d9a41ed6..5642d98beb 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -189,8 +189,6 @@ class HeatTestCase(testscenarios.WithScenarios, generic_rsrc.StackResourceType) resource._register_class('ResourceWithRestoreType', generic_rsrc.ResourceWithRestoreType) - resource._register_class('DynamicSchemaResource', - generic_rsrc.DynamicSchemaResource) resource._register_class('ResourceTypeUnSupportedLiberty', generic_rsrc.ResourceTypeUnSupportedLiberty) resource._register_class('ResourceTypeSupportedKilo', diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index b7b87e8852..5e1d728deb 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -379,30 +379,6 @@ class ResourceWithRestoreType(ResWithComplexPropsAndAttrs): 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): support_status = support.SupportStatus( version='5.0.0', diff --git a/heat/tests/openstack/neutron/test_neutron.py b/heat/tests/openstack/neutron/test_neutron.py index 9b46d1de74..6fc7bd4ad4 100644 --- a/heat/tests/openstack/neutron/test_neutron.py +++ b/heat/tests/openstack/neutron/test_neutron.py @@ -98,7 +98,9 @@ class NeutronTest(common.HeatTestCase): res = self._get_some_neutron_resource() res.attributes_schema.update( {'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'}, {'attr1': 'val1', 'attr2': 'val2'}, {'attr1': 'val1', 'attr2': 'val2'}, diff --git a/heat/tests/test_attributes.py b/heat/tests/test_attributes.py index 49ce6de1a3..5393ec1985 100644 --- a/heat/tests/test_attributes.py +++ b/heat/tests/test_attributes.py @@ -16,13 +16,8 @@ import six from heat.engine import attributes 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 template from heat.tests import common -from heat.tests import generic_resource -from heat.tests import utils class AttributeSchemaTest(common.HeatTestCase): @@ -298,25 +293,3 @@ class AttributesTypeTest(common.HeatTestCase): self.assertNotIn(msg, self.LOG.output) attribs._validate_type(attr, self.invalid_value) 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")