mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at a wait_for helper on model
This commit is contained in:
parent
e1fdfa8144
commit
e11a1eba13
3 changed files with 15 additions and 12 deletions
|
@ -97,6 +97,17 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wait_for(timeout = 600, &block)
|
||||||
|
start = Time.now
|
||||||
|
until instance_eval(&block)
|
||||||
|
if Time.now - start > timeout
|
||||||
|
break
|
||||||
|
end
|
||||||
|
reload
|
||||||
|
sleep(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def collection=(new_collection)
|
def collection=(new_collection)
|
||||||
|
|
|
@ -52,9 +52,7 @@ describe 'Fog::AWS::EC2::Address' do
|
||||||
|
|
||||||
it "should associate with instance to an already saved address" do
|
it "should associate with instance to an already saved address" do
|
||||||
@address.save.should be_true
|
@address.save.should be_true
|
||||||
while @instance.state == 'pending'
|
@instance.wait_for { state == 'running' }
|
||||||
@instance.reload
|
|
||||||
end
|
|
||||||
@address.instance = @instance
|
@address.instance = @instance
|
||||||
@address.instance_id.should == @instance.id
|
@address.instance_id.should == @instance.id
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,21 +49,15 @@ describe 'Fog::AWS::EC2::Volume' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
|
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
|
||||||
@volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => '/dev/sdz1')
|
@volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => '/dev/sdz1')
|
||||||
while @instance.state == 'pending'
|
@instance.wait_for { state == 'running' }
|
||||||
@instance.reload
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
@instance.destroy
|
@instance.destroy
|
||||||
if @volume.id
|
if @volume.id
|
||||||
while ['attaching', 'creating'].include?(@volume.status)
|
@volume.wait_for { status == 'attached' }
|
||||||
@volume.reload
|
|
||||||
end
|
|
||||||
@volume.instance = nil
|
@volume.instance = nil
|
||||||
while ['attached', 'detaching'].include?(@volume.status)
|
@volume.wait_for { status == 'available' }
|
||||||
@volume.reload
|
|
||||||
end
|
|
||||||
@volume.destroy
|
@volume.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue