Skip to content

Commit 767d5be

Browse files
committed
Added warning for restaging app on restricted stack
Signed-off-by: Rashed Kamal <rashed.kamal@broadcom.com>
1 parent 2b79df5 commit 767d5be

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

lib/cloud_controller/stack_state_validator.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ def self.validate_for_new_app!(stack)
1010

1111
raise RestrictedStackError.new(build_stack_error(stack, StackStates::STACK_RESTRICTED)) if stack.restricted?
1212

13-
stack.deprecated? ? [build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)] : []
13+
stack.deprecated? ? [build_stack_warning(stack, StackStates::STACK_DEPRECATED)] : []
1414
end
1515

1616
def self.validate_for_restaging!(stack)
17-
return [] if stack.active? || stack.restricted?
17+
return [] if stack.active?
18+
19+
return [build_stack_warning(stack, StackStates::STACK_RESTRICTED)] if stack.restricted?
20+
21+
return [build_stack_warning(stack, StackStates::STACK_DEPRECATED)] if stack.deprecated?
1822

1923
raise DisabledStackError.new(build_stack_error(stack, StackStates::STACK_DISABLED)) if stack.disabled?
2024

21-
stack.deprecated? ? [build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)] : []
25+
[]
2226
end
2327

2428
def self.build_stack_error(stack, state)
2529
"ERROR: Staging failed. The stack '#{stack.name}' is '#{state}' and cannot be used for staging."
2630
end
2731

28-
def self.build_deprecation_warning(stack, state)
32+
def self.build_stack_warning(stack, state)
2933
"WARNING: The stack '#{stack.name}' is '#{state}' and will be removed in the future."
3034
end
3135
end

spec/request/v2/apps_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,10 +1763,10 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
17631763
expect(last_response.status).to eq(201)
17641764
end
17651765

1766-
it 'does not include warnings header' do
1766+
it 'includes warning in header' do
17671767
post "/v2/apps/#{process.guid}/restage", nil, headers_for(user)
17681768

1769-
expect(last_response.headers['X-Cf-Warnings']).to be_nil
1769+
expect(last_response.headers['X-Cf-Warnings']).not_to be_nil
17701770
end
17711771
end
17721772
end

spec/unit/actions/v2/app_stage_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ module V2
302302
BuildModel.make(app: process.app, state: 'STAGED')
303303
end
304304

305-
it 'allows staging without warnings' do
305+
it 'allows staging with warnings' do
306306
expect { action.stage(process) }.not_to raise_error
307-
expect(action.warnings).to be_empty
307+
expect(action.warnings).not_to be_empty
308308
end
309309
end
310310
end

spec/unit/lib/cloud_controller/stack_state_validator_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ module VCAP::CloudController
116116
context 'when stack is RESTRICTED' do
117117
let(:stack) { Stack.make(state: StackStates::STACK_RESTRICTED, description: 'My RESTRICTED stack') }
118118

119-
it 'returns empty warnings' do
119+
it 'returns warnings for restaging' do
120120
result = StackStateValidator.validate_for_restaging!(stack)
121-
expect(result).to eq([])
121+
warning = result.first
122+
expect(warning).to include(stack.name)
123+
expect(warning).to include('RESTRICTED')
122124
end
123125

124126
it 'does not raise an error' do
@@ -147,21 +149,21 @@ module VCAP::CloudController
147149
let(:stack) { Stack.make(name: 'cflinuxfs3', description: 'End of life December 2025') }
148150

149151
it 'returns formatted warning string' do
150-
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
152+
warning = StackStateValidator.build_stack_warning(stack, StackStates::STACK_DEPRECATED)
151153
expect(warning).to be_a(String)
152154
expect(warning).to include('cflinuxfs3')
153155
expect(warning).to include('DEPRECATED')
154156
end
155157

156158
it 'includes stack name when description is empty' do
157159
stack.description = ''
158-
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
160+
warning = StackStateValidator.build_stack_warning(stack, StackStates::STACK_DEPRECATED)
159161
expect(warning).to include('cflinuxfs3')
160162
end
161163

162164
it 'handles nil description' do
163165
stack.description = nil
164-
warning = StackStateValidator.build_deprecation_warning(stack, StackStates::STACK_DEPRECATED)
166+
warning = StackStateValidator.build_stack_warning(stack, StackStates::STACK_DEPRECATED)
165167
expect(warning).to include('cflinuxfs3')
166168
end
167169
end
@@ -205,7 +207,7 @@ module VCAP::CloudController
205207

206208
it 'allows RESTRICTED without warnings' do
207209
result = StackStateValidator.validate_for_restaging!(restricted_stack)
208-
expect(result).to be_empty
210+
expect(result).not_to be_empty
209211
end
210212

211213
it 'rejects DISABLED' do

0 commit comments

Comments
 (0)