Add tests for pre-create hooks
The actual triggering of hooks during resource creation was not tested, this adds some tests. Change-Id: I5f46ae84e1aadf66325ec73e5882fabc73d67d48
This commit is contained in:
parent
1c4fdf564e
commit
6f39935019
|
@ -2783,10 +2783,6 @@ class ResourceHookTest(common.HeatTestCase):
|
|||
super(ResourceHookTest, self).setUp()
|
||||
|
||||
self.env = environment.Environment()
|
||||
self.env.load({u'resource_registry':
|
||||
{u'OS::Test::GenericResource': u'GenericResourceType',
|
||||
u'OS::Test::ResourceWithCustomConstraint':
|
||||
u'ResourceWithCustomConstraint'}})
|
||||
|
||||
self.stack = parser.Stack(utils.dummy_context(), 'test_stack',
|
||||
template.Template(empty_template,
|
||||
|
@ -2860,6 +2856,21 @@ class ResourceHookTest(common.HeatTestCase):
|
|||
self.assertRaises(exception.InvalidBreakPointHook,
|
||||
res.signal, {'unset_hook': 'pre-create'})
|
||||
|
||||
def test_hook_call(self):
|
||||
self.stack.env.registry.load(
|
||||
{'resources': {'res': {'hooks': 'pre-create'}}})
|
||||
snippet = rsrc_defn.ResourceDefinition('res',
|
||||
'GenericResourceType')
|
||||
res = resource.Resource('res', snippet, self.stack)
|
||||
res.id = '1234'
|
||||
task = scheduler.TaskRunner(res.create)
|
||||
task.start()
|
||||
task.step()
|
||||
self.assertTrue(res.has_hook('pre-create'))
|
||||
res.clear_hook('pre-create')
|
||||
task.run_to_completion()
|
||||
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
|
||||
|
||||
|
||||
class ResourceAvailabilityTest(common.HeatTestCase):
|
||||
def _mock_client_plugin(self, service_types=[], is_available=True):
|
||||
|
|
|
@ -368,6 +368,42 @@ class StackUpdateTest(common.HeatTestCase):
|
|||
{'Type': 'ResourceWithPropsType',
|
||||
'Properties': {'Foo': 'abc'}})
|
||||
|
||||
def test_update_replace_create_hook(self):
|
||||
tmpl = {
|
||||
'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Parameters': {
|
||||
'foo': {'Type': 'String'}
|
||||
},
|
||||
'Resources': {
|
||||
'AResource': {
|
||||
'Type': 'ResourceWithPropsType',
|
||||
'Properties': {'Foo': {'Ref': 'foo'}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.stack = stack.Stack(
|
||||
self.ctx, 'update_test_stack',
|
||||
template.Template(
|
||||
tmpl, env=environment.Environment({'foo': 'abc'})))
|
||||
self.stack.store()
|
||||
self.stack.create()
|
||||
self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
|
||||
env2 = environment.Environment({'foo': 'xyz'})
|
||||
# Add a create hook on the resource
|
||||
env2.registry.load(
|
||||
{'resources': {'AResource': {'hooks': 'pre-create'}}})
|
||||
updated_stack = stack.Stack(self.ctx, 'updated_stack',
|
||||
template.Template(tmpl, env=env2))
|
||||
|
||||
self.stack.update(updated_stack)
|
||||
# The hook is not called, and update succeeds properly
|
||||
self.assertEqual((stack.Stack.UPDATE, stack.Stack.COMPLETE),
|
||||
self.stack.state)
|
||||
self.assertEqual('xyz', self.stack['AResource'].properties['Foo'])
|
||||
|
||||
def test_update_modify_update_failed(self):
|
||||
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
|
||||
'Resources': {'AResource': {'Type': 'ResourceWithPropsType',
|
||||
|
|
Loading…
Reference in New Issue