]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1843] move command_sets/execute initialization
authorJelte Jansen <jelte@isc.org>
Thu, 19 Apr 2012 13:12:51 +0000 (15:12 +0200)
committerJelte Jansen <jelte@isc.org>
Thu, 19 Apr 2012 13:12:51 +0000 (15:12 +0200)
to command_sets, so that all setup is done in one file and not 3

src/bin/bindctl/bindcmd.py
src/bin/bindctl/bindctl_main.py.in
src/bin/bindctl/command_sets.py
src/lib/python/isc/config/tests/config_data_test.py

index 64ff878130442f6618017269f24dd70851a6bd00..8952158d83881923197748991e969520f938528c 100644 (file)
@@ -64,7 +64,6 @@ except ImportError:
 
 CSV_FILE_NAME = 'default_user.csv'
 CONFIG_MODULE_NAME = 'config'
-EXECUTE_MODULE_NAME = 'execute'
 CONST_BINDCTL_HELP = """
 usage: <module name> <command name> [param1 = value1 [, param2 = value2]]
 Type Tab character to get the hint of module/command/parameters.
@@ -398,7 +397,7 @@ class BindCmdInterpreter(Cmd):
         # Convert parameter value according parameter spec file.
         # Ignore check for commands belongs to module 'config' or 'execute
         if cmd.module != CONFIG_MODULE_NAME and\
-           cmd.module != EXECUTE_MODULE_NAME:
+           cmd.module != command_sets.EXECUTE_MODULE_NAME:
             for param_name in cmd.params:
                 param_spec = command_info.get_param_with_name(param_name).param_spec
                 try:
@@ -413,7 +412,7 @@ class BindCmdInterpreter(Cmd):
             self._handle_help(cmd)
         elif cmd.module == CONFIG_MODULE_NAME:
             self.apply_config_cmd(cmd)
-        elif cmd.module == EXECUTE_MODULE_NAME:
+        elif cmd.module == command_sets.EXECUTE_MODULE_NAME:
             self.apply_execute_cmd(cmd)
         else:
             self.apply_cmd(cmd)
@@ -749,8 +748,8 @@ class BindCmdInterpreter(Cmd):
             except IOError as ioe:
                 print("Error: " + str(ioe))
                 return
-        elif command.command == 'init_authoritative_server':
-            commands = command_sets.init_auth_server
+        elif command_sets.has_command_set(command.command):
+            commands = command_sets.get_commands(command.command)
         else:
             # Should not be reachable; parser should've caught this
             raise Exception("Unknown execute command type " + command.command)
index 25a3a446cec63d5da9d8103de0fc7203e61b1007..c2e4cece3f882e47352c73ac645f9280b71600da 100755 (executable)
@@ -25,6 +25,7 @@ from bindctl.bindcmd import *
 import pprint
 from optparse import OptionParser, OptionValueError
 import isc.util.process
+import command_sets
 
 isc.util.process.rename()
 
@@ -103,33 +104,6 @@ def prepare_config_commands(tool):
 
     tool.add_module_info(module)
 
-def prepare_execute_commands(tool):
-    # common parameter
-    param_show = ParamInfo(name="show", type="string", optional=True,
-        desc="Show the list of commands without executing them")
-
-    # The command module
-    module = ModuleInfo(name=EXECUTE_MODULE_NAME,
-                        desc="Execute a given set of commands")
-
-    # Command to execute a file
-    cmd = CommandInfo(name="file", desc="Read commands from file")
-    param = ParamInfo(name="filename", type="string", optional=False,
-                      desc="File to read the set of commands from.")
-    cmd.add_param(param)
-    cmd.add_param(param_show)
-    module.add_command(cmd)
-
-    cmd = CommandInfo(name="init_authoritative_server", desc=
-        "Configure and run a basic Authoritative server, with default "
-        "SQLite3 backend, and xfrin and xfrout functionality")
-    cmd.add_param(param_show)
-    cmd.add_param(ParamInfo(name="show", type="string", optional=True,
-        desc="Show the list of commands without executing them"))
-    module.add_command(cmd)
-
-    tool.add_module_info(module)
-
 def check_port(option, opt_str, value, parser):
     if (value < 0) or (value > 65535):
         raise OptionValueError('%s requires a port number (0-65535)' % opt_str)
@@ -173,6 +147,6 @@ if __name__ == '__main__':
     tool = BindCmdInterpreter(server_addr, pem_file=options.cert_chain,
                               csv_file_dir=options.csv_file_dir)
     prepare_config_commands(tool)
-    prepare_execute_commands(tool)
+    command_sets.prepare_execute_commands(tool)
     result = tool.run()
     sys.exit(result)
index 798e4934b316589d198abe5b4d073b1d544aba24..7e9e4376335e0886e2d389631f5a3c9bd2ed7f92 100644 (file)
 # This file provides a built-in set of 'execute' commands, for common
 # functions, such as adding an initial auth server
 # These sets must have an associated CommandInfo defined in
-# bindctl_main.py.in, in prepare_execute_commands
-
-init_auth_server = [
-'!echo adding Authoritative server component',
-'config add /Boss/components b10-auth',
-'config set /Boss/components/b10-auth/kind needed',
-'config set /Boss/components/b10-auth/special auth',
-'!echo adding Xfrin component',
-'config add /Boss/components b10-xfrin',
-'config set /Boss/components/b10-xfrin/address Xfrin',
-'config set /Boss/components/b10-xfrin/kind dispensable',
-'!echo adding Xfrout component',
-'config add /Boss/components b10-xfrout',
-'config set /Boss/components/b10-xfrout/address Xfrout',
-'config set /Boss/components/b10-xfrout/kind dispensable',
-'!echo adding Zone Manager component',
-'config add /Boss/components b10-zonemgr',
-'config set /Boss/components/b10-zonemgr/address Zonemgr',
-'config set /Boss/components/b10-zonemgr/kind dispensable',
-'!echo Components added. Please enter "config commit" to finalize initial'+
-' setup and run the components.'
-]
+# bindctl_main.py.in, in prepare_execute_commands, and
+# a handler in 
+
+from bindctl.moduleinfo import *
+# The name of the 'virtual' command set execution module in bindctl
+EXECUTE_MODULE_NAME = 'execute'
+
+# This is a map of command names to lists
+command_sets = {
+    'init_authoritative_server': {
+        'description':
+            'Configure and run a basic Authoritative server, with default '+
+            'SQLite3 backend, and xfrin and xfrout functionality',
+        'commands':
+            [
+            '!echo adding Authoritative server component',
+            'config add /Boss/components b10-auth',
+            'config set /Boss/components/b10-auth/kind needed',
+            'config set /Boss/components/b10-auth/special auth',
+            '!echo adding Xfrin component',
+            'config add /Boss/components b10-xfrin',
+            'config set /Boss/components/b10-xfrin/address Xfrin',
+            'config set /Boss/components/b10-xfrin/kind dispensable',
+            '!echo adding Xfrout component',
+            'config add /Boss/components b10-xfrout',
+            'config set /Boss/components/b10-xfrout/address Xfrout',
+            'config set /Boss/components/b10-xfrout/kind dispensable',
+            '!echo adding Zone Manager component',
+            'config add /Boss/components b10-zonemgr',
+            'config set /Boss/components/b10-zonemgr/address Zonemgr',
+            'config set /Boss/components/b10-zonemgr/kind dispensable',
+            '!echo Components added. Please enter "config commit" to finalize'+
+            'initial setup and run the components.'
+            ]
+    }
+}
+
+def has_command_set(name):
+    return name in command_sets
+
+def get_commands(name):
+    return command_sets[name]['commands']
+
+def get_description(name):
+    return command_sets[name]['description']
+
+# For each
+def prepare_execute_commands(tool):
+    """This function is called by bindctl_main, and sets up the commands
+       defined here for use in bindctl."""
+    # common parameter
+    param_show = ParamInfo(name="show", type="string", optional=True,
+        desc="Show the list of commands without executing them")
+
+    # The command module
+    module = ModuleInfo(name=EXECUTE_MODULE_NAME,
+                        desc="Execute a given set of commands")
+
+    # Command to execute a file
+    cmd = CommandInfo(name="file", desc="Read commands from file")
+    param = ParamInfo(name="filename", type="string", optional=False,
+                      desc="File to read the set of commands from.")
+    cmd.add_param(param)
+    cmd.add_param(param_show)
+    module.add_command(cmd)
+
+    # and loop through all command sets defined above
+    for name in command_sets:
+        cmd = CommandInfo(name=name, desc=get_description(name))
+        cmd.add_param(param_show)
+        module.add_command(cmd)
+
+    tool.add_module_info(module)
+
index 864fe708edcf067c2295b8b805968e23c86192db..c295c760c568f55d4ff1772299bd6e71aff55369 100644 (file)
@@ -420,7 +420,14 @@ class TestMultiConfigData(unittest.TestCase):
         self.mcd.set_value("Spec2/item1", 2)
         local_changes = self.mcd.get_local_changes()
         self.assertEqual({"Spec2": { "item1": 2}}, local_changes)
-        
+
+    def test_set_local_changes(self):
+        module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
+        self.mcd.set_specification(module_spec)
+        self.assertEqual({}, self.mcd.get_local_changes())
+        new_local_changes = {"Spec2": { "item1": 2}}
+        self.mcd.set_local_changes(new_local_changes)
+        self.assertEqual(new_local_changes, self.mcd.get_local_changes())
 
     def test_clear_local_changes(self):
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")