Only push metadata when required

Metadata only needs to be pushed on deployment update when the
config_id changes.

Tripleo are experiencing config being retriggered by deployment signalling,
causing eternal config loops.

Change-Id: I3953d45db745ee6a7a4a7b0f989f18cb0ecba3bf
Closes-Bug: #1320262
This commit is contained in:
Steve Baker 2014-05-16 10:35:17 -04:00
parent 5604168784
commit b221cd2da2
3 changed files with 81 additions and 3 deletions

View File

@ -1218,7 +1218,12 @@ class EngineService(service.Service):
update_data['status_reason'] = status_reason
sd = db_api.software_deployment_update(cnxt,
deployment_id, update_data)
self._push_metadata_software_deployments(cnxt, sd.server_id)
# only push metadata if this update resulted in the config_id
# changing, since metadata is just a list of configs
if config_id:
self._push_metadata_software_deployments(cnxt, sd.server_id)
return api.format_software_deployment(sd)
@request_context

View File

@ -3616,6 +3616,32 @@ class SoftwareDeploymentControllerTest(ControllerTest, HeatTestCase):
body=body, tenant_id=self.tenant)
self.assertEqual(expected, resp)
@mock.patch.object(policy.Enforcer, 'enforce')
def test_update_no_input_values(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'update')
config_id = 'd00ba4aa-db33-42e1-92f4-2a6469260107'
server_id = 'fb322564-7927-473d-8aad-68ae7fbf2abf'
body = {
'action': 'INIT',
'status': 'COMPLETE',
'status_reason': None,
'config_id': config_id}
return_value = body.copy()
deployment_id = 'a45559cd-8736-4375-bc39-d6a7bb62ade2'
return_value['id'] = deployment_id
req = self._put('/software_deployments/%s' % deployment_id,
json.dumps(body))
return_value['server_id'] = server_id
expected = {'software_deployment': return_value}
with mock.patch.object(
self.controller.rpc_client,
'update_software_deployment',
return_value=return_value):
resp = self.controller.update(
req, deployment_id=deployment_id,
body=body, tenant_id=self.tenant)
self.assertEqual(expected, resp)
@mock.patch.object(policy.Enforcer, 'enforce')
def test_update_not_found(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'update')

View File

@ -2904,8 +2904,22 @@ class SoftwareConfigServiceTest(HeatTestCase):
self.assertEqual(deployment_id, deployment['id'])
self.assertEqual(kwargs['input_values'], deployment['input_values'])
def test_update_software_deployment(self):
deployment = self._create_software_deployment()
def test_update_software_deployment_new_config(self):
server_id = str(uuid.uuid4())
self.m.StubOutWithMock(
self.engine, '_push_metadata_software_deployments')
# push on create
self.engine._push_metadata_software_deployments(
self.ctx, server_id).AndReturn(None)
# push on update with new config_id
self.engine._push_metadata_software_deployments(
self.ctx, server_id).AndReturn(None)
self.m.ReplayAll()
deployment = self._create_software_deployment(server_id=server_id)
self.assertIsNotNone(deployment)
deployment_id = deployment['id']
deployment_action = deployment['action']
@ -2920,6 +2934,39 @@ class SoftwareConfigServiceTest(HeatTestCase):
self.assertEqual(config_id, updated['config_id'])
self.assertEqual('DEPLOY', updated['action'])
self.assertEqual('WAITING', updated['status'])
self.m.VerifyAll()
def test_update_software_deployment_status(self):
server_id = str(uuid.uuid4())
self.m.StubOutWithMock(
self.engine, '_push_metadata_software_deployments')
# push on create
self.engine._push_metadata_software_deployments(
self.ctx, server_id).AndReturn(None)
# _push_metadata_software_deployments should not be called
# on update because config_id isn't being updated
self.m.ReplayAll()
deployment = self._create_software_deployment(server_id=server_id)
self.assertIsNotNone(deployment)
deployment_id = deployment['id']
deployment_action = deployment['action']
self.assertEqual('INIT', deployment_action)
updated = self.engine.update_software_deployment(
self.ctx, deployment_id=deployment_id, config_id=None,
input_values=None, output_values={}, action='DEPLOY',
status='WAITING', status_reason='')
self.assertIsNotNone(updated)
self.assertEqual('DEPLOY', updated['action'])
self.assertEqual('WAITING', updated['status'])
self.m.VerifyAll()
def test_update_software_deployment_fields(self):
deployment = self._create_software_deployment()
deployment_id = deployment['id']
config_id = deployment['config_id']
def check_software_deployment_updated(**kwargs):
values = {