コード例 #1
0
ファイル: test_scheduler.py プロジェクト: douban/pymesos
def test_reconcile_operations(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    op_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    operations = [
        {
            'operation_id': {
                'value': id
            }
        }
        for id in op_ids
    ]
    driver.reconcileOperations(operations)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.reconcileOperations(operations)
    driver._send.assert_called_once_with({
        'type': 'RECONCILE_OPERATIONS',
        'framework_id': {
            'value': ID
        },
        'reconcile_operations': {
            'operations': operations
        }
    })
コード例 #2
0
ファイル: test_scheduler.py プロジェクト: douban/pymesos
def test_send_framework_message(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    executor_id = {'value': str(uuid.uuid4())}
    agent_id = {'value': str(uuid.uuid4())}
    message = ''.join(random.choice(string.printable)
                      for _ in range(random.randint(1, 100)))
    message = encode_data(message.encode('utf-8'))
    driver.sendFrameworkMessage(executor_id, agent_id, message)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.sendFrameworkMessage(executor_id, agent_id, message)
    driver._send.assert_called_once_with({
        'type': 'MESSAGE',
        'framework_id': {
            'value': ID
        },
        'message': {
            'agent_id': agent_id,
            'executor_id': executor_id,
            'data': message,
        }
    })
コード例 #3
0
ファイル: test_scheduler.py プロジェクト: douban/pymesos
def test_acknowledge_operation_status_update(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    agent_id = dict(value=str(uuid.uuid4()))
    operation_id = dict(value=str(uuid.uuid4()))
    uid = encode_data(uuid.uuid4().bytes)
    status = {
        'agent_id': agent_id,
        'operation_id': operation_id,
        'uuid': uid
    }
    driver.acknowledgeOperationStatusUpdate(status)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.acknowledgeOperationStatusUpdate(status)
    driver._send.assert_called_once_with({
        'type': 'ACKNOWLEDGE_OPERATION_STATUS',
        'framework_id': {
            'value': ID
        },
        'acknowledge_operation_status': {
            'agent_id': agent_id,
            'operation_id': operation_id,
            'uuid': uid,
        }
    })
コード例 #4
0
ファイル: test_scheduler.py プロジェクト: yuyang0/pymesos
def test_reconcile_tasks(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    task_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    tasks = [
        {
            'task_id': {
                'value': id
            }
        }
        for id in task_ids
    ]
    driver.reconcileTasks(tasks)
    driver._send.assert_called_once_with({
        'type': 'RECONCILE',
        'framework_id': {
            'value': ID
        },
        'reconcile': {
            'tasks': tasks
        }
    })
コード例 #5
0
ファイル: test_scheduler.py プロジェクト: yanchaomars/pymesos
def test_accept_offers(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    operations = [{
        'type': 'LAUNCH',
        'launch': {
            'task_infos': [{
                'name': '1',
            }, {
                'name': '2',
            }]
        }
    }]
    driver.acceptOffers(offer_ids, operations)
    driver._send.assert_called_once_with({
        'type': 'ACCEPT',
        'framework_id': {
            'value': ID
        },
        'accept': {
            'offer_ids': offer_ids,
            'operations': operations,
        }
    })
コード例 #6
0
def test_request_resources(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    requests = [{
        'agent_id': {
            'value': str(uuid.uuid4())
        },
        'resources': {}
    } for _ in range(random.randint(1, 10))]
    driver.requestResources(requests)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.requestResources(requests)
    driver._send.assert_called_once_with({
        'type': 'REQUEST',
        'framework_id': {
            'value': ID
        },
        'request': {
            'requests': requests
        }
    })
コード例 #7
0
def test_acknowledge_operation_status_update(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    agent_id = dict(value=str(uuid.uuid4()))
    operation_id = dict(value=str(uuid.uuid4()))
    uid = encode_data(uuid.uuid4().bytes)
    status = {'agent_id': agent_id, 'operation_id': operation_id, 'uuid': uid}
    driver.acknowledgeOperationStatusUpdate(status)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.acknowledgeOperationStatusUpdate(status)
    driver._send.assert_called_once_with({
        'type': 'ACKNOWLEDGE_OPERATION_STATUS',
        'framework_id': {
            'value': ID
        },
        'acknowledge_operation_status': {
            'agent_id': agent_id,
            'operation_id': operation_id,
            'uuid': uid,
        }
    })
コード例 #8
0
def test_send_framework_message(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    executor_id = {'value': str(uuid.uuid4())}
    agent_id = {'value': str(uuid.uuid4())}
    message = ''.join(
        random.choice(string.printable) for _ in range(random.randint(1, 100)))
    message = encode_data(message.encode('utf-8'))
    driver.sendFrameworkMessage(executor_id, agent_id, message)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.sendFrameworkMessage(executor_id, agent_id, message)
    driver._send.assert_called_once_with({
        'type': 'MESSAGE',
        'framework_id': {
            'value': ID
        },
        'message': {
            'agent_id': agent_id,
            'executor_id': executor_id,
            'data': message,
        }
    })
コード例 #9
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_accept_offers(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    operations = [{
        'type': 'LAUNCH',
        'launch': {
            'task_infos': [
                {
                    'name': '1',
                },
                {
                    'name': '2',
                }
            ]
        }
    }]
    driver.acceptOffers(offer_ids, operations)
    driver._send.assert_called_once_with({
        'type': 'ACCEPT',
        'framework_id': {
            'value': ID
        },
        'accept': {
            'offer_ids': offer_ids,
            'operations': operations,
        }
    })
コード例 #10
0
ファイル: test_scheduler.py プロジェクト: yuyang0/pymesos
def test_acknowledge_status_update(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    agent_id = dict(value=str(uuid.uuid4()))
    task_id = dict(value=str(uuid.uuid4()))
    uid = encode_data(uuid.uuid4().bytes)
    status = {
        'agent_id': agent_id,
        'task_id': task_id,
        'uuid': uid
    }
    driver.acknowledgeStatusUpdate(status)
    driver._send.assert_called_once_with({
        'type': 'ACKNOWLEDGE',
        'framework_id': {
            'value': ID
        },
        'acknowledge': {
            'agent_id': agent_id,
            'task_id': task_id,
            'uuid': uid
        }
    })
コード例 #11
0
def test_reconcile_operations(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    op_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    operations = [
        {
            'operation_id': {
                'value': id
            }
        }
        for id in op_ids
    ]
    driver.reconcileOperations(operations)
    driver._send.assert_not_called()
    driver._stream_id = 'a-stream-id'
    driver.reconcileOperations(operations)
    driver._send.assert_called_once_with({
        'type': 'RECONCILE_OPERATIONS',
        'framework_id': {
            'value': ID
        },
        'reconcile_operations': {
            'operations': operations
        }
    })
コード例 #12
0
ファイル: test_scheduler.py プロジェクト: yanchaomars/pymesos
def test_revive_offers(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver._stream_id = str(uuid.uuid4())
    driver.reviveOffers()
    driver._send.assert_called_once_with({
        'type': 'REVIVE',
        'framework_id': {
            'value': ID
        },
    })
コード例 #13
0
ファイル: test_scheduler.py プロジェクト: yanchaomars/pymesos
def test_send(mocker):
    sched = mocker.Mock()
    framework = mocker.Mock()
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    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/scheduler',
        body=json.dumps({}).encode('utf-8'),
        headers={'Content-Type': 'application/json'})
コード例 #14
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_revive_offers(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver._stream_id = str(uuid.uuid4())
    driver.reviveOffers()
    driver._send.assert_called_once_with({
        'type': 'REVIVE',
        'framework_id': {
            'value': ID
        },
    })
コード例 #15
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_teardown(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver.stream_id = str(uuid.uuid4())
    assert driver.connected
    driver._teardown()
    driver._send.assert_called_once_with({
        'type': 'TEARDOWN',
        'framework_id': {
            'value': ID
        },
    })
コード例 #16
0
ファイル: test_scheduler.py プロジェクト: yanchaomars/pymesos
def test_teardown(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver.stream_id = str(uuid.uuid4())
    assert driver.connected
    driver._teardown()
    driver._send.assert_called_once_with({
        'type': 'TEARDOWN',
        'framework_id': {
            'value': ID
        },
    })
コード例 #17
0
ファイル: test_scheduler.py プロジェクト: yanchaomars/pymesos
def test_decline_offer(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    driver.declineOffer(offer_ids)
    driver._send.assert_called_once_with({
        'type': 'DECLINE',
        'framework_id': {
            'value': ID
        },
        'decline': {
            'offer_ids': offer_ids
        }
    })
コード例 #18
0
def test_suppress_offers_roles(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver._stream_id = str(uuid.uuid4())
    driver.suppressOffers(['role1', 'role2'])
    driver._send.assert_called_once_with({
        'type': 'SUPPRESS',
        'framework_id': {
            'value': ID
        },
        'suppress': {
            'roles': ['role1', 'role2']
        }
    })
コード例 #19
0
ファイル: test_scheduler.py プロジェクト: douban/pymesos
def test_kill_task(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver.killTask({"value": "my-task"})
    driver._send.assert_not_called()
    driver._stream_id = str(uuid.uuid4())
    driver.killTask({"value": "my-task"})
    driver._send.assert_called_once_with({
        'type': 'KILL',
        'framework_id': {'value': ID},
        'kill': {
            'task_id': {'value': 'my-task'},
        }
    })
コード例 #20
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_decline_offer(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    driver.declineOffer(offer_ids)
    driver._send.assert_called_once_with({
        'type': 'DECLINE',
        'framework_id': {
            'value': ID
        },
        'decline': {
            'offer_ids': offer_ids
        }
    })
コード例 #21
0
def test_kill_task(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver.killTask({"value": "my-task"})
    driver._send.assert_not_called()
    driver._stream_id = str(uuid.uuid4())
    driver.killTask({"value": "my-task"})
    driver._send.assert_called_once_with({
        'type': 'KILL',
        'framework_id': {'value': ID},
        'kill': {
            'task_id': {'value': 'my-task'},
        }
    })
コード例 #22
0
ファイル: test_scheduler.py プロジェクト: douban/pymesos
def test_suppress_offers_roles(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    driver._stream_id = str(uuid.uuid4())
    driver.suppressOffers(['role1', 'role2'])
    driver._send.assert_called_once_with({
        'type': 'SUPPRESS',
        'framework_id': {
            'value': ID
        },
        'suppress': {
            'roles': ['role1', 'role2']
        }
    })
コード例 #23
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_request_resources(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    requests = [{
        'agent_id': {'value': str(uuid.uuid4())},
        'resources': {}
    } for _ in range(random.randint(1, 10))]
    driver.requestResources(requests)
    driver._send.assert_called_once_with({
        'type': 'REQUEST',
        'framework_id': {
            'value': ID
        },
        'request': {
            'requests': requests
        }
    })
コード例 #24
0
ファイル: test_scheduler.py プロジェクト: windreamer/pymesos
def test_send(mocker):
    sched = mocker.Mock()
    framework = mocker.Mock()
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    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/scheduler',
        body=json.dumps({
        }).encode('utf-8'),
        headers={
            'Content-Type': 'application/json'
        }
    )