-# Copyright (C) 2010 Internet Systems Consortium.
+# Copyright (C) 2010-2012 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
from isc.net import addr
import isc
from isc.log_messages.notify_out_messages import *
+from isc.statistics import counter
logger = isc.log.Logger("notify_out")
notify message to its slaves). notify service can be started by
calling dispatcher(), and it can be stopped by calling shutdown()
in another thread. '''
- def __init__(self, datasrc_file, counter_handler=None, verbose=True,
- counter_notifyoutv4=None, counter_notifyoutv6=None):
+ def __init__(self, datasrc_file, counter_handler=None, verbose=True):
self._notify_infos = {} # key is (zone_name, zone_class)
self._waiting_zones = []
self._notifying_zones = []
# Use nonblock event to eliminate busy loop
# If there are no notifying zones, clear the event bit and wait.
self._nonblock_event = threading.Event()
- # Set counter handlers for counting notifies. An argument is
- # required for zone name.
- self._counter_notifyoutv4 = counter_notifyoutv4
- self._counter_notifyoutv6 = counter_notifyoutv6
def _init_notify_out(self, datasrc_file):
'''Get all the zones name and its notify target's address.
sock = zone_notify_info.create_socket(addrinfo[0])
sock.sendto(render.get_data(), 0, addrinfo)
# count notifying by IPv4 or IPv6 for statistics
- if zone_notify_info.get_socket().family \
- == socket.AF_INET \
- and self._counter_notifyoutv4 is not None:
- self._counter_notifyoutv4(zone_notify_info.zone_name)
- elif zone_notify_info.get_socket().family \
- == socket.AF_INET6 \
- and self._counter_notifyoutv6 is not None:
- self._counter_notifyoutv6(zone_notify_info.zone_name)
+ if zone_notify_info.get_socket().family == socket.AF_INET:
+ counter.inc_notifyoutv4(zone_notify_info.zone_name)
+ elif zone_notify_info.get_socket().family == socket.AF_INET6:
+ counter.inc_notifyoutv6(zone_notify_info.zone_name)
logger.info(NOTIFY_OUT_SENDING_NOTIFY, addrinfo[0],
addrinfo[1])
except (socket.error, addr.InvalidAddress) as err:
-# Copyright (C) 2010 Internet Systems Consortium.
+# Copyright (C) 2010-2012 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
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')
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
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)
+
# As long as the underlying data source validates RDATA this shouldn't
# happen, but right now it's not actually the case. Even if the
# data source does its job, it's prudent to confirm the behavior for
# an unexpected case.
- 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