Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixed the default test #139 #228

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/user/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ UCI configuration options must go in ``/etc/config/openwisp``.
- ``test_config``: whether a new configuration must be tested before being
considered applied, defaults to ``1``
- ``test_retries``: maximum number of retries when doing the default
configuration test, defaults to ``3``
configuration test, defaults to ``10``
- ``test_script``: custom test script, read more about this feature in
:ref:`config_configuration_test`
- ``uuid``: unique identifier of the router configuration in the
Expand Down
20 changes: 13 additions & 7 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ REGISTRATION_INTERVAL=${REGISTRATION_INTERVAL:-$((INTERVAL / 4))}
VERIFY_SSL=${VERIFY_SSL:-1}
MERGE_CONFIG=${MERGE_CONFIG:-1}
TEST_CONFIG=${TEST_CONFIG:-1}
TEST_RETRIES=${TEST_RETRIES:-3}
TEST_RETRIES=${TEST_RETRIES:-10}
CONSISTENT_KEY=${CONSISTENT_KEY:-1}
HARDWARE_ID_KEY=${HARDWARE_ID_KEY:-1}
BOOTUP_DELAY=${BOOTUP_DELAY:-10}
Expand Down Expand Up @@ -679,21 +679,27 @@ perform_default_test() {
# the default test is performed several times, as indicated by $TEST_RETRIES
for i in $(seq 1 "$TEST_RETRIES"); do
$FETCH_COMMAND -i "$CHECKSUM_URL" >$TEST_CHECKSUM
local result=$?
if [ $result -ne 0 ]; then
logger "Configuration test failed (attempt $i)" \
local exit_code=$?
if [ $exit_code -ne 0 ]; then
logger "Configuration test failed (attempt $i). Failed to connect to controller: curl exit code $exit_code" \
-t openwisp \
-p daemon.warning
sleep 5
sleep "$(/usr/sbin/openwisp-get-random-number 5 20)"
else
if ! is_http_status "$TEST_CHECKSUM" 200; then
status=$(head -n 1 "$TEST_CHECKSUM")
logger -s "Configuration test passed, but the controller returned $status" \
-t openwisp \
-p daemon.warning
fi
break
fi
done
rm $TEST_CHECKSUM
# "$result" contains the exit code (integer),
# "$exit_code" contains the exit code (integer),
# hence does not required to be wrapped in quotes.
# shellcheck disable=SC2086
return "$result"
return $exit_code
}

# stores unmanaged configuration sections that will be merged
Expand Down