From 0c877833c51554602838a379b5fff6d5f1e3dfaf Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 24 Jan 2022 08:49:20 -0500 Subject: [PATCH] Agent: Move master/threading_utils.py -> utils/threading.py Both create_daemon_thread() and interruptable_iter() will need to be used outside of the master. --- monkey/infection_monkey/master/automated_master.py | 2 +- monkey/infection_monkey/master/exploiter.py | 3 +-- monkey/infection_monkey/master/ip_scanner.py | 2 +- monkey/infection_monkey/master/propagator.py | 2 +- .../{master/threading_utils.py => utils/threading.py} | 0 .../test_threading_utils.py => utils/test_threading.py} | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) rename monkey/infection_monkey/{master/threading_utils.py => utils/threading.py} (100%) rename monkey/tests/unit_tests/infection_monkey/{master/test_threading_utils.py => utils/test_threading.py} (92%) diff --git a/monkey/infection_monkey/master/automated_master.py b/monkey/infection_monkey/master/automated_master.py index 1f0410d5b..94a508e0c 100644 --- a/monkey/infection_monkey/master/automated_master.py +++ b/monkey/infection_monkey/master/automated_master.py @@ -11,10 +11,10 @@ from infection_monkey.network import NetworkInterface from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.post_breach_telem import PostBreachTelem from infection_monkey.telemetry.system_info_telem import SystemInfoTelem +from infection_monkey.utils.threading import create_daemon_thread from infection_monkey.utils.timer import Timer from . import Exploiter, IPScanner, Propagator -from .threading_utils import create_daemon_thread CHECK_ISLAND_FOR_STOP_COMMAND_INTERVAL_SEC = 5 CHECK_FOR_TERMINATE_INTERVAL_SEC = CHECK_ISLAND_FOR_STOP_COMMAND_INTERVAL_SEC / 5 diff --git a/monkey/infection_monkey/master/exploiter.py b/monkey/infection_monkey/master/exploiter.py index f1a804ba7..8acca5ffa 100644 --- a/monkey/infection_monkey/master/exploiter.py +++ b/monkey/infection_monkey/master/exploiter.py @@ -7,8 +7,7 @@ from typing import Callable, Dict, List from infection_monkey.i_puppet import ExploiterResultData, IPuppet from infection_monkey.model import VictimHost - -from .threading_utils import run_worker_threads +from infection_monkey.utils.threading import run_worker_threads QUEUE_TIMEOUT = 2 diff --git a/monkey/infection_monkey/master/ip_scanner.py b/monkey/infection_monkey/master/ip_scanner.py index a95f6aec8..bae6358e2 100644 --- a/monkey/infection_monkey/master/ip_scanner.py +++ b/monkey/infection_monkey/master/ip_scanner.py @@ -13,9 +13,9 @@ from infection_monkey.i_puppet import ( PortStatus, ) from infection_monkey.network import NetworkAddress +from infection_monkey.utils.threading import run_worker_threads from . import IPScanResults -from .threading_utils import run_worker_threads logger = logging.getLogger() diff --git a/monkey/infection_monkey/master/propagator.py b/monkey/infection_monkey/master/propagator.py index e58fe5d06..87f9a1896 100644 --- a/monkey/infection_monkey/master/propagator.py +++ b/monkey/infection_monkey/master/propagator.py @@ -16,9 +16,9 @@ from infection_monkey.network.scan_target_generator import compile_scan_target_l from infection_monkey.telemetry.exploit_telem import ExploitTelem from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger from infection_monkey.telemetry.scan_telem import ScanTelem +from infection_monkey.utils.threading import create_daemon_thread from . import Exploiter, IPScanner, IPScanResults -from .threading_utils import create_daemon_thread logger = logging.getLogger() diff --git a/monkey/infection_monkey/master/threading_utils.py b/monkey/infection_monkey/utils/threading.py similarity index 100% rename from monkey/infection_monkey/master/threading_utils.py rename to monkey/infection_monkey/utils/threading.py diff --git a/monkey/tests/unit_tests/infection_monkey/master/test_threading_utils.py b/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py similarity index 92% rename from monkey/tests/unit_tests/infection_monkey/master/test_threading_utils.py rename to monkey/tests/unit_tests/infection_monkey/utils/test_threading.py index 11d4fdf61..659fc7205 100644 --- a/monkey/tests/unit_tests/infection_monkey/master/test_threading_utils.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py @@ -1,7 +1,7 @@ import logging from threading import Event -from infection_monkey.master.threading_utils import create_daemon_thread, interruptable_iter +from infection_monkey.utils.threading import create_daemon_thread, interruptable_iter def test_create_daemon_thread():