1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

consolidate wait_for usage and add more useful return values

This commit is contained in:
geemus 2010-05-01 15:08:44 -07:00
parent 960dca64b2
commit 2d08f1da84
21 changed files with 38 additions and 57 deletions

View file

@ -57,4 +57,18 @@ module Fog
!!@mocking
end
def self.wait_for(timeout = 600, &block)
duration = 0
start = Time.now
until yield || duration > timeout
sleep(1)
duration = Time.now - start
end
if duration > timeout
false
else
{ :duration => duration }
end
end
end

View file

@ -110,11 +110,8 @@ module Fog
end
def wait_for(timeout = 600, &block)
start = Time.now
begin
reload
sleep(1)
end until instance_eval(&block) || Time.now - start > timeout
reload
Fog.wait_for(timeout) { reload && instance_eval(&block) }
end
private

View file

@ -5,7 +5,7 @@ describe 'S3.get_service' do
before(:all) do
AWS[:s3].put_bucket('foggetservice')
wait_for { AWS[:s3].directories.get('foggetservice') }
Fog.wait_for { AWS[:s3].directories.get('foggetservice') }
end
after(:all) do

View file

@ -9,16 +9,6 @@ if ENV["FOG_MOCK"] == "true"
Fog.mock!
end
# unless defined?(LOADED_SPEC_OPTS)
# # inlined spec.opts
# require "#{current_directory}/compact_progress_bar_formatter"
# Spec::Runner.options.parse_format("Spec::Runner::Formatter::CompactProgressBarFormatter")
# Spec::Runner.options.loadby = 'mtime'
# Spec::Runner.options.reverse = true
# LOADED_SPEC_OPTS = true
# end
module AWS
class << self
def [](service)
@ -104,16 +94,6 @@ def eventually(max_delay = 16, &block)
end
end
def wait_for(timeout = 600, &block)
start = Time.now
until instance_eval(&block)
if Time.now - start > timeout
break
end
sleep(1)
end
end
unless defined?(GENTOO_AMI)
GENTOO_AMI = 'ami-5ee70037'
end

View file

@ -32,13 +32,3 @@ def validate_format(original_data, format)
end
valid
end
def wait_for(timeout = 600, &block)
start = Time.now
until instance_eval(&block)
if Time.now - start > timeout
break
end
sleep(1)
end
end

View file

@ -3,14 +3,14 @@ Shindo.tests('Rackspace::Servers#create_image', 'rackspace') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogcreateimage').body['server']['id']
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
@data = Rackspace[:servers].create_image(@server_id).body['image']
@image_id = @data['id']
end
after do
Rackspace[:servers].delete_server(@server_id)
wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_image(@image_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#create_server', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,12 +7,12 @@ Shindo.tests('Rackspace::Servers#delete_image', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
test('has proper output format') do
wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_image_details(@image_id).body['image']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_image(@image_id)
end

View file

@ -6,7 +6,7 @@ Shindo.tests('Rackspace::Servers#delete_server', 'rackspace') do
end
test('has proper output format') do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#get_server_details', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#list_addresses', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#list_private_addresses', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#list_public_addresses', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#list_servers_detail', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Rackspace::Servers#list_servers', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end

View file

@ -6,20 +6,20 @@ Shindo.tests('Rackspace::Servers#reboot_server', 'rackspace') do
end
after do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].delete_server(@server_id)
end
tests('HARD') do
test('has proper output format') do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].reboot_server(@server_id, 'HARD')
end
end
tests('SOFT') do
test('has proper output format') do
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Rackspace[:servers].reboot_server(@server_id, 'SOFT')
end
end

View file

@ -3,7 +3,7 @@ Shindo.tests('Rackspace::Servers#update_server', 'rackspace') do
before do
@server_id = Rackspace[:servers].create_server(1, 3, 'fogupdateserver').body['server']['id']
wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
Fog.wait_for { Rackspace[:servers].get_server_details(@server_id).body['server']['status'] == 'ACTIVE' }
@data = Rackspace[:servers].update_server(@server_id, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Slicehost#create_slice', 'slicehost') do
end
after do
wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Slicehost[:slices].delete_slice(@id)
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Slicehost#delete_slice', 'slicehost') do
end
test('has proper output format') do
wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Slicehost[:slices].delete_slice(@id)
end

View file

@ -8,7 +8,7 @@ Shindo.tests('Slicehost#get_slice', 'slicehost') do
end
after do
wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Slicehost[:slices].delete_slice(@id)
end

View file

@ -4,12 +4,12 @@ Shindo.tests('Slicehost#reboot_slice', 'slicehost') do
before do
@data = Slicehost[:slices].create_slice(1, 3, 'fogrebootslice').body
@id = @data['id']
wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
@data = Slicehost[:slices].reboot_slice(@id).body
end
after do
wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Fog.wait_for { Slicehost[:slices].get_slice(@id).body['status'] == 'active' }
Slicehost[:slices].delete_slice(@id)
end