Skip to content

Commit 9016168

Browse files
authored
Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight (#4402)
* Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix error message to be more descriptive * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix Rubocop errors * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Only update the error message for rolling deployments based on code review * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Revert changes that affect all actions since we only want to update rolling reployments * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix rubocop errors * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Update error message for space_app_instance_limit_exceeded * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix Rubocop errors * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Cleanup for Rubocop errors * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Update error message for org errors during rolling deployment * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix merge issues * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix Rubocop error * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Update from code review comments and cleanup * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Revert unintended change * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Fix rubocop errors * Improve error messaging for creating a Deployment that will violate quotas with high max-in-flight Rename method and remove unnecessary raise
1 parent 24bad0c commit 9016168

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

app/actions/deployment_create.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,27 @@ def create(app:, user_audit_info:, message:)
8383

8484
deployment
8585
rescue RevisionResolver::NoUpdateRollback, Sequel::ValidationFailed, AppStart::InvalidApp => e
86-
error = DeploymentCreate::Error.new(e.message)
86+
raise enhanced_deployment_create_error(e, app)
87+
end
88+
89+
def enhanced_deployment_create_error(e, app)
90+
space_quota_errors = %w[space_quota_exceeded space_app_instance_limit_exceeded]
91+
org_quota_errors = %w[quota_exceeded app_instance_limit_exceeded]
92+
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."
93+
org_error_msg_1 = " for organization #{app.organization.name}. "
94+
org_error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight."
95+
org_error_msg = org_error_msg_1 + org_error_msg_2
96+
error_message = e.message
97+
98+
if space_quota_errors.any? { |substring| e.message.include?(substring) }
99+
error_message += space_error_msg
100+
elsif org_quota_errors.any? { |substring| e.message.include?(substring) }
101+
error_message += org_error_msg
102+
end
103+
104+
error = DeploymentCreate::Error.new(error_message)
87105
error.set_backtrace(e.backtrace)
88-
raise error
106+
error
89107
end
90108

91109
def create_deployment_process(app, deployment_guid, revision, process_instances)

spec/unit/actions/deployment_create_spec.rb

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,18 @@ module VCAP::CloudController
605605
end
606606
end
607607

608+
context 'when the app fails to start due to space errors' do
609+
before do
610+
allow(VCAP::CloudController::AppStart).to receive(:start).and_raise(VCAP::CloudController::AppStart::InvalidApp.new('memory space_quota_exceeded'))
611+
end
612+
613+
it 'raises a DeploymentCreate::Error' do
614+
error_msg_1 = "memory space_quota_exceeded for space #{app.space.name}. "
615+
error_msg_2 = "This space's quota may not be large enough to support rolling deployments or your configured max-in-flight."
616+
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2)
617+
end
618+
end
619+
608620
context 'uses the web_instances from the message' do
609621
# stopped apps come up immediately and don't go through the deployment updater
610622
let(:web_instances) { 12 }
@@ -637,7 +649,9 @@ module VCAP::CloudController
637649
let(:web_instances) { 11 }
638650

639651
it 'throws an error' do
640-
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded')
652+
error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. "
653+
error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight."
654+
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2)
641655
end
642656
end
643657

@@ -683,7 +697,9 @@ module VCAP::CloudController
683697
let(:memory_in_mb) { 4000 }
684698

685699
it 'throws an error' do
686-
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded')
700+
error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. "
701+
error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight."
702+
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2)
687703
end
688704
end
689705

@@ -717,16 +733,6 @@ module VCAP::CloudController
717733
expect(deployment.canary_steps).to eq([{ 'instance_weight' => 40 }, { 'instance_weight' => 80 }])
718734
end
719735
end
720-
721-
context 'when the app fails to start' do
722-
before do
723-
allow(VCAP::CloudController::AppStart).to receive(:start).and_raise(VCAP::CloudController::AppStart::InvalidApp.new('memory quota_exceeded'))
724-
end
725-
726-
it 'raises a DeploymentCreate::Error' do
727-
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded')
728-
end
729-
end
730736
end
731737
end
732738

@@ -880,7 +886,9 @@ module VCAP::CloudController
880886
let(:web_instances) { 11 }
881887

882888
it 'throws an error' do
883-
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded')
889+
error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. "
890+
error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight."
891+
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2)
884892
end
885893
end
886894

@@ -935,7 +943,9 @@ module VCAP::CloudController
935943
let(:memory_in_mb) { 4000 }
936944

937945
it 'throws an error' do
938-
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, 'memory quota_exceeded')
946+
error_msg_1 = "memory quota_exceeded for organization #{app.organization.name}. "
947+
error_msg_2 = "This organization's quota may not be large enough to support rolling deployments or your configured max-in-flight."
948+
expect { DeploymentCreate.create(app:, message:, user_audit_info:) }.to raise_error(DeploymentCreate::Error, error_msg_1 + error_msg_2)
939949
end
940950
end
941951

0 commit comments

Comments
 (0)