def test_restart_with_lock(self): command = RestartCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, []) fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) mock_api = fake_context.get_api("test") mock_api.restart.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) updater_config = UpdaterConfig(mock_options.batch_size, mock_options.restart_threshold, mock_options.watch_secs, mock_options.max_per_instance_failures, mock_options.max_total_failures) mock_api.restart.assert_called_once_with( jobkey, mock_options.instance_spec.instance, updater_config, mock_options.healthcheck_interval_seconds, config=None) self.assert_lock_message(fake_context)
def test_restart_with_lock(self): command = RestartCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, []) fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) mock_api = fake_context.get_api("test") mock_api.restart.return_value = AuroraClientCommandTest.create_blank_response( ResponseCode.LOCK_ERROR, "Error.") with pytest.raises(Context.CommandError): command.execute(fake_context) restart_settings = RestartSettings( batch_size=mock_options.batch_size, restart_threshold=mock_options.restart_threshold, max_per_instance_failures=mock_options.max_per_instance_failures, max_total_failures=mock_options.max_total_failures, watch_secs=mock_options.watch_secs, health_check_interval_seconds=mock_options.healthcheck_interval_seconds) mock_api.restart.assert_called_once_with( jobkey, mock_options.instance_spec.instance, restart_settings, config=None) self.assert_lock_message(fake_context)
def test_restart_inactive_instance_spec(self): command = RestartCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, [1]) 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.message == "Invalid instance parameter: [1]"
def test_restart_opens_url(self): command = RestartCommand() jobkey = AuroraJobKey("cluster", "role", "env", "job") mock_options = mock_verb_options(command) mock_options.instance_spec = TaskInstanceKey(jobkey, None) mock_options.strict = True mock_options.open_browser = True fake_context = FakeAuroraCommandContext() fake_context.set_options(mock_options) fake_api = fake_context.fake_api fake_api.restart.return_value = AuroraClientCommandTest.create_simple_success_response() command.execute(fake_context) assert self.mock_webbrowser.mock_calls == [ call("http://something_or_other/scheduler/role/env/job") ]