diff --git a/lib/fog/dynect/dns.rb b/lib/fog/dynect/dns.rb index 245f7a30e..185af5f90 100644 --- a/lib/fog/dynect/dns.rb +++ b/lib/fog/dynect/dns.rb @@ -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 diff --git a/tests/dynect/requests/dns/dns_tests.rb b/tests/dynect/requests/dns/dns_tests.rb index fe4295bf3..a950ed498 100644 --- a/tests/dynect/requests/dns/dns_tests.rb +++ b/tests/dynect/requests/dns/dns_tests.rb @@ -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