From: Francis Dupont Date: Fri, 17 Mar 2017 07:18:31 +0000 (+0100) Subject: [5150a] Ported some shell fixes X-Git-Tag: trac5196_base~21^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8de4264de37358f3727571ff71755c8c70763dbd;p=thirdparty%2Fkea.git [5150a] Ported some shell fixes --- diff --git a/src/bin/shell/kea-shell.in b/src/bin/shell/kea-shell.in index e86c53c733..9937d7f230 100644 --- a/src/bin/shell/kea-shell.in +++ b/src/bin/shell/kea-shell.in @@ -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. diff --git a/src/bin/shell/kea-shell.xml b/src/bin/shell/kea-shell.xml index 55f90fd7c0..3a3b2dd457 100644 --- a/src/bin/shell/kea-shell.xml +++ b/src/bin/shell/kea-shell.xml @@ -64,7 +64,7 @@ The kea-shell 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. diff --git a/src/bin/shell/kea_conn.py b/src/bin/shell/kea_conn.py index bf94f64c07..45bd9b7490 100644 --- a/src/bin/shell/kea_conn.py +++ b/src/bin/shell/kea_conn.py @@ -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): diff --git a/src/bin/shell/tests/.gitignore b/src/bin/shell/tests/.gitignore index 433d20f111..13066d0906 100644 --- a/src/bin/shell/tests/.gitignore +++ b/src/bin/shell/tests/.gitignore @@ -1,2 +1 @@ shell_process_tests.sh -shell_unittest.py diff --git a/src/bin/shell/tests/shell_process_tests.sh.in b/src/bin/shell/tests/shell_process_tests.sh.in index 746b2f5aae..33deb2e5e4 100644 --- a/src/bin/shell/tests/shell_process_tests.sh.in +++ b/src/bin/shell/tests/shell_process_tests.sh.in @@ -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' (:1:76)\" } ]" \ + "\"Control-agent\": { \"http-port\": 80000 }" diff --git a/src/bin/shell/tests/shell_unittest.py.in b/src/bin/shell/tests/shell_unittest.py.in index e23b50d544..8a0d1e0ede 100644 --- a/src/bin/shell/tests/shell_unittest.py.in +++ b/src/bin/shell/tests/shell_unittest.py.in @@ -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):