Skip to content

Commit

Permalink
fix(#5219): Adding fixes from macOS and windows PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed May 2, 2024
1 parent 3ed8c05 commit 9b15424
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 49 deletions.
5 changes: 4 additions & 1 deletion deployability/modules/testing/tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# 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

from .agent import WazuhAgent
from .generic import HostConfiguration, HostInformation, HostMonitor, CheckFiles
from .agent import WazuhAgent
from .manager import WazuhManager
from .indexer import WazuhIndexer
from .dashboard import WazuhDashboard
from .central import WazuhCentralComponents
26 changes: 3 additions & 23 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def perform_uninstall_and_scan_for_agent(agent_params, wazuh_params) -> None:

@staticmethod
def assert_results(result, params = None) -> None:

"""
Gets the status of an agent given its name.
Expand All @@ -386,7 +385,8 @@ def assert_results(result, params = None) -> None:

assert result[category][action] == [], logger.error(f'{result[category][action]} was found in: {category} {action}')

def areAgent_processes_active(agent_params):
@staticmethod
def are_agent_processes_active(agent_params):
"""
Check if agent processes are active
Expand Down Expand Up @@ -419,7 +419,7 @@ def areAgent_processes_active(agent_params):
else:
return False


@staticmethod
def is_agent_port_open(inventory_path):
"""
Check if agent port is open
Expand Down Expand Up @@ -510,26 +510,6 @@ def get_agent_ip_status_and_name_by_id(wazuh_api: WazuhAPI, identifier):
return [None, None, None]


def get_agent_ip_status_and_name_by_id(wazuh_api: WazuhAPI, identifier):
"""
Get IP status and name by ID.
Args:
identifier (str): Agent ID.
Returns:
List: IP, name, and status of the agent.
"""
try:
agents_information = wazuh_api.get_agents_information()
for element in agents_information:
if element['id'] == identifier:
return [element['ip'], element['name'], element['status']]
except Exception as e:
logger.error(f"Unexpected error: {e}")
return [None, None, None]


def get_agent_os_version_by_name(wazuh_api: WazuhAPI, agent_name):
"""
Get Agent os version by Agent name
Expand Down
7 changes: 1 addition & 6 deletions deployability/modules/testing/tests/helpers/central.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# 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 requests
import socket

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import ConnectionManager, WazuhAPI
from .executor import ConnectionManager
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
from .utils import Utils


class WazuhCentralComponents:
Expand Down
16 changes: 13 additions & 3 deletions deployability/modules/testing/tests/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import winrm

from modules.testing.utils import logger
from .generic import HostInformation

paramiko_logger = logging.getLogger("paramiko")
paramiko_logger.setLevel(logging.CRITICAL)
Expand Down Expand Up @@ -49,8 +48,19 @@ def check_inventory_connection(inventory_path, attempts=10, sleep=30) -> bool:
username = inventory_data.get('ansible_user')
password = inventory_data.get('ansible_password', None)


os_type = HostInformation.get_os_type(inventory_path)
try:
with open(inventory_path.replace('inventory', 'track'), 'r') as file:
data = yaml.safe_load(file)
if 'platform' in data:
os_type = data['platform']
else:
raise KeyError("The 'platform' key was not found in the YAML file.")
except FileNotFoundError:
logger.error(f"The YAML file '{inventory_path}' was not found.")
except yaml.YAMLError as e:
logger.error(f"Error while loading the YAML file: {e}")
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")

if os_type == 'linux':
ssh = paramiko.SSHClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ def test_port(wazuh_params):

def test_processes(wazuh_params):
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are not active')
assert WazuhAgent.are_agent_processes_active(agent_params), logger.error('Agent processes are not active')
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_service(wazuh_params):
Waits.dynamic_wait(expected_condition_func, cycles=20, waiting_time=30)

def test_connection(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for agent_names, _ in wazuh_params['agents'].items():
wazuh_api = WazuhAPI(wazuh_params['master'])
assert agent_names in WazuhManager.get_agent_control_info(wazuh_params['master']), f'The {agent_names} is not present in the master by command'
assert any(d.get('name') == agent_names for d in WazuhAgent.get_agents_information(wazuh_api)), logger.error(f'The {agent_names} is not present in the master by API')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_status(wazuh_params):


def test_connection(wazuh_params):
for agent_names, agent_params in wazuh_params['agents'].items():
for agent_names, _ in wazuh_params['agents'].items():
assert agent_names in WazuhManager.get_agent_control_info(wazuh_params['master']), logger.error(f'{agent_names} is not present in agent_control information')


Expand All @@ -96,4 +96,4 @@ def test_port(wazuh_params):

def test_processes(wazuh_params):
for _, agent_params in wazuh_params['agents'].items():
assert WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are not active')
assert WazuhAgent.are_agent_processes_active(agent_params), logger.error('Agent processes are not active')
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ def test_port(wazuh_params):

def test_processes(wazuh_params):
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are still active')
assert not WazuhAgent.are_agent_processes_active(agent_params), logger.error('Agent processes are still active')
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ def test_port(wazuh_params):

def test_processes(wazuh_params):
for _, agent_params in wazuh_params['agents'].items():
assert not WazuhAgent.areAgent_processes_active(agent_params), logger.error('Agent processes are still active')
assert not WazuhAgent.are_agent_processes_active(agent_params), logger.error('Agent processes are still active')
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import pytest

from modules.testing.utils import logger
from ..helpers.constants import WAZUH_ROOT
from ..helpers.executor import WazuhAPI
from ..helpers.generic import HostConfiguration, HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from ..helpers.indexer import WazuhIndexer
from ..helpers.dashboard import WazuhDashboard
from ..helpers.central import WazuhCentralComponents
from modules.testing.utils import logger
from ..helpers.utils import Utils


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import pytest

from modules.testing.utils import logger
from ..helpers.generic import HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from ..helpers.dashboard import WazuhDashboard
from ..helpers.indexer import WazuhIndexer
from modules.testing.utils import logger


@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import pytest

from modules.testing.utils import logger
from ..helpers.generic import HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from ..helpers.dashboard import WazuhDashboard
from ..helpers.indexer import WazuhIndexer
from modules.testing.utils import logger


@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import pytest

from modules.testing.utils import logger
from ..helpers.constants import WAZUH_ROOT
from ..helpers.generic import HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from ..helpers.dashboard import WazuhDashboard
from ..helpers.indexer import WazuhIndexer
from ..helpers.central import WazuhCentralComponents
from modules.testing.utils import logger


@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import pytest

from modules.testing.utils import logger
from ..helpers.constants import WAZUH_ROOT
from ..helpers.executor import WazuhAPI
from ..helpers.generic import HostConfiguration, HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from modules.testing.utils import logger
from ..helpers.utils import Utils


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import pytest

from ..helpers.generic import HostInformation, GeneralComponentActions
from modules.testing.utils import logger
from ..helpers.generic import HostInformation, GeneralComponentActions


@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import pytest

from ..helpers.generic import HostInformation, GeneralComponentActions
from modules.testing.utils import logger
from ..helpers.generic import HostInformation, GeneralComponentActions



@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import pytest

from modules.testing.utils import logger
from ..helpers.constants import WAZUH_ROOT
from ..helpers.generic import HostInformation, GeneralComponentActions
from ..helpers.manager import WazuhManager
from modules.testing.utils import logger



@pytest.fixture(scope="module", autouse=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ version: 0.1
description: This workflow is used to test the Wazuh manager deployment for DDT1 PoC
variables:
central_components-os:
- linux-ubuntu-20.04-amd64
#- linux-ubuntu-22.04-amd64
#- linux-ubuntu-22.04-amd64
#- linux-oracle-9-amd64
#- linux-amazon-2-amd64
#- linux-redhat-7-amd64
#- linux-redhat-8-amd64
#- linux-redhat-9-amd64
#- linux-centos-7-amd64
- linux-centos-7-amd64
#- linux-centos-8-amd64
#- linux-debian-10-amd64
#- linux-debian-11-amd64
Expand Down

0 comments on commit 9b15424

Please sign in to comment.