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

[ec2] snapshots, parse missing fields, allow description, consolidated shindo tests

This commit is contained in:
geemus 2010-05-08 15:16:35 -07:00
parent b8823a7c8f
commit 04ecade81b
5 changed files with 80 additions and 6 deletions

View file

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

View file

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

View file

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

View file

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

View file

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