Commit 8de4264d authored by Francis Dupont's avatar Francis Dupont

[5150a] Ported some shell fixes

parent 3ac8487a
......@@ -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 parameters from stdin (they're optional for some commands)
# Read arguments 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.
......
......@@ -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 parameters may be specified on the
encapsulation. Optional arguments 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>
......
......@@ -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
params = ''
args = ''
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.params):
self.content += ', "parameters": { ' + self.params + ' }'
if len(self.args) > 1:
self.content += ', "arguments": { ' + self.args + ' }'
self.content += ' }'
def generate_headers(self):
......
shell_process_tests.sh
shell_unittest.py
......@@ -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-write\", \"list-commands\", \"shutdown\", \"version-get\" ], \"result\": 0 } ]" ""
"[ { \"arguments\": [ \"build-report\", \"config-test\", \"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 }"
......@@ -26,27 +26,27 @@ class CARequestUnitTest(unittest.TestCase):
"""
pass
def test_body_without_params(self):
def test_body_without_args(self):
"""
This test verifies if the CARequest object generates the request
content properly when there are no parameters.
content properly when there are no arguments.
"""
request = CARequest()
request.command = "foo"
request.generate_body()
self.assertEqual(request.content, '{ "command": "foo" }')
def test_body_with_params(self):
def test_body_with_args(self):
"""
This test verifies if the CARequest object generates the request
content properly when there are parameters.
content properly when there are arguments.
"""
request = CARequest()
request.command = "foo"
request.params = '"bar": "baz"'
request.args = '"bar": "baz"'
request.generate_body()
self.assertEqual(request.content,
'{ "command": "foo", "parameters": { "bar": "baz" } }')
'{ "command": "foo", "arguments": { "bar": "baz" } }')
@staticmethod
def check_header(headers, header_name, value):
......
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