Skip to content

Commit

Permalink
Merge pull request #5627 from wazuh/bug/5616-port_status_fixes
Browse files Browse the repository at this point in the history
 Adding fixed and dynamic waits to port status checks
  • Loading branch information
juliamagan authored Aug 1, 2024
2 parents 0a440dc + 1608dfc commit 1d5cc4c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
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

0 comments on commit 1d5cc4c

Please sign in to comment.