Skip to content

Commit 6d8a01d

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

File tree

6 files changed

+51
-67
lines changed

6 files changed

+51
-67
lines changed

lib/cloud_controller/stack_state_validator.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ 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

13-
stack.deprecated? ? [build_deprecation_warning(stack)] : []
13+
stack.deprecated? ? [build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)] : []
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

21-
stack.deprecated? ? [build_deprecation_warning(stack)] : []
21+
stack.deprecated? ? [build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)] : []
2222
end
2323

24-
def self.build_deprecation_warning(stack)
25-
"Stack '#{stack.name}' is deprecated and will be removed in the future. #{stack.description}"
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+
28+
def self.build_deprecation_warning(stack, state)
29+
"WARNING: The stack '#{stack.name}' is '#{state}' and will be removed in the future."
2630
end
2731
end
2832
end

spec/request/builds_spec.rb

Lines changed: 15 additions & 13 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
@@ -300,18 +301,19 @@
300301
expect(last_response.status).to eq(201)
301302
expect(parsed_response['state']).to eq('STAGING')
302303
expect(parsed_response['warnings']).to be_present
303-
expect(parsed_response['warnings'][0]['detail']).to include('deprecated')
304-
expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3 stack is deprecated')
304+
expect(parsed_response['warnings'][0]['detail']).to include('DEPRECATED')
305+
expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3')
306+
expect(parsed_response['warnings'][0]['detail']).to include('WARNING')
305307
end
306308

307-
it 'includes warming in response headers' do
309+
it 'includes warning in response headers' do
308310
post '/v3/builds', create_request.to_json, developer_headers
309311

310312
expect(last_response.status).to eq(201)
311313
expect(last_response.headers['X-Cf-Warnings']).to be_present
312314
warning = CGI.unescape(last_response.headers['X-Cf-Warnings'])
313-
expect(warning).to include('deprecated')
314-
expect(warning).to include('cflinuxfs3 stack is deprecated')
315+
expect(warning).to include('DEPRECATED')
316+
expect(warning).to include('cflinuxfs3')
315317
end
316318
end
317319

@@ -328,19 +330,19 @@
328330
expect(last_response.status).to eq(201)
329331
expect(parsed_response['state']).to eq('STAGING')
330332
expect(parsed_response['warnings']).to be_present
331-
expect(parsed_response['warnings'][0]['detail']).to include('deprecated')
332-
expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3 stack is deprecated')
333+
expect(parsed_response['warnings'][0]['detail']).to include('DEPRECATED')
334+
expect(parsed_response['warnings'][0]['detail']).to include('cflinuxfs3')
333335
expect(app_model.builds_dataset.count).to eq(2)
334336
end
335337

336-
it 'includes warming in response headers' do
338+
it 'includes warning in response headers' do
337339
post '/v3/builds', create_request.to_json, developer_headers
338340

339341
expect(last_response.status).to eq(201)
340342
expect(last_response.headers['X-Cf-Warnings']).to be_present
341343
warning = CGI.unescape(last_response.headers['X-Cf-Warnings'])
342-
expect(warning).to include('deprecated')
343-
expect(warning).to include('cflinuxfs3 stack is deprecated')
344+
expect(warning).to include('DEPRECATED')
345+
expect(warning).to include('cflinuxfs3')
344346
end
345347
end
346348
end

spec/request/v2/apps_spec.rb

Lines changed: 6 additions & 8 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
@@ -972,8 +972,8 @@
972972
expect(last_response.status).to eq(201)
973973
expect(last_response.headers['X-Cf-Warnings']).to be_present
974974
decoded_warning = CGI.unescape(last_response.headers['X-Cf-Warnings'])
975-
expect(decoded_warning).to include('deprecated')
976-
expect(decoded_warning).to include('EOL Dec 2025')
975+
expect(decoded_warning).to include('DEPRECATED')
976+
expect(decoded_warning).to include('cflinuxfs3')
977977
end
978978
end
979979
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
@@ -1716,9 +1715,8 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
17161715

17171716
expect(last_response.headers['X-Cf-Warnings']).to be_present
17181717
decoded_warning = CGI.unescape(last_response.headers['X-Cf-Warnings'])
1719-
expect(decoded_warning).to include('deprecated')
1718+
expect(decoded_warning).to include('DEPRECATED')
17201719
expect(decoded_warning).to include('cflinuxfs3')
1721-
expect(decoded_warning).to include('EOL Dec 2025')
17221720
end
17231721

17241722
it 'does not expose stack state field in response body' do

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ module V2
239239
action.stage(process)
240240

241241
expect(action.warnings).not_to be_empty
242-
expect(action.warnings.first).to include('deprecated')
242+
expect(action.warnings.first).to include('DEPRECATED')
243243
expect(action.warnings.first).to include('cflinuxfs3')
244-
expect(action.warnings.first).to include('EOL Dec 2025')
245244
end
246245
end
247246

@@ -269,7 +268,7 @@ module V2
269268
it 'raises StackValidationFailed error' do
270269
expect { action.stage(process) }.to raise_error(CloudController::Errors::ApiError) do |error|
271270
expect(error.name).to eq('StackValidationFailed')
272-
expect(error.message).to include('disabled')
271+
expect(error.message).to include('DISABLED')
273272
expect(error.message).to include('cannot be used for staging')
274273
end
275274
end
@@ -292,7 +291,8 @@ module V2
292291

