From 67d982ca895fe015cc4cb27677cd68b207797c81 Mon Sep 17 00:00:00 2001 From: Deblintrake09 Date: Thu, 1 Dec 2022 17:38:04 -0300 Subject: [PATCH] refactor(#1915): update callback imports --- .../test_disk_quota_default.py | 8 +++--- .../test_disk_quota_disabled.py | 3 +-- .../test_synchronization/test_sync_overlap.py | 25 +++++++++++-------- .../test_synchronization/test_sync_time.py | 10 ++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_default.py b/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_default.py index 18dd717418..101bf75634 100644 --- a/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_default.py +++ b/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_default.py @@ -67,7 +67,8 @@ from wazuh_testing.tools import PREFIX from wazuh_testing.tools.configuration import load_wazuh_configurations from wazuh_testing.tools.monitoring import FileMonitor, generate_monitoring_callback -from wazuh_testing.modules import fim +from wazuh_testing.modules.fim import FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS as local_internal_options +from wazuh_testing.modules.fim.event_monitor import CB_DISK_QUOTA_LIMIT_CONFIGURED_VALUE, ERR_MSG_DISK_QUOTA_LIMIT from wazuh_testing.modules.fim.utils import generate_params @@ -76,7 +77,6 @@ pytestmark = [pytest.mark.tier(level=1)] # Variables -local_internal_options = fim.FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) test_directories = [os.path.join(PREFIX, 'testdir1')] directory_str = ','.join(test_directories) @@ -149,8 +149,8 @@ def test_disk_quota_default(get_configuration, configure_environment, disk_quota_value = wazuh_log_monitor.start( timeout=global_parameters.default_timeout, - callback=generate_monitoring_callback(fim.CB_DISK_QUOTA_LIMIT_CONFIGURED_VALUE), - error_message=fim.ERR_MSG_DISK_QUOTA_LIMIT).result() + callback=generate_monitoring_callback(CB_DISK_QUOTA_LIMIT_CONFIGURED_VALUE), + error_message=ERR_MSG_DISK_QUOTA_LIMIT).result() if disk_quota_value: assert disk_quota_value == str(DEFAULT_SIZE), 'Wrong value for disk_quota' diff --git a/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_disabled.py b/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_disabled.py index 4688ecf3f7..883964128b 100644 --- a/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_disabled.py +++ b/tests/integration/test_fim/test_files/test_report_changes/test_disk_quota_disabled.py @@ -67,7 +67,7 @@ from wazuh_testing.tools import PREFIX from wazuh_testing.tools.configuration import load_wazuh_configurations from wazuh_testing.tools.monitoring import FileMonitor -from wazuh_testing.modules import fim +from wazuh_testing.modules.fim import FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS as local_internal_options from wazuh_testing.modules.fim.event_monitor import callback_disk_quota_limit_reached from wazuh_testing.modules.fim.utils import generate_params, create_file from test_fim.common import generate_string @@ -77,7 +77,6 @@ pytestmark = [pytest.mark.tier(level=1)] # Variables -local_internal_options = fim.FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) test_directories = [os.path.join(PREFIX, 'testdir1')] directory_str = ','.join(test_directories) diff --git a/tests/integration/test_fim/test_synchronization/test_sync_overlap.py b/tests/integration/test_fim/test_synchronization/test_sync_overlap.py index 503abe8430..97ffbd0423 100644 --- a/tests/integration/test_fim/test_synchronization/test_sync_overlap.py +++ b/tests/integration/test_fim/test_synchronization/test_sync_overlap.py @@ -66,8 +66,11 @@ from wazuh_testing.tools import LOG_FILE_PATH, configuration from wazuh_testing.tools.monitoring import FileMonitor, generate_monitoring_callback from wazuh_testing.modules import TIER1, AGENT, SERVER -from wazuh_testing.modules import fim -from wazuh_testing.modules.fim.event_monitor import callback_detect_synchronization +from wazuh_testing.modules.fim import FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS, MONITORED_DIR_1 +from wazuh_testing.modules.fim.event_monitor import (callback_detect_synchronization, CB_INVALID_CONFIG_VALUE, + ERR_MSG_INVALID_CONFIG_VALUE, ERR_MSG_FIM_SYNC_NOT_DETECTED, + CB_SYNC_SKIPPED, ERR_MSG_SYNC_SKIPPED_EVENT, + CB_SYNC_INTERVAL_RESET, ERR_MSG_SYNC_INTERVAL_RESET_EVENT) # Marks pytestmark = [AGENT, SERVER, TIER1] @@ -85,13 +88,13 @@ configuration_parameters, configuration_metadata, test_case_ids = configuration.get_test_cases_data(test_cases_path) # This assigns the monitored dir during runtime depending on the OS, cannot be added to yaml for count, value in enumerate(configuration_parameters): - configuration_parameters[count]['MONITORED_DIR'] = fim.MONITORED_DIR_1 + configuration_parameters[count]['MONITORED_DIR'] = MONITORED_DIR_1 configurations = configuration.load_configuration_template(configurations_path, configuration_parameters, configuration_metadata) # Variables wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) -local_internal_options = fim.FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS +local_internal_options = FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS # Tests @@ -162,21 +165,21 @@ def test_sync_overlap(configuration, metadata, set_wazuh_configuration, configur # If config is invalid, check that invalid config value message appers if metadata['response_timeout'] == 'invalid' or metadata['max_interval'] == 'invalid': wazuh_log_monitor.start(timeout=global_parameters.default_timeout, - callback=generate_monitoring_callback(fim.CB_INVALID_CONFIG_VALUE), - error_message=fim.ERR_MSG_INVALID_CONFIG_VALUE, + callback=generate_monitoring_callback(CB_INVALID_CONFIG_VALUE), + error_message=ERR_MSG_INVALID_CONFIG_VALUE, update_position=True).result() # Wait for new sync wazuh_log_monitor.start(timeout=global_parameters.default_timeout, callback=callback_detect_synchronization, - error_message=fim.ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() + error_message=ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() wazuh_log_monitor = FileMonitor(LOG_FILE_PATH) # Check if response_timeout has elapsed, and sync is still running, the sync interval is doubled interval = wazuh_log_monitor.start(timeout=global_parameters.default_timeout*5, - callback=generate_monitoring_callback(fim.CB_SYNC_SKIPPED), + callback=generate_monitoring_callback(CB_SYNC_SKIPPED), accum_results=metadata['doubled_times'], - error_message=fim.ERR_MSG_SYNC_SKIPPED_EVENT, update_position=True).result() + error_message=ERR_MSG_SYNC_SKIPPED_EVENT, update_position=True).result() if metadata['doubled_times'] > 1: new_interval = interval[-1] @@ -197,8 +200,8 @@ def test_sync_overlap(configuration, metadata, set_wazuh_configuration, configur # Check when sync ends sync_interval is returned to normal after response_timeout since last message. if not metadata['lower']: result = wazuh_log_monitor.start(timeout=global_parameters.default_timeout*10, - callback=generate_monitoring_callback(fim.CB_SYNC_INTERVAL_RESET), - error_message=fim.ERR_MSG_SYNC_INTERVAL_RESET_EVENT, + callback=generate_monitoring_callback(CB_SYNC_INTERVAL_RESET), + error_message=ERR_MSG_SYNC_INTERVAL_RESET_EVENT, update_position=True).result() assert int(result) == int(metadata['interval']), f"Invalid value for interval: {result}, it should be reset to\ diff --git a/tests/integration/test_fim/test_synchronization/test_sync_time.py b/tests/integration/test_fim/test_synchronization/test_sync_time.py index 45f91f7930..4a424fc518 100644 --- a/tests/integration/test_fim/test_synchronization/test_sync_time.py +++ b/tests/integration/test_fim/test_synchronization/test_sync_time.py @@ -64,13 +64,13 @@ from wazuh_testing.tools import LOG_FILE_PATH, configuration from wazuh_testing.tools.monitoring import FileMonitor from wazuh_testing.modules import TIER1, AGENT, SERVER -from wazuh_testing.modules import fim +from wazuh_testing.modules.fim import MONITORED_DIR_1, FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS from wazuh_testing.modules.fim import event_monitor as evm # Marks pytestmark = [AGENT, SERVER, TIER1] -local_internal_options = fim.FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS +local_internal_options = FIM_DEFAULT_LOCAL_INTERNAL_OPTIONS # Reference paths TEST_DATA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') @@ -85,7 +85,7 @@ configuration_parameters, configuration_metadata, test_case_ids = configuration.get_test_cases_data(test_cases_path) # This assigns the monitored_dir during runtime depending on the OS, cannot be added to yaml for count, value in enumerate(configuration_parameters): - configuration_parameters[count]['MONITORED_DIR'] = fim.MONITORED_DIR_1 + configuration_parameters[count]['MONITORED_DIR'] = MONITORED_DIR_1 configurations = configuration.load_configuration_template(configurations_path, configuration_parameters, configuration_metadata) @@ -158,12 +158,12 @@ def test_sync_time(configuration, metadata, set_wazuh_configuration, configure_l # Wait for new sync and get start time sync_time = wazuh_log_monitor.start(timeout=global_parameters.default_timeout, callback=evm.callback_sync_start_time, - error_message=fim.ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() + error_message=evm.ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() # Get the time of all the sync state events for the created files results = wazuh_log_monitor.start(timeout=global_parameters.default_timeout, callback=evm.callback_state_event_time, accum_results=3, - error_message=fim.ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() + error_message=evm.ERR_MSG_FIM_SYNC_NOT_DETECTED, update_position=True).result() # Calculate timedelta between start of sync and last message. # Add 1 second to take into account the first second from the scan