Convergence: Do create operation only if action is INIT

All resources that are new will have an INIT state. Instead
of having a complex strategy to decide whether the resource
should be created or updated, just check for the action
to see if it is in the INIT state or not. If it is not, then
always trigger the update workflow.

Also, this fixes a bug where we triggered a create for a
resource without a resource id that originally should've been
updated because it was in UPDATE_FAILED which was the unhandled
case.

Change-Id: I3f2318fecfe76592e8b54e9c09fdf1614197e83f
changes/71/208271/5
Sirushti Murugesan 7 years ago
parent a41cc2f6f7
commit 5d1027a135
  1. 7
      heat/engine/worker.py
  2. 26
      heat/tests/engine/test_engine_worker.py

@ -353,12 +353,7 @@ def check_resource_update(rsrc, template_id, resource_data, engine_id):
'''
Create or update the Resource if appropriate.
'''
if (rsrc.resource_id is None
and not (rsrc.action == resource.Resource.CREATE and
rsrc.status in [
resource.Resource.COMPLETE,
resource.Resource.FAILED
])):
if rsrc.action == resource.Resource.INIT:
rsrc.create_convergence(template_id, resource_data, engine_id)
else:
rsrc.update_convergence(template_id, resource_data, engine_id)

@ -508,32 +508,32 @@ class MiscMethodsTest(common.HeatTestCase):
self.assertTrue(mock_sync.called)
@mock.patch.object(resource.Resource, 'create_convergence')
def test_check_resource_update_create(self, mock_create):
worker.check_resource_update(self.resource, self.resource.stack.t.id,
{}, 'engine-id')
self.assertTrue(mock_create.called)
@mock.patch.object(resource.Resource, 'update_convergence')
def test_check_resource_update_update(self, mock_update):
self.resource.resource_id = 'physical-res-id'
def test_check_resource_update_init_action(self, mock_update, mock_create):
self.resource.action = 'INIT'
worker.check_resource_update(self.resource, self.resource.stack.t.id,
{}, 'engine-id')
self.assertTrue(mock_update.called)
self.assertTrue(mock_create.called)
self.assertFalse(mock_update.called)
@mock.patch.object(resource.Resource, 'create_convergence')
@mock.patch.object(resource.Resource, 'update_convergence')
def test_check_resource_update_complete(self, mock_update):
def test_check_resource_update_create_action(
self, mock_update, mock_create):
self.resource.action = 'CREATE'
self.resource.status = 'COMPLETE'
worker.check_resource_update(self.resource, self.resource.stack.t.id,
{}, 'engine-id')
self.assertFalse(mock_create.called)
self.assertTrue(mock_update.called)
@mock.patch.object(resource.Resource, 'create_convergence')
@mock.patch.object(resource.Resource, 'update_convergence')
def test_check_resource_update_failed(self, mock_update):
self.resource.action = 'CREATE'
self.resource.status = 'FAILED'
def test_check_resource_update_update_action(
self, mock_update, mock_create):
self.resource.action = 'UPDATE'
worker.check_resource_update(self.resource, self.resource.stack.t.id,
{}, 'engine-id')
self.assertFalse(mock_create.called)
self.assertTrue(mock_update.called)
@mock.patch.object(resource.Resource, 'delete_convergence')

Loading…
Cancel
Save