Skip to content

Commit

Permalink
Reset state before resource recreation
Browse files Browse the repository at this point in the history
So the destroyed resource can be recreated, and HARestarted main logic
resource destory and create can work.

Change-Id: Id79988560e105c254d304e30d598427a2bbc5b26
Fixes: bug #1202492
  • Loading branch information
JUN JIE NAN authored and openstack-gerrit committed Jul 22, 2013
1 parent 4a95c06 commit f0b6b55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions heat/engine/parser.py
Expand Up @@ -516,6 +516,7 @@ def restart_resource(self, resource_name):
for res in deps:
if not failed:
try:
res.state_reset()
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
logger.exception('create')
Expand Down
7 changes: 7 additions & 0 deletions heat/engine/resource.py
Expand Up @@ -622,6 +622,13 @@ def _resolve_attribute(self, name):
# 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)
Expand Down
12 changes: 12 additions & 0 deletions heat/tests/test_resource.py
Expand Up @@ -272,6 +272,18 @@ def test_create_fail_prop_typo(self):
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)
Expand Down

0 comments on commit f0b6b55

Please sign in to comment.