Beispiel #1
0
def test_send_status_update(mocker):
    agent_addr = 'mock_addr:12345'
    framework_id = str(uuid.uuid4())
    executor_id = str(uuid.uuid4())
    env = {
        'MESOS_LOCAL': 'true',
        'MESOS_AGENT_ENDPOINT': agent_addr,
        'MESOS_FRAMEWORK_ID': framework_id,
        'MESOS_EXECUTOR_ID': executor_id,
    }
    mocker.patch('os.environ', env)
    exc = mocker.Mock()
    driver = MesosExecutorDriver(exc)
    driver._send = mocker.Mock()
    status = {}
    driver.sendStatusUpdate(status)
    driver._send.assert_called_once_with({
        'type': 'UPDATE',
        'framework_id': {
            'value': framework_id,
        },
        'executor_id': {
            'value': executor_id,
        },
        'update': {
            'status': {
                'timestamp': status['timestamp'],
                'uuid': status['uuid'],
                'source': 'SOURCE_EXECUTOR',
            }
        }
    })
Beispiel #2
0
def test_send_message(mocker):
    agent_addr = 'mock_addr:12345'
    framework_id = str(uuid.uuid4())
    executor_id = str(uuid.uuid4())
    env = {
        'MESOS_LOCAL': 'true',
        'MESOS_AGENT_ENDPOINT': agent_addr,
        'MESOS_FRAMEWORK_ID': framework_id,
        'MESOS_EXECUTOR_ID': executor_id,
    }
    mocker.patch('os.environ', env)
    exc = mocker.Mock()
    driver = MesosExecutorDriver(exc)
    driver._send = mocker.Mock()
    message = ''.join(
        random.choice(string.printable) for _ in range(random.randint(1, 100)))
    message = encode_data(message.encode('utf8'))
    driver.sendFrameworkMessage(message)
    driver._send.assert_called_once_with({
        'type': 'MESSAGE',
        'framework_id': {
            'value': framework_id,
        },
        'executor_id': {
            'value': executor_id,
        },
        'message': {
            'data': message,
        }
    })
Beispiel #3
0
def test_send(mocker):
    agent_addr = 'mock_addr:12345'
    framework_id = str(uuid.uuid4())
    executor_id = str(uuid.uuid4())
    env = {
        'MESOS_LOCAL': 'true',
        'MESOS_AGENT_ENDPOINT': agent_addr,
        'MESOS_FRAMEWORK_ID': framework_id,
        'MESOS_EXECUTOR_ID': executor_id,
    }
    mocker.patch('os.environ', env)
    exc = mocker.Mock()
    driver = MesosExecutorDriver(exc)
    resp = mocker.Mock(status=200, read=mocker.Mock(return_value='{}'))
    conn = mocker.Mock(getresponse=mocker.Mock(return_value=resp))
    driver._get_conn = mocker.Mock(return_value=conn)
    assert driver._send({}) == {}
    driver._get_conn.assert_called_once_with()
    conn.request.assert_called_once_with(
        'POST',
        '/api/v1/executor',
        body=json.dumps({}).encode('utf-8'),
        headers={'Content-Type': 'application/json'})