1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #365 from dylanegan/optional_size_arg

Allow create_volume Mock to support size || snapshot_id || (snapshot_id && size)
This commit is contained in:
Wesley Beary 2011-06-20 22:07:56 -07:00
commit cdf518ca0c
3 changed files with 27 additions and 4 deletions

View file

@ -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 file

@ -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 = {

View file

@ -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