Skip to content

Commit

Permalink
Handling lookup for provisioning_state in ruby client runtime (Azure#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vishrutshah authored Jul 12, 2016
1 parent 0c749da commit fcbeb84
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ def update_state_from_get_resource_operation(request, polling_state, custom_dese

fail AzureOperationError, 'The response from long running operation does not contain a body' if result.response.body.nil? || result.response.body.empty?

if result.body.respond_to?(:provisioning_state) && !result.body.provisioning_state.nil?
# On non flattened resource, we should find provisioning_state inside 'properties'
if result.body.respond_to?(:properties) && result.body.properties.respond_to?(:provisioning_state) && !result.body.properties.provisioning_state.nil?
polling_state.status = result.body.properties.provisioning_state
# On flattened resource, we should find provisioning_state at the top level
elsif result.body.respond_to?(:provisioning_state) && !result.body.provisioning_state.nil?
polling_state.status = result.body.provisioning_state
else
polling_state.status = AsyncOperationStatus::SUCCESS_STATUS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def initialize(azure_response, retry_timeout)
update_response(azure_response.response)
@resource = azure_response.body

if !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil?
# On non flattened resource, we should find provisioning_state inside 'properties'
if (!@resource.nil? && @resource.respond_to?(:properties) && @resource.properties.respond_to?(:provisioning_state) && !@resource.properties.provisioning_state.nil?)
@status = @resource.properties.provisioning_state
# On flattened resource, we should find provisioning_state at the top level
elsif !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil?
@status = @resource.provisioning_state
else
case @response.status
Expand Down
15 changes: 14 additions & 1 deletion src/client/Ruby/ms-rest-azure/spec/polling_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module MsRestAzure

describe PollingState do
it 'should initialize status from response header' do
it 'should initialize status from flattened response body' do
response_body = double('response_body', :provisioning_state => 'InProgress')
response = double('response',
:request => nil,
Expand All @@ -20,6 +20,19 @@ module MsRestAzure
expect(polling_state.status).to eq('InProgress')
end

it 'should initialize status from non-flattened response body' do
provisioning_state = double('provisioning_state', :provisioning_state => 'Succeeded')
response_body = double('response_body', :properties => provisioning_state)
response = double('response',
:request => nil,
:response => nil,
:body => response_body)

polling_state = PollingState.new response, 0

expect(polling_state.status).to eq('Succeeded')
end

it 'should initialize status from response status' do
response = double('response', :status => 200, :headers => {})

Expand Down

0 comments on commit fcbeb84

Please sign in to comment.