Skip to content

Commit

Permalink
extend system tests to cover all command types
Browse files Browse the repository at this point in the history
Signed-off-by: Reuben Miller <[email protected]>
  • Loading branch information
reubenmiller committed Nov 1, 2023
1 parent 4049e2f commit 673135c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ Update configuration plugin config via local filesystem move (same directory)
Main Device ${PARENT_SN} ${PARENT_SN}
Child Device ${CHILD_SN} ${PARENT_SN}:device:${CHILD_SN}

Manual config_snapshot operation request
Set Device Context ${PARENT_SN}
Publish and Verify Local Command
... topic=te/device/main///cmd/config_snapshot/local-1111
... payload={"status":"init","tedgeUrl":"http://${PARENT_IP}:8000/tedge/file-transfer/${PARENT_SN}/config_snapshot/local-1111","type":"tedge-configuration-plugin"}
... expected_status=successful
... c8y_fragment=c8y_UploadConfigFile

Manual config_update operation request
Set Device Context ${PARENT_SN}
# Don't worry about the command failing, that is expected since the tedgeUrl path does not exist
Publish and Verify Local Command
... topic=te/device/main///cmd/config_update/local-2222
... payload={"status":"init","tedgeUrl":"http://${PARENT_IP}:8000/tedge/file-transfer/${PARENT_SN}/config_update/local-2222","remoteUrl":"","type":"tedge-configuration-plugin"}
... expected_status=failed
... c8y_fragment=c8y_DownloadConfigFile


*** Keywords ***

Set Configuration from Device
Expand Down Expand Up @@ -283,3 +301,18 @@ Copy Configuration Files
# Execute Command chown root:root /etc/tedge/plugins/tedge-configuration-plugin.toml /etc/config1.json
# Uncomment once https://github.com/thin-edge/thin-edge.io/issues/2253 is resolved
# ThinEdgeIO.Service Health Status Should Be Up tedge-configuration-plugin device=child1

Publish and Verify Local Command
[Arguments] ${topic} ${payload} ${expected_status}=successful ${c8y_fragment}=
[Teardown] Execute Command tedge mqtt pub --retain '${topic}' ''
Execute Command tedge mqtt pub --retain '${topic}' '${payload}'
${messages}= Should Have MQTT Messages ${topic} minimum=1 maximum=1 message_contains="status":"${expected_status}"

Sleep 5s reason=Given mapper a chance to react, if it does not react with 5 seconds it never will
${retained_message} Execute Command timeout 1 tedge mqtt sub --no-topic '${topic}' ignore_exit_code=${True} strip=${True}
Should Be Equal ${messages[0]} ${retained_message} msg=MQTT message should be unchanged

IF "${c8y_fragment}"
# There should not be any c8y related operation transition messages sent: https://cumulocity.com/guides/reference/smartrest-two/#updating-operations
Should Have MQTT Messages c8y/s/ds message_pattern=^(501|502|503),${c8y_fragment}.* minimum=0 maximum=0
END
27 changes: 20 additions & 7 deletions tests/RobotFramework/tests/cumulocity/log/log_operation.robot
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ Request with non-existing log type
... failure_reason=.*No such file or directory for log type: example1
... timeout=120

Manual log operation request
Manual log_upload operation request
Execute Command sudo -u tedge mkdir -p /var/tedge/file-transfer/${DEVICE_SN}/log_upload
Execute Command sudo -u tedge touch /var/tedge/file-transfer/${DEVICE_SN}/log_upload/example-1234
${start_timestamp}= Get Current Date UTC -24 hours result_format=%Y-%m-%dT%H:%M:%SZ
${end_timestamp}= Get Current Date UTC +60 seconds result_format=%Y-%m-%dT%H:%M:%SZ
Execute Command
... sudo tedge mqtt pub --retain 'te/device/main///cmd/log_upload/example-1234' '{"status":"init","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/${DEVICE_SN}/log_upload/example-1234","type":"example","dateFrom":"${start_timestamp}","dateTo":"${end_timestamp}","searchText":"first","lines":10}'
${messages}= Should Have MQTT Messages
... te/device/main///cmd/log_upload/example-1234
... minimum=3
... maximum=3
Publish and Verify Local Command
... topic=te/device/main///cmd/log_upload/example-1234
... payload={"status":"init","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/${DEVICE_SN}/log_upload/example-1234","type":"example","dateFrom":"${start_timestamp}","dateTo":"${end_timestamp}","searchText":"first","lines":10}
... c8y_fragment=c8y_DownloadConfigFile


*** Keywords ***
Expand All @@ -59,3 +57,18 @@ Custom Setup
Device Should Exist ${DEVICE_SN}

Setup LogFiles

Publish and Verify Local Command
[Arguments] ${topic} ${payload} ${expected_status}=successful ${c8y_fragment}=
[Teardown] Execute Command tedge mqtt pub --retain '${topic}' ''
Execute Command tedge mqtt pub --retain '${topic}' '${payload}'
${messages}= Should Have MQTT Messages ${topic} minimum=1 maximum=1 message_contains="status":"${expected_status}"

