def _wait_for_dependents(self): self.get_status() reason = '' while self.status != self.READY: if self.status == self.FAILED: reason = _('%(action)s [%(id)s] failed due to dependent ' 'action failure') % {'action': self.action, 'id': self.id} LOG.debug(reason) return self.RES_ERROR, reason if self.is_cancelled(): # During this period, if cancel request come, cancel this # cluster operation immediately, then release the cluster # lock and return. reason = _('%(action)s %(id)s cancelled') % { 'action': self.action, 'id': self.id} LOG.debug(reason) return self.RES_CANCEL, reason if self.is_timeout(): # Action timeout, return reason = _('%(action)s %(id)s timeout') % { 'action': self.action, 'id': self.id} LOG.debug(reason) return self.RES_TIMEOUT # Continue waiting (with reschedule) scheduler.reschedule(self, 1) self.get_status() return self.RES_OK, 'All dependents ended with success'
def _wait_for_dependents(self): """Wait for dependent actions to complete. :returns: A tuple containing the result and the corresponding reason. """ status = self.get_status() reason = '' while status != self.READY: if status == self.FAILED: reason = _('%(action)s [%(id)s] failed') % { 'action': self.action, 'id': self.id[:8]} LOG.debug(reason) return self.RES_ERROR, reason if self.is_cancelled(): # During this period, if cancel request comes, cancel this # operation immediately, then release the cluster lock reason = _('%(action)s [%(id)s] cancelled') % { 'action': self.action, 'id': self.id[:8]} LOG.debug(reason) return self.RES_CANCEL, reason if self.is_timeout(): # Action timeout, return reason = _('%(action)s [%(id)s] timeout') % { 'action': self.action, 'id': self.id[:8]} LOG.debug(reason) return self.RES_TIMEOUT, reason # Continue waiting (with reschedule) scheduler.reschedule(self.id, 3) status = self.get_status() return self.RES_OK, 'All dependents ended with success'
def test_reschedule(self): action = mock.Mock() action.id = '0123' mock_sleep = self.patchobject(eventlet, 'sleep') scheduler.reschedule(action.id) mock_sleep.assert_called_once_with(1) mock_sleep.reset_mock() scheduler.reschedule(action.id, None) self.assertEqual(0, mock_sleep.call_count)
def _wait_for_dependents(self, lifecycle_hook_timeout=None): """Wait for dependent actions to complete. :returns: A tuple containing the result and the corresponding reason. """ status = self.get_status() while status != self.READY: if status == self.FAILED: reason = ('%(action)s [%(id)s] failed' % { 'action': self.action, 'id': self.id[:8]}) LOG.debug(reason) return self.RES_ERROR, reason if self.is_cancelled(): # During this period, if cancel request comes, cancel this # operation immediately after signaling children to cancel, # then release the cluster lock reason = ('%(action)s [%(id)s] cancelled' % { 'action': self.action, 'id': self.id[:8]}) LOG.debug(reason) return self.RES_CANCEL, reason # When a child action is cancelled the parent action will update # its status to cancelled as well this allows it to exit. if status == self.CANCELLED: if self.check_children_complete(): reason = ('%(action)s [%(id)s] cancelled' % { 'action': self.action, 'id': self.id[:8]}) LOG.debug(reason) return self.RES_CANCEL, reason if self.is_timeout(): # Action timeout, return reason = ('%(action)s [%(id)s] timeout' % { 'action': self.action, 'id': self.id[:8]}) LOG.debug(reason) return self.RES_TIMEOUT, reason if (lifecycle_hook_timeout is not None and self.is_timeout(lifecycle_hook_timeout)): # if lifecycle hook timeout is specified and Lifecycle hook # timeout is reached, return reason = ('%(action)s [%(id)s] lifecycle hook timeout' '') % {'action': self.action, 'id': self.id[:8]} LOG.debug(reason) return self.RES_LIFECYCLE_HOOK_TIMEOUT, reason # Continue waiting (with reschedule) scheduler.reschedule(self.id, 3) status = self.get_status() dispatcher.start_action() return self.RES_OK, 'All dependents ended with success'