Skip to content

Commit 0b04c15

Browse files
committed
Update stck state validation error and warning messages
Signed-off-by: Rashed Kamal <[email protected]>
1 parent cf5d813 commit 0b04c15

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

lib/cloud_controller/stack_state_validator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ class RestrictedStackError < StackValidationError; end
66
def self.validate_for_new_app!(stack)
77
return [] if stack.active?
88

9-
raise DisabledStackError.new("Stack '#{stack.name}' is disabled and cannot be used for staging new applications. #{stack.description}") if stack.disabled?
9+
raise DisabledStackError.new(build_stack_error(stack, StackStates::STACK_DISABLED)) if stack.disabled?
1010

11-
raise RestrictedStackError.new("Stack '#{stack.name}' is restricted and cannot be used for staging new applications. #{stack.description}") if stack.restricted?
11+
raise RestrictedStackError.new(build_stack_error(stack, StackStates::STACK_RESTRICTED)) if stack.restricted?
1212

1313
stack.deprecated? ? [build_deprecation_warning(stack)] : []
1414
end
1515

1616
def self.validate_for_restaging!(stack)
1717
return [] if stack.active? || stack.restricted?
1818

19-
raise DisabledStackError.new("Stack '#{stack.name}' is disabled and cannot be used for staging new applications. #{stack.description}") if stack.disabled?
19+
raise DisabledStackError.new(build_stack_error(stack, StackStates::STACK_DISABLED)) if stack.disabled?
2020

2121
stack.deprecated? ? [build_deprecation_warning(stack)] : []
2222
end
2323

24+
def self.build_stack_error(stack, state)
25+
"ERROR: Staging failed. The stack '#{stack.name}' is '#{state}' and cannot be used for staging."
26+
end
27+
2428
def self.build_deprecation_warning(stack)
2529
"Stack '#{stack.name}' is deprecated and will be removed in the future. #{stack.description}"
2630
end

spec/request/builds_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@
222222
post '/v3/builds', create_request.to_json, developer_headers
223223

224224
expect(last_response.status).to eq(422)
225-
expect(parsed_response['errors'].first['detail']).to include('disabled')
226-
expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging new applications')
225+
expect(parsed_response['errors'].first['detail']).to include('DISABLED')
226+
expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging')
227227
expect(VCAP::CloudController::BuildModel.count).to eq(0)
228228
end
229229
end
@@ -252,7 +252,8 @@
252252
post '/v3/builds', create_request.to_json, developer_headers
253253

254254
expect(last_response.status).to eq(422)
255-
expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging new applications')
255+
expect(parsed_response['errors'].first['detail']).to include('cannot be used for staging')
256+
expect(parsed_response['errors'].first['detail']).to include('RESTRICTED')
256257
expect(VCAP::CloudController::BuildModel.count).to eq(0)
257258
end
258259
end

spec/request/v2/apps_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@
951951
expect(last_response.status).to eq(422)
952952
parsed_response = Oj.load(last_response.body)
953953
expect(parsed_response['error_code']).to eq('CF-StackValidationFailed')
954-
expect(parsed_response['description']).to include('disabled')
954+
expect(parsed_response['description']).to include('DISABLED')
955955
expect(parsed_response['description']).to include('cflinuxfs2')
956956
end
957957
end
@@ -1639,10 +1639,9 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
16391639
expect(last_response.status).to eq(422)
16401640
parsed_response = Oj.load(last_response.body)
16411641
expect(parsed_response['error_code']).to eq('CF-StackValidationFailed')
1642-
expect(parsed_response['description']).to include('disabled')
1642+
expect(parsed_response['description']).to include('DISABLED')
16431643
expect(parsed_response['description']).to include('cannot be used for staging')
16441644
expect(parsed_response['description']).to include('cflinuxfs2')
1645-
expect(parsed_response['description']).to include('Migrate to cflinuxfs4')
16461645
end
16471646

16481647
it 'does not expose stack state field in error response' do
@@ -1674,7 +1673,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
16741673
expect(last_response.status).to eq(422)
16751674
parsed_response = Oj.load(last_response.body)
16761675
expect(parsed_response['error_code']).to eq('CF-StackValidationFailed')
1677-
expect(parsed_response['description']).to include('cannot be used for staging new applications')
1676+
expect(parsed_response['description']).to include('cannot be used for staging')
16781677
expect(parsed_response['description']).to include('cflinuxfs3')
16791678
end
16801679
end

