thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
221 stars 54 forks source link

errors when uploading and applying binary configuration files to main and child devices #2318

Closed reubenmiller closed 11 months ago

reubenmiller commented 1 year ago

Describe the bug

thin-edge.io has the following bugs when dealing with the configuration management on the main and child devices:

To Reproduce

Main Device (Uploading from a device to cloud)

  1. Install thin-edge.io and configure to connect to Cumulocity IoT

  2. Configure the configuration plugin to access a binary file using the configuration file

    file: /etc/tedge/c8y/c8y-configuration-plugin.toml

    # Add the configurations to be managed by c8y-configuration-plugin
    files = [
        { path = '/etc/tedge/tedge.toml.tar.gz' },
    ]
  3. Create the dummy binary file on the thin-edge.io device (so there is something to upload)

    cd /etc/tedge
    tar czvf tedge.toml.tar.gz tedge.toml.tar.gz
  4. In the Cumulocity UI (Device management application), request the binary configuration file with type /etc/tedge/tedge.toml.tar.gz

Child Device

For downloads, the file is downloaded to the file server, however accessed by a child device, the local http server returns a status code 500 (indicating an unexpected error). Below shows the response shown by the server when access via curl:

curl -f http://172.21.0.2:8000/tedge/file-transfer/TST_bolt_snow_developer/config_update/config1
curl: (22) The requested URL returned error: 500 Internal Server Error

See the linked PR's system tests for the example procedure.

Expected behavior

Configuration files should be treated as plain bytes and the contents should not be assumed to be of any specific format (e.g. utf-8 encoded text). This is applicable for both the main and child devices.

Screenshots

Downloading

Downloading a binary from Cumulocity to the device fails with the failure reason:

Could not make a successful request to the remote server
Oct 05 20:23:49 pippin c8y-configuration-plugin[449]: 2023-10-05T10:23:49.62405932Z  INFO c8y_config_manager::download: Received c8y_DownloadConfigFile request for config type: /etc/tedge/tedge.toml.tar.gz from device: raspberry-d83add42f121
Oct 05 20:23:49 pippin c8y-configuration-plugin[449]: 2023-10-05T10:23:49.624588127Z  INFO c8y_config_manager::plugin_config: Reading the config file from /etc/tedge/c8y/c8y-configuration-plugin.toml
Oct 05 20:23:49 pippin c8y-configuration-plugin[449]: 2023-10-05T10:23:49.625644024Z  INFO C8Y-REST: Downloading from: "https://t2873877.latest.stage.c8y.io/inventory/binaries/3760205"
Oct 05 20:23:51 pippin c8y-configuration-plugin[449]: 2023-10-05T10:23:51.217535319Z ERROR c8y_config_manager::download: The configuration download for '/etc/tedge/tedge.toml.tar.gz' failed.

Uploading

Uploading a binary from the device to Cumulocity fails with the failure reason:

stream did not contain valid UTF-8

The log output shows the error:

Oct 05 20:19:54 pippin c8y-configuration-plugin[449]: 2023-10-05T10:19:54.530703447Z  INFO c8y_config_manager::upload: Received c8y_UploadConfigFile request for config type: /etc/tedge/tedge.toml.tar.gz from device: raspberry-d83add42f121
Oct 05 20:19:54 pippin c8y-configuration-plugin[449]: 2023-10-05T10:19:54.531131526Z  INFO c8y_config_manager::plugin_config: Reading the config file from /etc/tedge/c8y/c8y-configuration-plugin.toml
Oct 05 20:19:54 pippin c8y-configuration-plugin[449]: 2023-10-05T10:19:54.532242481Z ERROR c8y_config_manager::upload: The configuration upload for '/etc/tedge/tedge.toml.tar.gz' failed.

Environment (please complete the following information):

Property Value
OS [incl. version] Debian GNU/Linux 11 (bullseye)
Hardware [incl. revision] Raspberry Pi Zero 2 W Rev 1.0
System-Architecture Linux pippin 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
thin-edge.io version tedge 0.12.1~365+g5a52630

Additional context

reubenmiller commented 12 months ago

The issue has been resolved and the test cases have been expanded to cover for both the main and child devices and are viewable here:

The test cases were added as part of work in https://github.com/thin-edge/thin-edge.io/pull/2368

reubenmiller commented 11 months ago

QA has thoroughly checked the feature and here are the results: