Skip to content

Commit

Permalink
fix: adding retry mechanism for authd
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioDonda committed Jun 12, 2024
1 parent 6944027 commit 8a5c3e4
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'''
import sys
import pytest
import time

from pathlib import Path

Expand Down Expand Up @@ -71,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 @@ -126,9 +136,9 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
- Error logs related to the wrong configuration block
"""

agent_auth_launch_result = 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 @@ -148,8 +158,7 @@ def test_agent_auth_enrollment(test_configuration, test_metadata, set_wazuh_conf
raise error

else:
if agent_auth_launch_result != 0:
pytest.xfail(f"Xfailing agent-auth did not start execution result: {agent_auth_launch_result}")
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()
Expand Down

0 comments on commit 8a5c3e4

Please sign in to comment.