Skip to content

Commit

Permalink
refactor(#1915): update callback imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Deblintrake09 committed Dec 1, 2022
1 parent 67b32d5 commit 67d982c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 67d982c

Please sign in to comment.