spec/unit/actions/build_create_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ module VCAP::CloudController
466466
action.create_and_stage(package:, lifecycle:)
467467
end.to raise_error(CloudController::Errors::ApiError) do |error|
468468
expect(error.name).to eq('StackValidationFailed')
469-
expect(error.message).to include('disabled')
470-
expect(error.message).to include('cannot be used for staging new applications')
469+
expect(error.message).to include('DISABLED')
470+
expect(error.message).to include('cannot be used for staging')
471471
end
472472
end
473473

@@ -496,7 +496,8 @@ module VCAP::CloudController
496496
action.create_and_stage(package:, lifecycle:)
497497
end.to raise_error(CloudController::Errors::ApiError) do |error|
498498
expect(error.name).to eq('StackValidationFailed')
499-
expect(error.message).to include('annot be used for staging new applications')
499+
expect(error.message).to include('annot be used for staging')
500+
expect(error.message).to include('RESTRICTED')
500501
end
501502
end
502503

spec/unit/actions/v2/app_stage_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ module V2
269269
it 'raises StackValidationFailed error' do
270270
expect { action.stage(process) }.to raise_error(CloudController::Errors::ApiError) do |error|
271271
expect(error.name).to eq('StackValidationFailed')
272-
expect(error.message).to include('disabled')
272+
expect(error.message).to include('DISABLED')
273273
expect(error.message).to include('cannot be used for staging')
274274
end
275275
end
@@ -292,7 +292,8 @@ module V2
292292

293293
expect { action.stage(process) }.to raise_error(CloudController::Errors::ApiError) do |error|
294294
expect(error.name).to eq('StackValidationFailed')
295-
expect(error.message).to include('cannot be used for staging new applications')
295+
expect(error.message).to include('cannot be used for staging')
296+
expect(error.message).to include('RESTRICTED')
296297
end
297298
end
298299
end

spec/unit/lib/cloud_controller/stack_state_validator_spec.rb

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module VCAP::CloudController
4545
it 'raise RestrictedStackError' do
4646
expect do
4747
StackStateValidator.validate_for_new_app!(stack)
48-
end.to raise_error(StackStateValidator::RestrictedStackError, /Stack '#{stack.name}' is restricted and cannot be used for staging new applications./)
48+
end.to raise_error(StackStateValidator::RestrictedStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_RESTRICTED}' and cannot be used for staging./)
4949
end
5050

5151
it 'includes stack name in error message' do
@@ -54,12 +54,6 @@ module VCAP::CloudController
5454
end.to raise_error(StackStateValidator::RestrictedStackError, /#{stack.name}/)
5555
end
5656

57-
it 'includes stack description in error message' do
58-
expect do
59-
StackStateValidator.validate_for_new_app!(stack)
60-
end.to raise_error(StackStateValidator::RestrictedStackError, /#{stack.description}/)
61-
end
62-
6357
it 'raises RestrictedStackError which is a StackStateValidator::Error' do
6458
expect do
6559
StackStateValidator.validate_for_new_app!(stack)
@@ -73,20 +67,14 @@ module VCAP::CloudController
7367
it 'returns a disabled error message' do
7468
expect do
7569
StackStateValidator.validate_for_new_app!(stack)
76-
end.to raise_error(StackStateValidator::DisabledStackError, /Stack '#{stack.name}' is disabled and cannot be used for staging new applications./)
70+
end.to raise_error(StackStateValidator::DisabledStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_DISABLED}' and cannot be used for staging./)
7771
end
7872

7973
it 'includes stack name in error message' do
8074
expect do
8175
StackStateValidator.validate_for_new_app!(stack)
8276
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.name}/)
8377
end
84-
85-
it 'includes stack description in error message' do
86-
expect do
87-
StackStateValidator.validate_for_new_app!(stack)
88-
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.description}/)
89-
end
9078
end
9179
end
9280

@@ -146,20 +134,14 @@ module VCAP::CloudController
146134
it 'returns a disabled error message' do
147135
expect do
148136
StackStateValidator.validate_for_restaging!(stack)
149-
end.to raise_error(StackStateValidator::DisabledStackError, /Stack '#{stack.name}' is disabled and cannot be used for staging new applications./)
137+
end.to raise_error(StackStateValidator::DisabledStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_DISABLED}' and cannot be used for staging./)
150138
end
151139

152140
it 'includes stack name in error message' do
153141
expect do
154142
StackStateValidator.validate_for_restaging!(stack)
155143
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.name}/)
156144
end
157-
158-
it 'includes stack description in error message' do
159-
expect do
160-
StackStateValidator.validate_for_restaging!(stack)
161-
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.description}/)
162-
end
163145
end
164146
end
165147

0 commit comments

Comments
 (0)