From 345a1f951f0a9bf4a0c8fd4a3bea74c124ba9f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Mon, 4 Dec 2023 17:18:57 +0000 Subject: [PATCH] fix: don't exit with fping host is unreachable As ping can return unknown exit codes for unknown cases, just never bail out to avoid taking bad decisions, as we retry each second maximum, there's no DoS risk --- bin/plugin/open/alive | 12 ++++-------- tests/functional/launch_tests_on_instance.sh | 5 ++++- tests/functional/tests.d/360-plugins.sh | 3 +++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bin/plugin/open/alive b/bin/plugin/open/alive index ae9340ce0..92aa5a5e1 100755 --- a/bin/plugin/open/alive +++ b/bin/plugin/open/alive @@ -51,19 +51,18 @@ if (not $host) { osh_info "Waiting for $host to be alive..."; my $startedat = Time::HiRes::gettimeofday(); -my $isFping = 1; +my $firstLoop = 1; my @command = qw{ fping -- }; push @command, $host; while (1) { $fnret = OVH::Bastion::execute(cmd => \@command, noisy_stdout => 1, noisy_stderr => 1); if ($fnret->err eq 'ERR_EXEC_FAILED') { - if ($isFping) { - + if ($firstLoop) { # maybe fping doesn't work, fallback to ping @command = qw{ ping -c 1 -w 1 -- }; push @command, $host; - $isFping = 0; - next; + $firstLoop = 0; + next; # restart the loop to exec ping } osh_exit $fnret; # we tried both ping and fping :( } @@ -73,9 +72,6 @@ while (1) { osh_info "Alive after waiting for $delay seconds, exiting!"; osh_ok {waited_for => $delay + 0}; } - elsif (($isFping && $fnret->value->{'sysret'} >= 3) || ($fnret->value->{'sysret'} > 0)) { - osh_exit 'ERR_INTERNAL', "Fatal error returned by (f)ping, aborting"; - } sleep 1; } diff --git a/tests/functional/launch_tests_on_instance.sh b/tests/functional/launch_tests_on_instance.sh index d8f675b8b..59c02cf9b 100755 --- a/tests/functional/launch_tests_on_instance.sh +++ b/tests/functional/launch_tests_on_instance.sh @@ -654,7 +654,10 @@ sshclientconfigchg() dump_vars_and_funcs() { - set | grep -v -E '^(testno|section|code_warn_exclude|COPROC_PID|LINES|COLUMNS|PIPESTATUS|_|BASH_LINENO|basename|case|json|name|tmpscript|grepit|got|isbad|nbfailedgrep)=' + set | grep -v -E '^('\ +'testno|section|code_warn_exclude|COPROC_PID|LINES|COLUMNS|PIPESTATUS|_|'\ +'BASH_LINENO|basename|case|json|name|tmpscript|grepit|got|isbad|'\ +'nbfailedgrep|shouldbe)=' } runtests() diff --git a/tests/functional/tests.d/360-plugins.sh b/tests/functional/tests.d/360-plugins.sh index 05188b013..56d73440e 100644 --- a/tests/functional/tests.d/360-plugins.sh +++ b/tests/functional/tests.d/360-plugins.sh @@ -93,6 +93,9 @@ EOS success alive_withoutHost $a0 --osh alive 127.0.0.1 json .command alive .error_code OK .value.waited_for 0 + + run alive_unreachable $a0f --osh alive 192.0.2.0 + retvalshouldbe 124 } testsuite_plugins