BIND 10 trac811, updated. 2f30475b3116427988f8e3aaee081b42833f9b71 [trac811] use address from notify to check instead of for direct axfr
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Apr 26 12:24:29 UTC 2011
The branch, trac811 has been updated
via 2f30475b3116427988f8e3aaee081b42833f9b71 (commit)
via cca6eb6fc963300ec2a1c29f00921da54785a215 (commit)
via 38789769e28b4be9c4fc580f8af346264fb68e62 (commit)
via 8d8b745e9d53ae0bcaa01100472915367157fc08 (commit)
from a7851af501420e9693b3c37a71de97738c8adc0e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2f30475b3116427988f8e3aaee081b42833f9b71
Author: Jelte Jansen <jelte at isc.org>
Date: Tue Apr 19 11:15:37 2011 +0200
[trac811] use address from notify to check instead of for direct axfr
commit cca6eb6fc963300ec2a1c29f00921da54785a215
Author: Jelte Jansen <jelte at isc.org>
Date: Mon Apr 18 15:44:30 2011 +0200
[trac811] add master/tsig options to spec
commit 38789769e28b4be9c4fc580f8af346264fb68e62
Author: Jelte Jansen <jelte at isc.org>
Date: Mon Apr 18 15:30:54 2011 +0200
[trac811] move a few functions that don't need state out of the class
commit 8d8b745e9d53ae0bcaa01100472915367157fc08
Author: Jelte Jansen <jelte at isc.org>
Date: Mon Apr 18 14:49:53 2011 +0200
[trac811] reproduce some of the changes of the previous commit (which got lost)
-----------------------------------------------------------------------
Summary of changes:
src/bin/zonemgr/tests/zonemgr_test.py | 8 ++-
src/bin/zonemgr/zonemgr.py.in | 106 +++++++++++++++++++++++----------
src/bin/zonemgr/zonemgr.spec.pre.in | 16 +++++
3 files changed, 96 insertions(+), 34 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/zonemgr/tests/zonemgr_test.py b/src/bin/zonemgr/tests/zonemgr_test.py
index bd9cee0..c14e6c6 100644
--- a/src/bin/zonemgr/tests/zonemgr_test.py
+++ b/src/bin/zonemgr/tests/zonemgr_test.py
@@ -53,8 +53,10 @@ class FakeConfig:
self.zone_list = []
self.set_zone_list_from_name_classes([ZONE_NAME_CLASS1_IN,
ZONE_NAME_CLASS2_CH])
+
def set_zone_list_from_name_classes(self, zones):
self.zone_list = map(lambda nc: {"name": nc[0], "class": nc[1]}, zones)
+
def get(self, name):
if name == 'lowerbound_refresh':
return LOWERBOUND_REFRESH
@@ -112,11 +114,11 @@ class TestZonemgrRefresh(unittest.TestCase):
def test_random_jitter(self):
max = 100025.120
jitter = 0
- self.assertEqual(max, self.zone_refresh._random_jitter(max, jitter))
+ self.assertEqual(max, random_jitter(max, jitter))
jitter = max / 4
for i in range (0, 150):
- self.assertTrue((3 * max / 4) <= self.zone_refresh._random_jitter(max, jitter))
- self.assertTrue(self.zone_refresh._random_jitter(max, jitter) <= max)
+ self.assertTrue((3 * max / 4) <= random_jitter(max, jitter))
+ self.assertTrue(random_jitter(max, jitter) <= max)
i += 1;
def test_get_current_time(self):
diff --git a/src/bin/zonemgr/zonemgr.py.in b/src/bin/zonemgr/zonemgr.py.in
index f86d928..4014874 100755
--- a/src/bin/zonemgr/zonemgr.py.in
+++ b/src/bin/zonemgr/zonemgr.py.in
@@ -106,17 +106,67 @@ class ZoneData:
self.next_refresh_time = None
self.refresh_timeout = None
- def getNameClass(self):
+ def get_name_class(self):
"""Returns a tuple containing the zone name and its class, this
is used to reference info for a specific zone in
ZonemgrRefresh, which (right now) is a dict"""
return (self.zname, self.zclass)
- def updateConfigValue(self, other):
+ def update_config_value(self, other):
self.master_addr = other.master_addr
self.master_port = other.master_port
self.tsig_key = other.tsig_key
+class ZonemgrRefreshInfo:
+ def __init__(self):
+ self._info = {}
+
+ def __iter__(self):
+ return self._info.__iter__()
+
+ def __getitem__(self, key):
+ return self._info[key]
+
+ def __setitem__(self, key, value):
+ self._info[key] = value
+
+ def __delitem__(self, item):
+ del self._info[item]
+
+ def __contains__(self, item):
+ return (item in self._info)
+
+ def __len__(self):
+ return len(self._info)
+
+ def keys(self):
+ return self._info.keys()
+
+ def copy(self):
+ new_info = ZonemgrRefreshInfo()
+ new_info._info = self._info.copy()
+ return new_info
+
+ def set_zone_data(self, zone_info):
+ name_class = zone_info.get_name_class()
+ if name_class in self._info:
+ self._info[name_class].update_config_data(zone_info)
+ else:
+ self._info[name_class] = zone_info
+
+def random_jitter(max, jitter):
+ """Imposes some random jitters for refresh and
+ retry timers to avoid many zones need to do refresh
+ at the same time.
+ The value should be between (max - jitter) and max.
+ """
+ if 0 == jitter:
+ return max
+ return random.uniform(max - jitter, max)
+
+def get_current_time():
+ return time.time()
+
class ZonemgrRefresh:
"""This class will maintain and manage zone refresh info.
It also provides methods to keep track of zone timers and
@@ -130,28 +180,15 @@ class ZonemgrRefresh:
self._cc = cc
self._check_sock = slave_socket
self._db_file = db_file
- self._zonemgr_refresh_info = {}
+ self._zonemgr_refresh_info = ZonemgrRefreshInfo()
self.update_config_data(config_data)
self._running = False
- def _random_jitter(self, max, jitter):
- """Imposes some random jitters for refresh and
- retry timers to avoid many zones need to do refresh
- at the same time.
- The value should be between (max - jitter) and max.
- """
- if 0 == jitter:
- return max
- return random.uniform(max - jitter, max)
-
- def _get_current_time(self):
- return time.time()
-
def _set_zone_timer(self, zone_name_class, max, jitter):
"""Set zone next refresh time.
jitter should not be bigger than half the original value."""
- self._set_zone_next_refresh_time(zone_name_class, self._get_current_time() + \
- self._random_jitter(max, jitter))
+ self._set_zone_next_refresh_time(zone_name_class, get_current_time() + \
+ random_jitter(max, jitter))
def _set_zone_refresh_timer(self, zone_name_class):
"""Set zone next refresh time after zone refresh success.
@@ -187,7 +224,7 @@ class ZonemgrRefresh:
self.zonemgr_reload_zone(zone_name_class)
self._set_zone_refresh_timer(zone_name_class)
self._set_zone_state(zone_name_class, ZONE_OK)
- self._set_zone_last_refresh_time(zone_name_class, self._get_current_time())
+ self._set_zone_last_refresh_time(zone_name_class, get_current_time())
def zone_refresh_fail(self, zone_name_class):
"""Update zone info after zone refresh fail"""
@@ -206,7 +243,11 @@ class ZonemgrRefresh:
if (self._zone_not_exist(zone_name_class)):
raise ZonemgrException("[b10-zonemgr] Notified zone (%s, %s) "
"doesn't belong to zonemgr" % zone_name_class)
- self._set_zone_notifier_master(zone_name_class, master)
+ #self._set_zone_notifier_master(zone_name_class, master)
+ if (self._get_zone_notifier_master(zone_name_class) != master):
+ raise ZonemgrException("[b10-zonemgr] Notified zone (%s, %s) "
+ "from wrong master: %s" % (zone_name_class[0], zone_name_class[1], master))
+
self._set_zone_notify_timer(zone_name_class)
def zonemgr_reload_zone(self, zone_name_class):
@@ -216,23 +257,23 @@ class ZonemgrRefresh:
def zonemgr_add_zone(self, zone_info):
""" Add a zone into zone manager."""
- log_msg("Loading zone (%s, %s)" % zone_info.getNameClass())
+ log_msg("Loading zone (%s, %s)" % zone_info.get_name_class())
zone_soa = sqlite3_ds.get_zone_soa(str(zone_info.zname), self._db_file)
if not zone_soa:
- raise ZonemgrException("[b10-zonemgr] zone (%s, %s) doesn't have soa." % zone_info.getNameClass())
+ raise ZonemgrException("[b10-zonemgr] zone (%s, %s) doesn't have soa." % zone_info.get_name_class())
zone_info.zone_soa_rdata = zone_soa[7]
#zone_info.zone_state = ZONE_OK
- zone_info.last_refresh_time = self._get_current_time()
- zone_info.next_refresh_time = self._get_current_time() + \
+ zone_info.last_refresh_time = get_current_time()
+ zone_info.next_refresh_time = get_current_time() + \
float(zone_soa[7].split(" ")[REFRESH_OFFSET])
- self._zonemgr_refresh_info[zone_info.getNameClass()] = zone_info
+ self._zonemgr_refresh_info[zone_info.get_name_class()] = zone_info
def _zone_is_expired(self, zone_name_class):
"""Judge whether a zone is expired or not."""
zone_expired_time = float(self._get_zone_soa_rdata(zone_name_class).split(" ")[EXPIRED_OFFSET])
zone_last_refresh_time = self._get_zone_last_refresh_time(zone_name_class)
if (ZONE_EXPIRED == self._get_zone_state(zone_name_class) or
- zone_last_refresh_time + zone_expired_time <= self._get_current_time()):
+ zone_last_refresh_time + zone_expired_time <= get_current_time()):
return True
return False
@@ -296,7 +337,7 @@ class ZonemgrRefresh:
# If hasn't received refresh response but are within refresh timeout, skip the zone
if (ZONE_REFRESHING == zone_state and
self._get_zone_refresh_timeout(zone_name_class) and
- (self._get_zone_refresh_timeout(zone_name_class) > self._get_current_time())):
+ (self._get_zone_refresh_timeout(zone_name_class) > get_current_time())):
continue
# Get the zone with minimum next_refresh_time
@@ -306,7 +347,7 @@ class ZonemgrRefresh:
zone_need_refresh = zone_name_class
# Find the zone need do refresh
- if (self._get_zone_next_refresh_time(zone_need_refresh) < self._get_current_time()):
+ if (self._get_zone_next_refresh_time(zone_need_refresh) < get_current_time()):
break
return zone_need_refresh
@@ -316,10 +357,11 @@ class ZonemgrRefresh:
"""Do zone refresh."""
log_msg("Do refresh for zone (%s, %s)." % zone_name_class)
self._set_zone_state(zone_name_class, ZONE_REFRESHING)
- self._set_zone_refresh_timeout(zone_name_class, self._get_current_time() + self._max_transfer_timeout)
+ self._set_zone_refresh_timeout(zone_name_class, get_current_time() + self._max_transfer_timeout)
notify_master = self._get_zone_notifier_master(zone_name_class)
# If the zone has notify master, send notify command to xfrin module
if notify_master:
+ # TODO: add (optional) tsig_key here later
param = {"zone_name" : zone_name_class[0],
"zone_class" : zone_name_class[1],
"master" : notify_master
@@ -358,7 +400,7 @@ class ZonemgrRefresh:
if not zone_need_refresh:
timeout = self._lowerbound_retry
else:
- timeout = self._get_zone_next_refresh_time(zone_need_refresh) - self._get_current_time()
+ timeout = self._get_zone_next_refresh_time(zone_need_refresh) - get_current_time()
if (timeout < 0):
self._do_refresh(zone_need_refresh)
continue
@@ -448,13 +490,15 @@ class ZonemgrRefresh:
if 'master_port' in secondary_zone:
zone_data.master_port = secondary_zone['master_port']
if 'tsig_key' in secondary_zone:
+ # TODO: check validity of given string
+ # (but need #781 to be merged for that)
zone_data.tsig_key = secondary_zone['tsig_key']
# If it is there already, we should update the config
# values, but leave the timers
if not name_class in self._zonemgr_refresh_info:
self.zonemgr_add_zone(zone_data)
else:
- self._zonemgr_refresh_info[name_class].updateConfigValue(zone_data)
+ self._zonemgr_refresh_info[name_class].update_config_value(zone_data)
# Drop the zones that are no longer there
# Do it in two phases, python doesn't like deleting while iterating
diff --git a/src/bin/zonemgr/zonemgr.spec.pre.in b/src/bin/zonemgr/zonemgr.spec.pre.in
index 9df01f2..0d82e93 100644
--- a/src/bin/zonemgr/zonemgr.spec.pre.in
+++ b/src/bin/zonemgr/zonemgr.spec.pre.in
@@ -48,6 +48,22 @@
"item_type": "string",
"item_optional": false,
"item_default": ""
+ },
+ {
+ "item_name": "master_address",
+ "item_type": "string",
+ "item_optional": true
+ },
+ {
+ "item_name": "master_port",
+ "item_type": "integer",
+ "item_optional": true,
+ "item_default": 53
+ },
+ {
+ "item_name": "tsig_key",
+ "item_type": "string",
+ "item_optional": true
}
]
}
More information about the bind10-changes
mailing list