]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1789] refactor remote_config handling
authorJelte Jansen <jelte@isc.org>
Thu, 5 Apr 2012 13:02:29 +0000 (15:02 +0200)
committerJelte Jansen <jelte@isc.org>
Thu, 5 Apr 2012 13:02:29 +0000 (15:02 +0200)
moving add_remote to initialization, and cleanup to shutdown code
update 'database file' in remote config callback handler

src/bin/xfrin/tests/xfrin_test.py
src/bin/xfrin/xfrin.py.in

index a5c92ab01f02bffea7e3c746bc0dddc310b6af22..071b001797d7deeefb7f904cd3e0a657f18cab0f 100644 (file)
@@ -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.
 
index 863c5b9234a740deebc8d64a0cac6cdcc2847b33..be9b7c73a2be953c4119577d41c47f5e4acb2b32 100755 (executable)
@@ -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.