[dynect|dns] Job polling should use original expected statuses.

This commit is contained in:
Dan Peterson 2012-08-13 11:13:52 -03:00
parent 1b69f403f3
commit dfe13342a9
2 changed files with 30 additions and 12 deletions

View File

@ -102,7 +102,7 @@ module Fog
end
if response.status == 307 && params[:path] !~ %r{^/REST/Job/}
response = poll_job(response)
response = poll_job(response, params[:expects])
end
response
@ -118,11 +118,11 @@ module Fog
response
end
def poll_job(response, time_to_wait = 10)
def poll_job(response, original_expects, time_to_wait = 10)
job_location = response.headers['Location']
Fog.wait_for(time_to_wait) do
response = request(:expects => 200, :method => :get, :path => job_location)
response = request(:expects => original_expects, :method => :get, :path => job_location)
response.body['status'] != 'incomplete'
end

View File

@ -178,18 +178,36 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
old_mock_value = Excon.defaults[:mock]
Excon.stubs.clear
begin
Excon.defaults[:mock] = true
tests("returns final response from a complete job") do
begin
Excon.defaults[:mock] = true
Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 307, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 307, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
Fog::DNS::Dynect::Real.new.request(:method => :get, :path => "Zone/example.com").body.should == { "status" => "success" }
ensure
Excon.stubs.clear
Excon.defaults[:mock] = old_mock_value
Fog::DNS::Dynect::Real.new.request(:method => :get, :path => "Zone/example.com").body.should == { "status" => "success" }
ensure
Excon.stubs.clear
Excon.defaults[:mock] = old_mock_value
end
end
tests("passes expects through when polling a job") do
begin
Excon.defaults[:mock] = true
Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 404, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
Fog::DNS::Dynect::Real.new.request(:method => :get, :expects => 404, :path => "Zone/example.com").body.should == { "status" => "success" }
ensure
Excon.stubs.clear
Excon.defaults[:mock] = old_mock_value
end
end
end
end