Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tasks that will follow the Documentation instructions #2878

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 0 additions & 98 deletions tests/RobotFramework/tasks/E2E_Tutorials/Connect_to_c8y.robot

This file was deleted.

97 changes: 97 additions & 0 deletions tests/RobotFramework/tasks/E2E_Tutorials/Install.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
*** Settings ***

Resource ../../../../resources/common.resource
Library ThinEdgeIO adapter=${ADAPTER}
Library Cumulocity
Suite Setup Setup skip_bootstrap=True
Suite Teardown Get Logs


*** Variables ***

${ADAPTER} ssh


*** Tasks ***

Install/Update of thinedge curl
${log} Execute Command curl -fsSL https://thin-edge.io/install.sh | sh -s
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO

Install/Update of thinedge wget
${log} Execute Command wget -O - https://thin-edge.io/install.sh | sh -s
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO

Update using a package manager
${log} Execute Command sudo apt-get update && yes | sudo apt-get install tedge-full
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO

Optional: Linux distributions without systemd curl
${OUTPUT} Execute Command curl -fsSL https://thin-edge.io/install-services.sh | sh -s ignore_exit_code=True
#Not verifiing this test step because the test running in container already exists: tests/RobotFramework/tests/installation/install_on_linux.robot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Not verifiing this test step because the test running in container already exists: tests/RobotFramework/tests/installation/install_on_linux.robot
#Skip verification step as system tests already exist: tests/RobotFramework/tests/installation/install_on_linux.robot

#Checking only that the link is correct
Should Contain ${OUTPUT} Welcome to the thin-edge.io community!

Optional: Linux distributions without systemd wget
${OUTPUT} Execute Command wget -O - https://thin-edge.io/install-services.sh | sh -s
#Not verifiing this test step because the test running in container already exists: tests/RobotFramework/tests/installation/install_on_linux.robot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Not verifiing this test step because the test running in container already exists: tests/RobotFramework/tests/installation/install_on_linux.robot
#Skip verification step as system tests already exist: tests/RobotFramework/tests/installation/install_on_linux.robot

#Checking only that the link is correct
Should Contain ${OUTPUT} Welcome to the thin-edge.io community!

Manual repository setup and installation running with sudo
${OUTPUT} Execute Command curl -1sLf 'https://dl.cloudsmith.io/public/thinedge/tedge-release/setup.deb.sh' | sudo bash
Should Contain ${OUTPUT} The repository has been installed successfully - You're ready to rock!
${log} Execute Command sudo apt update
Check repository creation
${log} Execute Command sudo apt-get install -y tedge-full
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO
Remove created repository

Manual repository setup and installation running as root
${OUTPUT} Execute Command sudo su -c "whoami && curl -1sLf 'https://dl.cloudsmith.io/public/thinedge/tedge-release/setup.deb.sh' | bash && apt update && apt-get install -y tedge-full"
Should Contain ${OUTPUT} root
Should Contain ${OUTPUT} The repository has been installed successfully - You're ready to rock!
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO
Remove created repository

Install via tarball
${log} Execute Command curl -fsSL https://thin-edge.io/install.sh | sh -s -- --package-manager tarball
Verify ThinEdgeIO is installed
Uninstall ThinEdgeIO


*** Keywords ***

Verify ThinEdgeIO is installed
${OUTPUT} Execute Command tedge --help
Should Contain ${OUTPUT} tedge is the cli tool for thin-edge.io
Log ThinEdgeIO was successfully installed

Uninstall ThinEdgeIO
Transfer To Device ${CURDIR}/uninstall-thin-edge_io.sh /var/local/share/uninstall-thin-edge_io.sh
Execute Command chmod a+x /var/local/share/uninstall-thin-edge_io.sh
Execute Command /var/local/share/uninstall-thin-edge_io.sh purge

#Verify ThinEdgeIO is uninstalled
${OUTPUT} Execute Command command -V tedge exp_exit_code=!0
${OUTPUT} Execute Command command -V tedge exp_exit_code=!0

Check repository creation
${OUTPUT} Execute Command ls /etc/apt/sources.list.d/
Should Contain ${OUTPUT} *.list
reubenmiller marked this conversation as resolved.
Show resolved Hide resolved
${OUTPUT} Execute Command apt-cache search tedge
Should Contain ${OUTPUT} tedge - CLI tool use to control and configure thin-edge.io
Should Contain ${OUTPUT} tedge - CLI tool use to control and configure thin-edge.io
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated line.

Suggested change
Should Contain ${OUTPUT} tedge - CLI tool use to control and configure thin-edge.io
Should Contain ${OUTPUT} tedge - CLI tool use to control and configure thin-edge.io
Should Contain ${OUTPUT} tedge - CLI tool use to control and configure thin-edge.io

