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 } })
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, } })
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, } })
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 } })
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, } })
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 } })
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, } })
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, } })
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, } })
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 } })
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 }, })
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'})
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 }, })
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 } })
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'] } })
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'}, } })
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 } })
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' } )