Browse Source

[1843] initial addition of 'execute' command set

Jelte Jansen 13 years ago
parent
commit
233c7295de

+ 13 - 2
src/bin/bindctl/bindcmd.py

@@ -62,6 +62,7 @@ except ImportError:
 
 
 CSV_FILE_NAME = 'default_user.csv'
 CSV_FILE_NAME = 'default_user.csv'
 CONFIG_MODULE_NAME = 'config'
 CONFIG_MODULE_NAME = 'config'
+EXECUTE_MODULE_NAME = 'execute'
 CONST_BINDCTL_HELP = """
 CONST_BINDCTL_HELP = """
 usage: <module name> <command name> [param1 = value1 [, param2 = value2]]
 usage: <module name> <command name> [param1 = value1 [, param2 = value2]]
 Type Tab character to get the hint of module/command/parameters.
 Type Tab character to get the hint of module/command/parameters.
@@ -393,8 +394,9 @@ class BindCmdInterpreter(Cmd):
                 param_nr += 1
                 param_nr += 1
 
 
         # Convert parameter value according parameter spec file.
         # Convert parameter value according parameter spec file.
-        # Ignore check for commands belongs to module 'config'
+        # Ignore check for commands belongs to module 'config' or 'execute
-        if cmd.module != CONFIG_MODULE_NAME:
+        if cmd.module != CONFIG_MODULE_NAME and\
+           cmd.module != EXECUTE_MODULE_NAME:
             for param_name in cmd.params:
             for param_name in cmd.params:
                 param_spec = command_info.get_param_with_name(param_name).param_spec
                 param_spec = command_info.get_param_with_name(param_name).param_spec
                 try:
                 try:
@@ -418,6 +420,9 @@ class BindCmdInterpreter(Cmd):
                 print("Error: " + str(dape))
                 print("Error: " + str(dape))
             except KeyError as ke:
             except KeyError as ke:
                 print("Error: missing " + str(ke))
                 print("Error: missing " + str(ke))
+        elif cmd.module == EXECUTE_MODULE_NAME:
+            # TODO: catch errors
+            self.apply_execute_cmd(cmd)
         else:
         else:
             self.apply_cmd(cmd)
             self.apply_cmd(cmd)
 
 
@@ -728,6 +733,12 @@ class BindCmdInterpreter(Cmd):
 
 
         self.location = new_location
         self.location = new_location
 
 
+    def apply_execute_cmd(self, command):
+        '''Handles the 'execute' command, which executes a number of
+           (preset) statements. Currently only 'file' commands are supported,
+           e.g. 'execute file <file>'.'''
+        pass
+
     def apply_cmd(self, cmd):
     def apply_cmd(self, cmd):
         '''Handles a general module command'''
         '''Handles a general module command'''
         url = '/' + cmd.module + '/' + cmd.command
         url = '/' + cmd.module + '/' + cmd.command

+ 9 - 0
src/bin/bindctl/bindctl_main.py.in

@@ -103,6 +103,15 @@ def prepare_config_commands(tool):
 
 
     tool.add_module_info(module)
     tool.add_module_info(module)
 
 
+    module = ModuleInfo(name=EXECUTE_MODULE_NAME,
+                        desc="Execute a given set of commands")
+    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)
+    module.add_command(cmd)
+    tool.add_module_info(module)
+
 def check_port(option, opt_str, value, parser):
 def check_port(option, opt_str, value, parser):
     if (value < 0) or (value > 65535):
     if (value < 0) or (value > 65535):
         raise OptionValueError('%s requires a port number (0-65535)' % opt_str)
         raise OptionValueError('%s requires a port number (0-65535)' % opt_str)

+ 9 - 0
tests/lettuce/features/bindctl_commands.feature

@@ -63,3 +63,12 @@ Feature: control with bindctl
     bind10 module StatsHttpd should not be running
     bind10 module StatsHttpd should not be running
     bind10 module Stats should not be running
     bind10 module Stats should not be running
     bind10 module Resolver should not be running
     bind10 module Resolver should not be running
+
+    Scenario: Executing scripts
+    # This test tests the 'execute' command, which reads and executes
+    # bindctl commands from a file
+    Given I have bind10 running with configuration bindctl_commands.config
+    And wait for bind10 stderr message BIND10_STARTED_CC
+    And wait for bind10 stderr message CMDCTL_STARTED
+    When I send bind10 the command execute file data/commands/empty
+    last bindctl output should not contain Error