Should Contain ${OUTPUT} tedge-agent - thin-edge.io interacts with a Cloud Mapper and one or more Software Plugins
Should Contain ${OUTPUT} tedge-apt-plugin - thin-edge.io plugin for software management using apt
Should Contain ${OUTPUT} tedge-full - thin-edge.io virtual package to automatically install all tedge packages
Should Contain ${OUTPUT} tedge-mapper - thin-edge.io mapper that translates thin-edge.io data model to c8y/az data model.
Should Contain ${OUTPUT} tedge-watchdog - thin-edge.io component which checks the health of all the thin-edge.io components/services.
Remove created repository
${OUTPUT} Execute Command sudo rm /etc/apt/sources.list.d/thinedge-tedge-release.list
Should Not Contain ${OUTPUT} thinedge-tedge-release.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
*** Settings ***

Resource ../../../../resources/common.resource
Library ThinEdgeIO adapter=${ADAPTER}
Library Cumulocity
Library String
Suite Setup Custom Setup
Suite Teardown Custom Teardown

*** Variables ***

${ADAPTER} ssh
${C8Y_ROOT_CERT_PATH} /etc/ssl/certs

*** Tasks ***

Configure the device
[Documentation] Configure the device with the Cumulocity IoT URL and root certificate path.
Configure Cumulocity URL
Configure Root Certificate Path

Create the certificate
[Documentation] Create a self-signed certificate for the device and verify its contents.
Create Device Certificate
Check Device Certificate

Make the device trusted by Cumulocity
[Documentation] Upload the device certificate to Cumulocity and ensure it's trusted.
Upload Device Certificate
Sleep 3s reason=Wait for cert to be processed/distributed to all cores (in Cumulocity IoT)

Connect the device
[Documentation] Connect the device to Cumulocity IoT and verify the connection.
Connect to Cumulocity
Device Should Exist ${DEVICE_SN}

Sending simple measurements
[Documentation] Send a simple temperature measurement to Cumulocity IoT.
Send Temperature Measurement
Verify Measurement In Cumulocity temperature 25

Sending complex measurements
[Documentation] Send a complex measurement (three_phase_current and combined) to Cumulocity IoT.
Send Three Phase Current Measurement
Verify Measurement In Cumulocity three_phase_current {"L1": 9.5, "L2": 10.3, "L3": 8.8}
Send Combined Measurement
Verify Combined Measurement In Cumulocity

Sending child device measurements
[Documentation] Send a temperature measurement to a child device.
Send Child Device Temperature Measurement
Verify Child Device Measurement In Cumulocity child1 temperature 25

*** Keywords ***

Configure Cumulocity URL
[Documentation] Set the Cumulocity IoT URL for the device.
${HOSTNAME}= Replace String Using Regexp ${C8Y_CONFIG.host} ^.*:// ${EMPTY}
${HOSTNAME}= Strip String ${HOSTNAME} characters=/
Execute Command sudo tedge config set c8y.url ${HOSTNAME}
Log Configured Cumulocity URL to ${HOSTNAME}

Configure Root Certificate Path
[Documentation] Set the path to the root certificate for Cumulocity IoT.
Execute Command sudo tedge config set c8y.root_cert_path ${C8Y_ROOT_CERT_PATH}
Log Configured root certificate path to ${C8Y_ROOT_CERT_PATH}

Create Device Certificate
[Documentation] Create a self-signed certificate for the device.
Execute Command sudo tedge cert create --device-id ${DEVICE_SN}
Log Created device certificate for ${DEVICE_SN}

Check Device Certificate
[Documentation] Verify the contents of the device certificate.
${output}= Execute Command sudo tedge cert show
Log ${output}
Should Contain ${output} Device certificate: /etc/tedge/device-certs/tedge-certificate.pem
Should Contain ${output} Subject: CN=${DEVICE_SN}, O=Thin Edge, OU=Test Device
Should Contain ${output} Issuer: CN=${DEVICE_SN}, O=Thin Edge, OU=Test Device
Should Contain ${output} Valid from:
Should Contain ${output} Valid up to:
Should Contain ${output} Thumbprint:

Upload Device Certificate
[Documentation] Upload the device certificate to Cumulocity IoT.
${output} Execute Command sudo env C8YPASS\='${C8Y_CONFIG.password}' tedge cert upload c8y --user ${C8Y_CONFIG.username}
Log ${output}
Should Contain ${output} Certificate uploaded successfully.
Log Uploaded device certificate for ${DEVICE_SN}

