Permalink
Browse files

You only need either the size or the snapshot_id.

  • Loading branch information...
1 parent 59fc86a commit 4acd979a9ea3e08e9fa8f133168086bd3b2e1696 @dylanegan dylanegan committed Jun 20, 2011
Showing with 25 additions and 2 deletions.
  1. +9 −2 lib/fog/compute/requests/aws/create_volume.rb
  2. +16 −0 tests/compute/requests/aws/volume_tests.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 = {
@@ -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

0 comments on commit 4acd979

Please sign in to comment.