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

Corrections on conf and replacing timeout like agentd enrollment test #23608

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions tests/integration/test_enrollment/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def configure_socket_listener(request, test_metadata):
"""
Configures the socket listener to start listening on the socket.
"""
address_family = 'AF_INET6' if 'ipv6' in test_metadata else 'AF_INET'
manager_address = '::1' if 'ipv6' in test_metadata else MANAGER_ADDRESS

address_family = 'AF_INET6' if 'ipv6' in test_metadata else 'AF_INET'
manager_address = '::1' if 'ipv6' in test_metadata else MANAGER_ADDRESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
'''
import sys
import pytest
import time

from pathlib import Path

from wazuh_testing.constants.paths.logs import WAZUH_LOG_PATH
from wazuh_testing.constants.platforms import WINDOWS
from wazuh_testing.utils.configuration import get_test_cases_data, load_configuration_template
from wazuh_testing.tools.monitors import queue_monitor
from wazuh_testing.tools.monitors.file_monitor import FileMonitor
Expand All @@ -70,6 +72,15 @@

daemons_handler_configuration = {'all_daemons': True}

def launch_agent_with_retry(configuration, retries=5, delay=1):
for attempt in range(retries):
try:
return launch_agent_auth(configuration)
except Exception as e:
if attempt < retries - 1:
time.sleep(delay)
else:
pytest.xfail(f"Xfailing agent-auth start with error {e} after {retries} retries")

# Test function.
@pytest.mark.parametrize('test_configuration, test_metadata', zip(test_configuration, test_metadata), ids=cases_ids)
Expand Down Expand Up @@ -125,9 +136,9 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
- Error logs related to the wrong configuration block
"""

launch_agent_auth(test_metadata.get('configuration', {}))

if 'expected_error' in test_metadata:
launch_agent_auth(test_metadata.get('configuration', {}))

expected_error_dict = test_metadata['expected_error']
expected_error = expected_error_dict['agent-auth'] if 'agent-auth' in expected_error_dict else \
expected_error_dict
Expand All @@ -147,6 +158,8 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
raise error

else:
launch_agent_with_retry(test_metadata.get('configuration', {}))

test_expected = test_metadata['message']['expected'].format(host_name=get_host_name(),
agent_version=get_version()).encode()
test_response = test_metadata['message']['response'].format(host_name=get_host_name()).encode()
Expand All @@ -157,7 +170,7 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf

try:
# Start socket monitoring
socket_monitor.start(timeout=10, accumulations=2, callback=lambda received_event: received_event.encode() in event)
socket_monitor.start(timeout=60 if sys.platform == WINDOWS else 20, accumulations=2, callback=lambda received_event: received_event.encode() in event)
vikman90 marked this conversation as resolved.
Show resolved Hide resolved

assert socket_monitor.matches == 2
except Exception as error:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_enrollment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ def launch_agent_auth(test_configuration):
if test_configuration.get('groups'):
parser.add_groups(test_configuration.get('groups'))

subprocess.call(parser.get_command(), timeout=AGENT_AUTH_LAUNCH_TIMEOUT)
return subprocess.call(parser.get_command(), timeout=AGENT_AUTH_LAUNCH_TIMEOUT)
Loading