From 9c25b3590b4a032cfde813b8b1180e99a3870c2f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 1 Apr 2022 15:03:01 +0200 Subject: [PATCH] Agent: User ceil on ping timeouts This is due to older version of ping which doesn't support float timeouts. It is throwing `bad linger time` Error. --- monkey/infection_monkey/network_scanning/ping_scanner.py | 3 ++- .../unit_tests/infection_monkey/network_scanning/test_ping.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/network_scanning/ping_scanner.py b/monkey/infection_monkey/network_scanning/ping_scanner.py index e286be2b2..66ae79b2a 100644 --- a/monkey/infection_monkey/network_scanning/ping_scanner.py +++ b/monkey/infection_monkey/network_scanning/ping_scanner.py @@ -80,4 +80,5 @@ def _build_ping_command(host: str, timeout: float): ping_count_flag = "-n" if "win32" == sys.platform else "-c" ping_timeout_flag = "-w" if "win32" == sys.platform else "-W" - return ["ping", ping_count_flag, "1", ping_timeout_flag, str(timeout), host] + # on older version of ping the timeout must be an integer, thus we use ceil + return ["ping", ping_count_flag, "1", ping_timeout_flag, str(math.ceil(timeout)), host] diff --git a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_ping.py b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_ping.py index 45cd523b4..37e365682 100644 --- a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_ping.py +++ b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_ping.py @@ -1,3 +1,4 @@ +import math import subprocess from unittest.mock import MagicMock @@ -172,4 +173,4 @@ def test_linux_timeout(assert_expected_timeout): timeout_flag = "-W" timeout = 1.42379 - assert_expected_timeout(timeout_flag, timeout, str(timeout)) + assert_expected_timeout(timeout_flag, timeout, str(math.ceil(timeout)))