Sleep 5s reason=Given mapper a chance to react, if it does not react with 5 seconds it never will
${retained_message} Execute Command timeout 1 tedge mqtt sub --no-topic '${topic}' ignore_exit_code=${True} strip=${True}
Should Be Equal ${messages[0]} ${retained_message} msg=MQTT message should be unchanged

IF "${c8y_fragment}"
# There should not be any c8y related operation transition messages sent: https://cumulocity.com/guides/reference/smartrest-two/#updating-operations
Should Have MQTT Messages c8y/s/ds message_pattern=^(501|502|503),${c8y_fragment}.* minimum=0 maximum=0
END
24 changes: 24 additions & 0 deletions tests/RobotFramework/tests/cumulocity/restart/restart_device.robot
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ Supports restarting the device without sudo and running as root
${operation}= Cumulocity.Restart Device
Operation Should Be SUCCESSFUL ${operation} timeout=180

# Note: Sending an actual local restart operation to trigger a restart (e.g. status=init) is not feasible
# as the assertion would fail due to the device/container being unresponsive during the actual restart.
# Just checking that the messages do not trigger any c8y messages and does not clear the retained message
tedge-mapper-c8y does not react to local restart operations transitions
[Template] Publish and Verify Local Command
topic=te/device/main///cmd/restart/local-1111 payload={"status":"executing"} expected_status=executing c8y_fragment=c8y_Restart
topic=te/device/main///cmd/restart/local-2222 payload={"status":"failed"} expected_status=failed c8y_fragment=c8y_Restart
topic=te/device/main///cmd/restart/local-3333 payload={"status":"successful"} expected_status=successful c8y_fragment=c8y_Restart


*** Keywords ***

Expand All @@ -45,3 +54,18 @@ Custom Teardown
# Restore sudo in case if the tests are run on a device (and not in a container)
Execute Command [ -f /usr/bin/sudo.bak ] && mv /usr/bin/sudo.bak /usr/bin/sudo || true
Get Logs

Publish and Verify Local Command
[Arguments] ${topic} ${payload} ${expected_status}=successful ${c8y_fragment}=
[Teardown] Execute Command tedge mqtt pub --retain '${topic}' ''
Execute Command tedge mqtt pub --retain '${topic}' '${payload}'
${messages}= Should Have MQTT Messages ${topic} minimum=1 maximum=1 message_contains="status":"${expected_status}"

Sleep 2s reason=Given mapper a chance to react, if it does not react with 2 seconds it never will
${retained_message} Execute Command timeout 1 tedge mqtt sub --no-topic '${topic}' ignore_exit_code=${True} strip=${True}
Should Be Equal ${messages[0]} ${retained_message} msg=MQTT message should be unchanged

IF "${c8y_fragment}"
# There should not be any c8y related operation transition messages sent: https://cumulocity.com/guides/reference/smartrest-two/#updating-operations
Should Have MQTT Messages c8y/s/ds message_pattern=^(501|502|503),${c8y_fragment}.* minimum=0 maximum=0
END
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ Software list should only show currently installed software and not candidates
${VERSION}= Regexp Escape ${EXPECTED_VERSION}
Device Should Have Installed Software tedge,^${VERSION}::apt$ timeout=120

Manual software_list operation request
# Note: There isn't a Cumulocity IoT operation related to getting the software list, so no need to check for operation transitions
Publish and Verify Local Command
... topic=te/device/main///cmd/software_list/local-1111
... payload={"status":"init"}
... expected_status=successful

Manual software_update operation request
# Don't worry about the command failing, that is expected since the package to be installed does not exist
Publish and Verify Local Command
... topic=te/device/main///cmd/software_update/local-2222
... payload={"status":"init","updateList":[{"type":"apt","modules":[{"name":"package-does-not-exist","version":"latest","action":"install"}]}]}
... expected_status=failed
... c8y_fragment=c8y_SoftwareUpdate


*** Keywords ***

Custom Setup
Expand All @@ -50,3 +66,18 @@ Stop tedge-agent
Custom Teardown
Execute Command sudo stop-http-server.sh
Get Logs

Publish and Verify Local Command
[Arguments] ${topic} ${payload} ${expected_status}=successful ${c8y_fragment}=
[Teardown] Execute Command tedge mqtt pub --retain '${topic}' ''
Execute Command tedge mqtt pub --retain '${topic}' '${payload}'
${messages}= Should Have MQTT Messages ${topic} minimum=1 maximum=1 message_contains="status":"${expected_status}"

Sleep 5s reason=Given mapper a chance to react, if it does not react with 5 seconds it never will
${retained_message} Execute Command timeout 1 tedge mqtt sub --no-topic '${topic}' ignore_exit_code=${True} strip=${True}
Should Be Equal ${messages[0]} ${retained_message} msg=MQTT message should be unchanged

IF "${c8y_fragment}"
# There should not be any c8y related operation transition messages sent: https://cumulocity.com/guides/reference/smartrest-two/#updating-operations
Should Have MQTT Messages c8y/s/ds message_pattern=^(501|502|503),${c8y_fragment}.* minimum=0 maximum=0
END

0 comments on commit 673135c

Please sign in to comment.