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

Some file modification methods do not trigger the file-changed handler in c8y-configuration-plugin #1896

Closed reubenmiller closed 1 year ago

reubenmiller commented 1 year ago

Describe the bug

The c8y-configuration-plugin relies on inotify to detect when edits are done to its configuration file (/etc/tedge/c8y/c8y-configuration-plugin.toml).

Below are the following test cases and current results as of 0.10.0-93-g60e3ba4f.

Test case Example command Change detected
Copy over file cp myfile.toml /etc/tedge/c8y/c8y-configuration-plugin.toml Yes
Overwrite file via redirection echo '[]' > /etc/tedge/c8y/c8y-configuration-plugin.toml Yes
Move over file (same directory) mv /etc/tedge/c8y/myfile.toml /etc/tedge/c8y/c8y-configuration-plugin.toml No
Move over file (different directory) mv /etc/myfile.toml /etc/tedge/c8y/c8y-configuration-plugin.toml Yes
In place edit sed -i 's/CONFIG1/CONFIG3/g' /etc/tedge/c8y/c8y-configuration-plugin.toml No

To Reproduce

The tests are currently included in PR https://github.com/thin-edge/thin-edge.io/pull/1875.

File:

Expected behavior

Screenshots

Environment (please complete the following information):

Additional context

The following inotify events were produced in the different test cases.

The events were recorded by using the following command on the folder where the c8y-configuration-plugin.toml file is stored (not the file directly).

/usr/bin/inotifywait -m /etc/tedge/c8y/

Note: inotifywait can be installed on debian based systemd using apt-get install inotify-tools

PASS: Copy over file

/etc/tedge/c8y/ MODIFY c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ MODIFY c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_WRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml

PASS: Overwrite file via redirection

/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ MODIFY c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ MODIFY c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_WRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml

FAIL: Move over file (same directory)

/etc/tedge/c8y/ MOVED_TO c8y-configuration-plugin.toml

FAIL: In place edit

/etc/tedge/c8y/ OPEN c8y-configuration-plugin.toml
/etc/tedge/c8y/ ACCESS c8y-configuration-plugin.toml
/etc/tedge/c8y/ CLOSE_NOWRITE,CLOSE c8y-configuration-plugin.toml
/etc/tedge/c8y/ MOVED_TO c8y-configuration-plugin.toml
reubenmiller commented 1 year ago

I did a bit more digging and it seems that there are actually two cases for the Move over file (see below). It depends where the configuration file is being moved from. If the file is being moved from within /etc/tedge/c8y then the change in file is not detected, however if it is being moved from outside of /etc/tedge/c8y the change is detected.

These two robot framework test cases show the difference in behaviour (look at the Execute Command line in both test cases).

Case 1: Move over file (in same directory) - FAIL

Update configuration plugin config via local filesystem move (same directory)
    Cumulocity.Should Support Configurations    ${DEFAULT_CONFIG}    /etc/tedge/tedge.toml    system.toml    CONFIG1
    Transfer To Device    ${CURDIR}/c8y-configuration-plugin-updated.toml    /etc/tedge/c8y/
    Execute Command    mv /etc/tedge/c8y/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/c8y-configuration-plugin.toml
    Cumulocity.Should Support Configurations    ${DEFAULT_CONFIG}    /etc/tedge/tedge.toml    system.toml    CONFIG1    Config@2.0.0

Case 2: Move over file (different directory) - PASS

Update configuration plugin config via local filesystem move (different directory)
    Cumulocity.Should Support Configurations    ${DEFAULT_CONFIG}    /etc/tedge/tedge.toml    system.toml    CONFIG1
    Transfer To Device    ${CURDIR}/c8y-configuration-plugin-updated.toml    /etc/
    Execute Command    mv /etc/c8y-configuration-plugin-updated.toml /etc/tedge/c8y/c8y-configuration-plugin.toml
    Cumulocity.Should Support Configurations    ${DEFAULT_CONFIG}    /etc/tedge/tedge.toml    system.toml    CONFIG1    Config@2.0.0
reubenmiller commented 1 year ago

Covered by integration tests. https://github.com/thin-edge/thin-edge.io/blob/a1049ec4b05f5e9f7e2a6736a2b8169ed7963cca/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation.robot#L72