Commit 254b3aa8 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

make bindctl error if you try to perform a config command on an unknown or non-running module

added 'have_specification()' to MultiConfigData class
+tests of course
although bindcmd seems to be lacking much in the test department... (fitted it kinda-sorta into bindctl_test right now)


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac99@2643 e5f2f494-b856-4b98-b285-d166d9295462
parent be60a690
...@@ -543,6 +543,16 @@ class BindCmdInterpreter(Cmd): ...@@ -543,6 +543,16 @@ class BindCmdInterpreter(Cmd):
identifier = cmd.params['identifier'] identifier = cmd.params['identifier']
else: else:
identifier += cmd.params['identifier'] identifier += cmd.params['identifier']
# Check if the module is known; for unknown modules
# we currently deny setting preferences, as we have
# no way yet to determine if they are ok.
module_name = identifier.split('/')[1]
if self.config_data is None or \
not self.config_data.have_specification(module_name):
print("Error: Module '" + module_name + "' unknown or not running")
return
if cmd.command == "show": if cmd.command == "show":
values = self.config_data.get_value_maps(identifier) values = self.config_data.get_value_maps(identifier)
for value_map in values: for value_map in values:
......
...@@ -237,6 +237,11 @@ class TestNameSequence(unittest.TestCase): ...@@ -237,6 +237,11 @@ class TestNameSequence(unittest.TestCase):
assert self.random_names[i] == cmd_names[i+1] assert self.random_names[i] == cmd_names[i+1]
assert self.random_names[i] == module_names[i+1] assert self.random_names[i] == module_names[i+1]
i = i + 1 i = i + 1
def test_apply_cfg_command(self):
self.tool.location = '/'
cmd = cmdparse.BindCmdParse("config set identifier=\"foo/bar\" value=\"5\"")
self.tool.apply_config_cmd(cmd)
class FakeBindCmdInterpreter(bindcmd.BindCmdInterpreter): class FakeBindCmdInterpreter(bindcmd.BindCmdInterpreter):
def __init__(self): def __init__(self):
......
...@@ -251,6 +251,11 @@ class MultiConfigData: ...@@ -251,6 +251,11 @@ class MultiConfigData:
if module_name in self._specifications: if module_name in self._specifications:
del self._specifications[module_name] del self._specifications[module_name]
def have_specification(self, module_name):
"""Returns True if we have a specification for the module with the given name.
Returns False if we do not."""
return module_name in self._specifications
def get_module_spec(self, module): def get_module_spec(self, module):
"""Returns the ModuleSpec for the module with the given name. """Returns the ModuleSpec for the module with the given name.
If there is no such module, it returns None""" If there is no such module, it returns None"""
......
...@@ -267,12 +267,16 @@ class TestMultiConfigData(unittest.TestCase): ...@@ -267,12 +267,16 @@ class TestMultiConfigData(unittest.TestCase):
self.assertEqual({}, self.mcd._current_config) self.assertEqual({}, self.mcd._current_config)
self.assertEqual({}, self.mcd._local_changes) self.assertEqual({}, self.mcd._local_changes)
def test_set_specification(self): def test_set_remove_specification(self):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec1.spec") module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec1.spec")
self.assertFalse(self.mcd.have_specification(module_spec.get_module_name()))
self.mcd.set_specification(module_spec) self.mcd.set_specification(module_spec)
self.assertTrue(self.mcd.have_specification(module_spec.get_module_name()))
self.assert_(module_spec.get_module_name() in self.mcd._specifications) self.assert_(module_spec.get_module_name() in self.mcd._specifications)
self.assertEquals(module_spec, self.mcd._specifications[module_spec.get_module_name()]) self.assertEquals(module_spec, self.mcd._specifications[module_spec.get_module_name()])
self.assertRaises(ConfigDataError, self.mcd.set_specification, "asdf") self.assertRaises(ConfigDataError, self.mcd.set_specification, "asdf")
self.mcd.remove_specification(module_spec.get_module_name())
self.assertFalse(self.mcd.have_specification(module_spec.get_module_name()))
def test_get_module_spec(self): def test_get_module_spec(self):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec1.spec") module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec1.spec")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment