def test_determine_error(self): """Tests that a pre-task successfully determines the correct error""" scale_errors = [ ScaleDatabaseError(), ScaleIOError(), ScaleOperationalError(), MissingSetting('') ] for scale_error in scale_errors: config = ExecutionConfiguration() config.create_tasks(['pre']) config.set_task_ids(self.job_exe.get_cluster_id()) task = PreTask('agent_1', self.job_exe, self.job_exe.job_type, config) update = job_test_utils.create_task_status_update( task.id, task.agent_id, TaskStatusUpdate.RUNNING, now()) task.update(update) update = job_test_utils.create_task_status_update( task.id, task.agent_id, TaskStatusUpdate.FAILED, now(), exit_code=scale_error.exit_code) error = task.determine_error(update) self.assertEqual(scale_error.error_name, error.name)
def ready(self): """Registers basic errors""" from error.exceptions import ScaleDatabaseError, ScaleIOError, ScaleOperationalError, register_error register_error(ScaleDatabaseError()) register_error(ScaleIOError()) register_error(ScaleOperationalError())
def test_scale_pre_steps_io_error(self, mock_job_exe, mock_sys_exit): """Tests executing scale_pre_steps when an IO error occurs.""" # Set up mocks mock_job_exe.objects.get_job_exe_with_job_and_job_type.return_value.get_job_interface.return_value.perform_pre_steps.side_effect = IOError() # Call method to test cmd = PreCommand() cmd.run_from_argv(['manage.py', 'scale_pre_steps', '-i', str(self.job_exe.id)]) # Check results mock_sys_exit.assert_called_with(ScaleIOError().exit_code)
def test_scale_post_steps_io_error(self, mock_env_vars, mock_job_exe_manager, mock_sys_exit): """Tests executing scale_post_steps when an IO error occurs.""" # Set up mocks def get_env_vars(name, *args, **kwargs): return str(self.job.id) if name == 'SCALE_JOB_ID' else str( self.job_exe.exe_num) mock_env_vars.side_effect = get_env_vars mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.side_effect = IOError( ) # Call method to test cmd = PostCommand() cmd.run_from_argv(['manage.py', 'scale_post_steps']) # Check results mock_sys_exit.assert_called_with(ScaleIOError().exit_code)
def test_determine_error(self): """Tests that a pre-task successfully determines the correct error""" scale_errors = [ ScaleDatabaseError(), ScaleIOError(), ScaleOperationalError(), MissingSetting('') ] for scale_error in scale_errors: task = PreTask(self.job_exe) update = job_test_utils.create_task_status_update( task.id, task.agent_id, TaskStatusUpdate.RUNNING, now()) task.update(update) update = job_test_utils.create_task_status_update( task.id, task.agent_id, TaskStatusUpdate.FAILED, now(), exit_code=scale_error.exit_code) error = task.determine_error(update) self.assertEqual(scale_error.error_name, error.name)