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

volume#key_id and encrypted tests

This commit is contained in:
Josh Lane 2015-08-06 16:00:02 -07:00
parent 2ca24dcbdf
commit 5693a9cf2f
5 changed files with 75 additions and 43 deletions

View file

@ -9,10 +9,11 @@ module Fog
attribute :created_at, :aliases => 'createTime'
attribute :delete_on_termination, :aliases => 'deleteOnTermination'
attribute :device
attribute :encrypted
attribute :key_id, :aliases => ['KmsKeyId', 'kmsKeyId']
attribute :iops
attribute :server_id, :aliases => 'instanceId'
attribute :size
attribute :encrypted
attribute :snapshot_id, :aliases => 'snapshotId'
attribute :state, :aliases => 'status'
attribute :tags, :aliases => 'tagSet'
@ -44,9 +45,8 @@ module Fog
requires :iops
end
data = service.create_volume(availability_zone, size, 'SnapshotId' => snapshot_id, 'VolumeType' => type, 'Iops' => iops, 'Encrypted' => encrypted).body
new_attributes = data.reject {|key,value| key == 'requestId'}
merge_attributes(new_attributes)
data = service.create_volume(availability_zone, size, create_params).body
merge_attributes(data)
if tags = self.tags
# expect eventual consistency
@ -118,6 +118,16 @@ module Fog
reload
end
end
def create_params
{
'Encrypted' => encrypted,
'KmsKeyId' => key_id,
'Iops' => iops,
'SnapshotId' => snapshot_id,
'VolumeType' => type
}
end
end
end
end

View file

@ -5,7 +5,7 @@ module Fog
class CreateVolume < Fog::Parsers::Base
def end_element(name)
case name
when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId', 'volumeType'
when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId', 'volumeType', 'kmsKeyId'
@response[name] = value
when 'createTime'
@response[name] = Time.parse(value)

View file

@ -30,7 +30,7 @@ module Fog
@attachment[name] = Time.parse(value)
when 'deleteOnTermination'
@attachment[name] = value == 'true'
when 'device', 'instanceId', 'status', 'volumeId'
when 'device', 'instanceId', 'status', 'volumeId', 'kmsKeyId'
@attachment[name] = value
when 'item'
@volume['attachmentSet'] << @attachment

View file

@ -87,19 +87,24 @@ module Fog
end
end
if options['KmsKeyId'] && !options['Encrypted']
raise Fog::Compute::AWS::Error.new("InvalidParameterDependency => The parameter KmsKeyId requires the parameter Encrypted to be set.")
end
response.status = 200
volume_id = Fog::AWS::Mock.volume_id
data = {
'availabilityZone' => availability_zone,
'attachmentSet' => [],
'createTime' => Time.now,
'iops' => options['Iops'],
'encrypted' => options['Encrypted'] || false,
'size' => size,
'snapshotId' => options['SnapshotId'],
'status' => 'creating',
'volumeId' => volume_id,
'volumeType' => options['VolumeType'] || 'standard'
'availabilityZone' => availability_zone,
'attachmentSet' => [],
'createTime' => Time.now,
'iops' => options['Iops'],
'encrypted' => options['Encrypted'] || false,
'size' => size,
'snapshotId' => options['SnapshotId'],
'kmsKeyId' => options['KmsKeyId'] || nil, # @todo validate
'status' => 'creating',
'volumeId' => volume_id,
'volumeType' => options['VolumeType'] || 'standard'
}
self.data[:volumes][volume_id] = data
response.body = {

View file

@ -1,25 +1,25 @@
Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
@volume_format = {
'availabilityZone' => String,
'createTime' => Time,
'encrypted' => Fog::Boolean,
'iops' => Fog::Nullable::Integer,
'requestId' => String,
'size' => Integer,
'snapshotId' => Fog::Nullable::String,
'status' => String,
'volumeId' => String,
'volumeType' => String
'availabilityZone' => String,
'createTime' => Time,
'encrypted' => Fog::Boolean,
'iops' => Fog::Nullable::Integer,
'requestId' => String,
'size' => Integer,
'snapshotId' => Fog::Nullable::String,
'status' => String,
'volumeId' => String,
'volumeType' => String
}
@volume_attachment_format = {
'attachTime' => Time,
'device' => String,
'instanceId' => String,
'requestId' => String,
'status' => String,
'volumeId' => String
'attachTime' => Time,
'device' => String,
'instanceId' => String,
'requestId' => String,
'status' => String,
'volumeId' => String
}
@volume_status_format = {
@ -52,17 +52,18 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
@volumes_format = {
'volumeSet' => [{
'availabilityZone' => String,
'attachmentSet' => Array,
'createTime' => Time,
'encrypted' => Fog::Boolean,
'iops' => Fog::Nullable::Integer,
'size' => Integer,
'snapshotId' => Fog::Nullable::String,
'status' => String,
'tagSet' => Hash,
'volumeId' => String,
'volumeType' => String
'availabilityZone' => String,
'attachmentSet' => Array,
'createTime' => Time,
'encrypted' => Fog::Boolean,
'iops' => Fog::Nullable::Integer,
'size' => Integer,
'snapshotId' => Fog::Nullable::String,
'kmsKeyId' => Fog::Nullable::String,
'status' => String,
'tagSet' => Hash,
'volumeId' => String,
'volumeType' => String
}],
'requestId' => String
}
@ -83,7 +84,11 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
tests('#create_volume from snapshot').formats(@volume_format) do
volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
volume.wait_for { ready? }
snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
Fog::Compute[:aws].snapshots.new(snapshot).wait_for { ready? }
data = Fog::Compute[:aws].create_volume(@server.availability_zone, nil, 'SnapshotId' => snapshot['snapshotId']).body
@volume_id = data['volumeId']
data
@ -99,9 +104,21 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
Fog::Compute[:aws].delete_volume(@volume_id)
tests('#create_volume with encryption').returns(true) do
volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1, :encrypted => true)
@volume_id = volume.id
volume.reload.encrypted
end
Fog::Compute[:aws].delete_volume(@volume_id)
tests('#create_volume from snapshot with size').formats(@volume_format) do
volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
volume.wait_for { ready? }
snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
Fog::Compute[:aws].snapshots.new(snapshot).wait_for { ready? }
data = Fog::Compute[:aws].create_volume(@server.availability_zone, 1, 'SnapshotId' => snapshot['snapshotId']).body
@volume_id = data['volumeId']
data