From 04ecade81b79dfd8db79772cb2afb05dc683b79c Mon Sep 17 00:00:00 2001 From: geemus Date: Sat, 8 May 2010 15:16:35 -0700 Subject: [PATCH] [ec2] snapshots, parse missing fields, allow description, consolidated shindo tests --- lib/fog/aws/parsers/ec2/create_snapshot.rb | 6 ++- lib/fog/aws/parsers/ec2/describe_snapshots.rb | 6 ++- lib/fog/aws/requests/ec2/create_snapshot.rb | 9 ++-- tests/aws/helper.rb | 16 ++++++ tests/aws/requests/ec2/snapshot_tests.rb | 49 +++++++++++++++++++ 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tests/aws/requests/ec2/snapshot_tests.rb diff --git a/lib/fog/aws/parsers/ec2/create_snapshot.rb b/lib/fog/aws/parsers/ec2/create_snapshot.rb index b59c50b68..40e2efd0d 100644 --- a/lib/fog/aws/parsers/ec2/create_snapshot.rb +++ b/lib/fog/aws/parsers/ec2/create_snapshot.rb @@ -7,10 +7,14 @@ module Fog def end_element(name) case name - when 'progress', 'snapshotId', 'status', 'volumeId' + when 'description', 'ownerId', 'progress', 'snapshotId', 'status', 'volumeId' + @response[name] = @value + when 'requestId' @response[name] = @value when 'startTime' @response[name] = Time.parse(@value) + when 'volumeSize' + @response[name] = @value.to_i end end diff --git a/lib/fog/aws/parsers/ec2/describe_snapshots.rb b/lib/fog/aws/parsers/ec2/describe_snapshots.rb index a92a502b3..4da599a6e 100644 --- a/lib/fog/aws/parsers/ec2/describe_snapshots.rb +++ b/lib/fog/aws/parsers/ec2/describe_snapshots.rb @@ -15,10 +15,14 @@ module Fog when 'item' @response['snapshotSet'] << @snapshot @snapshot = {} - when 'progress', 'snapshotId', 'status', 'volumeId' + when 'description', 'ownerId', 'progress', 'snapshotId', 'status', 'volumeId' @snapshot[name] = @value + when 'requestId' + @response[name] = @value when 'startTime' @snapshot[name] = Time.parse(@value) + when 'volumeSize' + @snapshot[name] = @value.to_i end end diff --git a/lib/fog/aws/requests/ec2/create_snapshot.rb b/lib/fog/aws/requests/ec2/create_snapshot.rb index ac85c8637..62d6bcb91 100644 --- a/lib/fog/aws/requests/ec2/create_snapshot.rb +++ b/lib/fog/aws/requests/ec2/create_snapshot.rb @@ -17,11 +17,12 @@ module Fog # * 'startTime'<~Time> - timestamp when snapshot was initiated # * 'status'<~String> - state of snapshot # * 'volumeId'<~String> - id of volume snapshot targets - def create_snapshot(volume_id) + def create_snapshot(volume_id, description = nil) request( - 'Action' => 'CreateSnapshot', - 'VolumeId' => volume_id, - :parser => Fog::Parsers::AWS::EC2::CreateSnapshot.new + 'Action' => 'CreateSnapshot', + 'Description' => description, + 'VolumeId' => volume_id, + :parser => Fog::Parsers::AWS::EC2::CreateSnapshot.new ) end diff --git a/tests/aws/helper.rb b/tests/aws/helper.rb index 4d7c07acb..f5cb36263 100644 --- a/tests/aws/helper.rb +++ b/tests/aws/helper.rb @@ -46,6 +46,22 @@ module AWS 'return' => ::Fog::Boolean } + SNAPSHOT = { + 'description' => NilClass, + 'ownerId' => String, + 'progress' => String, + 'snapshotId' => String, + 'startTime' => Time, + 'status' => String, + 'volumeId' => String, + 'volumeSize' => Integer + } + + SNAPSHOTS = { + 'requestId' => String, + 'snapshotSet' => [SNAPSHOT] + } + VOLUME = { 'availabilityZone' => String, 'createTime' => Time, diff --git a/tests/aws/requests/ec2/snapshot_tests.rb b/tests/aws/requests/ec2/snapshot_tests.rb new file mode 100644 index 000000000..c3279c1a6 --- /dev/null +++ b/tests/aws/requests/ec2/snapshot_tests.rb @@ -0,0 +1,49 @@ +Shindo.tests('AWS::EC2 | snapshot requests', ['aws']) do + + @volume = AWS[:ec2].volumes.create(:availability_zone => 'us-east-1a', :size => 1) + + tests('success') do + + @snapshot_id = nil + + test("#create_snapshot(#{@volume.identity})") do + @data = AWS[:ec2].create_snapshot(@volume.identity).body + @snapshot_id = @data['snapshotId'] + has_format(@data, AWS::EC2::Formats::SNAPSHOT.merge('progress' => NilClass, 'requestId' => String)) + end + + test("#describe_snapshots") do + @data = AWS[:ec2].describe_snapshots.body + has_format(@data, AWS::EC2::Formats::SNAPSHOTS) + end + + test("#describe_snapshots('#{@snapshot_id}')") do + @data = AWS[:ec2].describe_snapshots(@snapshot_id).body + has_format(@data, AWS::EC2::Formats::SNAPSHOTS) + end + + test("#delete_snapshots(#{@snapshot_id})") do + @data = AWS[:ec2].delete_snapshot(@snapshot_id).body + has_format(@data, AWS::EC2::Formats::BASIC) + end + + end + tests ('failure') do + + test("#describe_snapshot('snap-00000000') raises BadRequest error") do + has_error(Excon::Errors::BadRequest) do + AWS[:ec2].describe_snapshots('snap-00000000') + end + end + + test("#delete_snapshot('snap-00000000') raises BadRequest error") do + has_error(Excon::Errors::BadRequest) do + AWS[:ec2].delete_snapshot('snap-00000000') + end + end + + end + + @volume.destroy + +end