Permalink
Browse files

Raise Slushy::Error on Fog timeouts

  • Loading branch information...
1 parent 27e8d3f commit 3c2bcd86fea00d69581f1ba60d3989c267bf095a Sam Umbach and Larry Karnowski committed Apr 30, 2012
Showing with 46 additions and 6 deletions.
  1. +4 −4 lib/slushy/instance.rb
  2. +42 −2 spec/lib/instance_spec.rb
@@ -5,7 +5,7 @@ class Slushy::Instance
def self.launch(connection, config)
server = connection.servers.create(config)
- server.wait_for { ready? }
+ server.wait_for { ready? } or raise Slushy::Error.new("Timeout launching server #{server.id}")
new(connection, server.id)
end
@@ -34,18 +34,18 @@ def snapshot(name, description)
response = connection.create_image(instance_id, name, description)
image_id = response.body["imageId"]
image = connection.images.get(image_id)
- image.wait_for { state == "available" }
+ image.wait_for(3600) { ready? } or raise Slushy::Error.new("Timeout creating snapshot #{image_id}")
image_id
end
def terminate
server.destroy
- server.wait_for { state == "terminated" }
+ server.wait_for { state == "terminated" } or raise Slushy::Error.new("Timeout terminating server #{server.id}")
end
def stop
server.stop
- server.wait_for { state == "stopped" }
+ server.wait_for { state == "stopped" } or raise Slushy::Error.new("Timeout stopping server #{server.id}")
end
def wait_for_connectivity
@@ -20,6 +20,13 @@ def mock_job(options={})
lambda { described_class.launch(connection, config) }.should change { connection.servers.size }.by(1)
end
+ it "raises if wait_for fails" do
+ servers = stub(:create => server)
+ connection.stub(:servers).and_return(servers)
+ server.stub(:wait_for).and_return(false)
+ lambda { described_class.launch(connection, config) }.should raise_error(Slushy::Error)
+ end
+
it "returns the instance object" do
described_class.launch(connection, config).should be_a Slushy::Instance
end
@@ -57,18 +64,51 @@ def mock_job(options={})
it "does NOT return until image creation is complete" do
connection.stub(:create_image).and_return(response)
images.should_receive(:get).with(:some_ami_id).and_return(image)
- image.should_receive(:wait_for)
+ image.should_receive(:ready?).ordered.and_return(false)
+ image.should_receive(:ready?).ordered.and_return(true)
instance.snapshot(:some_name, :some_description)
end
+
+ it "raises if wait_for fails" do
+ connection.stub(:create_image).and_return(response)
+ images.should_receive(:get).with(:some_ami_id).and_return(image)
+ image.stub(:wait_for).and_return(false)
+ lambda { instance.snapshot(:some_name, :some_description) }.should raise_error(Slushy::Error)
+ end
end
describe "#terminate" do
it "terminates the given instance" do
instance.stub(:server).and_return(server)
server.should_receive(:destroy)
- server.should_receive(:wait_for)
+ server.should_receive(:state).ordered.and_return("running")
+ server.should_receive(:state).ordered.and_return("terminated")
instance.terminate
end
+
+ it "raises if wait_for fails" do
+ instance.stub(:server).and_return(server)
+ server.stub(:destroy)
+ server.stub(:wait_for).and_return(false)
+ lambda { instance.terminate }.should raise_error(Slushy::Error)
+ end
+ end
+
+ describe "#stop" do
+ it "stops the given instance" do
+ instance.stub(:server).and_return(server)
+ server.should_receive(:stop)
+ server.should_receive(:state).ordered.and_return("running")
+ server.should_receive(:state).ordered.and_return("stopped")
+ instance.stop
+ end
+
+ it "raises if wait_for fails" do
+ instance.stub(:server).and_return(server)
+ server.stub(:stop)
+ server.stub(:wait_for).and_return(false)
+ lambda { instance.stop }.should raise_error(Slushy::Error)
+ end
end
describe '#wait_for_connectivity' do

0 comments on commit 3c2bcd8

Please sign in to comment.