diff --git a/lib/fog/compute/requests/aws/create_volume.rb b/lib/fog/compute/requests/aws/create_volume.rb index c01da7d5d..7d4194303 100644 --- a/lib/fog/compute/requests/aws/create_volume.rb +++ b/lib/fog/compute/requests/aws/create_volume.rb @@ -39,11 +39,18 @@ module Fog 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 = { diff --git a/tests/compute/requests/aws/volume_tests.rb b/tests/compute/requests/aws/volume_tests.rb index 724e27709..e5c160e31 100644 --- a/tests/compute/requests/aws/volume_tests.rb +++ b/tests/compute/requests/aws/volume_tests.rb @@ -46,6 +46,22 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do 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