Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #365 from dylanegan/optional_size_arg

Allow create_volume Mock to support size || snapshot_id || (snapshot_id && size)
  • Loading branch information...
commit cdf518ca0cba12a4c1a35b9f473343e54c8b1575 2 parents 436ad75 + 4acd979
Wesley Beary authored
View
4 Rakefile
@@ -1,7 +1,7 @@
require 'rubygems'
require 'bundler/setup'
require 'date'
-require 'lib/fog'
+require File.dirname(__FILE__) + '/lib/fog'
#############################################################################
#
@@ -340,4 +340,4 @@ def redirecter(path)
</body>
</html>
HTML
-end
+end
View
11 lib/fog/compute/requests/aws/create_volume.rb
@@ -39,11 +39,18 @@ class Mock
def create_volume(availability_zone, size, snapshot_id = nil)
response = Excon::Response.new
- if availability_zone && size
- if snapshot_id && !self.data[:snapshots][snapshot_id]
+ if availability_zone && (size || snapshot_id)
+ snapshot = self.data[:snapshots][snapshot_id]
+ if snapshot_id && !snapshot
raise Fog::Compute::AWS::NotFound.new("The snapshot '#{snapshot_id}' does not exist.")
end
+ if snapshot && size && size != snapshot['volumeSize']
+ raise Fog::Compute::AWS::NotFound.new("The snapshot '#{snapshot_id}' with the specified size of '#{size}' does not exist.")
+ elsif snapshot && !size
+ size = snapshot['volumeSize']
+ end
+
response.status = 200
volume_id = Fog::AWS::Mock.volume_id
data = {
View
16 tests/compute/requests/aws/volume_tests.rb
@@ -46,6 +46,22 @@
data
end
+ tests('#create_volume from snapshot').formats(@volume_format) do
+ volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
+ snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
+ data = Fog::Compute[:aws].create_volume(@server.availability_zone, nil, snapshot['snapshotId']).body
+ @volume_id = data['volumeId']
+ data
+ end
+
+ tests('#create_volume from snapshot with size').formats(@volume_format) do
+ volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
+ snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
+ data = Fog::Compute[:aws].create_volume(@server.availability_zone, 1, snapshot['snapshotId']).body
+ @volume_id = data['volumeId']
+ data
+ end
+
Fog::Compute[:aws].volumes.get(@volume_id).wait_for { ready? }
tests('#describe_volumes').formats(@volumes_format) do
Please sign in to comment.
Something went wrong with that request. Please try again.