Closed reubenmiller closed 1 year ago
The bug is fixed by #1692. I have tested manually with the shell script that @reubenmiller provided above and the following inputs and outputs.
# How to read the following the test cases.
<user input on c8y>
=>
<expected output recorded on c8y as RESPONSE>
1.
echo hello
echo world
=>
hello
world
2.
echo "helloworld"
=>
helloworld
3.
echo "hello"; echo "world"
=>
hello
world
4.
echo hello; echo world
=>
hello
world
5.
echo hello,world
=>
hello,world
6.
echo \"hello\"
=>
"hello"
7.
echo "testme"
echo "test again"
=>
testme
test again
8.
echo "line 1";
echo "line 2";
echo "line, 3";
=>
line 1
line 2
line, 3
Describe the bug
When implementing a custom operation, the mqtt message is not passed to the custom operation handler in its entirity. Most notably if the custom operation contains a newline (
\n
) characters. In this case only the first line is passed to the handler.This is best observed when implementing a custom Cumulocity IoT
c8y_Command
handler. The handler receives a multi-lined command from the Cumulocity IoT Shell interface, and the script only receives the first line.To Reproduce
Add the following files with the listed contents to the device running thin-edge.io
file: /etc/tedge/operations/c8y/c8y_Command
file: /etc/tedge/operations/command_handler.sh
Make sure the
command_handler.sh
script is executableRestart the
tedge-agent
and mapperCreate an
c8y_Command
operation with the following values`Wait for the operation to be set to
SUCCESSFUL
Inspect the operation, and the
c8y_Command.result
should be exactlyhello\nworld\n
(see below for the full operation snippet)Expected behavior
The handler should be given the full command passed as the first argument to the custom operation handler.
Screenshots
Environment (please complete the following information):
Additional context
The same produre was executed but with the debug line uncommented, and the following output showing how the handler was called
And below shows the full raw json of the operation after it was set to
SUCCESSFUL