Пример #1
0
def test_get_draining_hosts(
    mock_get_hosts_with_state,
):
    get_draining_hosts()
    assert mock_get_hosts_with_state.call_count == 1
    expected_args = mock.call(state='draining_machines')
    assert mock_get_hosts_with_state.call_args == expected_args
Пример #2
0
def get_tasks_by_state_for_app(app, drain_method, service, nerve_ns,
                               bounce_health_params, system_paasta_config):
    tasks_by_state = {
        'happy': set(),
        'unhappy': set(),
        'draining': set(),
        'at_risk': set(),
    }

    happy_tasks = bounce_lib.get_happy_tasks(app, service, nerve_ns,
                                             system_paasta_config,
                                             **bounce_health_params)
    draining_hosts = get_draining_hosts()
    for task in app.tasks:
        if drain_method.is_draining(task):
            state = 'draining'
        elif task in happy_tasks:
            if task.host in draining_hosts:
                state = 'at_risk'
            else:
                state = 'happy'
        else:
            state = 'unhappy'
        tasks_by_state[state].add(task)

    return tasks_by_state
Пример #3
0
def get_num_at_risk_tasks(app):
    """Determine how many of an application's tasks are running on
    at-risk (Mesos Maintenance Draining) hosts.

    :param app: A marathon application
    :returns: An integer representing the number of tasks running on at-risk hosts
    """
    hosts_tasks_running_on = [task.host for task in app.tasks]
    draining_hosts = get_draining_hosts()
    num_at_risk_tasks = 0
    for host in hosts_tasks_running_on:
        if host in draining_hosts:
            num_at_risk_tasks += 1
    log.debug("%s has %d tasks running on at-risk hosts." % (app.id, num_at_risk_tasks))
    return num_at_risk_tasks
Пример #4
0
def get_tasks_by_state_for_app(app, drain_method, service, nerve_ns, bounce_health_params,
                               system_paasta_config):
    tasks_by_state = {
        'happy': set(),
        'unhappy': set(),
        'draining': set(),
        'at_risk': set(),
    }

    happy_tasks = bounce_lib.get_happy_tasks(app, service, nerve_ns, system_paasta_config, **bounce_health_params)
    draining_hosts = get_draining_hosts()
    for task in app.tasks:
        if drain_method.is_draining(task):
            state = 'draining'
        elif task in happy_tasks:
            if task.host in draining_hosts:
                state = 'at_risk'
            else:
                state = 'happy'
        else:
            state = 'unhappy'
        tasks_by_state[state].add(task)

    return tasks_by_state
def test_get_draining_hosts(mock_get_hosts_with_state, ):
    get_draining_hosts()
    assert mock_get_hosts_with_state.call_count == 1
    expected_args = mock.call(state='draining_machines')
    assert mock_get_hosts_with_state.call_args == expected_args