BIND 10 trac615, updated. e33f9a6d1009753b2f02b43e43da1014b0df1964 [trac615] Prepagate corectly trough config manager
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 7 22:57:25 UTC 2011
The branch, trac615 has been updated
via e33f9a6d1009753b2f02b43e43da1014b0df1964 (commit)
via 07c01a7a90476fd6b90659bf809e7135ce26cff2 (commit)
via a1d7f70e7c660e847fb388c6f17d6709c93fe8e2 (commit)
via 96e55aef179874427ea28641316dd145fbd98175 (commit)
via ccdce3bab3f04bade1e92e66e3929ffd0db97f0b (commit)
via 79155a51eb422813900332ad1582ed5964d70f5c (commit)
from d686e3ada2141094413e756d601d2e727fb6f760 (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 e33f9a6d1009753b2f02b43e43da1014b0df1964
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 23:41:44 2011 +0100
[trac615] Prepagate corectly trough config manager
commit 07c01a7a90476fd6b90659bf809e7135ce26cff2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 21:29:09 2011 +0100
[trac615] Pass the config options to cfgmgr
Any idea how to reasonably test this? Boss and it's tests seem to be
written in test-unfriendly way for this :-(.
commit a1d7f70e7c660e847fb388c6f17d6709c93fe8e2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 20:55:19 2011 +0100
[trac615] Check even short opts for cfgmgr
commit 96e55aef179874427ea28641316dd145fbd98175
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 20:53:48 2011 +0100
[trac615] Parsing of --config-file and --data-path for boss
commit ccdce3bab3f04bade1e92e66e3929ffd0db97f0b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 20:50:47 2011 +0100
[trac615] Tests for boss parsing args
commit 79155a51eb422813900332ad1582ed5964d70f5c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon Mar 7 19:47:59 2011 +0100
[trac615] Take parsing of args to a function
The parsing is taken out so it can be tested independently on the rest.
We don't need to run the main function now.
-----------------------------------------------------------------------
Summary of changes:
src/bin/bind10/bind10.py.in | 51 ++++++++++++++++++------
src/bin/bind10/tests/bind10_test.py | 32 ++++++++++++++-
src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in | 6 +++
src/lib/python/isc/config/cfgmgr.py | 18 ++++++---
src/lib/python/isc/config/tests/cfgmgr_test.py | 16 ++++++-
5 files changed, 101 insertions(+), 22 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10.py.in b/src/bin/bind10/bind10.py.in
index 83acf1f..fea7f40 100755
--- a/src/bin/bind10/bind10.py.in
+++ b/src/bin/bind10/bind10.py.in
@@ -194,14 +194,17 @@ class CChannelConnectError(Exception): pass
class BoB:
"""Boss of BIND class."""
- def __init__(self, msgq_socket_file=None, nocache=False, verbose=False,
- setuid=None, username=None):
+ def __init__(self, msgq_socket_file=None, data_path = None,
+ config_filename = None, nocache=False, verbose=False, setuid=None,
+ username=None):
"""
Initialize the Boss of BIND. This is a singleton (only one can run).
The msgq_socket_file specifies the UNIX domain socket file that the
msgq process listens on. If verbose is True, then the boss reports
what it is doing.
+
+ Data path and config filename are passed trough to config manager.
"""
self.cc_session = None
self.ccs = None
@@ -219,6 +222,8 @@ class BoB:
self.uid = setuid
self.username = username
self.verbose = verbose
+ self.data_path = data_path
+ self.config_filename = config_filename
def config_handler(self, new_config):
# If this is initial update, don't do anything now, leave it to startup
@@ -390,7 +395,12 @@ class BoB:
Starts the configuration manager process
"""
self.log_starting("b10-cfgmgr")
- bind_cfgd = ProcessInfo("b10-cfgmgr", ["b10-cfgmgr"],
+ opts = ["b10-cfgmgr"]
+ if self.data_path is not None:
+ opts.append("--data-path=" + self.data_path)
+ if self.config_filename is not None:
+ opts.append("--database-filename=" + self.config_filename)
+ bind_cfgd = ProcessInfo("b10-cfgmgr", opts,
c_channel_env, uid=self.uid,
username=self.username)
self.processes[bind_cfgd.pid] = bind_cfgd
@@ -785,13 +795,11 @@ def process_rename(option, opt_str, value, parser):
"""Function that renames the process if it is requested by a option."""
isc.util.process.rename(value)
-def main():
- global options
- global boss_of_bind
- # Enforce line buffering on stdout, even when not a TTY
- sys.stdout = io.TextIOWrapper(sys.stdout.detach(), line_buffering=True)
-
- # Parse any command-line options.
+def parse_args(args=sys.argv[1:]):
+ """
+ Function for parsing command line arguments. Returns the
+ options object from OptionParser.
+ """
parser = OptionParser(version=VERSION)
parser.add_option("-m", "--msgq-socket-file", dest="msgq_socket_file",
type="string", default=None,
@@ -805,11 +813,27 @@ def main():
parser.add_option("--pretty-name", type="string", action="callback",
callback=process_rename,
help="Set the process name (displayed in ps, top, ...)")
- (options, args) = parser.parse_args()
+ parser.add_option("-c", "--config-file", action="store",
+ dest="config_file", default=None,
+ help="Configuration database filename")
+ parser.add_option("-p", "--data-path", dest="data_path",
+ help="Directory to search for configuration files",
+ default=None)
+ (options, args) = parser.parse_args(args)
if args:
parser.print_help()
sys.exit(1)
+ return options
+
+def main():
+ global options
+ global boss_of_bind
+ # Enforce line buffering on stdout, even when not a TTY
+ sys.stdout = io.TextIOWrapper(sys.stdout.detach(), line_buffering=True)
+
+ options = parse_args()
+
# Check user ID.
setuid = None
username = None
@@ -858,8 +882,9 @@ def main():
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
# Go bob!
- boss_of_bind = BoB(options.msgq_socket_file, options.nocache,
- options.verbose, setuid, username)
+ boss_of_bind = BoB(options.msgq_socket_file, options.data_path,
+ options.config_file, options.nocache, options.verbose,
+ setuid, username)
startup_result = boss_of_bind.startup()
if startup_result:
sys.stderr.write("[bind10] Error on startup: %s\n" % startup_result)
diff --git a/src/bin/bind10/tests/bind10_test.py b/src/bin/bind10/tests/bind10_test.py
index f3fe949..623a6fa 100644
--- a/src/bin/bind10/tests/bind10_test.py
+++ b/src/bin/bind10/tests/bind10_test.py
@@ -1,4 +1,4 @@
-from bind10 import ProcessInfo, BoB
+from bind10 import ProcessInfo, BoB, parse_args
# XXX: environment tests are currently disabled, due to the preprocessor
# setup that we have now complicating the environment
@@ -412,5 +412,35 @@ class TestStartStopProcessesBob(unittest.TestCase):
bob.config_handler({'start_auth': True, 'start_resolver': True})
+class TestParseArgs(unittest.TestCase):
+ """
+ This tests parsing of arguments of the bind10 master process.
+ """
+ #TODO: Write tests for the original parsing, bad options, etc.
+ def test_no_opts(self):
+ """
+ Test correct default values when no options are passed.
+ """
+ options = parse_args([])
+ self.assertEqual(None, options.data_path)
+ self.assertEqual(None, options.config_file)
+
+ def test_data_path(self):
+ """
+ Test it can parse the data path.
+ """
+ options = parse_args(['-p', '/data/path'])
+ self.assertEqual('/data/path', options.data_path)
+ options = parse_args(['--data-path=/data/path'])
+ self.assertEqual('/data/path', options.data_path)
+ def test_config_filename(self):
+ """
+ Test it can parse the config switch.
+ """
+ options = parse_args(['-c', 'config-file'])
+ self.assertEqual('config-file', options.config_file)
+ options = parse_args(['--config-file=config-file'])
+ self.assertEqual('config-file', options.config_file)
+
if __name__ == '__main__':
unittest.main()
diff --git a/src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in b/src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in
index 01b8ae5..e0a492b 100644
--- a/src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in
+++ b/src/bin/cfgmgr/tests/b10-cfgmgr_test.py.in
@@ -144,6 +144,9 @@ class TestParseArgs(unittest.TestCase):
parsed = b.parse_options(['--data-path=/path'], TestOptParser)
self.assertEqual('/path', parsed.data_path)
self.assertEqual("b10-config.db", parsed.file_name)
+ parsed = b.parse_options(['-p', '/path'], TestOptParser)
+ self.assertEqual('/path', parsed.data_path)
+ self.assertEqual("b10-config.db", parsed.file_name)
def test_db_filename(self):
"""
@@ -154,6 +157,9 @@ class TestParseArgs(unittest.TestCase):
TestOptParser)
self.assertEqual(b.DATA_PATH, parsed.data_path)
self.assertEqual("filename", parsed.file_name)
+ parsed = b.parse_options(['-f', 'filename'], TestOptParser)
+ self.assertEqual(b.DATA_PATH, parsed.data_path)
+ self.assertEqual("filename", parsed.file_name)
if __name__ == '__main__':
unittest.main()
diff --git a/src/lib/python/isc/config/cfgmgr.py b/src/lib/python/isc/config/cfgmgr.py
index 1c36fe1..6420f01 100644
--- a/src/lib/python/isc/config/cfgmgr.py
+++ b/src/lib/python/isc/config/cfgmgr.py
@@ -158,15 +158,18 @@ 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, session = None):
+ def __init__(self, data_path, database_filename = "b10-config.db",
+ session = None):
"""Initialize the configuration manager. The data_path string
is the path to the directory where the configuration is
- stored (in <data_path>/b10-config.db). Session is an optional
+ stored (in <data_path>/b10-config.db). 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."""
self.data_path = data_path
+ self.database_filename = database_filename
self.module_specs = {}
- self.config = ConfigManagerData(data_path)
+ self.config = ConfigManagerData(data_path, database_filename)
if session:
self.cc = session
else:
@@ -237,10 +240,13 @@ class ConfigManager:
"""Read the current configuration from the b10-config.db file
at the path specificied at init()"""
try:
- self.config = ConfigManagerData.read_from_file(self.data_path)
+ self.config = ConfigManagerData.read_from_file(self.data_path,
+ self.\
+ database_filename)
except ConfigManagerDataEmpty:
# ok, just start with an empty config
- self.config = ConfigManagerData(self.data_path)
+ self.config = ConfigManagerData(self.data_path,
+ self.database_filename)
def write_config(self):
"""Write the current configuration to the b10-config.db file
diff --git a/src/lib/python/isc/config/tests/cfgmgr_test.py b/src/lib/python/isc/config/tests/cfgmgr_test.py
index f9ddfd5..0ed3e2c 100644
--- a/src/lib/python/isc/config/tests/cfgmgr_test.py
+++ b/src/lib/python/isc/config/tests/cfgmgr_test.py
@@ -95,10 +95,22 @@ class TestConfigManager(unittest.TestCase):
self.data_path = os.environ['CONFIG_TESTDATA_PATH']
self.writable_data_path = os.environ['CONFIG_WR_TESTDATA_PATH']
self.fake_session = FakeModuleCCSession()
- self.cm = ConfigManager(self.writable_data_path, self.fake_session)
+ self.cm = ConfigManager(self.writable_data_path,
+ session=self.fake_session)
self.name = "TestModule"
self.spec = isc.config.module_spec_from_file(self.data_path + os.sep + "/spec2.spec")
-
+
+ def test_paths(self):
+ """
+ Test data_path and database filename is passed trough to
+ underlying ConfigManagerData.
+ """
+ cm = ConfigManager("/data/path", "filename", self.fake_session)
+ self.assertEqual("/data/path/filename", cm.config.db_filename)
+ # It should preserve it while reading
+ cm.read_config()
+ self.assertEqual("/data/path/filename", cm.config.db_filename)
+
def test_init(self):
self.assert_(self.cm.module_specs == {})
self.assert_(self.cm.data_path == self.writable_data_path)
More information about the bind10-changes
mailing list