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:
parent
960dca64b2
commit
2d08f1da84
21 changed files with 38 additions and 57 deletions
14
lib/fog.rb
14
lib/fog.rb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
Fog.wait_for(timeout) { reload && instance_eval(&block) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue