Move internal test resources to generic_resource
Move follow resources from the tests to common generic_resource module: - ResourceWithFnGetAttType - ResourceWithFnGetRefIdType - StackResourceType - ResourceWithListProp - ResourceWithRestoreType Change-Id: Ifa07b278469e115f6a475b571e5349df98629787
This commit is contained in:
@@ -146,6 +146,16 @@ class HeatTestCase(testscenarios.WithScenarios,
|
||||
generic_rsrc.ResourceWithComplexAttributes)
|
||||
resource._register_class('ResourceWithDefaultClientName',
|
||||
generic_rsrc.ResourceWithDefaultClientName)
|
||||
resource._register_class('OverwrittenFnGetAttType',
|
||||
generic_rsrc.ResourceWithFnGetAttType)
|
||||
resource._register_class('OverwrittenFnGetRefIdType',
|
||||
generic_rsrc.ResourceWithFnGetRefIdType)
|
||||
resource._register_class('ResourceWithListProp',
|
||||
generic_rsrc.ResourceWithListProp)
|
||||
resource._register_class('StackResourceType',
|
||||
generic_rsrc.StackResourceType)
|
||||
resource._register_class('ResourceWithRestoreType',
|
||||
generic_rsrc.ResourceWithRestoreType)
|
||||
|
||||
def patchobject(self, obj, attr, **kwargs):
|
||||
mockfixture = self.useFixture(mockpatch.PatchObject(obj, attr,
|
||||
|
||||
@@ -20,6 +20,7 @@ from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import signal_responder
|
||||
from heat.engine.resources import stack_resource
|
||||
from heat.engine.resources import stack_user
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -202,3 +203,50 @@ class ResourceWithAttributeType(GenericResource):
|
||||
|
||||
class ResourceWithDefaultClientName(resource.Resource):
|
||||
default_client_name = 'sample'
|
||||
|
||||
|
||||
class ResourceWithFnGetAttType(GenericResource):
|
||||
def FnGetAtt(self, name):
|
||||
pass
|
||||
|
||||
|
||||
class ResourceWithFnGetRefIdType(ResourceWithProps):
|
||||
def FnGetRefId(self):
|
||||
return 'ID-%s' % self.name
|
||||
|
||||
|
||||
class ResourceWithListProp(ResourceWithFnGetRefIdType):
|
||||
properties_schema = {"listprop": properties.Schema(properties.Schema.LIST)}
|
||||
|
||||
|
||||
class StackResourceType(stack_resource.StackResource, GenericResource):
|
||||
def physical_resource_name(self):
|
||||
return "cb2f2b28-a663-4683-802c-4b40c916e1ff"
|
||||
|
||||
def set_template(self, nested_template, params):
|
||||
self.nested_template = nested_template
|
||||
self.nested_params = params
|
||||
|
||||
def handle_create(self):
|
||||
return self.create_with_template(self.nested_template,
|
||||
self.nested_params)
|
||||
|
||||
def handle_adopt(self, resource_data):
|
||||
return self.create_with_template(self.nested_template,
|
||||
self.nested_params,
|
||||
adopt_data=resource_data)
|
||||
|
||||
def handle_delete(self):
|
||||
self.delete_nested()
|
||||
|
||||
|
||||
class ResourceWithRestoreType(ResWithComplexPropsAndAttrs):
|
||||
|
||||
def handle_restore(self, defn, data):
|
||||
props = dict(
|
||||
(key, value) for (key, value) in
|
||||
six.iteritems(defn.properties(self.properties_schema))
|
||||
if value is not None)
|
||||
value = data['resource_data']['a_string']
|
||||
props['a_string'] = value
|
||||
return defn.freeze(properties=props)
|
||||
|
||||
@@ -26,7 +26,6 @@ from heat.engine import rsrc_defn
|
||||
from heat.engine import stack
|
||||
from heat.engine import template
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource as generic_rsrc
|
||||
from heat.tests import utils
|
||||
|
||||
|
||||
@@ -235,11 +234,6 @@ class ValidateGetAttTest(common.HeatTestCase):
|
||||
env.load({u'resource_registry':
|
||||
{u'OS::Test::GenericResource': u'GenericResourceType'}})
|
||||
|
||||
class FakeResource(generic_rsrc.GenericResource):
|
||||
def FnGetAtt(self, name):
|
||||
pass
|
||||
|
||||
resource._register_class('OverwrittenFnGetAttType', FakeResource)
|
||||
env.load({u'resource_registry':
|
||||
{u'OS::Test::FakeResource': u'OverwrittenFnGetAttType'}})
|
||||
|
||||
|
||||
@@ -16,33 +16,21 @@ import six
|
||||
|
||||
from heat.common import grouputils
|
||||
from heat.common import template_format
|
||||
from heat.engine import resource
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource
|
||||
from heat.tests import utils
|
||||
|
||||
nested_stack = '''
|
||||
heat_template_version: 2013-05-23
|
||||
resources:
|
||||
r0:
|
||||
type: dummy.resource
|
||||
type: OverwrittenFnGetRefIdType
|
||||
r1:
|
||||
type: dummy.resource
|
||||
type: OverwrittenFnGetRefIdType
|
||||
'''
|
||||
|
||||
|
||||
class SimpleResource(generic_resource.ResourceWithProps):
|
||||
|
||||
def FnGetRefId(self):
|
||||
return 'ID-%s' % self.name
|
||||
|
||||
|
||||
class GroupUtilsTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(GroupUtilsTest, self).setUp()
|
||||
resource._register_class('dummy.resource', SimpleResource)
|
||||
|
||||
def test_non_nested_resource(self):
|
||||
group = mock.Mock()
|
||||
self.patchobject(group, 'nested', return_value=None)
|
||||
|
||||
@@ -17,12 +17,9 @@ import mock
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.heat import resource_group
|
||||
from heat.engine import stack as stackm
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource
|
||||
from heat.tests import utils
|
||||
|
||||
template = {
|
||||
@@ -33,7 +30,7 @@ template = {
|
||||
"properties": {
|
||||
"count": 2,
|
||||
"resource_def": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": "Bar"
|
||||
}
|
||||
@@ -47,7 +44,7 @@ template2 = {
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"dummy": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": "baz"
|
||||
}
|
||||
@@ -57,7 +54,7 @@ template2 = {
|
||||
"properties": {
|
||||
"count": 2,
|
||||
"resource_def": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": {"get_attr": ["dummy", "Foo"]}
|
||||
}
|
||||
@@ -75,7 +72,7 @@ template_repl = {
|
||||
"properties": {
|
||||
"count": 2,
|
||||
"resource_def": {
|
||||
"type": "dummy.listresource%index%",
|
||||
"type": "ResourceWithListProp%index%",
|
||||
"properties": {
|
||||
"Foo": "Bar_%index%",
|
||||
"listprop": [
|
||||
@@ -113,31 +110,10 @@ template_attr = {
|
||||
}
|
||||
|
||||
|
||||
class ResourceWithPropsAndId(generic_resource.ResourceWithProps):
|
||||
|
||||
def FnGetRefId(self):
|
||||
return "ID-%s" % self.name
|
||||
|
||||
|
||||
class ResourceWithListProp(ResourceWithPropsAndId):
|
||||
|
||||
def __init__(self):
|
||||
self.properties_schema.update({
|
||||
"listprop": properties.Schema(
|
||||
properties.Schema.LIST
|
||||
)
|
||||
})
|
||||
super(ResourceWithListProp, self).__init__(self)
|
||||
|
||||
|
||||
class ResourceGroupTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
common.HeatTestCase.setUp(self)
|
||||
resource._register_class("dummy.resource",
|
||||
ResourceWithPropsAndId)
|
||||
resource._register_class('dummy.listresource',
|
||||
ResourceWithListProp)
|
||||
self.m.StubOutWithMock(stackm.Stack, 'validate')
|
||||
|
||||
def test_assemble_nested(self):
|
||||
@@ -152,19 +128,19 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"0": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": "Bar"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": "Bar"
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {
|
||||
"Foo": "Bar"
|
||||
}
|
||||
@@ -185,7 +161,7 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"0": {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +191,7 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"0": {
|
||||
"type": "dummy.listresource%index%",
|
||||
"type": "ResourceWithListProp%index%",
|
||||
"properties": {
|
||||
"Foo": "Bar_0",
|
||||
"listprop": [
|
||||
@@ -224,7 +200,7 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"type": "dummy.listresource%index%",
|
||||
"type": "ResourceWithListProp%index%",
|
||||
"properties": {
|
||||
"Foo": "Bar_1",
|
||||
"listprop": [
|
||||
@@ -233,7 +209,7 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"type": "dummy.listresource%index%",
|
||||
"type": "ResourceWithListProp%index%",
|
||||
"properties": {
|
||||
"Foo": "Bar_2",
|
||||
"listprop": [
|
||||
@@ -255,7 +231,7 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"0": {
|
||||
"type": "dummy.listresource%index%",
|
||||
"type": "ResourceWithListProp%index%",
|
||||
"properties": {
|
||||
"Foo": "Bar_%index%",
|
||||
"listprop": [
|
||||
@@ -271,13 +247,13 @@ class ResourceGroupTest(common.HeatTestCase):
|
||||
res_def['properties']['Foo'] = "Bar___foo__"
|
||||
res_def['properties']['listprop'] = ["__foo___0", "__foo___1",
|
||||
"__foo___2"]
|
||||
res_def['type'] = "dummy.listresource__foo__"
|
||||
res_def['type'] = "ResourceWithListProp__foo__"
|
||||
resg = resource_group.ResourceGroup('test', snip, stack)
|
||||
expect = {
|
||||
"heat_template_version": "2013-05-23",
|
||||
"resources": {
|
||||
"0": {
|
||||
"type": "dummy.listresource__foo__",
|
||||
"type": "ResourceWithListProp__foo__",
|
||||
"properties": {
|
||||
"Foo": "Bar_0",
|
||||
"listprop": [
|
||||
@@ -466,11 +442,11 @@ class ResourceGroupEmptyParams(common.HeatTestCase):
|
||||
snip = stack.t.resource_definitions(stack)['group1']
|
||||
resg = resource_group.ResourceGroup('test', snip, stack)
|
||||
exp1 = {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": self.expected,
|
||||
}
|
||||
exp2 = {
|
||||
"type": "dummy.resource",
|
||||
"type": "OverwrittenFnGetRefIdType",
|
||||
"properties": self.expected_include,
|
||||
}
|
||||
self.assertEqual(exp1, resg._build_resource_definition())
|
||||
@@ -508,11 +484,6 @@ class ResourceGroupNameListTest(common.HeatTestCase):
|
||||
|
||||
class ResourceGroupAttrTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ResourceGroupAttrTest, self).setUp()
|
||||
resource._register_class("dummy.resource",
|
||||
ResourceWithPropsAndId)
|
||||
|
||||
def test_aggregate_attribs(self):
|
||||
"""
|
||||
Test attribute aggregation and that we mimic the nested resource's
|
||||
|
||||
@@ -871,21 +871,9 @@ class StackTest(common.HeatTestCase):
|
||||
this test fails the second instance
|
||||
'''
|
||||
|
||||
class ResourceTypeA(generic_rsrc.ResourceWithProps):
|
||||
count = 0
|
||||
|
||||
def handle_create(self):
|
||||
ResourceTypeA.count += 1
|
||||
self.resource_id_set('%s%d' % (self.name, self.count))
|
||||
|
||||
def handle_delete(self):
|
||||
return super(ResourceTypeA, self).handle_delete()
|
||||
|
||||
resource._register_class('ResourceTypeA', ResourceTypeA)
|
||||
|
||||
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Resources': {
|
||||
'AResource': {'Type': 'ResourceTypeA',
|
||||
'AResource': {'Type': 'OverwrittenFnGetRefIdType',
|
||||
'Properties': {'Foo': 'abc'}},
|
||||
'BResource': {'Type': 'ResourceWithPropsType',
|
||||
'Properties': {
|
||||
@@ -894,16 +882,18 @@ class StackTest(common.HeatTestCase):
|
||||
template.Template(tmpl),
|
||||
disable_rollback=True)
|
||||
|
||||
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_create')
|
||||
self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_delete')
|
||||
self.m.StubOutWithMock(ResourceTypeA, 'handle_delete')
|
||||
self.m.StubOutWithMock(generic_rsrc.ResourceWithFnGetRefIdType,
|
||||
'handle_create')
|
||||
self.m.StubOutWithMock(generic_rsrc.ResourceWithFnGetRefIdType,
|
||||
'handle_delete')
|
||||
|
||||
# create
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(Exception)
|
||||
generic_rsrc.ResourceWithFnGetRefIdType.handle_create().AndRaise(
|
||||
Exception)
|
||||
|
||||
# update
|
||||
generic_rsrc.ResourceWithProps.handle_delete()
|
||||
generic_rsrc.ResourceWithProps.handle_create()
|
||||
generic_rsrc.ResourceWithFnGetRefIdType.handle_delete()
|
||||
generic_rsrc.ResourceWithFnGetRefIdType.handle_create()
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -921,7 +911,7 @@ class StackTest(common.HeatTestCase):
|
||||
self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
self.assertEqual('abc', self.stack['AResource'].properties['Foo'])
|
||||
self.assertEqual('AResource1',
|
||||
self.assertEqual('ID-AResource',
|
||||
self.stack['BResource'].properties['Foo'])
|
||||
|
||||
self.m.VerifyAll()
|
||||
@@ -1835,21 +1825,9 @@ class StackTest(common.HeatTestCase):
|
||||
|
||||
def test_hot_restore(self):
|
||||
|
||||
class ResourceWithRestore(generic_rsrc.ResWithComplexPropsAndAttrs):
|
||||
|
||||
def handle_restore(self, defn, data):
|
||||
props = dict(
|
||||
(key, value) for (key, value) in
|
||||
six.iteritems(defn.properties(self.properties_schema))
|
||||
if value is not None)
|
||||
value = data['resource_data']['a_string']
|
||||
props['a_string'] = value
|
||||
return defn.freeze(properties=props)
|
||||
|
||||
resource._register_class('ResourceWithRestore', ResourceWithRestore)
|
||||
tpl = {'heat_template_version': '2013-05-23',
|
||||
'resources':
|
||||
{'A': {'type': 'ResourceWithRestore'}}}
|
||||
{'A': {'type': 'ResourceWithRestoreType'}}}
|
||||
self.stack = stack.Stack(self.ctx, 'stack_details_test',
|
||||
template.Template(tpl))
|
||||
self.stack.store()
|
||||
|
||||
@@ -32,7 +32,7 @@ from heat.tests import utils
|
||||
|
||||
|
||||
ws_res_snippet = {"HeatTemplateFormatVersion": "2012-12-12",
|
||||
"Type": "some_magic_type",
|
||||
"Type": "StackResourceType",
|
||||
"metadata": {
|
||||
"key": "value",
|
||||
"some": "more stuff"}}
|
||||
@@ -128,29 +128,7 @@ resources:
|
||||
'''
|
||||
|
||||
|
||||
class MyStackResource(stack_resource.StackResource,
|
||||
generic_rsrc.GenericResource):
|
||||
def physical_resource_name(self):
|
||||
return "cb2f2b28-a663-4683-802c-4b40c916e1ff"
|
||||
|
||||
def set_template(self, nested_template, params):
|
||||
self.nested_template = nested_template
|
||||
self.nested_params = params
|
||||
|
||||
def handle_create(self):
|
||||
return self.create_with_template(self.nested_template,
|
||||
self.nested_params)
|
||||
|
||||
def handle_adopt(self, resource_data):
|
||||
return self.create_with_template(self.nested_template,
|
||||
self.nested_params,
|
||||
adopt_data=resource_data)
|
||||
|
||||
def handle_delete(self):
|
||||
self.delete_nested()
|
||||
|
||||
|
||||
class MyImplementedStackResource(MyStackResource):
|
||||
class MyImplementedStackResource(generic_rsrc.StackResourceType):
|
||||
def child_template(self):
|
||||
return self.nested_template
|
||||
|
||||
@@ -161,8 +139,6 @@ class MyImplementedStackResource(MyStackResource):
|
||||
class StackResourceBaseTest(common.HeatTestCase):
|
||||
def setUp(self):
|
||||
super(StackResourceBaseTest, self).setUp()
|
||||
resource._register_class('some_magic_type',
|
||||
MyStackResource)
|
||||
self.ws_resname = "provider_resource"
|
||||
self.empty_temp = templatem.Template(
|
||||
{'HeatTemplateFormatVersion': '2012-12-12',
|
||||
@@ -175,9 +151,8 @@ class StackResourceBaseTest(common.HeatTestCase):
|
||||
stack_user_project_id='aprojectid')
|
||||
resource_defns = self.empty_temp.resource_definitions(
|
||||
self.parent_stack)
|
||||
self.parent_resource = MyStackResource('test',
|
||||
resource_defns[self.ws_resname],
|
||||
self.parent_stack)
|
||||
self.parent_resource = generic_rsrc.StackResourceType(
|
||||
'test', resource_defns[self.ws_resname], self.parent_stack)
|
||||
|
||||
|
||||
class StackResourceTest(StackResourceBaseTest):
|
||||
|
||||
@@ -1446,15 +1446,9 @@ class StackUpdateTest(common.HeatTestCase):
|
||||
|
||||
def test_update_deletion_policy_no_handle_update(self):
|
||||
|
||||
class ResourceWithNoUpdate(resource.Resource):
|
||||
properties_schema = {'Foo': {'Type': 'String'}}
|
||||
|
||||
resource._register_class('ResourceWithNoUpdate',
|
||||
ResourceWithNoUpdate)
|
||||
|
||||
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Resources': {
|
||||
'AResource': {'Type': 'ResourceWithNoUpdate',
|
||||
'AResource': {'Type': 'ResourceWithRequiredProps',
|
||||
'Properties': {'Foo': 'Bar'}}}}
|
||||
|
||||
self.stack = stack.Stack(self.ctx, 'update_test_stack',
|
||||
@@ -1468,7 +1462,7 @@ class StackUpdateTest(common.HeatTestCase):
|
||||
|
||||
new_tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Resources': {
|
||||
'AResource': {'Type': 'ResourceWithNoUpdate',
|
||||
'AResource': {'Type': 'ResourceWithRequiredProps',
|
||||
'DeletionPolicy': 'Retain',
|
||||
'Properties': {'Foo': 'Bar'}}}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user