-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add c8y_Command and c8y_RelayArray system tests with workflow
Signed-off-by: Rina Fujino <[email protected]>
- Loading branch information
Showing
10 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ulocity/custom_operation/custom_operation_c8y_RelayArray_workflow/c8y_RelayArray.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[exec] | ||
topic = "c8y/devicecontrol/notifications" | ||
on_fragment = "c8y_RelayArray" | ||
|
||
[exec.workflow] | ||
operation = "set_relay" | ||
input.relay = "${.payload.c8y_RelayArray}" |
56 changes: 56 additions & 0 deletions
56
...m_operation/custom_operation_c8y_RelayArray_workflow/operation_relay_array_workflow.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
*** Settings *** | ||
Resource ../../../../resources/common.resource | ||
Library Cumulocity | ||
Library ThinEdgeIO | ||
|
||
Suite Setup Custom Setup | ||
Test Teardown Get Logs | ||
|
||
Test Tags theme:c8y theme:troubleshooting theme:plugins | ||
|
||
|
||
*** Variables *** | ||
${PARENT_IP} ${EMPTY} | ||
${PARENT_SN} ${EMPTY} | ||
|
||
|
||
*** Test Cases *** | ||
Run c8y_RelayArray operation with workflow execution | ||
Symlink Should Exist /etc/tedge/operations/c8y/c8y_RelayArray | ||
Cumulocity.Should Contain Supported Operations c8y_RelayArray | ||
|
||
${operation}= Cumulocity.Create Operation | ||
... description=Set relays | ||
... fragments={"c8y_RelayArray":["OPEN", "CLOSED"]} | ||
|
||
Should Have MQTT Messages | ||
... c8y/s/us | ||
... message_pattern=^506,[0-9]+,OPEN,CLOSED | ||
... minimum=1 | ||
... maximum=1 | ||
Cumulocity.Operation Should Be SUCCESSFUL ${operation} | ||
Cumulocity.Managed Object Should Have Fragment Values c8y_RelayArray\=["OPEN", "CLOSED"] | ||
|
||
|
||
*** Keywords *** | ||
Transfer Configuration Files | ||
Transfer To Device ${CURDIR}/c8y_RelayArray.template /etc/tedge/operations/c8y/ | ||
Transfer To Device ${CURDIR}/set_relay.toml /etc/tedge/operations/ | ||
Transfer To Device ${CURDIR}/set_relay.sh /etc/tedge/operations/ | ||
Execute Command chmod a+x /etc/tedge/operations/set_relay.sh | ||
|
||
Custom Setup | ||
# Parent | ||
${parent_sn}= Setup skip_bootstrap=False | ||
Set Suite Variable $PARENT_SN ${parent_sn} | ||
|
||
${parent_ip}= Get IP Address | ||
Set Suite Variable $PARENT_IP ${parent_ip} | ||
|
||
Set Device Context ${PARENT_SN} | ||
Transfer Configuration Files | ||
Execute Command tedge config set mqtt.external.bind.address ${PARENT_IP} | ||
Execute Command tedge config set mqtt.external.bind.port 1883 | ||
Execute Command tedge reconnect c8y | ||
|
||
Cumulocity.Device Should Exist ${PARENT_SN} |
7 changes: 7 additions & 0 deletions
7
...k/tests/cumulocity/custom_operation/custom_operation_c8y_RelayArray_workflow/set_relay.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
MESSAGE="$1" | ||
|
||
echo :::begin-tedge::: | ||
printf '{"result":%s}\n' "$MESSAGE" | ||
echo :::end-tedge::: |
20 changes: 20 additions & 0 deletions
20
...tests/cumulocity/custom_operation/custom_operation_c8y_RelayArray_workflow/set_relay.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
operation = "set_relay" | ||
|
||
[init] | ||
action = "proceed" | ||
on_success = "executing" | ||
|
||
[executing] | ||
action = "proceed" | ||
on_success = "run" | ||
|
||
[run] | ||
script = "/etc/tedge/operations/set_relay.sh ${.payload.relay}" | ||
on_success = "successful" | ||
on_error = { status = "failed", reason = "Command returned a non-zero exit code" } | ||
|
||
[successful] | ||
action = "cleanup" | ||
|
||
[failed] | ||
action = "cleanup" |
7 changes: 7 additions & 0 deletions
7
.../tests/cumulocity/custom_operation/custom_operation_command_workflow/c8y_Command.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[exec] | ||
topic = "c8y/devicecontrol/notifications" | ||
on_fragment = "c8y_Command" | ||
|
||
[exec.workflow] | ||
operation = "shell_execute" | ||
input.command = "${.payload.c8y_Command.text}" |
55 changes: 55 additions & 0 deletions
55
...ocity/custom_operation/custom_operation_command_workflow/operation_command_workflow.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
*** Settings *** | ||
Resource ../../../../resources/common.resource | ||
Library Cumulocity | ||
Library ThinEdgeIO | ||
|
||
Suite Setup Custom Setup | ||
Test Teardown Get Logs | ||
|
||
Test Tags theme:c8y theme:troubleshooting theme:plugins | ||
|
||
|
||
*** Variables *** | ||
${PARENT_IP} ${EMPTY} | ||
${PARENT_SN} ${EMPTY} | ||
|
||
|
||
*** Test Cases *** | ||
Run c8y_Command operation with workflow execution | ||
Symlink Should Exist /etc/tedge/operations/c8y/c8y_Command | ||
Cumulocity.Should Contain Supported Operations c8y_Command | ||
|
||
${operation}= Cumulocity.Create Operation | ||
... description=echo helloworld | ||
... fragments={"c8y_Command":{"text":"echo helloworld"}} | ||
|
||
Should Have MQTT Messages | ||
... c8y/s/us | ||
... message_pattern=^506,[0-9]+($|,\\"helloworld\n\\") | ||
... minimum=1 | ||
... maximum=1 | ||
Cumulocity.Operation Should Be SUCCESSFUL ${operation} | ||
|
||
|
||
*** Keywords *** | ||
Transfer Configuration Files | ||
Transfer To Device ${CURDIR}/c8y_Command.template /etc/tedge/operations/c8y/ | ||
Transfer To Device ${CURDIR}/shell_execute.toml /etc/tedge/operations/ | ||
Transfer To Device ${CURDIR}/shell_execute.sh /etc/tedge/operations/ | ||
Execute Command chmod a+x /etc/tedge/operations/shell_execute.sh | ||
|
||
Custom Setup | ||
# Parent | ||
${parent_sn}= Setup skip_bootstrap=False | ||
Set Suite Variable $PARENT_SN ${parent_sn} | ||
|
||
${parent_ip}= Get IP Address | ||
Set Suite Variable $PARENT_IP ${parent_ip} | ||
|
||
Set Device Context ${PARENT_SN} | ||
Transfer Configuration Files | ||
Execute Command tedge config set mqtt.external.bind.address ${PARENT_IP} | ||
Execute Command tedge config set mqtt.external.bind.port 1883 | ||
Execute Command tedge reconnect c8y | ||
|
||
Cumulocity.Device Should Exist ${PARENT_SN} |
28 changes: 28 additions & 0 deletions
28
...work/tests/cumulocity/custom_operation/custom_operation_command_workflow/shell_execute.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
info() { | ||
echo "$(date --iso-8601=seconds 2>/dev/null || date -Iseconds) : INFO : $*" >&2 | ||
} | ||
|
||
# Parse the message | ||
COMMAND="${1}" | ||
|
||
TMP_OUTPUT=$(mktemp) | ||
info "Writing command output to file. path=$TMP_OUTPUT" | ||
|
||
EXIT_CODE=0 | ||
|
||
set +e | ||
bash -c "$COMMAND" >"$TMP_OUTPUT" 2>&1 | ||
EXIT_CODE=$? | ||
set -e | ||
|
||
if [ "${EXIT_CODE}" -ne 0 ]; then | ||
info "Command returned a non-zero exit code. code=$EXIT_CODE" | ||
fi | ||
|
||
echo :::begin-tedge::: | ||
printf '{"result":%s}\n' "$(jq -R -s '.' < "$TMP_OUTPUT")" | ||
echo :::end-tedge::: | ||
|
||
exit "$EXIT_CODE" |
20 changes: 20 additions & 0 deletions
20
...rk/tests/cumulocity/custom_operation/custom_operation_command_workflow/shell_execute.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
operation = "shell_execute" | ||
|
||
[init] | ||
action = "proceed" | ||
on_success = "executing" | ||
|
||
[executing] | ||
action = "proceed" | ||
on_success = "run" | ||
|
||
[run] | ||
script = "/etc/tedge/operations/shell_execute.sh ${.payload.command}" | ||
on_success = "successful" | ||
on_error = { status = "failed", reason = "Command returned a non-zero exit code" } | ||
|
||
[successful] | ||
action = "cleanup" | ||
|
||
[failed] | ||
action = "cleanup" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters