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

Fix up describe_volume_status to work with THE ARRAYZ. ✌️

This commit is contained in:
Dylan Egan 2012-06-16 15:05:34 +02:00
parent 42b7e1dca6
commit 4bd698d772
3 changed files with 96 additions and 52 deletions

View file

@ -3,64 +3,81 @@ module Fog
module Compute
module AWS
class DescribeVolumeStatus < Fog::Parsers::Base
def new_volume
@volume = { 'volumeStatus' => { 'details' => [] }, 'eventsSet' => {}, 'actionsSet' => {} }
end
def reset
@volume_status = {}
@action_set = {}
@detail = {}
@event_set = {}
@volume_status = { 'details' => [] }
@volume = { 'actionsSet' => [], 'eventsSet' => [] }
@response = { 'volumeStatusSet' => [] }
@inside = nil
end
def start_element(name, attrs=[])
super
case name
when 'item'
new_volume if @inside.nil?
when 'volumeStatus'
@inside = :volume_status
when 'details'
@inside = :details
when 'eventsSet'
@inside = :events
when 'actionsSet'
@inside = :actions
@in_actions_set = true
when 'details'
@in_details = true
when 'eventsSet'
@in_events_set = true
when 'volumeStatus'
@in_volume_status = true
end
end
def end_element(name)
case name
#Simple closers
when 'details'
@inside = nil
when 'volumeStatus'
@inside = nil
when 'eventsSet'
@inside = nil
when 'actionsSet'
@inside = nil
when 'item'
@response['volumeStatusSet'] << @volume if @inside.nil?
#Top level
when 'nextToken', 'requestId'
@response[name] = value
# Volume Stuff
when 'volumeId', 'availabilityZone'
@volume[name] = value
#The mess...
when 'name', 'status'
case @inside
when :details
@volume['volumeStatus']['details'] << {name => value }
when :volume_status
@volume['volumeStatus'][name] = value
if @in_actions_set
case name
when 'actionsSet'
@in_actions_set = false
when 'code', 'eventId', 'eventType', 'description'
@action_set[name] = value.strip
when 'item'
@volume['actionsSet'] << @action_set
@action_set = {}
end
elsif @in_details
case name
when 'details'
@in_details = false
when 'name', 'status'
@detail[name] = value
when 'item'
@volume_status['details'] << @detail
@detail = {}
end
elsif @in_events_set
case name
when 'eventsSet'
@in_events_set = false
when 'code', 'eventId', 'eventType', 'description'
@event_set[name] = value.strip
when 'notAfter', 'notBefore'
@event_set[name] = Time.parse(value)
when 'item'
@volume['eventsSet'] << @event_set
@event_set = {}
end
elsif @in_volume_status
case name
when 'volumeStatus'
@volume['volumeStatus'] = @volume_status
@volume_status = { 'details' => [] }
@in_volume_status = false
when 'status'
@volume_status[name] = value
end
else
case name
when 'volumeId', 'availabilityZone'
@volume[name] = value
when 'nextToken', 'requestId'
@response[name] = value
when 'item'
@response['volumeStatusSet'] << @volume
@volume = { 'actionsSet' => [], 'eventsSet' => [] }
end
when 'code', 'eventId', 'eventType', 'description'
@volume["#{@inside}Set"][name] = value.strip
when 'notAfter', 'notBefore'
@volume["#{@inside}Set"][name] = Time.parse(value)
end
end
end

View file

@ -2,9 +2,7 @@ module Fog
module Parsers
module Compute
module AWS
class DescribeVolumes < Fog::Parsers::Base
def reset
@attachment = {}
@in_attachment_set = false

View file

@ -19,6 +19,34 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
'volumeId' => String
}
@volume_status_format = {
'volumeStatusSet' => [{
'availabilityZone' => String,
'volumeId' => String,
'volumeStatus' => {
'status' => String,
'details' => [{
'name' => String,
'status' => String
}]
},
'actionsSet' => [{
'code' => String,
'description' => String,
'eventId' => String,
'eventType' => String
}],
'eventsSet' => [{
'description' => String,
'eventId' => String,
'eventType' => String,
'notBefore' => Time,
'notAfter' => Time
}]
}],
'requestId' => String
}
@volumes_format = {
'volumeSet' => [{
'availabilityZone' => String,
@ -37,7 +65,6 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
@server.wait_for { ready? }
tests('success') do
@volume_id = nil
tests('#create_volume').formats(@volume_format) do
@ -82,6 +109,11 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
Fog::Compute[:aws].describe_volumes('attachment.device' => '/dev/sdh').body
end
tests("#describe_volume_status('volume-id' => #{@volume_id})").formats(@volume_status_format) do
pending if Fog.mocking?
Fog::Compute[:aws].describe_volume_status('volume-id' => @volume_id).body
end
tests("#detach_volume('#{@volume_id}')").formats(@volume_attachment_format) do
Fog::Compute[:aws].detach_volume(@volume_id).body
end
@ -91,10 +123,9 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
tests("#delete_volume('#{@volume_id}')").formats(AWS::Compute::Formats::BASIC) do
Fog::Compute[:aws].delete_volume(@volume_id).body
end
end
tests('failure') do
tests('failure') do
@volume = Fog::Compute[:aws].volumes.create(:availability_zone => @server.availability_zone, :size => 1)
tests("#attach_volume('i-00000000', '#{@volume.identity}', '/dev/sdh')").raises(Fog::Compute::AWS::NotFound) do
@ -118,9 +149,7 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
end
@volume.destroy
end
@server.destroy
end