Skip to content

Commit

Permalink
add smartrest 1.0 system tests
Browse files Browse the repository at this point in the history
Signed-off-by: Reuben Miller <reuben.d.miller@gmail.com>
  • Loading branch information
reubenmiller authored and rina23q committed Oct 23, 2024
1 parent f883310 commit 9f634db
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 88 deletions.
27 changes: 27 additions & 0 deletions tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,33 @@ def bridge_should_be_down(self, cloud: str, **kwargs) -> str:
self.get_bridge_service_name(cloud), **kwargs
)

def _get_device_sn(self, name):
device = self.current
if name:
if name in self.devices:
device = self.devices.get(name)

return name or device.get_id()

@keyword("Delete SmartREST 1.0 Template")
def delete_smartrest_one_template(self, template_id: str):
try:
mo_id = c8y_lib.c8y.identity.get_id(
template_id, "c8y_SmartRestDeviceIdentifier"
)
log.info(
"Deleting SmartREST 1.0 template. external_id=%s, managed_object_id=%s",
template_id,
mo_id,
)
c8y_lib.c8y.inventory.delete(mo_id)
except Exception as ex:
log.warning(
"Could not deleted SmartREST 1.0 template. id=%s, ex=%s",
template_id,
ex,
)


def to_date(value: relativetime_) -> datetime:
if isinstance(value, datetime):
Expand Down
12 changes: 10 additions & 2 deletions tests/RobotFramework/resources/common.resource
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ ${DEVICE_ADAPTER} %{DEVICE_ADAPTER=docker}
&{LOCAL_CONFIG} skip_bootstrap=False bootstrap_script=%{LOCAL_CONFIG_BOOTSTRAP_SCRIPT= }

# Cumulocity settings
&{C8Y_CONFIG} host=%{C8Y_BASEURL= } username=%{C8Y_USER= } password=%{C8Y_PASSWORD= }
&{C8Y_CONFIG}
... host=%{C8Y_BASEURL= }
... username=%{C8Y_USER= }
... password=%{C8Y_PASSWORD= }
... bootstrap_username=%{C8Y_BOOTSTRAP_USER=}
... bootstrap_password=%{C8Y_BOOTSTRAP_PASSWORD=}

# AWS settings
&{AWS_CONFIG} access_key_id=%{AWS_ACCESS_KEY_ID= } access_key=%{AWS_SECRET_ACCESS_KEY= } region=%{AWS_REGION= }
&{AWS_CONFIG}
... access_key_id=%{AWS_ACCESS_KEY_ID= }
... access_key=%{AWS_SECRET_ACCESS_KEY= }
... region=%{AWS_REGION= }

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,78 @@
*** Settings ***
Resource ../../../../resources/common.resource
Library Cumulocity
Library ThinEdgeIO
Resource ../../../../resources/common.resource
Library Cumulocity
Library ThinEdgeIO

Test Teardown Custom Teardown

Test Tags theme:c8y theme:operation


*** Variables ***
${SMART_REST_ONE_TEMPLATES}=
... SEPARATOR=\n
... 10,339,GET,/identity/externalIds/c8y_Serial/%%,,application/vnd.com.nsn.cumulocity.externalId+json,%%,STRING,
... 10,311,GET,/alarm/alarms?source\=%%&status\=%%&pageSize\=100,,,%%,UNSIGNED STRING,
... 11,800,$.managedObject,,$.id
... 11,808,$.alarms,,$.id,$.type

Test Tags theme:c8y theme:operation
Test Setup Custom Setup
Test Teardown Get Logs

*** Test Cases ***
Supports SmartREST 1.0 Templates
[Template] Register and Use SmartREST 1.0. Templates
use_builtin_bridge=true
use_builtin_bridge=false

Register SmartREST 1 templates
${TEMPLATE_XID}= Set Variable templateXIDexample01
# Execute Command cmd=curl -XPOST -H "X-Id: templateXIDexample01" -d "10,107,GET,/inventory/managedObjects/%%/childDevices?pageSize=100,,,%%,," http://127.0.0.1:8001/c8y/s
Execute Command cmd=tedge mqtt pub c8y/s/ul "15,${TEMPLATE_XID}\n10,107,GET,/inventory/managedObjects/%%/childDevices?pageSize=100,,,%%,,\n"
Log debug
# 10,107,GET,/inventory/managedObjects/%%/childDevices?pageSize=100,,,%%,,\n
# Should Have MQTT Messages c8y/s/us message_pattern=114,c8y_DownloadConfigFile,c8y_LogfileRequest,c8y_RemoteAccessConnect,c8y_Restart,c8y_SoftwareUpdate,c8y_UploadConfigFile minimum=1 maximum=1


*** Keywords ***
Register and Use SmartREST 1.0. Templates
[Arguments] ${use_builtin_bridge}
Custom Setup use_builtin_bridge=${use_builtin_bridge}

${TEMPLATE_XID}= Get Random Name prefix=TST_Template
Set Test Variable $TEMPLATE_XID
Execute Command tedge config set c8y.smartrest1.templates "${TEMPLATE_XID}"
Execute Command tedge connect c8y timeout=10
${mo}= Device Should Exist ${DEVICE_SN}

# register templates
Execute Command
... curl --max-time 15 -sf -XPOST http://127.0.0.1:8001/c8y/s -H "Content-Type: plain/text" -H "X-Id: ${TEMPLATE_XID}" --data "${SMART_REST_ONE_TEMPLATES}"

# Use templates
# Get managed object id
Execute Command cmd=tedge mqtt pub c8y/s/ul/${TEMPLATE_XID} '339,${DEVICE_SN}'
Should Have MQTT Messages c8y/s/dl/${TEMPLATE_XID} message_pattern=^800,\\d+,${mo["id"]} timeout=10

Execute Command cmd=tedge mqtt pub te/device/main///a/test '{"text":"test alarm","severity":"major"}' -r
Device Should Have Alarm/s type=test expected_text=test alarm

# Get alarms
Execute Command cmd=tedge mqtt pub c8y/s/ul/${TEMPLATE_XID} '311,${mo["id"]},ACTIVE'
Should Have MQTT Messages c8y/s/dl/${TEMPLATE_XID} message_pattern=^808,\\d+,\\d+,test timeout=10

# Operations
${OPERATION}= Get Configuration tedge-configuration-plugin
Operation Should Be SUCCESSFUL ${OPERATION}

Register Device
[Arguments] ${SERIAL}
${CREDENTIALS}= Cumulocity.Bulk Register Device With Basic Auth external_id=${SERIAL}

Execute Command
... cmd=printf '[c8y]\nusername = "%s"\npassword = "%s"\n' "${CREDENTIALS.username}" "${CREDENTIALS.password}" > /etc/tedge/credentials

Custom Setup
${DEVICE_SN}= Setup
[Arguments] ${use_builtin_bridge}
${DEVICE_SN}= Setup skip_bootstrap=${True}
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-connect || true
Execute Command tedge config set mqtt.bridge.built_in ${use_builtin_bridge}
Execute Command tedge config set c8y.use_basic_auth true

Set Suite Variable $DEVICE_SN
Device Should Exist ${DEVICE_SN}

Register Device ${DEVICE_SN}

Custom Teardown
Get Logs
IF $TEMPLATE_XID Delete SmartREST 1.0 Template ${TEMPLATE_XID}

0 comments on commit 9f634db

Please sign in to comment.