Beispiel #1
0
def test_get_local_slave_state_connection_error(mock_getfqdn, mock_requests_get):
    fake_request = requests.Request("GET", url="doesnt_matter")
    mock_getfqdn.return_value = "fake_hostname"
    mock_requests_get.side_effect = requests.ConnectionError("fake_message", request=fake_request)

    with raises(mesos_tools.MesosSlaveConnectionError):
        mesos_tools.get_local_slave_state()
Beispiel #2
0
def test_get_local_slave_state_connection_error(mock_getfqdn,
                                                mock_requests_get):
    fake_request = requests.Request("GET", url="doesnt_matter")
    mock_getfqdn.return_value = "fake_hostname"
    mock_requests_get.side_effect = requests.ConnectionError(
        "fake_message", request=fake_request)

    with raises(mesos_tools.MesosSlaveConnectionError):
        mesos_tools.get_local_slave_state()
Beispiel #3
0
def test_get_local_slave_state_connection_error(
    mock_getfqdn,
    mock_requests_get,
):
    fake_request = requests.Request('GET', url='doesnt_matter')
    mock_getfqdn.return_value = 'fake_hostname'
    mock_requests_get.side_effect = requests.ConnectionError(
        'fake_message',
        request=fake_request,
    )

    with raises(mesos_tools.MesosSlaveConnectionError):
        mesos_tools.get_local_slave_state()
def test_get_local_slave_state_connection_error(
    mock_getfqdn,
    mock_requests_get,
):
    fake_request = requests.Request('GET', url='doesnt_matter')
    mock_getfqdn.return_value = 'fake_hostname'
    mock_requests_get.side_effect = requests.ConnectionError(
        'fake_message',
        request=fake_request,
    )

    with raises(mesos_tools.MesosSlaveConnectionError):
        mesos_tools.get_local_slave_state()
Beispiel #5
0
def get_running_task_ids_from_mesos_slave():
    state = mesos_tools.get_local_slave_state()
    frameworks = state.get('frameworks')
    executors = [
        ex for fw in frameworks for ex in fw.get('executors', [])
        if u'TASK_RUNNING' in [t[u'state'] for t in ex.get('tasks', [])]
    ]
    return set([e["id"] for e in executors])
Beispiel #6
0
def marathon_services_running_here_works(context):
    with mock.patch('paasta_tools.mesos_tools.socket.getfqdn',
                    return_value='mesosslave'):
        discovered = paasta_tools.marathon_tools.marathon_services_running_here(
        )
        assert len(discovered) == 1, (repr(discovered),
                                      get_local_slave_state())
        assert discovered == [(u'test_marathon_app', u'instance', mock.ANY)
                              ], repr(discovered)
def get_running_task_ids_from_mesos_slave():
    state = mesos_tools.get_local_slave_state()
    frameworks = state.get("frameworks")
    executors = [
        ex
        for fw in frameworks
        for ex in fw.get("executors", [])
        if u"TASK_RUNNING" in [t[u"state"] for t in ex.get("tasks", [])]
    ]
    return set([e["id"] for e in executors])
Beispiel #8
0
def marathon_services_running_here():
    """See what marathon services are being run by a mesos-slave on this host.
    :returns: A list of triples of (service, instance, port)"""
    slave_state = get_local_slave_state()
    frameworks = [fw for fw in slave_state.get('frameworks', []) if 'marathon' in fw['name']]
    executors = [ex for fw in frameworks for ex in fw.get('executors', [])
                 if u'TASK_RUNNING' in [t[u'state'] for t in ex.get('tasks', [])]]
    srv_list = []
    for executor in executors:
        (srv_name, srv_instance, _, __) = deformat_job_id(executor['id'])
        srv_port = int(re.findall('[0-9]+', executor['resources']['ports'])[0])
        srv_list.append((srv_name, srv_instance, srv_port))
    return srv_list
Beispiel #9
0
def marathon_services_running_here():
    """See what marathon services are being run by a mesos-slave on this host.
    :returns: A list of triples of (service, instance, port)"""
    slave_state = get_local_slave_state()
    frameworks = [fw for fw in slave_state.get('frameworks', []) if 'marathon' in fw['name']]
    executors = [ex for fw in frameworks for ex in fw.get('executors', [])
                 if 'TASK_RUNNING' in [t['state'] for t in ex.get('tasks', [])]]
    srv_list = []
    for executor in executors:
        app_id, task_uuid = get_app_id_and_task_uuid_from_executor_id(executor['id'])
        (srv_name, srv_instance, _, __) = deformat_job_id(app_id)
        srv_port = int(re.findall('[0-9]+', executor['resources']['ports'])[0])
        srv_list.append((srv_name, srv_instance, srv_port))
    return srv_list
def marathon_services_running_here():
    """See what marathon services are being run by a mesos-slave on this host.
    :returns: A list of triples of (service, instance, port)"""
    slave_state = get_local_slave_state()
    frameworks = [fw for fw in slave_state.get("frameworks", []) if "marathon" in fw["name"]]
    executors = [
        ex
        for fw in frameworks
        for ex in fw.get("executors", [])
        if u"TASK_RUNNING" in [t[u"state"] for t in ex.get("tasks", [])]
    ]
    srv_list = []
    for executor in executors:
        app_id, task_uuid = get_app_id_and_task_uuid_from_executor_id(executor["id"])
        (srv_name, srv_instance, _, __) = deformat_job_id(app_id)
        srv_port = int(re.findall("[0-9]+", executor["resources"]["ports"])[0])
        srv_list.append((srv_name, srv_instance, srv_port))
    return srv_list
Beispiel #11
0
def marathon_services_running_here_works(context):
    with mock.patch('paasta_tools.mesos_tools.socket.getfqdn', return_value='mesosslave'):
        discovered = paasta_tools.marathon_tools.marathon_services_running_here()
        assert len(discovered) == 1, (repr(discovered), get_local_slave_state())
        assert discovered == [('test_marathon_app', 'instance', mock.ANY)], repr(discovered)
def get_running_task_ids_from_mesos_slave():
    state = mesos_tools.get_local_slave_state()
    frameworks = state.get('frameworks')
    executors = [ex for fw in frameworks for ex in fw.get('executors', [])
                 if u'TASK_RUNNING' in [t[u'state'] for t in ex.get('tasks', [])]]
    return set([e["id"] for e in executors])