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

Return exit code 1 if tedge config get doesn't find a value #2990

Closed rina23q closed 3 months ago

rina23q commented 3 months ago

Is your feature improvement request related to a problem? Please describe. Currently, tedge config get returns 0 when the provided key is not set.

root@0d735c3815ef:/setup# tedge config get aws.url
The provided config key: 'aws.url' is not set
root@0d735c3815ef:/setup# echo $?
0

It is inconvenient for writing a third party plugin. See Additional Context.

Describe the solution you'd like Return 1 instead of 0 if the key doesn't have value set. If the key has a default value, returns 0 since it's anyway set.

Describe alternatives you've considered

Additional context While writing a configuration file for tedge-monit-setup, this check "if c8y.url is not set, unmonitor c8y" is required. However, since the exit code is anyway 0 regardless whether it's set or not, the rule needed a kind of workaround.

check program c8y-enabled with path "/bin/sh -c '[ -n \0x22$(tedge config get c8y.url)\0x22 ]'"
    with timeout 5 seconds
    every 2 cycles
    if status != 0 then unmonitor
    group c8y

This could have been re-written more simply if the status is non-zero like below.

check program c8y-enabled with path "/usr/bin/tedge config get c8y.url"
    with timeout 5 seconds
    every 2 cycles
    if status != 0 then unmonitor
    group c8y
reubenmiller commented 3 months ago

As reference, git also returns a non-zero exit code (1) if a specific configuration item is not set. This makes it possible to use a simple one-liner to do an action if something isn't set:

git config user.name || echo "user.name is not set"
rina23q commented 3 months ago

Resolved by #2995

gligorisaev commented 3 months ago

QA Report for Ticket #2990

PR: https://github.com/thin-edge/thin-edge.io/pull/2995

Summary

The purpose of this PR is to address and resolve the issues outlined in this ticket.

Testing Performed

Unit Tests:

crates/core/tedge/tests/main.rs

Integration Tests:

Conducted integration tests to verify end-to-end functionality. Tested various configuration update scenarios to confirm proper handling.

Manual Testing:

Manually updated configurations and observed system behavior. Verified log entries for accuracy and completeness.

Automated Testing

tests/RobotFramework/tests/tedge/tedge_config_get.robot

The changes introduced in PR https://github.com/thin-edge/thin-edge.io/pull/2995 successfully resolve the issues outlined in this Ticket.

The implementation is robust, thoroughly tested, and ready for deployment.