Skip to content

Commit

Permalink
fix(#5229): Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed May 2, 2024
1 parent b9b6a7c commit 65ca9b4
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion deployability/modules/testing/tests/helpers/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _authenticate(self):
result = ConnectionManager.execute_commands(self.inventory_path, 'pwd')
file_path = result.get('output') + '/wazuh-install-files/wazuh-passwords.txt'
result = ConnectionManager.execute_commands(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"')
if not 'true' in result.get('output'):
if 'true' not in result.get('output'):
ConnectionManager.execute_commands(self.inventory_path, 'tar -xvf wazuh-install-files.tar')
result = ConnectionManager.execute_commands(self.inventory_path, "grep api_password wazuh-install-files/wazuh-passwords.txt | head -n 1 | awk '{print $NF}'")
password = result.get('output')[1:-1]
Expand Down
9 changes: 9 additions & 0 deletions deployability/modules/testing/tests/helpers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ def get_os_name_and_version_from_inventory(inventory_path) -> tuple:

@staticmethod
def get_os_version_from_inventory(inventory_path) -> str:
"""
It returns the os version from the inventory information
Args:
inventory_path: host's inventory path
Returns:
str: os version
"""
os_type = HostInformation.get_os_type(inventory_path)

if 'manager' in inventory_path:
Expand Down
1 change: 0 additions & 1 deletion deployability/modules/testing/tests/helpers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import requests
import socket

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import WazuhAPI, ConnectionManager
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/testing/tests/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def check_inventory_connection(inventory_path, attempts=10, sleep=30) -> bool:
logger.info("WinRM connection successful.")
return True
else:
logger.error(f'WinRM connection failed. Check the credentials in the inventory file.')
logger.error('WinRM connection failed. Check the credentials in the inventory file.')
return False
except Exception as e:
logger.warning(f'Error on attempt {attempt} of {attempts}: {e}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent, WazuhAPI
from ..helpers.constants import WAZUH_ROOT, WINDOWS_ROOT_DIR, MACOS_ROOT_DIR
from ..helpers.generic import HostInformation, GeneralComponentActions, Waits
from modules.testing.utils import logger
from ..helpers.manager import WazuhManager
from ..helpers.utils import Utils


Expand Down Expand Up @@ -95,10 +94,10 @@ def test_wazuh_os_version(wazuh_params):
assert os_name in WazuhAgent.get_agent_os_name_by_name(wazuh_api, agent_names).replace(' ', ''), logger.error('There is a mismatch between the OS name and the OS name of the installed agent')

def test_wazuh_version(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert wazuh_params['wazuh_version'] in GeneralComponentActions.get_component_version(agent_params), logger.error(f"The version {HostInformation.get_os_name_and_version_from_inventory(agent_params)} is not {wazuh_params['wazuh_version']} by command")


def test_wazuh_revision(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert wazuh_params['wazuh_revision'] in GeneralComponentActions.get_component_revision(agent_params), logger.error(f"The revision {HostInformation.get_os_name_and_version_from_inventory(agent_params)} is not {wazuh_params['wazuh_revision']} by command")
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent, WazuhAPI
from ..helpers.generic import HostInformation, GeneralComponentActions, Waits
from ..helpers.manager import WazuhManager, WazuhAPI
from modules.testing.utils import logger
from ..helpers.utils import Utils


Expand Down Expand Up @@ -74,7 +74,8 @@ def test_connection(wazuh_params):
def test_status(wazuh_params):
for agent in wazuh_params['agents'].values():
status = GeneralComponentActions.get_component_status(agent, 'wazuh-agent')
assert 'active' in status or 'connected' in status or "Running" in status or "is running" in status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} is not active')
valid_statuses = ['active', 'connected', 'Running', 'is running']
assert any(valid_status in status for valid_status in valid_statuses), logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} is not active')


def test_service(wazuh_params):
Expand All @@ -92,10 +93,10 @@ def test_clientKeys(wazuh_params):


def test_port(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.isAgent_port_open(agent_params), logger.error('Port is closed')


def test_processes(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are not active')
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent
from ..helpers.constants import WAZUH_ROOT, WINDOWS_ROOT_DIR, MACOS_ROOT_DIR
from ..helpers.generic import HostConfiguration, HostInformation, GeneralComponentActions
from modules.testing.utils import logger
from ..helpers.manager import WazuhManager
from ..helpers.utils import Utils

Expand Down Expand Up @@ -64,7 +64,7 @@ def setup_test_environment(wazuh_params):

def test_installation(wazuh_params):
# Checking connection
for manager_name, manager_params in wazuh_params['managers'].items():
for _, manager_params in wazuh_params['managers'].items():
Utils.check_inventory_connection(manager_params)

# Certs creation, firewall management and Manager installation
Expand Down Expand Up @@ -99,4 +99,5 @@ def test_installation(wazuh_params):
def test_status(wazuh_params):
for agent in wazuh_params['agents'].values():
agent_status = GeneralComponentActions.get_component_status(agent, 'wazuh-agent')
assert 'loaded' in agent_status or 'Stopped' in agent_status or 'not running' in agent_status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} status is not loaded')
valid_statuses = ['loaded', 'Stopped', 'not running']
assert any(valid_status in agent_status for valid_status in valid_statuses), logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(agent)} status is not loaded')
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent, WazuhAPI
from ..helpers.generic import HostInformation, GeneralComponentActions, Waits
from ..helpers.manager import WazuhManager, WazuhAPI
from modules.testing.utils import logger
from ..helpers.utils import Utils

@pytest.fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -65,7 +65,7 @@ def setup_test_environment(wazuh_params):


def test_status(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
WazuhAgent.register_agent(agent_params, wazuh_params['master'])
for agent in wazuh_params['agents'].values():
status = GeneralComponentActions.get_component_status(agent, 'wazuh-agent')
Expand Down
13 changes: 7 additions & 6 deletions deployability/modules/testing/tests/test_agent/test_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent
from ..helpers.generic import GeneralComponentActions, HostInformation
from modules.testing.utils import logger
from ..helpers.manager import WazuhManager
from ..helpers.utils import Utils

Expand Down Expand Up @@ -63,14 +63,15 @@ def setup_test_environment(wazuh_params):
wazuh_params['agents'] = updated_agents

def test_restart(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
GeneralComponentActions.component_restart(agent_params, 'wazuh-agent')


def test_status(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
status = GeneralComponentActions.get_component_status(agent_params, 'wazuh-agent')
assert 'active' in status or 'Running' in status or 'is running' in status, logger.error(f'{agent_names} is not active by command')
valid_statuses = ['active', 'Running', 'is running']
assert any(valid_status in status for valid_status in valid_statuses), logger.error(f'{agent_names} is not active by command')

def test_connection(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
Expand All @@ -88,10 +89,10 @@ def test_clientKeys(wazuh_params):


def test_port(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.isAgent_port_open(agent_params), logger.error('Port is closed')


def test_processes(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are not active')
11 changes: 6 additions & 5 deletions deployability/modules/testing/tests/test_agent/test_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent, WazuhAPI
from ..helpers.generic import GeneralComponentActions, Waits, HostInformation
from modules.testing.utils import logger
from ..helpers.utils import Utils

@pytest.fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -72,17 +72,18 @@ def test_service(wazuh_params):

for agent_names, agent_params in wazuh_params['agents'].items():
status = GeneralComponentActions.get_component_status(agent_params, 'wazuh-agent')
assert 'inactive' in status or 'Stopped' in status or 'StopPending' in status or 'not running' in status, logger.error(f'{agent_names} is still active by command')
valid_statuses = ['inactive', 'Stopped', 'StopPending', 'not running']
assert any(valid_status in status for valid_status in valid_statuses), logger.error(f'{agent_names} is still active by command')

expected_condition_func = lambda: 'disconnected' == WazuhAgent.get_agent_status(wazuh_api, agent_names)
Waits.dynamic_wait(expected_condition_func, cycles=20, waiting_time=30)


def test_port(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.isAgent_port_open(agent_params), logger.error('Port is still opened')


def test_processes(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are still active')
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Created by Wazuh, Inc. <[email protected]>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import pytest
import re
import pytest

from modules.testing.utils import logger
from ..helpers.agent import WazuhAgent
from ..helpers.constants import WAZUH_ROOT, WINDOWS_CONFIGURATIONS_DIR, WINDOWS_ROOT_DIR, MACOS_ROOT_DIR, MACOS_CONFIGURATIONS_DIR
from ..helpers.generic import HostInformation, GeneralComponentActions, Waits
from ..helpers.manager import WazuhManager, WazuhAPI
from modules.testing.utils import logger
from ..helpers.utils import Utils

@pytest.fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -109,10 +109,10 @@ def test_service(wazuh_params):


def test_port(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.isAgent_port_open(agent_params), logger.error('Port is still opened')


def test_processes(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are still active')
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_uninstall(wazuh_params):
for manager in wazuh_params['managers'].values():
manager_status = GeneralComponentActions.get_component_status(manager, 'wazuh-manager')
assert 'active' in manager_status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(manager)} is not active')
for manager_name, manager_params in wazuh_params['managers'].items():
for _, manager_params in wazuh_params['managers'].items():
WazuhManager.perform_uninstall_and_scan_for_manager(manager_params)


Expand Down

0 comments on commit 65ca9b4

Please sign in to comment.