Skip to content
GitLab
Menu
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
8de4264d
Commit
8de4264d
authored
Mar 17, 2017
by
Francis Dupont
Browse files
[5150a] Ported some shell fixes
parent
3ac8487a
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/bin/shell/kea-shell.in
View file @
8de4264d
...
...
@@ -80,17 +80,18 @@ def shell_body():
params.timeout = cmd_args.timeout
params.version = VERSION
params.generate_body()
params.generate_headers()
# Load command processor
# @todo - command specific processing will be added as part of
# future work (either #5138 or #5139, whichever is implemented
# first)
# Read
p
ar
ameter
s from stdin (they're optional for some commands)
# Read ar
gument
s from stdin (they're optional for some commands)
for line in sys.stdin:
params.params += line
params.args += line
# Now we have the arguments so we can build the request
params.generate_body()
params.generate_headers()
# Set the timeout timer. If the connection takes too long,
# it will send a signal to us.
...
...
src/bin/shell/kea-shell.xml
View file @
8de4264d
...
...
@@ -64,7 +64,7 @@
The
<command>
kea-shell
</command>
provides a REST client for the
Kea Control Agent (CA). It takes command as a command-line parameter
that is being sent to CA with proper JSON
encapsulation. Optional
p
ar
ameter
s may be specified on the
encapsulation. Optional ar
gument
s may be specified on the
standard input. The request it sent of HTTP and a response is
retrieved. That response is displayed out on the standard output.
</para>
...
...
src/bin/shell/kea_conn.py
View file @
8de4264d
...
...
@@ -17,6 +17,7 @@ class CARequest:
- http-port - TCP port of the CA
- command - specifies the command to send (e.g. list-commands)
- timeout - timeout (in ms)
- args - extra arguments my be added here
- headers - extra HTTP headers may be added here
- version - version to be reported in HTTP header
"""
...
...
@@ -25,7 +26,7 @@ class CARequest:
http_port
=
0
command
=
''
timeout
=
0
p
ar
am
s
=
''
ar
g
s
=
''
headers
=
{}
version
=
""
# This is a storage for generated command (input data to be sent over POST)
...
...
@@ -35,12 +36,11 @@ class CARequest:
"""
Generates the content, out of specified command line
and optional content.
@todo: Add support for parameters
this stores the output in self.content
"""
self
.
content
=
'{ "command": "'
+
self
.
command
+
'"'
if
len
(
self
.
p
ar
ams
)
:
self
.
content
+=
', "
p
ar
ameter
s": { '
+
self
.
p
ar
am
s
+
' }'
if
len
(
self
.
ar
gs
)
>
1
:
self
.
content
+=
', "ar
gument
s": { '
+
self
.
ar
g
s
+
' }'
self
.
content
+=
' }'
def
generate_headers
(
self
):
...
...
src/bin/shell/tests/.gitignore
View file @
8de4264d
shell_process_tests.sh
shell_unittest.py
src/bin/shell/tests/shell_process_tests.sh.in
View file @
8de4264d
...
...
@@ -111,7 +111,7 @@ shell_command_test() {
shell_exit_code=$?
if [ ${shell_exit_code} -ne 0 ]; then
echo "ERROR:" \
"kea-shell returned ${shell_exit_code} exit code, expected 0."
"kea-shell returned ${shell_exit_code} exit code, expected 0."
else
echo "kea-shell returned ${shell_exit_code} exit code as expected."
fi
...
...
@@ -123,8 +123,8 @@ shell_command_test() {
diff_code=$?
if [ ${diff_code} -ne 0 ]; then
echo "ERROR:" \
"content returned is different than expected." \
"See ${tmpfile_path}/shell-*.txt"
"content returned is different than expected." \
"See ${tmpfile_path}/shell-*.txt"
echo "EXPECTED:"
cat ${tmpfile_path}/shell-expected.txt
echo "ACTUAL RESULT:"
...
...
@@ -171,13 +171,24 @@ version_test() {
test_finish 0
else
echo "ERROR:" \
"Expected version ${EXPECTED_VERSION}, got ${REPORTED_VERSION}"
"Expected version ${EXPECTED_VERSION}, got ${REPORTED_VERSION}"
test_finish 1
fi
}
version_test "shell.version"
shell_command_test "shell.list-commands" "list-commands" \
"[ { \"arguments\": [ \"build-report\", \"config-
get\", \"config-test\", \"config-wri
te\", \"list-commands\", \"shutdown\", \"version-get\" ], \"result\": 0 } ]" ""
"[ { \"arguments\": [ \"build-report\", \"config-te
st
\", \"list-commands\", \"shutdown\", \"version-get\" ], \"result\": 0 } ]" ""
shell_command_test "shell.bogus" "give-me-a-beer" \
"[ { \"result\": 1, \"text\": \"'give-me-a-beer' command not supported.\" } ]" ""
shell_command_test "shell.empty-config-test" "config-test" \
"[ { \"result\": 1, \"text\": \"Missing mandatory 'arguments' parameter.\" } ]" ""
shell_command_test "shell.no-app-config-test" "config-test" \
"[ { \"result\": 1, \"text\": \"Missing mandatory 'Control-agent' parameter.\" } ]" \
"\"FooBar\": { }"
shell_command_test "shell.no-map-config-test" "config-test" \
"[ { \"result\": 1, \"text\": \"'Control-agent' parameter expected to be a map.\" } ]" \
"\"Control-agent\": [ ]"
shell_command_test "shell.bad-value-config-test" "config-test" \
"[ { \"result\": 2, \"text\": \"out of range value (80000) specified for parameter 'http-port' (<string>:1:76)\" } ]" \
"\"Control-agent\": { \"http-port\": 80000 }"
src/bin/shell/tests/shell_unittest.py.in
View file @
8de4264d
...
...
@@ -26,27 +26,27 @@ class CARequestUnitTest(unittest.TestCase):
"""
pass
def test_body_without_
p
ar
am
s(self):
def test_body_without_ar
g
s(self):
"""
This test verifies if the CARequest object generates the request
content properly when there are no
p
ar
ameter
s.
content properly when there are no ar
gument
s.
"""
request = CARequest()
request.command = "foo"
request.generate_body()
self.assertEqual(request.content, '{ "command": "foo" }')
def test_body_with_
p
ar
am
s(self):
def test_body_with_ar
g
s(self):
"""
This test verifies if the CARequest object generates the request
content properly when there are
p
ar
ameter
s.
content properly when there are ar
gument
s.
"""
request = CARequest()
request.command = "foo"
request.
p
ar
am
s = '"bar": "baz"'
request.ar
g
s = '"bar": "baz"'
request.generate_body()
self.assertEqual(request.content,
'{ "command": "foo", "
p
ar
ameter
s": { "bar": "baz" } }')
'{ "command": "foo", "ar
gument
s": { "bar": "baz" } }')
@staticmethod
def check_header(headers, header_name, value):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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