def test_kill_lock_error_batches(self): """Verify that the batch kill path short circuits and includes the lock error message.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result( AuroraClientCommandTest.create_query_call_result( AuroraClientCommandTest.create_scheduled_task(1, ScheduleStatus.RUNNING))) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with( self.TEST_JOBKEY, mock_options.instance_spec.instance, config=None) self.assert_lock_message(fake_context)
def test_kill_nobatch_passes_config(self): """Verify that the no batch code path correctly passes job config to the api.""" command = KillCommand() config = self.get_valid_config() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, []) mock_options.no_batching = True mock_options.config = config fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_config(config) mock_api = fake_context.get_api('test') fake_context.add_expected_query_result( AuroraClientCommandTest.create_empty_task_result()) mock_api.kill_job.return_value = self.create_simple_success_response() command.execute(fake_context) assert mock_api.kill_job.mock_calls == [ call(self.TEST_JOBKEY, mock_options.instance_spec.instance, config=config) ]
def test_kill_updating_error_nobatch(self): """Verify that the no batch code path correctly includes the lock error message.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, []) mock_options.no_batching = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result( self.create_query_call_result(), job_key=self.TEST_JOBKEY) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.JOB_UPDATING_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with( self.TEST_JOBKEY, mock_options.instance_spec.instance, config=None, message=None) self.assert_lock_message(fake_context)
def test_kill_batched_passes_config(self): """Verify that the batched code path correctly passes job config to the api.""" command = KillCommand() config = self.get_valid_config() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False mock_options.config = config fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_config(config) fake_context.add_expected_query_result( AuroraClientCommandTest.create_query_call_result( AuroraClientCommandTest.create_scheduled_task(1, ScheduleStatus.RUNNING))) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = self.create_simple_success_response() command.execute(fake_context) assert mock_api.kill_job.mock_calls == [ call(self.TEST_JOBKEY, mock_options.instance_spec.instance, config=config) ]
def test_kill_lock_error_batches(self): """Verify that the batch kill path short circuits and includes the lock error message.""" command = KillCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result( AuroraClientCommandTest.create_query_call_result( AuroraClientCommandTest.create_scheduled_task( 1, ScheduleStatus.RUNNING))) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with( jobkey, mock_options.instance_spec.instance) self.assert_lock_message(fake_context)
def test_kill_batched_passes_config(self): """Verify that the batched code path correctly passes job config to the api.""" command = KillCommand() config = self.get_valid_config() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False mock_options.config = config fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_config(config) fake_context.add_expected_query_result( AuroraClientCommandTest.create_query_call_result( AuroraClientCommandTest.create_scheduled_task( 1, ScheduleStatus.RUNNING))) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = self.create_simple_success_response() command.execute(fake_context) assert mock_api.kill_job.mock_calls == [ call(self.TEST_JOBKEY, mock_options.instance_spec.instance, config=config, message=None) ]
def test_kill_nobatch_passes_config(self): """Verify that the no batch code path correctly passes job config to the api.""" command = KillCommand() config = self.get_valid_config() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, []) mock_options.no_batching = True mock_options.config = config fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_config(config) mock_api = fake_context.get_api('test') fake_context.add_expected_query_result( self.create_query_call_result(), job_key=self.TEST_JOBKEY) fake_context.add_expected_query_result(AuroraClientCommandTest.create_empty_task_result()) mock_api.kill_job.return_value = self.create_simple_success_response() command.execute(fake_context) assert mock_api.kill_job.mock_calls == [ call(self.TEST_JOBKEY, mock_options.instance_spec.instance, config=config, message=None) ]
def test_kill_updating_error_batches(self): """Verify that the batch kill path short circuits and includes the lock error message.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result(self.create_query_call_result(), job_key=self.TEST_JOBKEY) fake_context.add_expected_query_result( AuroraClientCommandTest.create_query_call_result( AuroraClientCommandTest.create_scheduled_task( 1, ScheduleStatus.RUNNING))) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.JOB_UPDATING_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with( self.TEST_JOBKEY, mock_options.instance_spec.instance, config=None, message=None) self.assert_lock_message(fake_context)
def test_kill_batched_queries_active_instances(self): """Verify that the batch kill operates on active instances only.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result(AuroraClientCommandTest.create_empty_task_result()) command.execute(fake_context) message = "No tasks to kill found for job %s" % self.TEST_JOBKEY.to_path() assert fake_context.get_err()[0] == message
def test_kill_inactive_instance_spec(self): """Verify the instance spec is validated in a batched kill.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.no_batching = False mock_options.strict = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result(AuroraClientCommandTest.create_empty_task_result()) with pytest.raises(Context.CommandError) as e: command.execute(fake_context) assert e.value.message == "Invalid instance parameter: [1]"
def test_kill_opens_url(self): """Verify the kill commands opens the job page if requested""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, [1]) mock_options.open_browser = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result(AuroraClientCommandTest.create_empty_task_result()) command.execute(fake_context) assert self.mock_webbrowser.mock_calls == [ call("http://something_or_other/scheduler/bozo/test/hello") ]
def test_kill_batched_queries_active_instances(self): """Verify that the batch kill operates on active instances only.""" command = KillCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result(AuroraClientCommandTest.create_empty_task_result()) command.execute(fake_context) assert fake_context.get_err()[0] == "No tasks to kill found for job cluster/role/env/job"
def test_kill_batched_queries_active_instances(self): """Verify that the batch kill operates on active instances only.""" command = KillCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, [1]) mock_options.no_batching = False fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_context.add_expected_query_result( AuroraClientCommandTest.create_empty_task_result()) command.execute(fake_context) assert fake_context.get_err( )[0] == "No tasks to kill found for job cluster/role/env/job"
def test_kill_lock_error_nobatch(self): """Verify that the no batch code path correctly includes the lock error message.""" command = KillCommand() mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(self.TEST_JOBKEY, []) mock_options.no_batching = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with( self.TEST_JOBKEY, mock_options.instance_spec.instance, config=None) self.assert_lock_message(fake_context)
def test_kill_lock_error_nobatch(self): """Verify that the no batch code path correctly includes the lock error message.""" command = KillCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, []) mock_options.no_batching = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) mock_api = fake_context.get_api('test') mock_api.kill_job.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) mock_api.kill_job.assert_called_once_with(jobkey, mock_options.instance_spec.instance) self.assert_lock_message(fake_context)