Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GCloud IT: test_max_messages error #3006

Merged
merged 9 commits into from
Jun 28, 2022
Merged
5 changes: 3 additions & 2 deletions deps/wazuh_testing/wazuh_testing/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ def detect_gcp_start(file_monitor):


def callback_received_messages_number(line):
match = re.match(r'.*wm_gcp_pubsub_run\(\): INFO: - INFO - Received and acknowledged (\d+) messages', line)
received_messages_number = rf".*wm_gcp_pubsub_run\(\): INFO: - INFO - Received and acknowledged (\d+) messages"
match = re.findall(received_messages_number, line)
if match:
return match.group(1)
return match
return None


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
copyright: Copyright (C) 2015-2021, Wazuh Inc.
copyright: Copyright (C) 2015-2022, Wazuh Inc.

Created by Wazuh, Inc. <[email protected]>.

Expand Down Expand Up @@ -61,8 +61,8 @@
'''
import os
import sys

import pytest

from wazuh_testing import global_parameters
from wazuh_testing.fim import generate_params
from wazuh_testing.gcloud import callback_detect_start_fetching_logs, callback_received_messages_number
Expand Down Expand Up @@ -109,6 +109,7 @@

# fixtures


@pytest.fixture(scope='module', params=configurations)
def get_configuration(request):
"""Get configurations from the module."""
Expand All @@ -123,7 +124,8 @@ def get_configuration(request):
['- DEBUG - GCP message' for _ in range(100)],
['- DEBUG - GCP message' for _ in range(120)]
], indirect=True)
def test_max_messages(get_configuration, configure_environment, reset_ossec_log, publish_messages, daemons_handler, wait_for_gcp_start):
def test_max_messages(get_configuration, configure_environment, reset_ossec_log, publish_messages,
daemons_handler, wait_for_gcp_start):
'''
description: Check if the 'gcp-pubsub' module pulls a message number less than or equal to the limit set
in the 'max_messages' tag. For this purpose, the test will use a fixed limit and generate a
Expand Down Expand Up @@ -172,6 +174,7 @@ def test_max_messages(get_configuration, configure_environment, reset_ossec_log,
- logs
- scheduled
'''
count_message = 0
str_interval = get_configuration['sections'][0]['elements'][4]['interval']['value']
time_interval = int(''.join(filter(str.isdigit, str_interval)))

Expand All @@ -181,26 +184,20 @@ def test_max_messages(get_configuration, configure_environment, reset_ossec_log,
error_message='Did not receive expected '
'"Starting fetching of logs" event')

numbers_pulled = wazuh_log_monitor.start(timeout=pull_messages_timeout,
callback=callback_received_messages_number,
error_message='Did not receive expected '
'- INFO - Received and acknowledged x messages').result()
if publish_messages <= max_messages:
number_pulled = wazuh_log_monitor.start(timeout=pull_messages_timeout,
callback=callback_received_messages_number,
error_message='Did not receive expected '
'- INFO - Received and acknowledged x messages').result()
# GCP might log messages from sources other than ourselves
assert int(number_pulled) >= publish_messages
for number_pulled in numbers_pulled:
if int(number_pulled) != 0:
if (int(number_pulled) >= publish_messages):
# A counter is used to prevent it from failing due to logs from other sources
count_message += 1
assert int(number_pulled) <= max_messages
assert count_message >= 1
else:
ntimes = int(publish_messages / max_messages)
remainder = int(publish_messages % max_messages)

for i in range(ntimes):
number_pulled = wazuh_log_monitor.start(timeout=pull_messages_timeout,
callback=callback_received_messages_number,
error_message='Did not receive expected '
'Received and acknowledged x messages').result()
assert int(number_pulled) == max_messages
number_pulled = wazuh_log_monitor.start(timeout=pull_messages_timeout,
callback=callback_received_messages_number,
error_message='Did not receive expected '
'- INFO - Received and acknowledged x messages').result()
# GCP might log messages from sources other than ourselves
assert int(number_pulled) >= remainder
for number_pulled in numbers_pulled:
if int(number_pulled) != 0:
assert int(number_pulled) <= max_messages