Esempio n. 1
0
 def test_dns_dict_to_string(self):
     """
     Test with a simple dict
     """
     d = {'a': 'vala', 'c': 'valc', 'b': 'valb'}
     s = "{'a': 'vala', 'b': 'valb', 'c': 'valc'}"
     foo = dns_dict_to_string(d)
     assert foo == s
Esempio n. 2
0
 def test_dns_dict_to_string_deep(self):
     """
     Test with a deep dict
     """
     d = {'a': 'vala', 'c': {'cc': 'valcc', 'ca': 'valca', 'cb': 'valcb'}, 'b': 'valb'}
     s = "{'a': 'vala', 'b': 'valb', 'c': {'ca': 'valca', 'cb': 'valcb', 'cc': 'valcc'}}"
     foo = dns_dict_to_string(d)
     assert foo == s
Esempio n. 3
0
 def test_dns_dict_to_string(self):
     """
     Test with a simple dict
     """
     d = {'a': 'vala', 'c': 'valc', 'b': 'valb'}
     s = "{'a': 'vala', 'b': 'valb', 'c': 'valc'}"
     foo = dns_dict_to_string(d)
     assert foo == s
Esempio n. 4
0
 def test_dns_dict_to_string_deep(self):
     """
     Test with a deep dict
     """
     d = {
         'a': 'vala',
         'c': {
             'cc': 'valcc',
             'ca': 'valca',
             'cb': 'valcb'
         },
         'b': 'valb'
     }
     s = "{'a': 'vala', 'b': 'valb', 'c': {'ca': 'valca', 'cb': 'valcb', 'cc': 'valcc'}}"
     foo = dns_dict_to_string(d)
     assert foo == s
Esempio n. 5
0
    def confirm_name(self, n):
        """
        Confirms that the given name returns the
        same result in TEST and PROD.

        @param n name
        """
        res = {
            'result': None,
            'message': None,
            'secondary': [],
            'warnings': []
        }
        name = n
        # make sure we have a FQDN
        if name.find('.') == -1:
            name = name + self.config.default_domain

        # resolve with both test and prod
        qt = self.DNS.resolve_name(name, self.config.server_test)
        qp = self.DNS.resolve_name(name, self.config.server_prod)
        if 'status' in qt:
            if 'status' not in qp:
                res['message'] = "test server returned status %s for name %s, but prod returned valid answer of %s" % (
                    qt['status'], n, qp['answer']['data'])
                res['result'] = False
                return res
            if qp['status'] == qt['status']:
                res['message'] = "both test and prod returned status %s for name %s" % (
                    qt['status'], n)
                res['result'] = True
                return res
            # else both have different statuses
            res['message'] = "test server returned status %s for name %s, but prod returned status %s" % (
                qt['status'], n, qp['status'])
            res['result'] = False
            return res
        if 'status' in qp and 'status' not in qt:
            res['message'] = "prod server returned status %s for name %s, but test returned valid answer of %s" % (
                qp['status'], n, qt['answer']['data'])
            res['result'] = False
            return res

        # remove ttl if we want to ignore it
        if self.config.ignore_ttl:
            qp['answer'].pop('ttl', None)
            qt['answer'].pop('ttl', None)

        # ok, both returned an ansewer. diff them.
        same_res = True
        for k in qt['answer']:
            if k not in qp['answer']:
                res['warnings'].append(
                    "NG: test response has %s of '%s'; prod response does not include %s"
                    % (k, qt['answer'][k], k))
                same_res = False
            elif qt['answer'][k] != qp['answer'][k]:
                res['warnings'].append(
                    "NG: test response has %s of '%s' but prod response has '%s'"
                    % (k, qt['answer'][k], qp['answer'][k]))
                same_res = False
        for k in qp['answer']:
            if k not in qt['answer']:
                res['warnings'].append(
                    "NG: prod response has %s of '%s'; test response does not include %s"
                    % (k, qp['answer'][k], k))
                same_res = False

        # for testing
        res['warnings'] = sorted(res['warnings'])

        if same_res is False:
            res['message'] = "prod and test servers return different responses for '%s'" % n
            res['result'] = False
            return res
        res['message'] = "prod and test servers return same response for '%s'" % n
        res['secondary'].append("response: %s" %
                                dns_dict_to_string(qp['answer']))
        res['result'] = True
        return res
Esempio n. 6
0
    def confirm_name(self, n):
        """
        Confirms that the given name returns the
        same result in TEST and PROD.

        @param n name
        """
        res = {'result': None, 'message': None, 'secondary': [], 'warnings': []}
        name = n
        # make sure we have a FQDN
        if name.find('.') == -1:
            name = name + self.config.default_domain

        # resolve with both test and prod
        qt = self.DNS.resolve_name(name, self.config.server_test)
        qp = self.DNS.resolve_name(name, self.config.server_prod)
        if 'status' in qt:
            if 'status' not in qp:
                res['message'] = "test server returned status %s for name %s, but prod returned valid answer of %s" % (qt['status'], n, qp['answer']['data'])
                res['result'] = False
                return res
            if qp['status'] == qt['status']:
                res['message'] = "both test and prod returned status %s for name %s" % (qt['status'], n)
                res['result'] = True
                return res
            # else both have different statuses
            res['message'] = "test server returned status %s for name %s, but prod returned status %s" % (qt['status'], n, qp['status'])
            res['result'] = False
            return res
        if 'status' in qp and 'status' not in qt:
            res['message'] = "prod server returned status %s for name %s, but test returned valid answer of %s" % (qp['status'], n, qt['answer']['data'])
            res['result'] = False
            return res

        # remove ttl if we want to ignore it
        if self.config.ignore_ttl:
            qp['answer'].pop('ttl', None)
            qt['answer'].pop('ttl', None)

        # ok, both returned an ansewer. diff them.
        same_res = True
        for k in qt['answer']:
            if k not in qp['answer']:
                res['warnings'].append("NG: test response has %s of '%s'; prod response does not include %s" % (k, qt['answer'][k], k))
                same_res = False
            elif qt['answer'][k] != qp['answer'][k]:
                res['warnings'].append("NG: test response has %s of '%s' but prod response has '%s'" % (k, qt['answer'][k], qp['answer'][k]))
                same_res = False
        for k in qp['answer']:
            if k not in qt['answer']:
                res['warnings'].append("NG: prod response has %s of '%s'; test response does not include %s" % (k, qp['answer'][k], k))
                same_res = False

        # for testing
        res['warnings'] = sorted(res['warnings'])

        if same_res is False:
            res['message'] = "prod and test servers return different responses for '%s'" % n
            res['result'] = False
            return res
        res['message'] = "prod and test servers return same response for '%s'" % n
        res['secondary'].append("response: %s" % dns_dict_to_string(qp['answer']))
        res['result'] = True
        return res