Permalink
Browse files

Validate stack presence before searching for available stager

Raises a user-friendly error if no dea has requested stack
  • Loading branch information...
1 parent c7b097c commit 6591288f28e654e75d23e2e0c8dc428668b26cf8 Maria Shaldibina and Mark Rushakoff committed Mar 20, 2013
Showing with 16 additions and 4 deletions.
  1. +7 −0 lib/cloud_controller/stager_pool.rb
  2. +9 −4 spec/stager_pool_spec.rb
@@ -31,6 +31,7 @@ def process_advertise_message(msg)
def find_stager(stack, memory)
mutex.synchronize do
+ validate_stack_availability(stack)
@stagers.keys.shuffle.each do |id|
stager = @stagers[id]
if stager_expired?(stager)
@@ -43,6 +44,12 @@ def find_stager(stack, memory)
end
end
+ def validate_stack_availability(stack)
+ unless @stagers.find { |_, stager| stager[:advertisement][:stacks].include?(stack) }
+ raise Errors::StackNotFound, "The requested app stack #{stack} is not available on this system."
+ end
+ end
+
private
def stager_expired?(stager)
View
@@ -38,10 +38,15 @@ module VCAP::CloudController
}
end
+ it "raises if there are no stagers with that stack" do
+ subject.process_advertise_message(staging_advertise_msg)
+ expect { subject.find_stager("unknown-stack-name", 0) }.to raise_error(Errors::StackNotFound)
+ end
+
it "only finds registered stagers" do
- expect {
- subject.process_advertise_message(staging_advertise_msg)
- }.to change { subject.find_stager("stack-name", 0) }.from(nil).to("staging-id")
+ expect { subject.find_stager("stack-name", 0) }.to raise_error(Errors::StackNotFound)
+ subject.process_advertise_message(staging_advertise_msg)
+ subject.find_stager("stack-name", 0).should == "staging-id"
end
end
@@ -94,7 +99,7 @@ module VCAP::CloudController
it "only finds deas that can satisfy runtime request" do
subject.process_advertise_message(staging_advertise_msg)
- subject.find_stager("unknown-stack-name", 0).should be_nil
+ expect { subject.find_stager("unknown-stack-name", 0) }.to raise_error(Errors::StackNotFound)
subject.find_stager("known-stack-name", 0).should == "staging-id"
end
end

0 comments on commit 6591288

Please sign in to comment.