Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 551107c

Browse files
author
Derik Evangelista
committed
v3: cannot create SI for non-available broker
[#168400228](https://www.pivotaltracker.com/story/show/168400228)
1 parent d126d98 commit 551107c

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

app/controllers/v3/service_instances_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def create_managed(message, space:)
189189
visible_to_current_user?(plan: service_plan) &&
190190
service_plan.visible_in_space?(space)
191191

192+
broker_unavailable! unless service_plan.service_broker.available?
193+
192194
job = ServiceInstanceCreateManaged.new(service_event_repository).create(message)
193195

194196
url_builder = VCAP::CloudController::Presenters::ApiUrlBuilder.new
@@ -277,4 +279,8 @@ def unprocessable_space!
277279
def unprocessable_service_plan!
278280
unprocessable!('Invalid service plan. Ensure that the service plan exists and you have access to it.')
279281
end
282+
283+
def broker_unavailable!
284+
unprocessable!('The service instance cannot be created because there is an operation in progress for the service broker')
285+
end
280286
end

app/models/services/service_broker.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def in_transitional_state?
3838
[ServiceBrokerStateEnum::SYNCHRONIZING, ServiceBrokerStateEnum::DELETE_IN_PROGRESS].include?(self.state)
3939
end
4040

41+
def available?
42+
self.state == ServiceBrokerStateEnum::AVAILABLE
43+
end
44+
4145
def space_scoped?
4246
!!space_id
4347
end

spec/request/service_instances_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,30 @@ def check_filtered_instances(*instances)
933933
end
934934
end
935935

936+
context 'when there is an operation in progress for the service broker' do
937+
let(:service_broker) { service_plan.service_broker }
938+
939+
before do
940+
service_broker.update(state: broker_state)
941+
end
942+
943+
context 'when the service broker is being deleted' do
944+
let(:broker_state) { VCAP::CloudController::ServiceBrokerStateEnum::DELETE_IN_PROGRESS }
945+
it 'fails to create a service instance' do
946+
api_call.call(space_dev_headers)
947+
expect(last_response).to have_status_code(422)
948+
end
949+
end
950+
951+
context 'when the service broker is synchronising the catalog' do
952+
let(:broker_state) { VCAP::CloudController::ServiceBrokerStateEnum::SYNCHRONIZING }
953+
it 'fails to create a service instance' do
954+
api_call.call(space_dev_headers)
955+
expect(last_response).to have_status_code(422)
956+
end
957+
end
958+
end
959+
936960
describe 'service plan checks' do
937961
context 'does not exist' do
938962
let(:service_plan_guid) { 'does-not-exist' }

spec/support/fakes/blueprints.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ module VCAP::CloudController
460460
ServiceBroker.blueprint do
461461
name { Sham.name }
462462
broker_url { Sham.url }
463+
state { ServiceBrokerStateEnum::AVAILABLE }
463464
auth_username { Sham.auth_username }
464465
auth_password { Sham.auth_password }
465466
end

spec/unit/models/services/service_broker_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,31 @@ module VCAP::CloudController
9393
end
9494
end
9595

96+
describe '#available?' do
97+
let(:broker) { ServiceBroker.make }
98+
99+
it 'returns false when state is SYNCHRONIZING' do
100+
broker.state = ServiceBrokerStateEnum::SYNCHRONIZING
101+
expect(broker.available?).to eq false
102+
end
103+
it 'returns false when state is SYNCHRONIZATION_FAILED' do
104+
broker.state = ServiceBrokerStateEnum::SYNCHRONIZATION_FAILED
105+
expect(broker.available?).to eq false
106+
end
107+
it 'returns true when state is AVAILABLE' do
108+
broker.state = ServiceBrokerStateEnum::AVAILABLE
109+
expect(broker.available?).to eq true
110+
end
111+
it 'returns false when state is DELETE_IN_PROGRESS' do
112+
broker.state = ServiceBrokerStateEnum::DELETE_IN_PROGRESS
113+
expect(broker.available?).to eq false
114+
end
115+
it 'returns false when state is DELETE_FAILED' do
116+
broker.state = ServiceBrokerStateEnum::DELETE_FAILED
117+
expect(broker.available?).to eq false
118+
end
119+
end
120+
96121
describe '#destroy' do
97122
let(:service_broker) { ServiceBroker.make }
98123

0 commit comments

Comments
 (0)