Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
64f69a14
Commit
64f69a14
authored
Apr 18, 2012
by
Jelte Jansen
Browse files
[1843] basic bindctl execute directives and lettuce tests
parent
233c7295
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/bin/bindctl/bindcmd.py
View file @
64f69a14
...
...
@@ -737,7 +737,52 @@ class BindCmdInterpreter(Cmd):
'''Handles the 'execute' command, which executes a number of
(preset) statements. Currently only 'file' commands are supported,
e.g. 'execute file <file>'.'''
pass
try
:
command_file
=
open
(
command
.
params
[
'filename'
])
self
.
apply_commands_from_file
(
command_file
)
except
IOError
as
ioe
:
print
(
"Error: "
+
str
(
ioe
))
def
apply_commands_from_file
(
self
,
command_file
):
'''Applies the configuration commands from the given opened file.
This is the method that catches, comments, echo statements, and
other directives. All commands not filtered by this method are
interpreted as if they are directly entered in an active session.
Lines starting with any of the following characters are not
passed directly:
# - These are comments
! - These are directives
!echo: print the rest of the line
!verbose on/off: print the commands themselves too
Unknown directives are ignored (with a warning)
The execution is stopped if there are any errors.
'''
verbose
=
False
try
:
for
line
in
command_file
:
line
=
line
.
strip
()
if
verbose
:
print
(
line
)
if
line
.
startswith
(
'#'
):
continue
elif
line
.
startswith
(
'!'
):
if
line
.
startswith
(
'!echo '
)
and
len
(
line
)
>
6
:
print
(
line
[
6
:])
elif
line
.
startswith
(
'!verbose on'
):
verbose
=
True
elif
line
.
startswith
(
'!verbose off'
):
verbose
=
False
else
:
print
(
"Warning: ignoring unknown directive: "
+
line
)
else
:
cmd
=
BindCmdParse
(
line
)
self
.
_validate_cmd
(
cmd
)
self
.
_handle_cmd
(
cmd
)
except
isc
.
config
.
ModuleCCSessionError
as
mcse
:
print
(
str
(
mcse
))
except
(
IOError
,
http
.
client
.
HTTPException
,
BindCtlException
,
isc
.
cc
.
data
.
DataTypeError
)
as
err
:
print
(
'Error: '
,
err
)
def
apply_cmd
(
self
,
cmd
):
'''Handles a general module command'''
...
...
tests/lettuce/data/commands/bad_command
0 → 100644
View file @
64f69a14
!echo shouldshow
some bad command
!echo shouldnotshow
tests/lettuce/data/commands/directives
0 → 100644
View file @
64f69a14
# this is a comment: commentexample1
!echo this is an echo: echoexample
!verbose on
# this is a comment with verbose on: verbosecommentexample
!verbose off
# this is a comment with verbose off again: commentexample2
tests/lettuce/data/commands/empty
0 → 100644
View file @
64f69a14
tests/lettuce/data/commands/nested
0 → 100644
View file @
64f69a14
# include a different file
execute file data/commands/nested1
tests/lettuce/data/commands/nested1
0 → 100644
View file @
64f69a14
# this is included by nested
!echo shouldshow
tests/lettuce/features/bindctl_commands.feature
View file @
64f69a14
...
...
@@ -70,5 +70,34 @@ Feature: control with bindctl
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
# first a few bad commands
When
I send bind10 the command execute
last
bindctl
output
should
contain
Error
When
I send bind10 the command execute file
last
bindctl
output
should
contain
Error
When
I send bind10 the command execute file data/commands/nosuchfile
last
bindctl
output
should
contain
Error
# empty list should be no-op
When
I send bind10 the command execute file data/commands/empty
last
bindctl
output
should
not
contain
Error
# some tests of directives like !echo and !verbose
When
I send bind10 the command execute file data/commands/directives
last
bindctl
output
should
not
contain
Error
last
bindctl
output
should
not
contain
commentexample1
last
bindctl
output
should
contain
echoexample
last
bindctl
output
should
contain
verbosecommentexample
last
bindctl
output
should
not
contain
commentexample2
# bad_command contains a bad command, at which point execution should stop
When
I send bind10 the command execute file data/commands/bad_command
last
bindctl
output
should
contain
shouldshow
last
bindctl
output
should
contain
Error
last
bindctl
output
should
not
contain
shouldnotshow
# nested_command contains another execute script
When
I send bind10 the command execute file data/commands/nested
last
bindctl
output
should
contain
shouldshow
last
bindctl
output
should
not
contain
Error
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment