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

Adding fixed and dynamic waits to port status checks #5627

Merged
merged 1 commit into from
Aug 1, 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
51 changes: 36 additions & 15 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import requests
import yaml
import time

from modules.testing.utils import logger
from .constants import WAZUH_CONF, WAZUH_ROOT, WAZUH_WINDOWS_CONF, WAZUH_MACOS_CONF
Expand Down Expand Up @@ -444,26 +445,46 @@ def is_agent_port_open(inventory_path):
str: Os name.
"""
os_type = HostInformation.get_os_type(inventory_path)
time.sleep(5)
if os_type == 'linux':
result = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":1514" | grep ESTAB')
if result.get('success'):
return 'ESTAB' in result.get('output')
else:
return False
for attempt in range(3):
result = ConnectionManager.execute_commands(
inventory_path,
'ss -t -a -n | grep ":1514" | grep ESTAB'
)
if result.get('success'):
if 'ESTAB' in result.get('output'):
return True
if attempt < 2:
time.sleep(5)
return False

elif os_type == 'windows':
result = ConnectionManager.execute_commands(inventory_path, 'netstat -ano | Select-String -Pattern "TCP" | Select-String -Pattern "ESTABLISHED" | Select-String -Pattern ":1514"')
if result.get('success'):
return 'ESTABLISHED' in result.get('output')
else:
return False
for attempt in range(3):
result = ConnectionManager.execute_commands(
inventory_path,
'netstat -ano | Select-String -Pattern "TCP" | Select-String -Pattern "ESTABLISHED" | Select-String -Pattern ":1514"'
)
if result.get('success'):
if 'ESTABLISHED' in result.get('output'):
return True
if attempt < 2:
time.sleep(5)
return False

elif os_type == 'macos':
result = ConnectionManager.execute_commands(inventory_path, 'netstat -an | grep ".1514 " | grep ESTABLISHED')
if result.get('success'):
return 'ESTABLISHED' in result.get('output')
else:
return False
for attempt in range(3):
result = ConnectionManager.execute_commands(
inventory_path,
'netstat -an | grep ".1514 " | grep ESTABLISHED'
)
if result.get('success'):
if 'ESTABLISHED' in result.get('output'):
return True
if attempt < 2:
time.sleep(5)
return False


def get_agents_information(wazuh_api: WazuhAPI) -> list:
"""
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/testing/tests/helpers/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def is_dashboard_port_open(inventory_path, wait=10, cycles=50):
Returns:
str: OS name.
"""
time.sleep(5)
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/testing/tests/helpers/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def is_indexer_port_open(inventory_path, wait=10, cycles=50) -> bool:
Returns:
str: OS name.
"""
time.sleep(5)
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":9200"').get('output') or ""
Expand Down
3 changes: 3 additions & 0 deletions deployability/modules/testing/tests/helpers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def is_wazuh_api_port_open(inventory_path, wait=10, cycles=50) -> bool:
Returns:
bool: True if port is opened.
"""
time.sleep(5)
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
Expand All @@ -266,6 +267,7 @@ def is_wazuh_agent_port_open(inventory_path, wait=10, cycles=50) -> bool:
Returns:
bool: True if port is opened.
"""
time.sleep(5)
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":1514"').get('output') or ""
Expand All @@ -291,6 +293,7 @@ def is_wazuh_agent_enrollment_port_open(inventory_path, wait=10, cycles=50) -> b
Returns:
bool: True if port is opened.
"""
time.sleep(5)
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
Expand Down