From: Jelte Jansen Date: Thu, 5 Apr 2012 13:02:29 +0000 (+0200) Subject: [1789] refactor remote_config handling X-Git-Tag: trac2351_base~226^2~116^2~40^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=97389bad9bf82cd32329407557aed4ea669401f4;p=thirdparty%2Fkea.git [1789] refactor remote_config handling moving add_remote to initialization, and cleanup to shutdown code update 'database file' in remote config callback handler --- diff --git a/src/bin/xfrin/tests/xfrin_test.py b/src/bin/xfrin/tests/xfrin_test.py index a5c92ab01f..071b001797 100644 --- a/src/bin/xfrin/tests/xfrin_test.py +++ b/src/bin/xfrin/tests/xfrin_test.py @@ -139,6 +139,9 @@ class MockCC(MockModuleCCSession): if identifier == "zones/use_ixfr": return False + def remove_remote_config(self, module_name): + pass + class MockDataSourceClient(): '''A simple mock data source client. diff --git a/src/bin/xfrin/xfrin.py.in b/src/bin/xfrin/xfrin.py.in index 863c5b9234..be9b7c73a2 100755 --- a/src/bin/xfrin/xfrin.py.in +++ b/src/bin/xfrin/xfrin.py.in @@ -1246,6 +1246,10 @@ class Xfrin: def __init__(self): self._max_transfers_in = 10 self._zones = {} + # keep a separate list so we can more easily update either for now + # these are the zones that are served by the in-memory datasource, + # but transfers are handled by sqlite3 + self._memory_zones = {} self._cc_setup() self.recorder = XfrinRecorder() self._shutdown_event = threading.Event() @@ -1264,6 +1268,8 @@ class Xfrin: self._module_cc.start() config_data = self._module_cc.get_full_config() self.config_handler(config_data) + self._module_cc.add_remote_config(AUTH_SPECFILE_LOCATION, + self.auth_config_handler) def _cc_check_command(self): '''This is a straightforward wrapper for cc.check_command, @@ -1310,10 +1316,16 @@ class Xfrin: return create_answer(0) + def auth_config_handler(self, new_config, foo): + # Config handler for changes in Auth configuration + print("[XX] Hi. XFRIN HERE. AUTH CONFIG UPDATE") + self._set_db_file() + def shutdown(self): ''' shutdown the xfrin process. the thread which is doing xfrin should be terminated. ''' + self._module_cc.remove_remote_config(AUTH_SPECFILE_LOCATION) self._module_cc.send_stopping() self._shutdown_event.set() main_thread = threading.currentThread() @@ -1446,20 +1458,18 @@ class Xfrin: return (addr.family, socket.SOCK_STREAM, (str(addr), port)) def _get_db_file(self): - #TODO, the db file path should be got in auth server's configuration - # if we need access to this configuration more often, we - # should add it on start, and not remove it here - # (or, if we have writable ds, we might not need this in - # the first place) - self._module_cc.add_remote_config(AUTH_SPECFILE_LOCATION) - db_file, is_default = self._module_cc.get_remote_config_value("Auth", "database_file") + return self._db_file + + def _set_db_file(self): + db_file, is_default =\ + self._module_cc.get_remote_config_value("Auth", "database_file") if is_default and "B10_FROM_BUILD" in os.environ: # this too should be unnecessary, but currently the # 'from build' override isn't stored in the config # (and we don't have writable datasources yet) - db_file = os.environ["B10_FROM_BUILD"] + os.sep + "bind10_zones.sqlite3" - self._module_cc.remove_remote_config(AUTH_SPECFILE_LOCATION) - return db_file + db_file = os.environ["B10_FROM_BUILD"] + os.sep +\ + "bind10_zones.sqlite3" + self._db_file = db_file def publish_xfrin_news(self, zone_name, zone_class, xfr_result): '''Send command to xfrout/zone manager module.