Reset state before resource recreation

So the destroyed resource can be recreated, and HARestarted main logic
resource destory and create can work.

Change-Id: Id79988560e105c254d304e30d598427a2bbc5b26
Fixes: bug #1202492
This commit is contained in:
JUN JIE NAN 2013-07-18 15:39:10 +08:00 committed by Gerrit Code Review
parent 4a95c06a16
commit f0b6b550d9
3 changed files with 20 additions and 0 deletions

View File

@ -516,6 +516,7 @@ class Stack(object):
for res in deps:
if not failed:
try:
res.state_reset()
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
logger.exception('create')

View File

@ -622,6 +622,13 @@ class Resource(object):
# By default, no attributes resolve
pass
def state_reset(self):
"""
Reset state to (INIT, COMPLETE)
"""
self.action = self.INIT
self.status = self.COMPLETE
def state_set(self, action, status, reason="state changed"):
if action not in self.ACTIONS:
raise ValueError("Invalid action %s" % action)

View File

@ -272,6 +272,18 @@ class ResourceTest(HeatTestCase):
self.assertRaises(exception.ResourceFailure, create)
self.assertEqual((res.CREATE, res.FAILED), res.state)
def test_create_resource_after_destroy(self):
tmpl = {'Type': 'GenericResourceType'}
rname = 'test_res_id_none'
res = generic_rsrc.ResourceWithProps(rname, tmpl, self.stack)
res.id = 'test_res_id'
(res.action, res.status) = (res.INIT, res.DELETE)
self.assertRaises(exception.ResourceFailure, res.create)
res.destroy()
res.state_reset()
scheduler.TaskRunner(res.create)()
self.assertEqual((res.CREATE, res.COMPLETE), res.state)
def test_update_ok(self):
tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}}
res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack)