def test_launch_tasks(self): """Tests calling TaskManager.launch_tasks()""" task_id = 'task_1' task_name = 'My Task' agent_id = 'agent_1' task_1 = ImplementedTask(task_id, task_name, agent_id) task_id = 'task_2' task_name = 'My Task' agent_id = 'agent_1' task_2 = ImplementedTask(task_id, task_name, agent_id) task_id = 'task_3' task_name = 'My Task' agent_id = 'agent_2' task_3 = ImplementedTask(task_id, task_name, agent_id) when = now() manager = TaskManager() # Duplicate task_3 to test re-launching duplicate tasks manager.launch_tasks([task_1, task_2, task_3, task_3], when) self.assertTrue(task_1.has_been_launched) self.assertEqual(task_1._launched, when) self.assertTrue(task_2.has_been_launched) self.assertEqual(task_2._launched, when) self.assertTrue(task_3.has_been_launched) self.assertEqual(task_3._launched, when)
def test_job_exe_clean_task(self): """Tests the NodeManager where a cleanup task is returned to clean up a job execution""" when = now() node_mgr = NodeManager() node_mgr.register_agents([self.agent_1, self.agent_2]) node_mgr.sync_with_database(scheduler_mgr.config) cleanup_mgr = CleanupManager() cleanup_mgr.update_nodes(node_mgr.get_nodes()) tasks = node_mgr.get_next_tasks(when) task_mgr = TaskManager() # Complete initial cleanup tasks for task in tasks: task_mgr.launch_tasks([task], now()) update = job_test_utils.create_task_status_update( task.id, task.agent_id, TaskStatusUpdate.FINISHED, now()) task_mgr.handle_task_update(update) node_mgr.handle_task_update(update) # Mark image pull done to get rid of image tasks for node in node_mgr.get_nodes(): node._image_pull_completed() node._update_state() job_exe = job_test_utils.create_running_job_exe(agent_id=self.agent_1, node=self.node_1) # Add a job execution to clean up and get the cleanup task for it cleanup_mgr.add_job_execution(job_exe) tasks = node_mgr.get_next_tasks(when) self.assertEqual(len(tasks), 1) task = tasks[0] self.assertEqual(task.agent_id, self.agent_1.agent_id) self.assertFalse(task.is_initial_cleanup) self.assertEqual(len(task.job_exes), 1)
def test_handle_task_update(self): """Tests calling TaskManager.handle_task_update()""" task_id = 'task_1' task_name = 'My Task' agent_id = 'agent_1' task_1 = ImplementedTask(task_id, task_name, agent_id) when_launched = now() manager = TaskManager() manager.launch_tasks([task_1], when_launched) when_finished = datetime.timedelta(seconds=1) update_1 = job_test_utils.create_task_status_update( task_1.id, task_1.agent_id, TaskStatusUpdate.FINISHED, when=when_finished) manager.handle_task_update(update_1) self.assertTrue(task_1.has_ended) self.assertEqual(task_1._ended, when_finished) update_2 = job_test_utils.create_task_status_update( 'task_2', 'New Agent', TaskStatusUpdate.RUNNING, when=now()) manager.handle_task_update(update_2) # Should ignore, no error
def setUp(self): django.setup() self.node_agent = 'agent_1' self.node = node_test_utils.create_node(hostname='host_1', slave_id=self.node_agent) self.job_exe = job_test_utils.create_job_exe(node=self.node) self.task_mgr = TaskManager()
def setUp(self): django.setup() self.agent_id = 'agent_1' self.system_task_mgr = SystemTaskManager() self.task_mgr = TaskManager() # Make sure messaging service is "off" for these tests scheduler_mgr.config.num_message_handlers = 0
def setUp(self): django.setup() # Clear error cache so tests work correctly reset_error_cache() self.agent_id = 'agent' self.node_model_1 = node_test_utils.create_node() self.job_exe_1 = job_test_utils.create_running_job_exe(agent_id=self.agent_id, node=self.node_model_1) self.node_model_2 = node_test_utils.create_node() self.job_exe_2 = job_test_utils.create_running_job_exe(agent_id=self.agent_id, node=self.node_model_2) self.task_mgr = TaskManager() self.job_exe_mgr = JobExecutionManager()
def test_pull_task_change_agent_id(self): """Tests the NodeManager where a node's agent ID changes during a pull task""" when = now() manager = NodeManager() manager.register_agents([self.agent_1, self.agent_2]) manager.sync_with_database(scheduler_mgr.config) for node in manager.get_nodes(): node._last_health_task = when node._initial_cleanup_completed() node._update_state() tasks = manager.get_next_tasks(when) task_mgr = TaskManager() task_2 = None for task in tasks: task_mgr.launch_tasks([task], when) if task.agent_id == self.agent_2.agent_id: task_2 = task # Node 2 changes agent ID to 3 manager.lost_node(self.agent_2.agent_id) manager.register_agents([self.agent_3]) manager.sync_with_database(scheduler_mgr.config) for node in manager.get_nodes(): node._last_health_task = when node._initial_cleanup_completed() node._update_state() # Should get new Docker pull task for node 2 tasks = manager.get_next_tasks(when) self.assertEqual(len(tasks), 1) new_task_2 = tasks[0] self.assertEqual(new_task_2.agent_id, self.agent_3.agent_id) # Task update comes back for original node 2 Docker pull task, manager should ignore with no exception update = job_test_utils.create_task_status_update( task_2.id, task_2.agent_id, TaskStatusUpdate.FAILED, when) task_mgr.handle_task_update(update) manager.handle_task_update(update)
def test_generate_status_json(self): """Tests calling TaskManager.generate_status_json()""" task_id = 'task_1' task_name = 'My Task' agent_id = 'agent_1' task_1 = ImplementedNodeTask(task_id, task_name, agent_id) task_id = 'task_2' task_name = 'My Task' agent_id = 'agent_1' task_2 = ImplementedNodeTask(task_id, task_name, agent_id) task_id = 'task_3' task_name = 'My Task' agent_id = 'agent_1' task_3 = ImplementedSystemTask(task_id, task_name, agent_id) task_id = 'task_4' task_name = 'My Task' agent_id = 'agent_1' task_4 = ImplementedSystemTask(task_id, task_name, agent_id) when = now() manager = TaskManager() manager.launch_tasks([task_1, task_2, task_3, task_4], when) nodes_list = [{'agent_id': 'agent_1'}] manager.generate_status_json(nodes_list) self.assertEqual(nodes_list[0]['node_tasks'][0]['type'], 'impl-node-task') self.assertEqual(nodes_list[0]['node_tasks'][0]['count'], 2) self.assertEqual(nodes_list[0]['system_tasks'][0]['type'], 'impl-system-task') self.assertEqual(nodes_list[0]['system_tasks'][0]['count'], 2)
def setUp(self): django.setup() reset_error_cache() self.task_mgr = TaskManager()
def setUp(self): django.setup() self.task_mgr = TaskManager()