def test_task_attempts_from_event(self):
     event = {
         u'event_type': u'task_failed',
         u'timestamp': u'2015-07-09 13:10:11.885+0000',
         u'@timestamp': u'2015-07-09T13:10:11.889Z',
         u'message_code': None,
         u'@version': u'1',
         u'context': {
             u'deployment_id': u'nc2',
             u'task_current_retries': 3,
             u'task_id': u'9cabd4fc-0608-4c29-870c-dec054103fe9',
             u'blueprint_id': u'nc',
             u'plugin': u'diamond',
             u'task_target': u'nodejs_host_6afd6',
             u'node_name': u'nodejs_host',
             u'workflow_id': u'hosts_software_install',
             u'node_id': u'nodejs_host_6afd6',
             u'task_name': u'diamond_agent.tasks.install',
             u'operation': u'cloudify.interfaces.monitoring_agent.install',
             u'task_total_retries': -1,
             u'execution_id': u'5a557b53-c2f3-4b36-96b6-e6587e972422',
             },
         u'message': {u'text':
                      u'Task failed \'diamond_agent.tasks.install\' -> '
                      'RecoverableError("OSError: [Errno 17] File exists: '
                      '\'/home/ubuntu/cloudify.nodejs_host_6afd6/diamond/'
                      'collectors/sockstat\'",) [attempt 4]',
                      u'arguments': None},
         u'type': u'cloudify_event',
     }
     expected = 4
     res = utils.event_task_attempts(event)
     self.assertEquals(res, expected)
def _wait_for_execution_finish(execution_id, attempt_limit, sm):
    canceled = False
    for event in _events_generator(execution_id, sm):
        if not canceled and event.get("event_type") == "task_failed":
            attempt = utils.event_task_attempts(event)
            if attempt is not None and attempt_limit >= 0 and attempt >= attempt_limit:
                # We need to cancel executions:
                msg_format = "Retry limit exceeded, current: {0}, limit: {1}"
                msg = msg_format.format(attempt, attempt_limit)
                status = sm.get_execution(execution_id).status
                if status in (models.Execution.PENDING, models.Execution.STARTED):
                    # We cancel execution only if it is still running:
                    sm.update_execution_status(execution_id, models.Execution.CANCELLING, msg)
                canceled = True
    if canceled:
        return utils.EXIT_RETRY_LIMIT_EXCEEDED
    status = sm.get_execution(execution_id).status
    if status == models.Execution.FAILED:
        return utils.EXIT_ERROR
    return utils.EXIT_OK
示例#3
0
def _wait_for_execution_finish(execution_id, attempt_limit, sm):
    canceled = False
    for event in _events_generator(execution_id, sm):
        if (not canceled and event.get('event_type') == 'task_failed'):
            attempt = utils.event_task_attempts(event)
            if (attempt is not None and attempt_limit >= 0
                    and attempt >= attempt_limit):
                # We need to cancel executions:
                msg_format = 'Retry limit exceeded, current: {0}, limit: {1}'
                msg = msg_format.format(attempt, attempt_limit)
                status = sm.get_execution(execution_id).status
                if status in (models.Execution.PENDING,
                              models.Execution.STARTED):
                    # We cancel execution only if it is still running:
                    sm.update_execution_status(execution_id,
                                               models.Execution.CANCELLING,
                                               msg)
                canceled = True
    if canceled:
        return utils.EXIT_RETRY_LIMIT_EXCEEDED
    status = sm.get_execution(execution_id).status
    if status == models.Execution.FAILED:
        return utils.EXIT_ERROR
    return utils.EXIT_OK
示例#4
0
 def test_task_attempts_from_event(self):
     event = {
         u'event_type': u'task_failed',
         u'timestamp': u'2015-07-09 13:10:11.885+0000',
         u'@timestamp': u'2015-07-09T13:10:11.889Z',
         u'message_code': None,
         u'@version': u'1',
         u'context': {
             u'deployment_id': u'nc2',
             u'task_current_retries': 3,
             u'task_id': u'9cabd4fc-0608-4c29-870c-dec054103fe9',
             u'blueprint_id': u'nc',
             u'plugin': u'diamond',
             u'task_target': u'nodejs_host_6afd6',
             u'node_name': u'nodejs_host',
             u'workflow_id': u'hosts_software_install',
             u'node_id': u'nodejs_host_6afd6',
             u'task_name': u'diamond_agent.tasks.install',
             u'operation': u'cloudify.interfaces.monitoring_agent.install',
             u'task_total_retries': -1,
             u'execution_id': u'5a557b53-c2f3-4b36-96b6-e6587e972422',
         },
         u'message': {
             u'text':
             u'Task failed \'diamond_agent.tasks.install\' -> '
             'RecoverableError("OSError: [Errno 17] File exists: '
             '\'/home/ubuntu/cloudify.nodejs_host_6afd6/diamond/'
             'collectors/sockstat\'",) [attempt 4]',
             u'arguments':
             None
         },
         u'type': u'cloudify_event',
     }
     expected = 4
     res = utils.event_task_attempts(event)
     self.assertEquals(res, expected)