]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1443] add command-line arguments
authorJelte Jansen <jelte@isc.org>
Wed, 21 Mar 2012 16:35:03 +0000 (17:35 +0100)
committerJelte Jansen <jelte@isc.org>
Wed, 21 Mar 2012 16:35:03 +0000 (17:35 +0100)
also extend log message a bit

src/bin/bind10/bind10_src.py.in
src/bin/bind10/tests/bind10_test.py.in
src/bin/cfgmgr/b10-cfgmgr.py.in
src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in
src/lib/python/isc/config/cfgmgr.py
src/lib/python/isc/config/cfgmgr_messages.mes

index edc1b69d54172d7c2c8a320141ae6dd2aae1aceb..5a3f792b7d40f4786f2464a35ef349384c66398e 100755 (executable)
@@ -167,8 +167,8 @@ class BoB:
     """Boss of BIND class."""
     
     def __init__(self, msgq_socket_file=None, data_path=None,
-    config_filename=None, nocache=False, verbose=False, setuid=None,
-    username=None, cmdctl_port=None, wait_time=10):
+    config_filename=None, clear_config=False, nocache=False, verbose=False,
+    setuid=None, username=None, cmdctl_port=None, wait_time=10):
         """
             Initialize the Boss of BIND. This is a singleton (only one can run).
         
@@ -210,6 +210,7 @@ class BoB:
         self.verbose = verbose
         self.data_path = data_path
         self.config_filename = config_filename
+        self.clear_config = clear_config
         self.cmdctl_port = cmdctl_port
         self.wait_time = wait_time
         self._component_configurator = isc.bind10.component.Configurator(self,
@@ -465,6 +466,8 @@ class BoB:
             args.append("--data-path=" + self.data_path)
         if self.config_filename is not None:
             args.append("--config-filename=" + self.config_filename)
+        if self.clear_config is not None:
+            args.append("--clear-config")
         bind_cfgd = ProcessInfo("b10-cfgmgr", args,
                                 self.c_channel_env)
         bind_cfgd.spawn()
@@ -1053,6 +1056,9 @@ def parse_args(args=sys.argv[1:], Parser=OptionParser):
     parser.add_option("-c", "--config-file", action="store",
                       dest="config_file", default=None,
                       help="Configuration database filename")
+    parser.add_option("--clear-config", action="store_true",
+                      dest="clear_config", default=False,
+                      help="Back up the configuration file and start with a clean one")
     parser.add_option("-p", "--data-path", dest="data_path",
                       help="Directory to search for configuration files",
                       default=None)
@@ -1165,8 +1171,8 @@ def main():
     try:
         # Go bob!
         boss_of_bind = BoB(options.msgq_socket_file, options.data_path,
-                           options.config_file, options.nocache,
-                           options.verbose, setuid, username,
+                           options.config_file, options.clear_config,
+                           options.nocache, options.verbose, setuid, username,
                            options.cmdctl_port, options.wait_time)
         startup_result = boss_of_bind.startup()
         if startup_result:
index 882824d43a46db59f92bf81d4bc79b62e8ec0e4f..6633b68a1ef9225b19ea88a9b90233d820ec3af2 100644 (file)
@@ -1012,6 +1012,12 @@ class TestParseArgs(unittest.TestCase):
         options = parse_args(['--config-file=config-file'], TestOptParser)
         self.assertEqual('config-file', options.config_file)
 
+    def test_clear_config(self):
+        options = parse_args([], TestOptParser)
+        self.assertEqual(False, options.clear_config)
+        options = parse_args(['--clear-config'], TestOptParser)
+        self.assertEqual(True, options.clear_config)
+
     def test_cmdctl_port(self):
         """
         Test it can parse the command control port.
index 2ccc4304b034b25d454844110cbffda0c13e988b..760b6d8e97ad0643de58b3d736b0054aebf03039 100755 (executable)
@@ -49,6 +49,10 @@ def parse_options(args=sys.argv[1:], Parser=OptionParser):
                       help="Configuration database filename " +
                       "(default=" + DEFAULT_CONFIG_FILE + ")",
                       default=DEFAULT_CONFIG_FILE)
+    parser.add_option("--clear-config", action="store_true",
+                      dest="clear_config", default=False,
+                      help="Back up the configuration file and start with " +
+                           "a clean one")
     (options, args) = parser.parse_args(args)
     if args:
         parser.error("No non-option arguments allowed")
