Commit 10c84106 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1298] tests for format_ functions

parent 23cfc5b4
......@@ -2146,6 +2146,52 @@ class TestMain(unittest.TestCase):
MockXfrin.check_command_hook = raise_exception
main(MockXfrin, False)
class TestFormatting(unittest.TestCase):
# If the formatting functions are moved to a more general library
# (ticket #1379), these tests should be moved with them.
def test_format_zone_str(self):
self.assertEqual("example.com/IN",
format_zone_str(isc.dns.Name("example.com"),
isc.dns.RRClass("IN")))
self.assertEqual("example.com/CH",
format_zone_str(isc.dns.Name("example.com"),
isc.dns.RRClass("CH")))
self.assertEqual("example.org/IN",
format_zone_str(isc.dns.Name("example.org"),
isc.dns.RRClass("IN")))
def test_format_addrinfo(self):
# This test may need to be updated if the input type is changed,
# right now it is a nested tuple:
# (family, sockettype, (address, port))
# of which sockettype is ignored
self.assertEqual("192.0.2.1:53",
format_addrinfo((socket.AF_INET, None,
("192.0.2.1", 53))))
self.assertEqual("192.0.2.2:53",
format_addrinfo((socket.AF_INET, None,
("192.0.2.2", 53))))
self.assertEqual("192.0.2.1:54",
format_addrinfo((socket.AF_INET, None,
("192.0.2.1", 54))))
self.assertEqual("[::1]:53",
format_addrinfo((socket.AF_INET6, None,
("::1", 53))))
self.assertEqual("[::2]:53",
format_addrinfo((socket.AF_INET6, None,
("::2", 53))))
self.assertEqual("[::1]:54",
format_addrinfo((socket.AF_INET6, None,
("::1", 54))))
self.assertEqual("/some/file",
format_addrinfo((socket.AF_UNIX, None,
"/some/file")))
self.assertRaises(TypeError, format_addrinfo, 1)
self.assertRaises(TypeError, format_addrinfo,
(socket.AF_INET, "asdf"))
self.assertRaises(TypeError, format_addrinfo,
(socket.AF_INET, "asdf", ()))
if __name__== "__main__":
try:
isc.log.resetUnitTestRootLogger()
......
......@@ -129,7 +129,7 @@ def format_zone_str(zone_name, zone_class):
zone_name (isc.dns.Name) name to format
zone_class (isc.dns.RRClass) class to format
"""
return zone_name.to_text() + '/' + str(zone_class)
return zone_name.to_text(True) + '/' + str(zone_class)
def format_addrinfo(addrinfo):
"""Helper function to format the addrinfo as a string of the form
......@@ -141,12 +141,16 @@ def format_addrinfo(addrinfo):
depending on the family, either a 2-tuple with the address
and port, or a filename
"""
if addrinfo[0] == socket.AF_INET:
return str(addrinfo[2][0]) + ":" + str(addrinfo[2][1])
elif addrinfo[0] == socket.AF_INET6:
return "[" + str(addrinfo[2][0]) + "]:" + str(addrinfo[2][1])
else:
return str(addrinfo[2])
try:
if addrinfo[0] == socket.AF_INET:
return str(addrinfo[2][0]) + ":" + str(addrinfo[2][1])
elif addrinfo[0] == socket.AF_INET6:
return "[" + str(addrinfo[2][0]) + "]:" + str(addrinfo[2][1])
else:
return str(addrinfo[2])
except IndexError:
raise TypeError("addrinfo argument to format_addrinfo() does not"
"appear to be consisting of (family, socktype, (addr, port))")
def get_soa_serial(soa_rdata):
'''Extract the serial field of an SOA RDATA and returns it as an intger.
......@@ -1093,7 +1097,7 @@ class Xfrin:
if zone_info is None:
# TODO what to do? no info known about zone. defaults?
errmsg = "Got notification to retransfer unknown zone " + zone_str
logger.error(XFRIN_RETRANSFER_UNKNOWN_ZONE, zone_str)
logger.info(XFRIN_RETRANSFER_UNKNOWN_ZONE, zone_str)
answer = create_answer(1, errmsg)
else:
master_addr = zone_info.get_master_addr_info()
......
......@@ -70,7 +70,7 @@ was killed.
There was a problem sending a message to the zone manager. This most
likely means that the msgq daemon has quit or was killed.
% XFRIN_NOTIFY_UNKNOWN_MASTER got notification to retransfer zone %1 from %2/%3, expected %4/%5
% XFRIN_NOTIFY_UNKNOWN_MASTER got notification to retransfer zone %1 from %2, expected %3
The system received a notify for the given zone, but the address it came
from does not match the master address in the Xfrin configuration. The notify
is ignored. This may indicate that the configuration for the master is wrong,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment