Skip to content

Commit

Permalink
[ibm] avoid using constants (Rails loads files multiple times, issue f…
Browse files Browse the repository at this point in the history
  • Loading branch information
decklin committed Mar 22, 2012
1 parent f9e25a6 commit 256337d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
9 changes: 5 additions & 4 deletions lib/fog/ibm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ module IBM

# 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

class Connection < Fog::Connection
def self.timeout
1800
end

ENDPOINT = 'https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331'
class Connection < Fog::Connection

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
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/ibm/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def allocate_ip(wait_for_ready=true)
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
Expand Down
6 changes: 3 additions & 3 deletions tests/ibm/models/compute/server_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

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
Expand Down Expand Up @@ -66,7 +66,7 @@
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
Expand All @@ -80,7 +80,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions tests/ibm/models/compute/servers_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/ibm/models/storage/volume_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion tests/ibm/requests/compute/address_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
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

Expand Down
6 changes: 3 additions & 3 deletions tests/ibm/requests/compute/image_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
: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
Expand All @@ -100,9 +100,9 @@
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
Expand Down
6 changes: 3 additions & 3 deletions tests/ibm/requests/compute/instance_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
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
Expand All @@ -74,14 +74,14 @@
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
Expand Down
6 changes: 3 additions & 3 deletions tests/ibm/requests/storage/volume_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@
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'] }
end

# 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
Expand Down

0 comments on commit 256337d

Please sign in to comment.