def test_get_tasks_from_app_id(): with contextlib.nested( mock.patch( 'paasta_tools.mesos_tools.get_running_tasks_from_active_frameworks', autospec=True), ) as ( mock_get_running_tasks_from_active_frameworks, ): mock_task_1 = mock.Mock(slave={'hostname': 'host1'}) mock_task_2 = mock.Mock(slave={'hostname': 'host2'}) mock_task_3 = mock.Mock(slave={'hostname': 'host2.domain'}) mock_get_running_tasks_from_active_frameworks.return_value = [ mock_task_1, mock_task_2, mock_task_3 ] ret = mesos_tools.get_tasks_from_app_id('app_id') mock_get_running_tasks_from_active_frameworks.assert_called_with( 'app_id') expected = [mock_task_1, mock_task_2, mock_task_3] assert len(expected) == len(ret) and sorted(ret) == sorted(expected) ret = mesos_tools.get_tasks_from_app_id('app_id', slave_hostname='host2') mock_get_running_tasks_from_active_frameworks.assert_called_with( 'app_id') expected = [mock_task_2, mock_task_3] assert len(expected) == len(ret) and sorted(ret) == sorted(expected)
def test_get_tasks_from_app_id(): with contextlib.nested( mock.patch('paasta_tools.mesos_tools.get_running_tasks_from_active_frameworks', autospec=True), ) as ( mock_get_running_tasks_from_active_frameworks, ): mock_task_1 = mock.Mock(slave={'hostname': 'host1'}) mock_task_2 = mock.Mock(slave={'hostname': 'host2'}) mock_task_3 = mock.Mock(slave={'hostname': 'host2.domain'}) mock_get_running_tasks_from_active_frameworks.return_value = [mock_task_1, mock_task_2, mock_task_3] ret = mesos_tools.get_tasks_from_app_id('app_id') mock_get_running_tasks_from_active_frameworks.assert_called_with('app_id') expected = [mock_task_1, mock_task_2, mock_task_3] assert len(expected) == len(ret) and sorted(ret) == sorted(expected) ret = mesos_tools.get_tasks_from_app_id('app_id', slave_hostname='host2') mock_get_running_tasks_from_active_frameworks.assert_called_with('app_id') expected = [mock_task_2, mock_task_3] assert len(expected) == len(ret) and sorted(ret) == sorted(expected)
def instance_tasks(request): status = instance_status(request) slave_hostname = request.swagger_data.get('slave_hostname', None) verbose = request.swagger_data.get('verbose', False) try: mstatus = status['marathon'] except KeyError: raise ApiFailure("Only marathon tasks supported", 400) tasks = get_tasks_from_app_id(mstatus['app_id'], slave_hostname=slave_hostname) if verbose: tasks = [add_executor_info(task) for task in tasks] tasks = [add_slave_info(task) for task in tasks] return [task._Task__items for task in tasks]
def instance_tasks(request): status = instance_status(request) slave_hostname = request.swagger_data.get('slave_hostname', None) verbose = request.swagger_data.get('verbose', False) try: mstatus = status['marathon'] except KeyError: raise ApiFailure("Only marathon tasks supported", 400) tasks = get_tasks_from_app_id(mstatus['app_id'], slave_hostname=slave_hostname) if verbose: tasks = [add_executor_info(task) for task in tasks] tasks = [add_slave_info(task) for task in tasks] return [task._Task__items for task in tasks]