293292
expect { action.stage(process) }.to raise_error(CloudController::Errors::ApiError) do |error|
294293
expect(error.name).to eq('StackValidationFailed')
295-
expect(error.message).to include('cannot be used for staging new applications')
294+
expect(error.message).to include('cannot be used for staging')
295+
expect(error.message).to include('RESTRICTED')
296296
end
297297
end
298298
end

spec/unit/lib/cloud_controller/stack_state_validator_spec.rb

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ module VCAP::CloudController
2323
result = StackStateValidator.validate_for_new_app!(stack)
2424
expect(result).to be_an(Array)
2525
expect(result.size).to eq(1)
26-
expect(result.first).to include("Stack '#{stack.name}' is deprecated and will be removed in the future. #{stack.description}")
26+
expect(result.first).to include("stack '#{stack.name}' is '#{StackStates::STACK_DEPRECATED}' and will be removed in the future")
2727
end
2828

2929
it 'returns a warning message with stack name' do
3030
result = StackStateValidator.validate_for_new_app!(stack)
3131
warning = result.first
3232
expect(warning).to include(stack.name)
33-
expect(warning).to include(stack.description)
34-
expect(warning).to include('deprecated')
33+
expect(warning).to include('DEPRECATED')
3534
end
3635

3736
it 'does not raise an error' do
@@ -45,7 +44,7 @@ module VCAP::CloudController
4544
it 'raise RestrictedStackError' do
4645
expect do
4746
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./)
47+
end.to raise_error(StackStateValidator::RestrictedStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_RESTRICTED}' and cannot be used for staging./)
4948
end
5049

5150
it 'includes stack name in error message' do
@@ -54,12 +53,6 @@ module VCAP::CloudController
5453
end.to raise_error(StackStateValidator::RestrictedStackError, /#{stack.name}/)
5554
end
5655

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-
6356
it 'raises RestrictedStackError which is a StackStateValidator::Error' do
6457
expect do
6558
StackStateValidator.validate_for_new_app!(stack)
@@ -73,20 +66,14 @@ module VCAP::CloudController
7366
it 'returns a disabled error message' do
7467
expect do
7568
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./)
69+
end.to raise_error(StackStateValidator::DisabledStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_DISABLED}' and cannot be used for staging./)
7770
end
7871

7972
it 'includes stack name in error message' do
8073
expect do
8174
StackStateValidator.validate_for_new_app!(stack)
8275
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.name}/)
8376
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
9077
end
9178
end
9279

@@ -111,15 +98,14 @@ module VCAP::CloudController
11198
result = StackStateValidator.validate_for_restaging!(stack)
11299
expect(result).to be_an(Array)
113100
expect(result.size).to eq(1)
114-
expect(result.first).to include("Stack '#{stack.name}' is deprecated and will be removed in the future. #{stack.description}")
101+
expect(result.first).to include("stack '#{stack.name}' is '#{StackStates::STACK_DEPRECATED}' and will be removed in the future")
115102
end
116103

117104
it 'returns a warning message with stack name' do
118105
result = StackStateValidator.validate_for_restaging!(stack)
119106
warning = result.first
120107
expect(warning).to include(stack.name)
121-
expect(warning).to include(stack.description)
122-
expect(warning).to include('deprecated')
108+
expect(warning).to include('DEPRECATED')
123109
end
124110

125111
it 'does not raise an error' do
@@ -146,43 +132,36 @@ module VCAP::CloudController
146132
it 'returns a disabled error message' do
147133
expect do
148134
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./)
135+
end.to raise_error(StackStateValidator::DisabledStackError, /The stack '#{stack.name}' is '#{StackStates::STACK_DISABLED}' and cannot be used for staging./)
150136
end
151137

152138
it 'includes stack name in error message' do
153139
expect do
154140
StackStateValidator.validate_for_restaging!(stack)
155141
end.to raise_error(StackStateValidator::DisabledStackError, /#{stack.name}/)
156142
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
163143
end
164144
end
165145

166146
describe '.build_deprecation_warning' do
167147
let(:stack) { Stack.make(name: 'cflinuxfs3', description: 'End of life December 2025') }
168148

169149
it 'returns formatted warning string' do
170-
warning = StackStateValidator.build_deprecation_warning(stack)
150+
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
171151
expect(warning).to be_a(String)
172152
expect(warning).to include('cflinuxfs3')
173-
expect(warning).to include('deprecated')
174-
expect(warning).to include('End of life December 2025')
153+
expect(warning).to include('DEPRECATED')
175154
end
176155

177156
it 'includes stack name when description is empty' do
178157
stack.description = ''
179-
warning = StackStateValidator.build_deprecation_warning(stack)
158+
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
180159
expect(warning).to include('cflinuxfs3')
181160
end
182161

183162
it 'handles nil description' do
184163
stack.description = nil
185-
warning = StackStateValidator.build_deprecation_warning(stack)
164+
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
186165
expect(warning).to include('cflinuxfs3')
187166
end
188167
end

0 commit comments

Comments
 (0)