Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling lookup for provisioning_state in ruby client runtime #1223

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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