@@ -85,7 +89,8 @@ def main():
     options = parse_options()
     global cm
     try:
-        cm = ConfigManager(options.data_path, options.config_file)
+        cm = ConfigManager(options.data_path, options.config_file,
+                           None, options.clear_config)
         signal.signal(signal.SIGINT, signal_handler)
         signal.signal(signal.SIGTERM, signal_handler)
         cm.read_config()
index ea5fc8b51906dcbf68a29554c97f3b94fae43814..141bf6e8e30d6eeb89169c6e51d0824bdaec2890 100644 (file)
@@ -24,12 +24,13 @@ import bind10_config
 from isc.testutils.parse_args import OptsError, TestOptParser
 
 class MyConfigManager:
-    def __init__(self, path, filename):
+    def __init__(self, path, filename, session=None, rename_config_file=None):
         self._path = path
         self.read_config_called = False
         self.notify_boss_called = False
         self.run_called = False
         self.write_config_called = False
+        self.rename_config_called = False
         self.running = True
         self.virtual_modules = []
 
@@ -45,6 +46,9 @@ class MyConfigManager:
     def write_config(self):
         self.write_config_called = True
 
+    def rename_config_file(self, ofile, nfile):
+        self.rename_config_called = True
+
     def set_virtual_module(self, spec, function):
         self.virtual_modules.append((spec, function))
 
@@ -90,6 +94,7 @@ class TestConfigManagerStartup(unittest.TestCase):
         self.assertTrue(self.loaded_plugins)
         # if there are no changes, config is not written
         self.assertFalse(b.cm.write_config_called)
+        self.assertFalse(b.cm.rename_config_called)
 
         self.assertTrue(b.cm.running)
         b.signal_handler(None, None)
@@ -187,6 +192,14 @@ class TestParseArgs(unittest.TestCase):
         self.assertRaises(OptsError, b.parse_options, ['--config-filename'],
                           TestOptParser)
 
+    def test_clear_config(self):
+        b = __import__("b10-cfgmgr")
+        parsed = b.parse_options([], TestOptParser)
+        self.assertFalse(parsed.clear_config)
+        parsed = b.parse_options(['--clear-config'], TestOptParser)
+        self.assertTrue(parsed.clear_config)
+        
+
 if __name__ == '__main__':
     unittest.main()
 
index 9a17c221461cc2047791095ef93f774673059332..df7d30a75392f48a6c3707b58d38dc38122f724c 100644 (file)
@@ -178,14 +178,16 @@ class ConfigManager:
        channel session. If not, a new session will be created.
        The ability to specify a custom session is for testing purposes
        and should not be needed for normal usage."""
-    def __init__(self, data_path, database_filename, session=None):
+    def __init__(self, data_path, database_filename, session=None,
+                 clear_config=False):
         """Initialize the configuration manager. The data_path string
            is the path to the directory where the configuration is
            stored (in <data_path>/<database_filename> or in
            <database_filename>, if it is absolute). The dabase_filename
            is the config file to load. Session is an optional
            cc-channel session. If this is not given, a new one is
-           created."""
+           created. If clear_config is True, the configuration file is
+           renamed and a new one is created."""
         self.data_path = data_path
         self.database_filename = database_filename
         self.module_specs = {}
@@ -194,6 +196,8 @@ class ConfigManager:
         # of some other process
         self.virtual_modules = {}
         self.config = ConfigManagerData(data_path, database_filename)
+        if clear_config:
+            self.config.rename_config_file()
         if session:
             self.cc = session
         else:
index dab93503e9178a32305db59d1c1fe04a50799daa..b307604dec0a3f10f6027a2fbf4545825da690fb 100644 (file)
@@ -55,7 +55,7 @@ configuration is not stored.
 There was a keyboard interrupt signal to stop the cfgmgr daemon. The
 daemon will now shut down.
 
-% CFGMGR_RENAMED_CONFIG_FILE renamed configuration file %1 to %2
+% CFGMGR_RENAMED_CONFIG_FILE renamed configuration file %1 to %2, will create new %1
 BIND 10 has been started with the command to clear the configuration file.
 The existing file is backed up to the given file name, so that data is not
 immediately lost if this was done by accident.