From 256337db77684ec86abe31fd2f5577d4783feb02 Mon Sep 17 00:00:00 2001 From: Decklin Foster Date: Thu, 22 Mar 2012 08:49:20 -0400 Subject: [PATCH] [ibm] avoid using constants (Rails loads files multiple times, issue #807) --- lib/fog/ibm.rb | 9 +++++---- lib/fog/ibm/models/compute/server.rb | 2 +- tests/ibm/models/compute/server_tests.rb | 6 +++--- tests/ibm/models/compute/servers_tests.rb | 4 ++-- tests/ibm/models/storage/volume_tests.rb | 2 +- tests/ibm/requests/compute/address_tests.rb | 2 +- tests/ibm/requests/compute/image_tests.rb | 6 +++--- tests/ibm/requests/compute/instance_tests.rb | 6 +++--- tests/ibm/requests/storage/volume_tests.rb | 6 +++--- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/fog/ibm.rb b/lib/fog/ibm.rb index a0906de10..22f12eae8 100644 --- a/lib/fog/ibm.rb +++ b/lib/fog/ibm.rb @@ -10,17 +10,18 @@ module Fog # Provisioning is very slow. We'll pass this arg explicitly until there's a way # to set the default timeout on a per-provider basis. - TIMEOUT = 1800 + + def self.timeout + 1800 + end class Connection < Fog::Connection - ENDPOINT = 'https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331' - def initialize(user, password) require 'multi_json' @user = user @password = password - @endpoint = URI.parse(ENDPOINT) + @endpoint = URI.parse('https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331') @base_path = @endpoint.path super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}") end diff --git a/lib/fog/ibm/models/compute/server.rb b/lib/fog/ibm/models/compute/server.rb index 3211bb16e..43c1230a6 100644 --- a/lib/fog/ibm/models/compute/server.rb +++ b/lib/fog/ibm/models/compute/server.rb @@ -104,7 +104,7 @@ module Fog requires :location_id new_ip = connection.addresses.new(:location => location_id) new_ip.save - new_ip.wait_for(Fog::IBM::TIMEOUT) { ready? } if wait_for_ready + new_ip.wait_for(Fog::IBM.timeout) { ready? } if wait_for_ready secondary_ip << new_ip new_ip end diff --git a/tests/ibm/models/compute/server_tests.rb b/tests/ibm/models/compute/server_tests.rb index b5af46ffb..02b1b5583 100644 --- a/tests/ibm/models/compute/server_tests.rb +++ b/tests/ibm/models/compute/server_tests.rb @@ -32,7 +32,7 @@ Shindo.tests('Fog::Compute[:ibm] | server', ['ibm']) do tests('Fog::Compute::IBM::Server#wait_for { ready? }') do @server = Fog::Compute[:ibm].servers.get(@instance_id) - @server.wait_for(Fog::IBM::TIMEOUT) { ready? } + @server.wait_for(Fog::IBM.timeout) { ready? } end tests('Fog::Compute::IBM::Server#id') do @@ -66,7 +66,7 @@ Shindo.tests('Fog::Compute[:ibm] | server', ['ibm']) do body = @server.to_image(:name => @server.name) returns(@server.name) { body['name'] } image = Fog::Compute[:ibm].images.get(body['id']) - image.wait_for(Fog::IBM::TIMEOUT) { ready? || state == 'New' } + image.wait_for(Fog::IBM.timeout) { ready? || state == 'New' } unless image.state == 'Capturing' returns(true) { Fog::Compute[:ibm].delete_image(image.id).body['success'] } end @@ -80,7 +80,7 @@ Shindo.tests('Fog::Compute[:ibm] | server', ['ibm']) do returns(true) { @server.destroy } end - @key.wait_for(Fog::IBM::TIMEOUT) { instance_ids.empty? } + @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? } @key.destroy end diff --git a/tests/ibm/models/compute/servers_tests.rb b/tests/ibm/models/compute/servers_tests.rb index 042737e04..bcf4bd299 100644 --- a/tests/ibm/models/compute/servers_tests.rb +++ b/tests/ibm/models/compute/servers_tests.rb @@ -21,12 +21,12 @@ Shindo.tests('Fog::Compute[:ibm] | servers', ['ibm']) do returns(@instance_id) { @server.id } end - if @server.wait_for(Fog::IBM::TIMEOUT) { ready? } + if @server.wait_for(Fog::IBM.timeout) { ready? } @server.destroy else pending end - if @key.wait_for(Fog::IBM::TIMEOUT) { instance_ids.empty? } + if @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? } @key.destroy else pending diff --git a/tests/ibm/models/storage/volume_tests.rb b/tests/ibm/models/storage/volume_tests.rb index 16267eb2b..a0855ad6d 100644 --- a/tests/ibm/models/storage/volume_tests.rb +++ b/tests/ibm/models/storage/volume_tests.rb @@ -24,7 +24,7 @@ Shindo.tests('Fog::Storage[:ibm] | volume', ['ibm']) do tests('Fog::Storage::IBM::Volume#save') do returns(true) { @volume.save } returns(String) { @volume.id.class } - @volume.wait_for(Fog::IBM::TIMEOUT) { ready? } + @volume.wait_for(Fog::IBM.timeout) { ready? } @volume_id = @volume.id end diff --git a/tests/ibm/requests/compute/address_tests.rb b/tests/ibm/requests/compute/address_tests.rb index 159a0cd10..26a85eee2 100644 --- a/tests/ibm/requests/compute/address_tests.rb +++ b/tests/ibm/requests/compute/address_tests.rb @@ -35,7 +35,7 @@ Shindo.tests('Fog::Compute[:ibm] | address requests', ['ibm']) do end tests("#delete_address('#{@address_id}')") do - Fog::Compute[:ibm].addresses.get(@address_id).wait_for(Fog::IBM::TIMEOUT) { ready? } + Fog::Compute[:ibm].addresses.get(@address_id).wait_for(Fog::IBM.timeout) { ready? } returns(true) { Fog::Compute[:ibm].delete_address(@address_id).body['success'] } end diff --git a/tests/ibm/requests/compute/image_tests.rb b/tests/ibm/requests/compute/image_tests.rb index 647f3b93c..3976f4b41 100644 --- a/tests/ibm/requests/compute/image_tests.rb +++ b/tests/ibm/requests/compute/image_tests.rb @@ -80,7 +80,7 @@ Shindo.tests('Fog::Compute[:ibm] | image requests', ['ibm']) do :key_name => @key_name ).body @instance_id = response['instances'][0]['id'] - Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM::TIMEOUT) { ready? } + Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM.timeout) { ready? } data = Fog::Compute[:ibm].create_image(@instance_id, @image_name, "").body @id = data['id'] data @@ -100,9 +100,9 @@ Shindo.tests('Fog::Compute[:ibm] | image requests', ['ibm']) do end @server = Fog::Compute[:ibm].servers.get(@instance_id) - @server.wait_for(Fog::IBM::TIMEOUT) { ready? } + @server.wait_for(Fog::IBM.timeout) { ready? } @server.destroy - @key.wait_for(Fog::IBM::TIMEOUT) { instance_ids.empty? } + @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? } @key.destroy end diff --git a/tests/ibm/requests/compute/instance_tests.rb b/tests/ibm/requests/compute/instance_tests.rb index 28eb06f8f..e0ac46087 100644 --- a/tests/ibm/requests/compute/instance_tests.rb +++ b/tests/ibm/requests/compute/instance_tests.rb @@ -53,7 +53,7 @@ Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do response = Fog::Compute[:ibm].get_instance(@instance_id).body end - Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM::TIMEOUT) { ready? } + Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM.timeout) { ready? } tests("#list_instances").formats(@instances_format) do instances = Fog::Compute[:ibm].list_instances.body @@ -74,14 +74,14 @@ Shindo.tests('Fog::Compute[:ibm] | instance requests', ['ibm']) do end tests("#delete_instance('#{@instance_id}')") do - if Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM::TIMEOUT) { ready? } + if Fog::Compute[:ibm].servers.get(@instance_id).wait_for(Fog::IBM.timeout) { ready? } data = Fog::Compute[:ibm].delete_instance(@instance_id) else pending end end - if @key.wait_for(Fog::IBM::TIMEOUT) { instance_ids.empty? } + if @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? } @key.destroy else pending diff --git a/tests/ibm/requests/storage/volume_tests.rb b/tests/ibm/requests/storage/volume_tests.rb index 67ac62e55..05b63aaea 100644 --- a/tests/ibm/requests/storage/volume_tests.rb +++ b/tests/ibm/requests/storage/volume_tests.rb @@ -82,7 +82,7 @@ Shindo.tests('Fog::Storage[:ibm] | volume requests', ['ibm']) do Fog::Compute[:ibm].delete_instance(@instance_id) end - Fog::Storage[:ibm].volumes.get(@volume_id).wait_for(Fog::IBM::TIMEOUT) { ready? } + Fog::Storage[:ibm].volumes.get(@volume_id).wait_for(Fog::IBM.timeout) { ready? } tests("#delete_volume('#{@volume_id}')") do returns(true) { Fog::Storage[:ibm].delete_volume(@volume_id).body['success'] } @@ -90,9 +90,9 @@ Shindo.tests('Fog::Storage[:ibm] | volume requests', ['ibm']) do # See above # @server = Fog::Compute[:ibm].servers.get(@instance_id) - # @server.wait_for(Fog::IBM::TIMEOUT) { ready? } + # @server.wait_for(Fog::IBM.timeout) { ready? } # @server.destroy - # @key.wait_for(Fog::IBM::TIMEOUT) { instance_ids.empty? } + # @key.wait_for(Fog::IBM.timeout) { instance_ids.empty? } # @key.destroy end