thin-edge.io
thin-edge.io copied to clipboard
configuration plugin does not support multiple operations at once
Describe the bug If the device is offline (or the plugin is not started) and c8y requests more than one configuration file, one of these operations will be lost when the plugin is started.
At start of the cunfigurations plugin it asks for all pending operations, but is does not expect that the operations are send with in one MQTT message sparated by a new line:
c8y/s/ds 526,10000000b1bc91d3,t3k_PlcList
526,10000000b1bc91d3,c8y-configuration-plugin
To Reproduce
-
systemctl stop c8y-configuration-plugin
- Get more than one configuration snapshot from device
-
systemctl start c8y-configuration-plugin
- Only one configuration file is uploaded to c8y
Expected behavior Consideration of multilined SmartRest operations.
Environment (please complete the following information):
- Raspi
- thin-edge.io version [0.7.3]
AC
- The plugin to filter the messages meant for itself only (524 and 526 for config management) and ignore the rest. The ignored operations will be handled by their own respective plugins/mappers.
- The c8y-log-plugin and c8y-mapper(for software management) should also be fixed along the same lines
- The pending operations spread across multiple lines must be parsed and split first, before they are fed to the operation handling main loop of the plugin. We should avoid handling multi-line requests and individual requests separately
I opened a PR #1483 to fix the issue for c8y_log_plugin, c8y_configuration_plugin, and tedge_mapper c8y.
How to test
c8y_configuration_plugin
Prerequisites:
- tedge and c8y_configuration_plugin are installed on a device. (it doesn't matter if more packages are installed)
- DTU is configured to connect a Cumulocity tenant. And DTU is connected to c8y (
sudo tedge connect c8y
is done successfully) -
c8y-configuration-plugin.service
is stopped. (confirmed bysudo systemctl status c8y-configuration-plugin.service
. If not, please stop bysudo systemctl stop c8y-configuration-plugin.service
)
Steps:
- Edit
/etc/tedge/c8y/c8y-configuration-plugin.toml
. At least two different types must be enabled. Example:
# Add the configurations to be managed by c8y-configuration-plugin
files = [
{ path = '/etc/tedge/tedge.toml' },
{ path = '/etc/tedge/mosquitto-conf/c8y-bridge.conf', type = 'c8y-bridge.conf' },
# { path = '/etc/tedge/mosquitto-conf/tedge-mosquitto.conf', type = 'tedge-mosquitto.conf' },
# { path = '/etc/mosquitto/mosquitto.conf', type = 'mosquitto.conf' },
# { path = '/etc/tedge/c8y/example.txt', type = 'example', user = 'tedge', group = 'tedge', mode = 0o444 }
]
- Start
c8y-configuration-plugin.service
bysudo systemctl start c8y-configuration-plugin.service
. - Confirm you have the configuration types visible in your c8y tenants "Configuration" tab. In this example, you should see like this screenshot.
- Stop
c8y-configuration-plugin.service
bysudo systemctl stop c8y-configuration-plugin.service
. - Press "Get snapshot from device" on c8y UI for at least two different types. For example, "c8y-configuration-plugin" and "c8y-bridge.conf".
- Confirm the operations that you created in step 5 are marked "PENDING" on "Control" tab on c8y UI.
- Start
c8y-configuration-plugin.service
again bysudo systemctl start c8y-configuration-plugin.service
. - Check the status of the operations created by step 5 on "Control" tab on c8y UI.
- If they are marked "successful" (green), then test is succeeded.
How to test
c8y_log_plugin
Prerequisites:
- tedge and c8y_log_plugin are installed on a device. (it doesn't matter if more packages are installed)
- DTU is configured to connect a Cumulocity tenant. And DTU is connected to c8y (
sudo tedge connect c8y
is done successfully) -
c8y-log-plugin.service
is stopped. (confirmed bysudo systemctl status c8y-log-plugin.service
. If not, please stop bysudo systemctl stop c8y-log-plugin.service
)
Steps:
- Create at least two request log file operations from "Logs" tab on c8y UI. (the Type of log "software-management, others don't matter, use the default)
- Confirm the operations that you created in step 1 are marked "PENDING" on "Control" tab on c8y UI.
- Start
c8y-log-plugin.service
bysudo systemctl start c8y-log-plugin.service
. - Publish a message by
tedge mqtt pub c8y/s/us 500
on your terminal. - Check the status of the operations created by step 1 on "Control" tab on c8y UI.
- If they are marked either "successful" (green) or "failed" (red), then the test is succeeded.
Note: This test checks if the operation status changes to the final state (successful or failed). Therefore, successful or failed doesn't matter.
How to test
tedge_mapper c8y
Prerequisites:
- tedge and tedge_mapper are installed on a device. (it doesn't matter if more packages are installed)
Steps:
- Run
sudo tedge config set c8y.smartrest.templates testTemp
to set a custom SmartREST template. - Create
/etc/tedge/operations/c8y_Test
file owned bytedge:tedge
, with the content below.
[exec]
topic = "c8y/s/dc/testTemp"
on_message = "abc"
command = "/bin/pwd"
- Disconnect to c8y in order to ensure if it's not connected (
sudo tedge disconnect c8y
) - Connect to c8y (
sudo tedge connect c8y
is done successfully) - Check if
tedge-mapper-c8y.service
is active. (confirmed bysudo systemctl status tedge-mapper-c8y.service
) - Run
tedge mqtt sub "c8y/s/us"
- Run these two commands.
STR=$'abc\nabc'
tedge mqtt pub c8y/s/dc/testTemp "$STR"
- Check these 4 lines are recorded by the subscribed on Step 6. Then the test is succeeded.
[c8y/s/us] 501,c8y_Test
[c8y/s/us] 503,c8y_Test
[c8y/s/us] 501,c8y_Test
[c8y/s/us] 503,c8y_Test
Build number #868
We fixed it in 0.7.7. @toewsar Can we close this issue? You can try either 0.7.7 or 0.8.0.