From ad5ef995ceb2123624f96571da4c80193cc1257d Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Tue, 14 Jan 2025 09:56:43 +0000 Subject: [PATCH 1/2] test: add system test for smartrest template custom operation Signed-off-by: Krzysztof Piotrowski --- .../requirements/requirements.txt | 2 +- .../set_wifi | 4 ++ .../set_wifi.json | 18 ++++++++ .../set_wifi.sh | 17 ++++++++ .../smartrest_template.robot | 42 +++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi create mode 100644 tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.json create mode 100644 tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.sh create mode 100644 tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/smartrest_template.robot diff --git a/tests/RobotFramework/requirements/requirements.txt b/tests/RobotFramework/requirements/requirements.txt index 2fe73c550a8..1a4b9455601 100644 --- a/tests/RobotFramework/requirements/requirements.txt +++ b/tests/RobotFramework/requirements/requirements.txt @@ -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/robotframework-aws.git@0.0.9 robotframework-debuglibrary~=2.5.0 robotframework-jsonlibrary~=0.5 diff --git a/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi new file mode 100644 index 00000000000..62e694bb19d --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi @@ -0,0 +1,4 @@ +[exec] +command = "/etc/tedge/operations/set_wifi.sh" +topic = "c8y/s/dc/custom_devmgmt" +on_message = "dm101" diff --git a/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.json b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.json new file mode 100644 index 00000000000..b0a37b0b672 --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.json @@ -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" + ] + } + ] + } +} diff --git a/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.sh b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.sh new file mode 100644 index 00000000000..e0857e222cb --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/set_wifi.sh @@ -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" diff --git a/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/smartrest_template.robot b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/smartrest_template.robot new file mode 100644 index 00000000000..c394e563209 --- /dev/null +++ b/tests/RobotFramework/tests/cumulocity/custom_operation/custom_operation_smartrest_template/smartrest_template.robot @@ -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 From adde0571ea0abc81d58ac8f4ab9502f51cd19e40 Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Tue, 14 Jan 2025 10:34:11 +0000 Subject: [PATCH 2/2] docs: fix the smartrest templates script content Signed-off-by: Krzysztof Piotrowski --- docs/src/operate/c8y/smartrest-templates.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/operate/c8y/smartrest-templates.md b/docs/src/operate/c8y/smartrest-templates.md index 2e52e4ac0d8..2aa117c9983 100644 --- a/docs/src/operate/c8y/smartrest-templates.md +++ b/docs/src/operate/c8y/smartrest-templates.md @@ -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"