Miscellaneous fixes

- Remove unused code path for RES_LIFECYCLE_COMPLETE in set_status
- Wrap policy_check in try finally to always release cluster lock
- Change node lock failure log level to warning to match cluster lock
  failure log level.

Change-Id: Ic45c22ed9ae5136950a064cf651d85f39840f896
This commit is contained in:
Duc Truong 2019-01-16 19:30:14 +00:00
parent 0700a8bf29
commit b9c9cfaac4
4 changed files with 13 additions and 20 deletions

View File

@ -433,10 +433,6 @@ class Action(object):
status = self.CANCELLED
ao.Action.mark_cancelled(self.context, self.id, timestamp)
elif result == self.RES_LIFECYCLE_COMPLETE:
status = self.SUCCEEDED
ao.Action.mark_ready(self.context, self.id, timestamp)
else: # result == self.RES_RETRY:
retries = self.data.get('retries', 0)
# Action failed at the moment, but can be retried

View File

@ -257,13 +257,16 @@ class NodeAction(base.Action):
if not res:
return self.RES_RETRY, 'Failed in locking cluster'
self.policy_check(self.entity.cluster_id, 'BEFORE')
if self.data['status'] != pb.CHECK_OK:
# Don't emit message since policy_check should have done it
senlin_lock.cluster_lock_release(saved_cluster_id, self.id,
senlin_lock.NODE_SCOPE)
return self.RES_ERROR, ('Policy check: ' +
self.data['reason'])
try:
self.policy_check(self.entity.cluster_id, 'BEFORE')
finally:
if self.data['status'] != pb.CHECK_OK:
# Don't emit message since policy_check should have
# done it
senlin_lock.cluster_lock_release(
saved_cluster_id, self.id, senlin_lock.NODE_SCOPE)
return self.RES_ERROR, ('Policy check: ' +
self.data['reason'])
elif self.cause == consts.CAUSE_DERIVED_LCH:
self.policy_check(self.entity.cluster_id, 'BEFORE')

View File

@ -136,9 +136,9 @@ def node_lock_acquire(context, node_id, action_id, engine=None,
ao.Action.mark_failed(context, action.id, time.time(), reason)
return True
LOG.error('Node is already locked by action %(old)s, '
'action %(new)s failed grabbing the lock',
{'old': owner, 'new': action_id})
LOG.warning('Node is already locked by action %(old)s, '
'action %(new)s failed grabbing the lock',
{'old': owner, 'new': action_id})
return False

View File

@ -704,12 +704,6 @@ class ActionBaseTest(base.SenlinTestCase):
mark_cancel.assert_called_once_with(action.context, 'FAKE_ID',
mock.ANY)
mark_fail.reset_mock()
action.set_status(action.RES_LIFECYCLE_COMPLETE, 'LIFECYCLE COMPLETE')
self.assertEqual(action.SUCCEEDED, action.status)
self.assertEqual('LIFECYCLE COMPLETE', action.status_reason)
mark_ready.assert_called_once_with(action.context, 'FAKE_ID', mock.ANY)
mark_fail.reset_mock()
action.set_status(action.RES_RETRY, 'BUSY')
self.assertEqual(action.READY, action.status)