Deprecating the old style attribute Schema

There is last patch to migrate on new attribute Schema.
The main changes are:
 - Deprecation warning was added in from_attribute function.
   If attribute have old format, it will be converted to new schema format
   and Deprecation warning will be raised.
 - Translation to new Schema was added in function schema_from_outputs.
 - All generic resources have been changed and use new Schema class now.
 - Some others tests have been fixed and use new Schema class now.

Change-Id: Icf92f2d275a86a13c656b0e74b725a442db3e532
Closes-Bug: #1307319
This commit is contained in:
Sergey Kraynev 2014-04-22 08:20:01 -04:00
parent 9ba541b9ee
commit be26f4089e
5 changed files with 37 additions and 30 deletions

View File

@ -12,6 +12,7 @@
# under the License.
import collections
import warnings
from heat.engine import constraints as constr
from heat.engine import support
@ -50,9 +51,10 @@ class Schema(constr.Schema):
"""
if isinstance(schema_dict, cls):
return schema_dict
# it's necessary for supporting old attribute schema format,
# where value is not Schema object
return cls(description=schema_dict)
warnings.warn('<name>: <description> schema definition is deprecated. '
'Use <name>: attributes.Schema(<description>) instead.',
DeprecationWarning)
return cls(schema_dict)
def schemata(schema):
@ -123,7 +125,7 @@ class Attributes(collections.Mapping):
@staticmethod
def schema_from_outputs(json_snippet):
if json_snippet:
return dict((k, v.get("Description"))
return dict((k, Schema(v.get("Description")))
for k, v in json_snippet.items())
return {}

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from heat.engine import attributes
from heat.engine import resource
from heat.engine import signal_responder
from heat.engine import stack_user
@ -25,8 +26,8 @@ class GenericResource(resource.Resource):
Dummy resource for use in tests
'''
properties_schema = {}
attributes_schema = {'foo': 'A generic attribute',
'Foo': 'Another generic attribute'}
attributes_schema = {'foo': attributes.Schema('A generic attribute'),
'Foo': attributes.Schema('Another generic attribute')}
def handle_create(self):
logger.warning(_('Creating generic resource (Type "%s")') %
@ -58,9 +59,9 @@ class ResWithComplexPropsAndAttrs(GenericResource):
'a_list': {'Type': 'List'},
'a_map': {'Type': 'Map'}}
attributes_schema = {'list': 'A list',
'map': 'A map',
'string': 'A string'}
attributes_schema = {'list': attributes.Schema('A list'),
'map': attributes.Schema('A map'),
'string': attributes.Schema('A string')}
def _resolve_attribute(self, name):
try:
@ -88,11 +89,12 @@ class ResourceWithResourceID(GenericResource):
class ResourceWithComplexAttributes(GenericResource):
attributes_schema = {'list': 'A list',
'flat_dict': 'A flat dictionary',
'nested_dict': 'A nested dictionary',
'none': 'A None'
}
attributes_schema = {
'list': attributes.Schema('A list'),
'flat_dict': attributes.Schema('A flat dictionary'),
'nested_dict': attributes.Schema('A nested dictionary'),
'none': attributes.Schema('A None')
}
list = ['foo', 'bar']
flat_dict = {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}
@ -118,7 +120,7 @@ class ResourceWithRequiredProps(GenericResource):
class SignalResource(signal_responder.SignalResponder):
properties_schema = {}
attributes_schema = {'AlarmUrl': 'Get a signed webhook'}
attributes_schema = {'AlarmUrl': attributes.Schema('Get a signed webhook')}
def handle_create(self):
super(SignalResource, self).handle_create()

View File

@ -58,10 +58,10 @@ class AttributeSchemaTest(testtools.TestCase):
self.assertEqual('Do not use this ever',
attrs._attributes['bar_dep'].support_status().message)
def test_from_attribute_old_schema_format(self):
def test_old_attribute_schema_format(self):
s = 'Test description.'
self.assertEqual(type(attributes.Schema(s)),
type(attributes.Schema.from_attribute(s)))
self.assertIsInstance(attributes.Schema.from_attribute(s),
attributes.Schema)
self.assertEqual('Test description.',
attributes.Schema.from_attribute(s).description)
@ -75,7 +75,8 @@ class AttributeTest(common.HeatTestCase):
"Value": '{"Fn::GetAtt": ["test_resource", "test1"]}',
"Description": "The first test attribute"
}
attr = attributes.Attribute("test1", "The first test attribute")
attr = attributes.Attribute(
"test1", attributes.Schema("The first test attribute"))
self.assertEqual(expected, attr.as_output("test_resource"))
@ -83,9 +84,9 @@ class AttributesTest(common.HeatTestCase):
"""Test the Attributes class."""
attributes_schema = {
"test1": "Test attrib 1",
"test2": "Test attrib 2",
"test3": "Test attrib 3"
"test1": attributes.Schema("Test attrib 1"),
"test2": attributes.Schema("Test attrib 2"),
"test3": attributes.Schema("Test attrib 3"),
}
def setUp(self):
@ -137,9 +138,9 @@ class AttributesTest(common.HeatTestCase):
}
MyTestResourceClass = self.m.CreateMockAnything()
MyTestResourceClass.attributes_schema = {
"test1": "Test attrib 1",
"test2": "Test attrib 2",
"test3": "Test attrib 3"
"test1": attributes.Schema("Test attrib 1"),
"test2": attributes.Schema("Test attrib 2"),
"test3": attributes.Schema("Test attrib 3"),
}
self.m.ReplayAll()
self.assertEqual(

View File

@ -19,6 +19,7 @@ import yaml
from heat.common import exception
from heat.common import template_format
from heat.common import urlfetch
from heat.engine import attributes
from heat.engine import environment
from heat.engine import parser
from heat.engine import properties
@ -103,7 +104,7 @@ class ProviderTemplateTest(HeatTestCase):
files = {'test_resource.template': json.dumps(provider)}
class DummyResource(object):
attributes_schema = {"Foo": "A test attribute"}
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
properties_schema = {
"Foo": {"Type": "String"},
"AList": {"Type": "List"},
@ -170,7 +171,7 @@ class ProviderTemplateTest(HeatTestCase):
class DummyResource(object):
properties_schema = {}
attributes_schema = {"Foo": "A test attribute"}
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
@ -200,7 +201,7 @@ class ProviderTemplateTest(HeatTestCase):
class DummyResource(object):
properties_schema = {}
attributes_schema = {"Foo": "A test attribute"}
attributes_schema = {"Foo": attributes.Schema("A test attribute")}
json_snippet = {
"Type": "DummyResource",

View File

@ -19,6 +19,7 @@ import mock
from heat.common import exception
from heat.db import api as db_api
from heat.engine import attributes
from heat.engine import dependencies
from heat.engine import environment
from heat.engine import parser
@ -674,8 +675,8 @@ class ResourceTest(HeatTestCase):
}
attributes_schema = {
'output1': 'output1_desc',
'output2': 'output2_desc'
'output1': attributes.Schema('output1_desc'),
'output2': attributes.Schema('output2_desc')
}
expected_template = {