diff --git a/app/actions/deployment_create.rb b/app/actions/deployment_create.rb index 67a92c6c60..d2b13e4481 100644 --- a/app/actions/deployment_create.rb +++ b/app/actions/deployment_create.rb @@ -83,7 +83,25 @@ def create(app:, user_audit_info:, message:) deployment rescue RevisionResolver::NoUpdateRollback, Sequel::ValidationFailed, AppStart::InvalidApp => e - error = DeploymentCreate::Error.new(e.message) + raise handle_deployment_create_error(e, app) + end + + def handle_deployment_create_error(e, app) + space_quota_errors = %w[space_quota_exceeded space_app_instance_limit_exceeded] + org_quota_errors = %w[quota_exceeded app_instance_limit_exceeded] + space_error_msg = " for space #{app.space.name}. This space's quota may not be large enough to support rolling deployments or your configured max-in-flight." + org_error_msg_1 = " for organization #{app.organization.name}. " + org_error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight." + org_error_msg = org_error_msg_1 + org_error_msg_2 + error_message = e.message + + if space_quota_errors.any? { |substring| e.message.include?(substring) } + error_message += space_error_msg + elsif org_quota_errors.any? { |substring| e.message.include?(substring) } + error_message += org_error_msg + end + + error = DeploymentCreate::Error.new(error_message) error.set_backtrace(e.backtrace) raise error end diff --git a/spec/unit/actions/deployment_create_spec.rb b/spec/unit/actions/deployment_create_spec.rb index 5f2f6cfa7f..0526d4bae4 100644 --- a/spec/unit/actions/deployment_create_spec.rb +++ b/spec/unit/actions/deployment_create_spec.rb @@ -605,6 +605,18 @@ module VCAP::CloudController end end + context 'when the app fails to start due to space errors' do + before do + allow(VCAP::CloudController::AppStart).to receive(:start).and_raise(VCAP::CloudController::AppStart::InvalidApp.new('memory space_quota_exceeded')) + end + + it 'raises a DeploymentCreate::Error' do + error_msg_1 = "memory space_quota_exceeded for space #{app.space.name}. " + error_msg_2 = "This space's quota may not be large enough to support rolling deployments or your configured max-in-flight." + expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2) + end + end + context 'uses the web_instances from the message' do # stopped apps come up immediately and don't go through the deployment updater let(:web_instances) { 12 } @@ -637,7 +649,9 @@ module VCAP::CloudController let(:web_instances) { 11 } it 'throws an error' do - expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded') + error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. " + error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight." + expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2) end end @@ -683,7 +697,9 @@ module VCAP::CloudController let(:memory_in_mb) { 4000 } it 'throws an error' do - expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded') + error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. " + error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight." + expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2) end end @@ -717,16 +733,6 @@ module VCAP::CloudController expect(deployment.canary_steps).to eq([{ 'instance_weight' => 40 }, { 'instance_weight' => 80 }]) end end - - context 'when the app fails to start' do - before do - allow(VCAP::CloudController::AppStart).to receive(:start).and_raise(VCAP::CloudController::AppStart::InvalidApp.new('memory quota_exceeded')) - end - - it 'raises a DeploymentCreate::Error' do - expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded') - end - end end end @@ -880,7 +886,9 @@ module VCAP::CloudController let(:web_instances) { 11 } it 'throws an error' do - expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded') + error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. " + error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight." + expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2) end end @@ -935,7 +943,9 @@ module VCAP::CloudController let(:memory_in_mb) { 4000 } it 'throws an error' do - expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded') + error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. " + error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight." + expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2) end end