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

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

View file

@ -178,18 +178,36 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
old_mock_value = Excon.defaults[:mock] old_mock_value = Excon.defaults[:mock]
Excon.stubs.clear Excon.stubs.clear
begin tests("returns final response from a complete job") do
Excon.defaults[:mock] = true 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/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/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" } Fog::DNS::Dynect::Real.new.request(:method => :get, :path => "Zone/example.com").body.should == { "status" => "success" }
ensure ensure
Excon.stubs.clear Excon.stubs.clear
Excon.defaults[:mock] = old_mock_value 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 end
end end