Logo Search packages:      
Sourcecode: namebench version File versions  Download package

def libnamebench::health_checks::NameServerHealthChecks::TestAnswers (   self,
  record_type,
  record,
  expected,
  fatal = True,
  timeout = None 
) [inherited]

Test to see that an answer returns correct IP's.

Args:
  record_type: text record type for NS query (A, CNAME, etc)
  record: string to query for
  expected: tuple of strings expected in all answers

Returns:
  (is_broken, error_msg, duration)

Definition at line 44 of file health_checks.py.

00044                                                                                 :
    """Test to see that an answer returns correct IP's.

    Args:
      record_type: text record type for NS query (A, CNAME, etc)
      record: string to query for
      expected: tuple of strings expected in all answers

    Returns:
      (is_broken, error_msg, duration)
    """
    is_broken = False
    response_text = None
    unmatched_answers = []
    warning = None
    if not timeout:
      timeout = self.health_timeout
    (response, duration, error_msg) = self.TimedRequest(record_type, record, timeout)
    if not response:
      is_broken = True
    elif not response.answer:
      if fatal:
        is_broken = True
      # Avoid preferring broken DNS servers that respond quickly
      duration = self.health_timeout
      error_msg = 'No answer for %s' % record
    else:
      unmatched_answers = []
      found_usable_record = False

      for answer in response.answer:
        if found_usable_record:
          break

        # Process the first sane rdata object available in the answers
        for rdata in answer:
          # CNAME
          if rdata.rdtype == 5:
            reply = str(rdata.target)
          # A Record
          elif rdata.rdtype ==  1:
            reply = str(rdata.address)
          else:
            continue

          found_usable_record = True
          found_match = False
          for string in expected:
            if reply.startswith(string) or reply.endswith(string):
              found_match = True
              break
          if not found_match:
            unmatched_answers.append(reply)

      if unmatched_answers:
        error_msg = 'Incorrect result for %s: %s' % (record, ', '.join(unmatched_answers))

    return (is_broken, error_msg, duration)

  def TestLocalhostResponse(self):


Generated by  Doxygen 1.6.0   Back to index