From 5693a9cf2f37351ef082f46658001a2228b2d723 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Thu, 6 Aug 2015 16:00:02 -0700 Subject: [PATCH] volume#key_id and encrypted tests --- lib/fog/aws/models/compute/volume.rb | 18 +++-- lib/fog/aws/parsers/compute/create_volume.rb | 2 +- .../aws/parsers/compute/describe_volumes.rb | 2 +- lib/fog/aws/requests/compute/create_volume.rb | 25 ++++--- tests/requests/compute/volume_tests.rb | 71 ++++++++++++------- 5 files changed, 75 insertions(+), 43 deletions(-) diff --git a/lib/fog/aws/models/compute/volume.rb b/lib/fog/aws/models/compute/volume.rb index b139ff18e..374746890 100644 --- a/lib/fog/aws/models/compute/volume.rb +++ b/lib/fog/aws/models/compute/volume.rb @@ -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 diff --git a/lib/fog/aws/parsers/compute/create_volume.rb b/lib/fog/aws/parsers/compute/create_volume.rb index f1d8aea2c..e9a0699d5 100644 --- a/lib/fog/aws/parsers/compute/create_volume.rb +++ b/lib/fog/aws/parsers/compute/create_volume.rb @@ -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) diff --git a/lib/fog/aws/parsers/compute/describe_volumes.rb b/lib/fog/aws/parsers/compute/describe_volumes.rb index 266e75987..8ee0f61ce 100644 --- a/lib/fog/aws/parsers/compute/describe_volumes.rb +++ b/lib/fog/aws/parsers/compute/describe_volumes.rb @@ -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 diff --git a/lib/fog/aws/requests/compute/create_volume.rb b/lib/fog/aws/requests/compute/create_volume.rb index cda0a7036..f2c64dd36 100644 --- a/lib/fog/aws/requests/compute/create_volume.rb +++ b/lib/fog/aws/requests/compute/create_volume.rb @@ -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 = { diff --git a/tests/requests/compute/volume_tests.rb b/tests/requests/compute/volume_tests.rb index 8d3824fe5..9302dd9ca 100644 --- a/tests/requests/compute/volume_tests.rb +++ b/tests/requests/compute/volume_tests.rb @@ -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