From aed95ef0199d4acc45f33c59b377e64310f67070 Mon Sep 17 00:00:00 2001 From: gligorisaev Date: Mon, 11 Mar 2024 07:59:48 +0100 Subject: [PATCH] add deregistering entities test Signed-off-by: gligorisaev --- ...ion.robot => registration_lifecycle.robot} | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) rename tests/RobotFramework/tests/cumulocity/registration/{device_registration.robot => registration_lifecycle.robot} (92%) diff --git a/tests/RobotFramework/tests/cumulocity/registration/device_registration.robot b/tests/RobotFramework/tests/cumulocity/registration/registration_lifecycle.robot similarity index 92% rename from tests/RobotFramework/tests/cumulocity/registration/device_registration.robot rename to tests/RobotFramework/tests/cumulocity/registration/registration_lifecycle.robot index 683fa2e28c3..5c26d7840f4 100644 --- a/tests/RobotFramework/tests/cumulocity/registration/device_registration.robot +++ b/tests/RobotFramework/tests/cumulocity/registration/registration_lifecycle.robot @@ -3,7 +3,7 @@ Resource ../../../resources/common.resource Library Cumulocity Library ThinEdgeIO -Test Tags theme:c8y theme:registration +Test Tags theme:c8y theme:registration theme:deregistration Suite Setup Custom Setup Test Setup Test Setup Test Teardown Get Logs ${DEVICE_SN} @@ -30,6 +30,18 @@ Child device registration Cumulocity.Set Device ${DEVICE_SN} Cumulocity.Should Be A Child Device Of Device ${CHILD_SN} + # Deregister Child device + Execute Command mosquitto_sub --remove-retained -W 3 -t "te/device/${CHILD_SN}/+/+/#" exp_exit_code=27 + + # Check if deregistration was successful + Sleep 1s reason=Allowing components to process messages + Should Have Retained Message Count te/device/${CHILD_SN}/+/+/# 0 + + # Checking if child device will be recreated after mapper restart + Restart Service tedge-mapper-c8y + Sleep 5s reason=Allowing startup to complete + Should Have Retained Message Count te/device/${CHILD_SN}/+/+/# 0 + Register child device with defaults via MQTT Execute Command tedge mqtt pub --retain 'te/device/${CHILD_SN}//' '{"@type":"child-device"}' Check Child Device parent_sn=${DEVICE_SN} child_sn=${CHILD_XID} child_name=${CHILD_XID} child_type=thin-edge.io-child @@ -73,6 +85,12 @@ Register service on a child device via MQTT # Check service registration Check Service child_sn=${CHILD_XID} service_sn=${CHILD_XID}:service:custom-app service_name=custom-app service_type=custom-type service_status=up + # Deregister service on a child device + Execute Command mosquitto_sub --remove-retained -W 3 -t 'te/device/${CHILD_SN}/service/custom-app/#' exp_exit_code=27 + + # Check if deregistration was successful + Sleep 1s reason=Allowing components to process messages + Should Have Retained Message Count te/device/${CHILD_SN}/service/custom-app/# 0 Register devices using custom MQTT schema [Documentation] Complex example showing how to use custom MQTT topics to register devices/services using @@ -234,6 +252,11 @@ Entities send to cloud on restart *** Keywords *** +Should Have Retained Message Count + [Arguments] ${topic} ${exp_count} + ${output}= Execute Command mosquitto_sub --retained-only -W 3 -t "${topic}" -v exp_exit_code=27 return_stdout=True + Length Should Be ${output.splitlines()} ${exp_count} + Re-enable auto-registration and collect logs [Teardown] Get Logs ${DEVICE_SN} Execute Command sudo tedge config unset c8y.entity_store.auto_register @@ -251,7 +274,7 @@ Check Child Device ${child_mo}= Device Should Exist ${child_sn} ${child_mo}= Cumulocity.Device Should Have Fragment Values name\=${child_name} - Should Be Equal ${child_mo["owner"]} device_${DEVICE_SN} # The parent is the owner of the child + Should Be Equal ${child_mo["owner"]} device_${DEVICE_SN} Should Be Equal ${child_mo["name"]} ${child_name} Should Be Equal ${child_mo["type"]} ${child_type}