In order to be able to test SUA, the proper test environment must be prepared, which would simulate/mock the components with which the SUA is interacting. Depending if the test is being done for the native version od containerized variant, the preparation steps will differ:
For the native variant all tools have to be installed on the host machine:
- Install the mosquitto server and client
sudo apt-get update
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
- Ensure the python3 is installed.
mosquitto
Set the IP of the machine where the mosquitto broker is running, for the simplest case it would be the localhost
:
SoftwareUpdateAgent::SoftwareUpdateAgent()
{
sua::MqttConfiguration conf;
conf.brokerHost = "localhost"
./sdv-self-update-agent
Ensure that the proper test bundle is put into hosted directory. Adjust the IP and Port as needed.
cd docs/testing/fileserver/bundle
python3 -m http.server --bind 127.0.0.1 5555
The content of the json file shall be adjusted, so that url of hosted bundle is valid.
mosquitto_pub -t "selfupdate/desiredstate" -f docs/testing/mqtt/start.json
mosquitto_pub -t "selfupdate/desiredstate/command" -f docs/testing/mqtt/command-download.json
To test if the SUA is behaving correctly and sending proper mqtt messages, subscribe to the topics:
mosquitto_sub -t "selfupdate/currentstate"
mosquitto_sub -t "selfupdate/desiredstatefeedback"
mosquitto_pub -t "selfupdate/currentstate/get" -f docs/testing/mqtt/current-state-get.json
For testing the container variant, it shall be ensured that all the components are connected to the same network and using proper ports mapping, so that they would be able to communicate with each other.
docker network create -d bridge my-network
docker run -it --network=my-network -p 1883:1883 -v /absolute/path/sdv-self-update-agent/docs/testing/mqtt/mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log --name mosquitto eclipse-mosquitto
Hint: it is required to use the absolute path to the mosquitto configuration file.
cd docs/testing/fileserver
docker build -t host .
docker run -it --network=my-network -p 5555:5555 --name fileserver host
The bundle file will be available under: fileserver:5555/bundle
url, so the value in start.json
shall be adjusted.
docker run -it --network=my-network sua:latest
Hint: before building and running sua, ensure that the broker host ia having the same value as the name parameter, specified for mosquitto broker:
SoftwareUpdateAgent::SoftwareUpdateAgent()
{
sua::MqttConfiguration conf;
conf.brokerHost = "mosquitto"
...
mosquitto_sub -t "selfupdate/selfupdate/desiredstatefeedback" -h ipAddress_of_mosquitto_container
mosquitto_sub -t "selfupdate/currentstate" -h ipAddress_of_mosquitto_container
From this tab console we can observe if the SUA is sending proper messages.
Hint: to figure out the the ip address of mosquitto container, run following command:
docker container ls // copy the containerID of mosquitto container
docker container inspect containerID
and locate the IPAddress
value.
mosquitto_pub -t "selfupdate/desiredstate" -f docs/testing/mqtt/start.json -h ipAddress_of_mosquitto_container
After sending this signal, you should be able to observe the SUA behavior on the console.