From 4bd698d77284bc4bbe087693009f1316b8a44099 Mon Sep 17 00:00:00 2001 From: Dylan Egan Date: Sat, 16 Jun 2012 15:05:34 +0200 Subject: [PATCH] Fix up describe_volume_status to work with THE ARRAYZ. :v: --- .../parsers/compute/describe_volume_status.rb | 107 ++++++++++-------- .../aws/parsers/compute/describe_volumes.rb | 2 - tests/aws/requests/compute/volume_tests.rb | 39 ++++++- 3 files changed, 96 insertions(+), 52 deletions(-) diff --git a/lib/fog/aws/parsers/compute/describe_volume_status.rb b/lib/fog/aws/parsers/compute/describe_volume_status.rb index 2d898ac16..9a37fe680 100644 --- a/lib/fog/aws/parsers/compute/describe_volume_status.rb +++ b/lib/fog/aws/parsers/compute/describe_volume_status.rb @@ -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 diff --git a/lib/fog/aws/parsers/compute/describe_volumes.rb b/lib/fog/aws/parsers/compute/describe_volumes.rb index 16f7684ab..4e4449029 100644 --- a/lib/fog/aws/parsers/compute/describe_volumes.rb +++ b/lib/fog/aws/parsers/compute/describe_volumes.rb @@ -2,9 +2,7 @@ module Fog module Parsers module Compute module AWS - class DescribeVolumes < Fog::Parsers::Base - def reset @attachment = {} @in_attachment_set = false diff --git a/tests/aws/requests/compute/volume_tests.rb b/tests/aws/requests/compute/volume_tests.rb index 89e931fc5..f68b4a791 100644 --- a/tests/aws/requests/compute/volume_tests.rb +++ b/tests/aws/requests/compute/volume_tests.rb @@ -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