From: Jelte Jansen Date: Fri, 9 Mar 2012 17:33:26 +0000 (+0100) Subject: [1321] make notify a user command in xfrout X-Git-Tag: trac2351_base~226^2~116^2~126^2~1^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5043998b29c17dd31a06cdfa9bcd73eb2832127b;p=thirdparty%2Fkea.git [1321] make notify a user command in xfrout And because users can mistype, the send_notify command now returns whether it knows about the zone --- diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in index 165560bc0f..8f236ecf68 100755 --- a/src/bin/xfrout/xfrout.py.in +++ b/src/bin/xfrout/xfrout.py.in @@ -926,7 +926,7 @@ class XfroutServer: self._notifier.dispatcher() def send_notify(self, zone_name, zone_class): - self._notifier.send_notify(zone_name, zone_class) + return self._notifier.send_notify(zone_name, zone_class) def config_handler(self, new_config): '''Update config data. TODO. Do error check''' @@ -982,10 +982,16 @@ class XfroutServer: elif cmd == notify_out.ZONE_NEW_DATA_READY_CMD: zone_name = args.get('zone_name') zone_class = args.get('zone_class') - if zone_name and zone_class: + if not zone_class: + zone_class = str(RRClass.IN()) + if zone_name: logger.info(XFROUT_NOTIFY_COMMAND, zone_name, zone_class) - self.send_notify(zone_name, zone_class) - answer = create_answer(0) + if self.send_notify(zone_name, zone_class): + answer = create_answer(0) + else: + zonestr = notify_out.format_zone_str(Name(zone_name), + zone_class) + answer = create_answer(1, "Unknown zone: " + zonestr) else: answer = create_answer(1, "Bad command parameter:" + str(args)) diff --git a/src/bin/xfrout/xfrout.spec.pre.in b/src/bin/xfrout/xfrout.spec.pre.in index ce8686e60e..30c9d56fae 100644 --- a/src/bin/xfrout/xfrout.spec.pre.in +++ b/src/bin/xfrout/xfrout.spec.pre.in @@ -71,6 +71,19 @@ "item_optional": true } ] + }, + { "command_name": "notify", + "command_description": "Send notifies for zone", + "command_args": [ + { "item_name": "zone_name", + "item_type": "string", + "item_optional": false, + "item_default": "" }, + { "item_name": "zone_class", + "item_type": "string", + "item_optional": true, + "item_default": "IN" + } ] } ] } diff --git a/src/lib/python/isc/notify/notify_out.py b/src/lib/python/isc/notify/notify_out.py index 153a00ab26..589bf60721 100644 --- a/src/lib/python/isc/notify/notify_out.py +++ b/src/lib/python/isc/notify/notify_out.py @@ -34,7 +34,7 @@ logger = isc.log.Logger("notify_out") # initialized yet. see trac ticket #1103 from isc.dns import * -ZONE_NEW_DATA_READY_CMD = 'zone_new_data_ready' +ZONE_NEW_DATA_READY_CMD = 'notify' _MAX_NOTIFY_NUM = 30 _MAX_NOTIFY_TRY_NUM = 5 _EVENT_NONE = 0 @@ -164,17 +164,19 @@ class NotifyOut: the only interface for class NotifyOut which can be called by other object. Internally, the function only set the zone's notify-reply - timeout to now, then notify message will be sent out. ''' + timeout to now, then notify message will be sent out. + Returns False if the zone/class is not known, True if it is + (even if there are no slaves)''' if zone_name[len(zone_name) - 1] != '.': zone_name += '.' zone_id = (zone_name, zone_class) if zone_id not in self._notify_infos: - return + return False # Has no slave servers, skip it. if (len(self._notify_infos[zone_id].notify_slaves) <= 0): - return + return True with self._lock: if (self.notify_num >= _MAX_NOTIFY_NUM) or (zone_id in self._notifying_zones): @@ -186,6 +188,7 @@ class NotifyOut: self._notifying_zones.append(zone_id) if not self._nonblock_event.isSet(): self._nonblock_event.set() + return True def _dispatcher(self, started_event): started_event.set() # Let the master know we are alive already diff --git a/src/lib/python/isc/notify/tests/notify_out_test.py b/src/lib/python/isc/notify/tests/notify_out_test.py index d64c20308a..f14eebd868 100644 --- a/src/lib/python/isc/notify/tests/notify_out_test.py +++ b/src/lib/python/isc/notify/tests/notify_out_test.py @@ -114,38 +114,48 @@ class TestNotifyOut(unittest.TestCase): notify_out._MAX_NOTIFY_NUM = 2 self._notify._nonblock_event.clear() - self._notify.send_notify('example.net') + self.assertTrue(self._notify.send_notify('example.net')) self.assertTrue(self._notify._nonblock_event.isSet()) self.assertEqual(self._notify.notify_num, 1) self.assertEqual(self._notify._notifying_zones[0], ('example.net.', 'IN')) - self._notify.send_notify('example.com') + self.assertTrue(self._notify.send_notify('example.com')) self.assertEqual(self._notify.notify_num, 2) self.assertEqual(self._notify._notifying_zones[1], ('example.com.', 'IN')) # notify_num is equal to MAX_NOTIFY_NUM, append it to waiting_zones list. self._notify._nonblock_event.clear() - self._notify.send_notify('example.com', 'CH') + self.assertTrue(self._notify.send_notify('example.com', 'CH')) # add waiting zones won't set nonblock_event. self.assertFalse(self._notify._nonblock_event.isSet()) self.assertEqual(self._notify.notify_num, 2) self.assertEqual(1, len(self._notify._waiting_zones)) # zone_id is already in notifying_zones list, append it to waiting_zones list. - self._notify.send_notify('example.net') + self.assertTrue(self._notify.send_notify('example.net')) self.assertEqual(2, len(self._notify._waiting_zones)) self.assertEqual(self._notify._waiting_zones[1], ('example.net.', 'IN')) # zone_id is already in waiting_zones list, skip it. - self._notify.send_notify('example.net') + self.assertTrue(self._notify.send_notify('example.net')) self.assertEqual(2, len(self._notify._waiting_zones)) # has no slave masters, skip it. - self._notify.send_notify('example.org.', 'CH') + self.assertTrue(self._notify.send_notify('example.org.', 'CH')) self.assertEqual(self._notify.notify_num, 2) self.assertEqual(2, len(self._notify._waiting_zones)) - self._notify.send_notify('example.org.') + self.assertTrue(self._notify.send_notify('example.org.')) + self.assertEqual(self._notify.notify_num, 2) + self.assertEqual(2, len(self._notify._waiting_zones)) + + # zone does not exist, should return False, and no change in other + # values + self.assertFalse(self._notify.send_notify('does.not.exist.')) + self.assertEqual(self._notify.notify_num, 2) + self.assertEqual(2, len(self._notify._waiting_zones)) + + self.assertFalse(self._notify.send_notify('example.net.', 'CH')) self.assertEqual(self._notify.notify_num, 2) self.assertEqual(2, len(self._notify._waiting_zones))