From 1efffe5d85a7343d14813a00521541d2286b6da3 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 20 Dec 2012 09:15:56 -0600 Subject: [PATCH] updated save method in Fog::Rackspace::BlockStorage::Volume and Fog::Rackspace::BlockStorage::Snapshot to skip creating cloud reources if identity was already set Fixes #1402 --- .../models/block_storage/snapshot.rb | 1 + .../rackspace/models/block_storage/volume.rb | 1 + .../models/block_storage/snapshot_tests.rb | 29 ++++++++++++------- .../models/block_storage/volume_tests.rb | 18 ++++++++---- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/fog/rackspace/models/block_storage/snapshot.rb b/lib/fog/rackspace/models/block_storage/snapshot.rb index 5f0e653d5..67657398d 100644 --- a/lib/fog/rackspace/models/block_storage/snapshot.rb +++ b/lib/fog/rackspace/models/block_storage/snapshot.rb @@ -26,6 +26,7 @@ module Fog def save(force = false) requires :volume_id + return true if identity data = connection.create_snapshot(volume_id, { :display_name => display_name, :display_description => display_description, diff --git a/lib/fog/rackspace/models/block_storage/volume.rb b/lib/fog/rackspace/models/block_storage/volume.rb index 61dbf3aff..24e681b97 100644 --- a/lib/fog/rackspace/models/block_storage/volume.rb +++ b/lib/fog/rackspace/models/block_storage/volume.rb @@ -37,6 +37,7 @@ module Fog def save requires :size + return true if identity data = connection.create_volume(size, { :display_name => display_name, :display_description => display_description, diff --git a/tests/rackspace/models/block_storage/snapshot_tests.rb b/tests/rackspace/models/block_storage/snapshot_tests.rb index f2b0bedab..5999cfa85 100644 --- a/tests/rackspace/models/block_storage/snapshot_tests.rb +++ b/tests/rackspace/models/block_storage/snapshot_tests.rb @@ -3,18 +3,25 @@ Shindo.tests('Fog::Rackspace::BlockStorage | snapshot', ['rackspace']) do pending if Fog.mocking? service = Fog::Rackspace::BlockStorage.new - volume = service.volumes.create({ - :display_name => "fog_#{Time.now.to_i.to_s}", - :size => 100 - }) + begin + volume = service.volumes.create({ + :display_name => "fog_#{Time.now.to_i.to_s}", + :size => 100 + }) - volume.wait_for { ready? } + volume.wait_for { ready? } - options = { :display_name => "fog_#{Time.now.to_i.to_s}", :volume_id => volume.id } - model_tests(service.snapshots, options, false) do - @instance.wait_for { ready? } + options = { :display_name => "fog_#{Time.now.to_i.to_s}", :volume_id => volume.id } + model_tests(service.snapshots, options, false) do + @instance.wait_for { ready? } + + tests('double save').returns(true) do + @instance.save + end + end + + volume.wait_for { snapshots.empty? } + ensure + volume.destroy if volume end - - volume.wait_for { snapshots.empty? } - volume.destroy end diff --git a/tests/rackspace/models/block_storage/volume_tests.rb b/tests/rackspace/models/block_storage/volume_tests.rb index f39ca4812..964d1b32f 100644 --- a/tests/rackspace/models/block_storage/volume_tests.rb +++ b/tests/rackspace/models/block_storage/volume_tests.rb @@ -6,7 +6,11 @@ Shindo.tests('Fog::Rackspace::BlockStorage | volume', ['rackspace']) do options = { :display_name => "fog_#{Time.now.to_i.to_s}", :size => 100 } model_tests(service.volumes, options, false) do - @instance.wait_for { ready? } + @instance.wait_for(timeout=1200) { ready? } + + tests('double save').returns(true) do + @instance.save + end tests('#attached?').succeeds do @instance.state = 'in-use' @@ -14,12 +18,14 @@ Shindo.tests('Fog::Rackspace::BlockStorage | volume', ['rackspace']) do end tests('#snapshots').succeeds do - snapshot = service.snapshots.create({ :volume_id => @instance.id }) - snapshot.wait_for { ready? } + begin + snapshot = service.snapshots.create({ :volume_id => @instance.id }) + snapshot.wait_for(timeout = 1200) { ready? } - returns(true) { @instance.snapshots.first.id == snapshot.id } - - snapshot.destroy + returns(true) { @instance.snapshots.first.id == snapshot.id } + ensure + snapshot.destroy if snapshot + end end @instance.wait_for { snapshots.empty? }