diff options
author | Steve Kemp <steve@steve.org.uk> | 2017-08-08 13:28:23 +0300 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2017-08-08 13:28:23 +0300 |
commit | 3ddad643888312cfb32b27aee3a057106e1895e1 (patch) | |
tree | 553cc6fc92ea90554371c6559f36129556e3307a /lib/custodian | |
parent | e77603a491d3980c5d1fe8ae0af4c7414dde6eb4 (diff) |
Updated to move ignore-dns-failure code into routine.
That is then tested when resolve-errors are handled.
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/protocoltest/http.rb | 148 |
1 files changed, 75 insertions, 73 deletions
diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 71388c8..88ac568 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -38,6 +38,78 @@ module Custodian attr_reader :expected_status, :expected_content # + # Should we ignore a (temporary) DNS error in this test? + # + # We've been beset by a series of false-alerts in the recent + # past which have all occurred at this point: + # + # * We get bogus errors in resolving DNS from curb/libcurl. + # + # * These errors go away on retry. + # + # * But the retry isn't fast enough to outrace the + # supression-time of our alerts. + # + # For the moment we're going to _temporarily_ ignore these errors. + # + # * If a host has Connection-Refused, the wrong status-cde + # or similar failure it will be handled as normal. + # + # * If the host has genuinely lost DNS then we're going to + # raise an alert, but if it is this false-error then we + # will silently disable this test-run. + # + def ignore_failure? + + # IP addresses we found for the host + ips = [] + + # Get the hostname we're connecting to. + u = URI.parse(@url) + target = u.host + + # + # Resolve the target to an IP, unless it is already an address. + # + if (target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || + (target =~ /^([0-9a-f:]+)$/) + ips.push(target) + else + + # + # OK if it didn't look like an IP address then attempt to + # look it up, as both IPv4 and IPv6. + # + begin + timeout(30) do + + Resolv::DNS.open do |dns| + + ress = dns.getresources(target, Resolv::DNS::Resource::IN::A) + ress.map { |r| ips.push(r.address.to_s) } + + ress = dns.getresources(target, Resolv::DNS::Resource::IN::AAAA) + ress.map { |r| ips.push(r.address.to_s) } + end + end + rescue Timeout::Error => _e + # NOP + end + end + + # + # At this point we either have: + # + # "ips" containing entries - because the hostname resolved + # + # "ips" being empty because the DNS failure was genuine + # + return ( ! ips.empty? ) + end + + + + # # Constructor # def initialize(line) @@ -337,78 +409,6 @@ module Custodian rescue Curl::Err::TooManyRedirectsError errors << "#{protocol_msg}: More than 10 redirections." rescue Curl::Err::HostResolutionError => x - - # - # We've been beset by a series of false-alerts in the recent - # past which have all occurred at this point: - # - # * We get bogus errors in resolving DNS from curb/libcurl. - # - # * These errors go away on retry. - # - # * But the retry isn't fast enough to outrace the - # supression-time of our alerts. - # - # For the moment we're going to _temporarily_ ignore these - # errors. - # - # * If a host has Connection-Refused, the wrong status-cde - # or similar failure it will be handled as normal. - # - # * If the host has genuinely lost DNS then we're going to - # raise an alert, but if it is this false-error then we - # will silently disable this test-run. - # - # - - # IP addresses we found for the host - ips = [] - - # Get the hostname we're connecting to. - u = URI.parse(test_url) - target = u.host - - # - # Resolve the target to an IP, unless it is already an address. - # - if (target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || - (target =~ /^([0-9a-f:]+)$/) - ips.push(target) - else - - # - # OK if it didn't look like an IP address then attempt to - # look it up, as both IPv4 and IPv6. - # - begin - timeout(30) do - - Resolv::DNS.open do |dns| - - ress = dns.getresources(target, Resolv::DNS::Resource::IN::A) - ress.map { |r| ips.push(r.address.to_s) } - - ress = dns.getresources(target, Resolv::DNS::Resource::IN::AAAA) - ress.map { |r| ips.push(r.address.to_s) } - end - end - rescue Timeout::Error => _e - # NOP - end - end - - # - # At this point we either have: - # - # "ips" containing entries - because the hostname resolved - # - # "ips" being empty because the DNS failure was genuine - # - return Custodian::TestResult::TEST_SKIPPED unless ips.empty? - - # - # Log the DNS error-message, as this is genuine. - # resolution_errors << "#{protocol_msg}: #{x.class}: #{x.message}\n #{x.backtrace.join("\n ")}." rescue => x @@ -432,8 +432,10 @@ module Custodian # uh-oh! Resolution failed on both protocols! if resolution_errors.length > 1 - errors << "DNS Error when resolving host - #{resolution_errors.join(',')}" + return Custodian::TestResult::TEST_SKIPPED if ignore_failure? + + errors << "DNS Error when resolving host - #{resolution_errors.join(',')}" end if !errors.empty? |