"""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).
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,
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()
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)
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:
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.
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")
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()
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 = []
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))
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)
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()
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 = {}
# 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:
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.