Skip to content

Commit

Permalink
Merge pull request #3328 from Ruadhri17/smartest-templates-custom-ope…
Browse files Browse the repository at this point in the history
…ration-test

test: missing test for custom operation execution using smartrest templates
  • Loading branch information
Ruadhri17 authored Jan 16, 2025
2 parents 03b0756 + adde057 commit c698673
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/src/operate/c8y/smartrest-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ On your %%te%% device, run the following steps:

# Input arguments
MESSAGE="$1"
NAME=$(echo "$COMMAND" | cut -d, -f 3)
SSID=$(echo "$COMMAND" | cut -d, -f 4)
TYPE=$(echo "$COMMAND" | cut -d, -f 5)
NAME=$(echo "$MESSAGE" | cut -d, -f 3)
SSID=$(echo "$MESSAGE" | cut -d, -f 4)
TYPE=$(echo "$MESSAGE" | cut -d, -f 5)

echo "Processing message: $MESSAGE"
echo "NAME: $NAME"
Expand Down
2 changes: 1 addition & 1 deletion tests/RobotFramework/requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dateparser~=1.2.0
paho-mqtt~=1.6.1
python-dotenv~=1.0.0
robotframework~=7.0.0
robotframework-c8y @ git+https://github.com/thin-edge/robotframework-c8y.git@0.37.4
robotframework-c8y @ git+https://github.com/thin-edge/robotframework-c8y.git@0.39.1
robotframework-aws @ git+https://github.com/thin-edge/[email protected]
robotframework-debuglibrary~=2.5.0
robotframework-jsonlibrary~=0.5
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[exec]
command = "/etc/tedge/operations/set_wifi.sh"
topic = "c8y/s/dc/custom_devmgmt"
on_message = "dm101"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"com_cumulocity_model_smartrest_csv_CsvSmartRestTemplate": {
"requestTemplates": [],
"responseTemplates": [
{
"msgId": "dm101",
"condition": "set_wifi",
"base": "set_wifi",
"name": "set_wifi",
"pattern": [
"name",
"ssid",
"type"
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

# Constants
OK=0

# Input arguments
MESSAGE="$1"
NAME=$(echo "$MESSAGE" | cut -d, -f 3)
SSID=$(echo "$MESSAGE" | cut -d, -f 4)
TYPE=$(echo "$MESSAGE" | cut -d, -f 5)

echo "Processing message: $MESSAGE"
echo "NAME: $NAME"
echo "SSID: $SSID"
echo "TYPE: $TYPE"
exit "$OK"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
*** Settings ***
Resource ../../../../resources/common.resource
Library Cumulocity
Library ThinEdgeIO

Test Setup Custom Setup
Test Teardown Get Logs

Test Tags theme:c8y theme:operation theme:custom theme:smartrest theme:template


*** Test Cases ***
smartrest template custom operation successful
Create SmartREST2 Template ${CURDIR}/set_wifi.json ${DEVICE_SN}
Should Have SmartREST2 Template ${DEVICE_SN}

${operation}= Cumulocity.Create Operation
... description=do something
... fragments={"set_wifi":{"name":"Factory Wifi","ssid":"factory-onboarding-wifi","type":"WPA3-Personal"}}
Operation Should Be SUCCESSFUL ${operation}

${c8y_messages}= Should Have MQTT Messages
... c8y/s/dc/${DEVICE_SN}
... minimum=1
... maximum=1
... message_contains=dm101,${DEVICE_SN},Factory Wifi,factory-onboarding-wifi,WPA3-Personal


*** Keywords ***
Custom Setup
${DEVICE_SN}= Setup
Set Suite Variable $DEVICE_SN
Device Should Exist ${DEVICE_SN}

ThinEdgeIO.Transfer To Device ${CURDIR}/set_wifi /etc/tedge/operations/c8y/set_wifi
Execute Command sed -i -e 's/custom_devmgmt/${DEVICE_SN}/g' /etc/tedge/operations/c8y/set_wifi

ThinEdgeIO.Transfer To Device ${CURDIR}/set_wifi.sh /etc/tedge/operations/set_wifi.sh
Execute Command chmod a+x /etc/tedge/operations/set_wifi.sh

Execute Command tedge config set c8y.smartrest.templates ${DEVICE_SN}
Execute Command tedge reconnect c8y

0 comments on commit c698673

Please sign in to comment.