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

Commit 62c35f4

Browse files
v3(services): Prevent route binding while other operations are in progress
[#174540070](https://www.pivotaltracker.com/story/show/174540070)
1 parent a5d2d96 commit 62c35f4

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

app/actions/service_route_binding_create.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ def initialize(service_event_repository)
66
end
77

88
def precursor(service_instance, route)
9-
not_supported! unless service_instance.route_service?
10-
not_bindable! unless service_instance.bindable?
11-
route_is_internal! if route.try(:internal?)
12-
space_mismatch! unless route.space == service_instance.space
13-
already_exists! if route.service_instance == service_instance
14-
already_bound! if route.service_instance
9+
validate!(service_instance, route)
1510

1611
RouteBinding.new.save_with_new_operation(
1712
{
@@ -98,6 +93,16 @@ class BindingNotRetrievable < StandardError; end
9893

9994
private
10095

96+
def validate!(service_instance, route)
97+
not_supported! unless service_instance.route_service?
98+
not_bindable! unless service_instance.bindable?
99+
route_is_internal! if route.try(:internal?)
100+
space_mismatch! unless route.space == service_instance.space
101+
already_exists! if route.service_instance == service_instance
102+
already_bound! if route.service_instance
103+
operation_in_progress! if service_instance.operation_in_progress?
104+
end
105+
101106
attr_reader :service_event_repository
102107

103108
def fetch_last_operation(client, binding)
@@ -154,6 +159,10 @@ def bindings_retrievable?(binding)
154159
binding.service_instance.service.bindings_retrievable
155160
end
156161

162+
def operation_in_progress!
163+
raise UnprocessableCreate.new('There is an operation in progress for the service instance')
164+
end
165+
157166
def route_is_internal!
158167
raise UnprocessableCreate.new('Route services cannot be bound to internal routes')
159168
end

spec/request/service_route_bindings_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,21 @@
504504
expect(VCAP::CloudController::RouteBinding.all).to be_empty
505505
end
506506
end
507+
508+
context 'there is an operation in progress for the service instance' do
509+
it 'responds with 422' do
510+
service_instance.save_with_new_operation({}, { type: 'guacamole', state: 'in progress' })
511+
512+
post '/v3/service_route_bindings', request.to_json, space_dev_headers
513+
514+
expect(last_response).to have_status_code(422)
515+
expect(parsed_response['errors']).to include(include({
516+
'detail' => include('There is an operation in progress for the service instance'),
517+
'title' => 'CF-UnprocessableEntity',
518+
'code' => 10008,
519+
}))
520+
end
521+
end
507522
end
508523

509524
context 'user-provided service instance' do

spec/unit/actions/service_route_binding_create_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ module V3
120120
)
121121
end
122122
end
123+
124+
context 'when there is an operation in progress for the service instance' do
125+
it 'raises an error' do
126+
service_instance.save_with_new_operation({}, { type: 'tacos', state: 'in progress' })
127+
128+
expect {
129+
action.precursor(service_instance, route)
130+
}.to raise_error(
131+
ServiceRouteBindingCreate::UnprocessableCreate,
132+
'There is an operation in progress for the service instance'
133+
)
134+
end
135+
end
123136
end
124137

125138
context 'user-provided service instance' do

0 commit comments

Comments
 (0)