|
@@ -1,4 +1,4 @@
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -92,17 +92,28 @@ class TestZoneNotifyInfo(unittest.TestCase):
|
|
|
temp_info.prepare_notify_out()
|
|
|
self.assertIsNone(temp_info.get_current_notify_target())
|
|
|
|
|
|
+class DummyNotifyOutCounter:
|
|
|
+ _notifiesv4 = []
|
|
|
+ _notifiesv6 = []
|
|
|
+ def inc_notifyoutv4(self, arg):
|
|
|
+ self._notifiesv4.append(arg)
|
|
|
+ def inc_notifyoutv6(self, arg):
|
|
|
+ self._notifiesv6.append(arg)
|
|
|
+ def get_notifyoutv4(self, arg):
|
|
|
+ return self._notifiesv4.count(arg)
|
|
|
+ def get_notifyoutv6(self, arg):
|
|
|
+ return self._notifiesv6.count(arg)
|
|
|
+ def clear_counters(self):
|
|
|
+ self._notifiesv4 = []
|
|
|
+ self._notifiesv6 = []
|
|
|
+
|
|
|
+counter = DummyNotifyOutCounter()
|
|
|
+notify_out.counter = counter
|
|
|
|
|
|
class TestNotifyOut(unittest.TestCase):
|
|
|
def setUp(self):
|
|
|
self._db_file = TESTDATA_SRCDIR + '/test.sqlite3'
|
|
|
- self._notifiedv4_zone_name = None
|
|
|
- def _dummy_counter_notifyoutv4(z): self._notifiedv4_zone_name = z
|
|
|
- self._notifiedv6_zone_name = None
|
|
|
- def _dummy_counter_notifyoutv6(z): self._notifiedv6_zone_name = z
|
|
|
- self._notify = notify_out.NotifyOut(self._db_file,
|
|
|
- counter_notifyoutv4=_dummy_counter_notifyoutv4,
|
|
|
- counter_notifyoutv6=_dummy_counter_notifyoutv6)
|
|
|
+ self._notify = notify_out.NotifyOut(self._db_file)
|
|
|
self._notify._notify_infos[('example.com.', 'IN')] = MockZoneNotifyInfo('example.com.', 'IN')
|
|
|
self._notify._notify_infos[('example.com.', 'CH')] = MockZoneNotifyInfo('example.com.', 'CH')
|
|
|
self._notify._notify_infos[('example.net.', 'IN')] = MockZoneNotifyInfo('example.net.', 'IN')
|
|
@@ -117,6 +128,9 @@ class TestNotifyOut(unittest.TestCase):
|
|
|
com_ch_info = self._notify._notify_infos[('example.com.', 'CH')]
|
|
|
com_ch_info.notify_slaves.append(('1.1.1.1', 5353))
|
|
|
|
|
|
+ def tearDown(self):
|
|
|
+ counter.clear_counters()
|
|
|
+
|
|
|
def test_send_notify(self):
|
|
|
notify_out._MAX_NOTIFY_NUM = 2
|
|
|
|
|
@@ -268,77 +282,47 @@ class TestNotifyOut(unittest.TestCase):
|
|
|
|
|
|
def test_send_notify_message_udp_ipv4(self):
|
|
|
example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
+
|
|
|
+ self.assertEqual(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertEqual(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
+
|
|
|
example_com_info.prepare_notify_out()
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
ret = self._notify._send_notify_message_udp(example_com_info,
|
|
|
('192.0.2.1', 53))
|
|
|
self.assertTrue(ret)
|
|
|
self.assertEqual(socket.AF_INET, example_com_info.sock_family)
|
|
|
- self.assertEqual(self._notifiedv4_zone_name, 'example.net.')
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
+ self.assertGreater(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertEqual(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
|
|
|
def test_send_notify_message_udp_ipv6(self):
|
|
|
example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
+
|
|
|
+ self.assertEqual(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertEqual(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
+
|
|
|
ret = self._notify._send_notify_message_udp(example_com_info,
|
|
|
('2001:db8::53', 53))
|
|
|
self.assertTrue(ret)
|
|
|
self.assertEqual(socket.AF_INET6, example_com_info.sock_family)
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertEqual(self._notifiedv6_zone_name, 'example.net.')
|
|
|
-
|
|
|
- def test_send_notify_message_udp_ipv4_with_nonetype_notifyoutv4(self):
|
|
|
- example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
- example_com_info.prepare_notify_out()
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
- self._notify._counter_notifyoutv4 = None
|
|
|
- self._notify._send_notify_message_udp(example_com_info,
|
|
|
- ('192.0.2.1', 53))
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
-
|
|
|
- def test_send_notify_message_udp_ipv4_with_notcallable_notifyoutv4(self):
|
|
|
- example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
- example_com_info.prepare_notify_out()
|
|
|
- self._notify._counter_notifyoutv4 = 'NOT CALLABLE'
|
|
|
- self.assertRaises(TypeError,
|
|
|
- self._notify._send_notify_message_udp,
|
|
|
- example_com_info, ('192.0.2.1', 53))
|
|
|
-
|
|
|
- def test_send_notify_message_udp_ipv6_with_nonetype_notifyoutv6(self):
|
|
|
- example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
- self._notify._counter_notifyoutv6 = None
|
|
|
- self._notify._send_notify_message_udp(example_com_info,
|
|
|
- ('2001:db8::53', 53))
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
-
|
|
|
- def test_send_notify_message_udp_ipv6_with_notcallable_notifyoutv6(self):
|
|
|
- example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
- self._notify._counter_notifyoutv6 = 'NOT CALLABLE'
|
|
|
- self.assertRaises(TypeError,
|
|
|
- self._notify._send_notify_message_udp,
|
|
|
- example_com_info, ('2001:db8::53', 53))
|
|
|
+ self.assertEqual(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertGreater(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
|
|
|
def test_send_notify_message_with_bogus_address(self):
|
|
|
example_com_info = self._notify._notify_infos[('example.net.', 'IN')]
|
|
|
|
|
|
+ self.assertEqual(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertEqual(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
ret = self._notify._send_notify_message_udp(example_com_info,
|
|
|
('invalid', 53))
|
|
|
self.assertFalse(ret)
|
|
|
- self.assertIsNone(self._notifiedv4_zone_name)
|
|
|
- self.assertIsNone(self._notifiedv6_zone_name)
|
|
|
+
|
|
|
+ self.assertEqual(counter.get_notifyoutv4('example.net.'), 0)
|
|
|
+ self.assertEqual(counter.get_notifyoutv6('example.net.'), 0)
|
|
|
|
|
|
def test_zone_notify_handler(self):
|
|
|
old_send_msg = self._notify._send_notify_message_udp
|