Connect to Cumulocity
[Documentation] Connect the device to Cumulocity IoT.
${output}= Execute Command sudo tedge connect c8y
Log ${output}
Should Contain ${output} Checking if systemd is available.
Should Contain ${output} Checking if configuration for requested bridge already exists.
Should Contain ${output} Validating the bridge certificates.
Should Contain ${output} Creating the device in Cumulocity cloud.
Should Contain ${output} Saving configuration for requested bridge.
Should Contain ${output} Restarting mosquitto service.
Should Contain ${output} Awaiting mosquitto to start. This may take up to 5 seconds.
Should Contain ${output} Enabling mosquitto service on reboots.
Should Contain ${output} Successfully created bridge connection!
Should Contain ${output} Sending packets to check connection. This may take up to 2 seconds.
Should Contain ${output} Connection check is successful.
Should Contain ${output} Checking if tedge-mapper is installed.
Should Contain ${output} Starting tedge-mapper-c8y service.
Should Contain ${output} Persisting tedge-mapper-c8y on reboot.
Should Contain ${output} tedge-mapper-c8y service successfully started and enabled!
Should Contain ${output} Enabling software management.
Should Contain ${output} Checking if tedge-agent is installed.
Should Contain ${output} Starting tedge-agent service.
Should Contain ${output} Persisting tedge-agent on reboot.
Should Contain ${output} tedge-agent service successfully started and enabled!
reubenmiller marked this conversation as resolved.
Show resolved Hide resolved
Log Connected to Cumulocity IoT and verified connection for ${DEVICE_SN}

Send Temperature Measurement
[Documentation] Send a temperature measurement.
Execute Command tedge mqtt pub 'te/device/main///m/environment' '{"temperature": 25}'
Log Sent temperature measurement: 25°C

Send Three Phase Current Measurement
[Documentation] Send a three-phase current measurement.
Execute Command tedge mqtt pub 'te/device/main///m/electrical' '{"three_phase_current": {"L1": 9.5, "L2": 10.3, "L3": 8.8}}'
Log Sent three-phase current measurement

Send Combined Measurement
[Documentation] Send a combined measurement.
Execute Command tedge mqtt pub 'te/device/main///m/combined' '{"time": "2020-10-15T05:30:47+00:00", "temperature": 25, "current": {"L1": 9.5, "L2": 10.3, "L3": 8.8}, "pressure": 98}'
Log Sent combined measurement

Send Child Device Temperature Measurement
[Documentation] Send a temperature measurement to a child device.
Execute Command tedge mqtt pub 'te/device/child1///m/environment' '{"temperature": 25}'
Log Sent temperature measurement to child device: 25°C

Verify Measurement In Cumulocity
[Arguments] ${type} ${value}
[Documentation] Verify the measurement in Cumulocity.
# Add implementation for checking the measurement in Cumulocity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a TODO, so it might make sense to add it in the PR (since we already have an assertion for this included in the Cumulocity RobotFramework library).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this task the right place for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it makes sense to add it since we are taking about a new file, so we shouldn't be adding active TODOs to new files. Either remove the step completely or add the check...But it should be a simple Device Should Have Measurements type=environment minimum=1 maximum=1 (updating to fit the measurements being created).

Log Verified ${type} measurement with value ${value} in Cumulocity

Verify Combined Measurement In Cumulocity
[Documentation] Verify the combined measurement in Cumulocity.
# Add implementation for checking the combined measurement in Cumulocity
Log Verified combined measurement in Cumulocity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you can use the same Verify Measurement In Cumulocity keyword to verify that this message is also published.


Verify Child Device Measurement In Cumulocity
[Arguments] ${child_id} ${type} ${value}
[Documentation] Verify the child device measurement in Cumulocity.
# Add implementation for checking the child device measurement in Cumulocity
Log Verified ${type} measurement for child device ${child_id} with value ${value} in Cumulocity

Custom Setup
[Documentation] Initializes the device environment.
... Sets up the device, transfers necessary packages,
... installs them, and configures Cumulocity for connectivity.
${DEVICE_SN}= Setup skip_bootstrap=True
Set Suite Variable ${DEVICE_SN}
${log} Transfer To Device target/aarch64-unknown-linux-musl/packages/*.deb /home/pi/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes you are running on an arm64/aarch64 system. We should be more dynamic and allow detecting the target architecture and then selecting the correct package to install.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as stated in the other Task, I do use this exclusively with Raspberry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though the idea is to have something which can be applied to also different devices, and doesn't fail when using on a Raspberry Pi armv7 device...

Or alternatively, clearly state at the top of the task that this script is only intended to be run on Raspberry Pi devices with an aarch64/arm64 architecture.

Execute Command sudo dpkg -i *.deb
Log Installed new packages on device

Custom Teardown
[Documentation] Cleans up the device environment.
... Uninstalls ThinEdgeIO, removes packages and scripts, and retrieves logs.
Transfer To Device ${CURDIR}/uninstall-thin-edge_io.sh /home/pi/uninstall-thin-edge_io.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Transfer To Device ${CURDIR}/uninstall-thin-edge_io.sh /home/pi/uninstall-thin-edge_io.sh
Transfer To Device ${CURDIR}/uninstall-thin-edge_io.sh /var/local/share/uninstall-thin-edge_io.sh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though there are other places which also use the /home/pi folder...best to avoid this all together.

Execute Command sudo chmod a+x uninstall-thin-edge_io.sh
Execute Command ./uninstall-thin-edge_io.sh purge
Log Successfully uninstalled with purge
Execute Command sudo rm -rf /home/pi/*.deb
Execute Command sudo rm -rf /home/pi/*.sh
Get Logs
Loading
Loading