def test_mesos_executor_driver_status_update(self): os.environ['MESOS_SLAVE_PID'] = str(self.slave.pid) executor = Executor() driver = PesosExecutorDriver(executor, context=self.context) assert driver.start() == mesos_pb2.DRIVER_RUNNING # wait until registered driver.executor_process.connected.wait(timeout=MAX_TIMEOUT) assert driver.executor_process.connected.is_set() task_status = mesos_pb2.TaskStatus( task_id=mesos_pb2.TaskID(value='task-id'), state=mesos_pb2.TASK_FAILED, ) assert driver.send_status_update( task_status) == mesos_pb2.DRIVER_RUNNING self.slave.status_update_event.wait(timeout=MAX_TIMEOUT) assert self.slave.status_update_event.is_set() assert len(self.slave.status_updates) == 1 assert self.slave.status_updates[0][0] == driver.executor_process.pid status_update_message = self.slave.status_updates[0][1] status_update = status_update_message.update assert status_update.slave_id == self.slave.slave_id assert status_update.framework_id == mesos_pb2.FrameworkID( value=self.FRAMEWORK_ID) assert status_update.executor_id == mesos_pb2.ExecutorID( value=self.EXECUTOR_ID) assert status_update.status.task_id == task_status.task_id assert status_update.status.state == task_status.state assert status_update.HasField('timestamp') assert status_update.HasField('uuid')
def test_mesos_executor_driver_framework_message(self): os.environ['MESOS_SLAVE_PID'] = str(self.slave.pid) executor = Executor() driver = PesosExecutorDriver(executor, context=self.context) assert driver.start() == mesos_pb2.DRIVER_RUNNING # wait until registered driver.executor_process.connected.wait(timeout=MAX_TIMEOUT) assert driver.executor_process.connected.is_set() # send and wait for framework message assert driver.send_framework_message( b'beep boop beep') == mesos_pb2.DRIVER_RUNNING self.slave.framework_message_event.wait(timeout=MAX_TIMEOUT) assert self.slave.framework_message_event.is_set() framework_message = internal.ExecutorToFrameworkMessage( slave_id=self.slave.slave_id, framework_id=mesos_pb2.FrameworkID(value=self.FRAMEWORK_ID), executor_id=mesos_pb2.ExecutorID(value=self.EXECUTOR_ID), data=b'beep boop beep', ) assert len(self.slave.framework_messages) == 1 assert self.slave.framework_messages[0][ 0] == driver.executor_process.pid assert self.slave.framework_messages[0][1] == framework_message, ( '%s != %s' % (self.slave.framework_messages[0][1], framework_message))
def test_mesos_executor_framework_message_delivery(self): os.environ['MESOS_SLAVE_PID'] = str(self.slave.pid) framework_message_event, framework_message_call, framework_message_side_effect = ( self.mock_method()) executor = mock.create_autospec(Executor, spec_set=True) executor.frameworkMessage = mock.Mock( side_effect=framework_message_side_effect) driver = PesosExecutorDriver(executor, context=self.context) assert driver.start() == mesos_pb2.DRIVER_RUNNING # wait until registered driver.executor_process.connected.wait(timeout=MAX_TIMEOUT) assert driver.executor_process.connected.is_set() self.slave.send_framework_message( driver.executor_process.pid, mesos_pb2.FrameworkID(value=self.FRAMEWORK_ID), mesos_pb2.ExecutorID(value=self.EXECUTOR_ID), data=b'beep boop beep', ) framework_message_event.wait(timeout=MAX_TIMEOUT) assert framework_message_event.is_set() assert framework_message_call.mock_calls == [ mock.call(driver, b'beep boop beep') ]
def test_mesos_executor_kill_task(self): os.environ['MESOS_SLAVE_PID'] = str(self.slave.pid) kill_task_event, kill_task_call, kill_task_side_effect = self.mock_method( ) executor = mock.create_autospec(Executor, spec_set=True) executor.killTask = mock.Mock(side_effect=kill_task_side_effect) driver = PesosExecutorDriver(executor, context=self.context) assert driver.start() == mesos_pb2.DRIVER_RUNNING # wait until registered driver.executor_process.connected.wait(timeout=MAX_TIMEOUT) assert driver.executor_process.connected.is_set() # now launch task task_id = mesos_pb2.TaskID(value='task-id') self.slave.send_kill_task( driver.executor_process.pid, mesos_pb2.FrameworkID(value=self.FRAMEWORK_ID), task_id, ) kill_task_event.wait(timeout=MAX_TIMEOUT) assert kill_task_event.is_set() assert kill_task_call.mock_calls == [mock.call(driver, task_id)]
def setUp(self): self.framework_id = mesos_pb2.FrameworkID(value=self.FRAMEWORK_ID) self.framework_info = mesos_pb2.FrameworkInfo( user='******', name='fake_framework_name', ) self.context = Context() self.context.start() self.master = MockMaster() self.context.spawn(self.master) self.close_contexts = []
def setUp(self): command_info = mesos_pb2.CommandInfo(value='wat') framework_id = mesos_pb2.FrameworkID(value=self.FRAMEWORK_ID) executor_id = mesos_pb2.ExecutorID(value=self.EXECUTOR_ID) self.executor_info = mesos_pb2.ExecutorInfo( executor_id=executor_id, framework_id=framework_id, command=command_info, ) self.framework_info = mesos_pb2.FrameworkInfo( user='******', name='fake_framework_name', ) self.context = Context() self.context.start() self.slave = MockSlave( mesos_pb2.SlaveID(value=self.SLAVE_ID), {self.EXECUTOR_ID: self.executor_info}, {self.FRAMEWORK_ID: self.framework_info}, ) self.context.spawn(self.slave) self.close_contexts = []
def test_scheduler_registration(self): registered_event, registered_call, registered_side_effect = self.mock_method() scheduler = mock.create_autospec(Scheduler, spec_set=True) scheduler.registered = mock.Mock(side_effect=registered_side_effect) driver = PesosSchedulerDriver( scheduler, self.framework_info, str(self.master.pid), context=self.context) assert driver.start() == mesos_pb2.DRIVER_RUNNING driver.scheduler_process.connected.wait(timeout=MAX_TIMEOUT) assert driver.scheduler_process.connected.is_set() registered_event.wait(timeout=MAX_TIMEOUT) assert registered_event.is_set() assert len(self.master.frameworks) == 1 framework_id = next(iter(self.master.frameworks)) assert registered_call.mock_calls == [mock.call( driver, mesos_pb2.FrameworkID(value=framework_id), pid_to_master_info(self.master.master_id, self.master.pid))] assert driver.stop() == mesos_pb2.DRIVER_STOPPED
def send_simple(self, to, framework_id, pid): self.send( to, internal.UpdateFrameworkMessage( framework_id=mesos_pb2.FrameworkID(value=framework_id), pid=pid))