From eb44df732c3869317a88035307c9f5621ba595a4 Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 24 Apr 2024 10:18:57 +0200 Subject: [PATCH 1/9] enhancement(#5219): Adding Central component tests --- deployability/modules/testing/main.py | 2 +- deployability/modules/testing/models.py | 2 +- .../modules/testing/tests/helpers/central.py | 177 ++++++++++++++++++ .../testing/tests/helpers/dashboard.py | 0 .../modules/testing/tests/helpers/filebeat.py | 0 .../modules/testing/tests/helpers/generic.py | 10 +- .../modules/testing/tests/helpers/indexer.py | 0 .../modules/testing/tests/helpers/manager.py | 8 +- .../modules/testing/tests/helpers/utils.py | 2 + .../tests/test_central_components/__init__.py | 6 + .../test_central_components/test_install.py | 95 ++++++++++ .../test_central_components/test_restart.py | 60 ++++++ .../test_central_components/test_stop.py | 68 +++++++ .../test_central_components/test_uninstall.py | 61 ++++++ .../testing/tests/test_manager/test_stop.py | 1 + .../dtt1-central_components-poc-vagrant.yaml | 62 ++++++ .../dtt1-central_components-poc-vagrant.yaml | 60 ++++++ 17 files changed, 607 insertions(+), 7 deletions(-) create mode 100644 deployability/modules/testing/tests/helpers/central.py create mode 100644 deployability/modules/testing/tests/helpers/dashboard.py create mode 100644 deployability/modules/testing/tests/helpers/filebeat.py create mode 100644 deployability/modules/testing/tests/helpers/indexer.py create mode 100644 deployability/modules/testing/tests/test_central_components/__init__.py create mode 100644 deployability/modules/testing/tests/test_central_components/test_install.py create mode 100644 deployability/modules/testing/tests/test_central_components/test_restart.py create mode 100644 deployability/modules/testing/tests/test_central_components/test_stop.py create mode 100644 deployability/modules/testing/tests/test_central_components/test_uninstall.py create mode 100644 deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml create mode 100644 deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml diff --git a/deployability/modules/testing/main.py b/deployability/modules/testing/main.py index 3cf78f564f..fc71d3ef89 100755 --- a/deployability/modules/testing/main.py +++ b/deployability/modules/testing/main.py @@ -16,7 +16,7 @@ def parse_arguments(): parser = argparse.ArgumentParser(description="Wazuh testing tool") parser.add_argument("--targets", action='append', default=[], required=True) parser.add_argument("--tests", required=True) - parser.add_argument("--component", choices=['manager', 'agent'], required=True) + parser.add_argument("--component", choices=['manager', 'agent', 'central_components'], required=True) parser.add_argument("--dependencies", action='append', default=[], required=False) parser.add_argument("--cleanup", required=False, default=True) parser.add_argument("--wazuh-version", required=True) diff --git a/deployability/modules/testing/models.py b/deployability/modules/testing/models.py index f4e168efa8..179ae852aa 100644 --- a/deployability/modules/testing/models.py +++ b/deployability/modules/testing/models.py @@ -7,7 +7,7 @@ class ExtraVars(BaseModel): """Extra vars for testing module.""" - component: Literal['manager', 'agent'] + component: Literal['manager', 'agent', 'central_components'] wazuh_version: str wazuh_revision: str wazuh_branch: str | None = None diff --git a/deployability/modules/testing/tests/helpers/central.py b/deployability/modules/testing/tests/helpers/central.py new file mode 100644 index 0000000000..3cc37dcbbc --- /dev/null +++ b/deployability/modules/testing/tests/helpers/central.py @@ -0,0 +1,177 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# 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 Executor, WazuhAPI +from .generic import HostInformation, CheckFiles +from modules.testing.utils import logger +from .utils import Utils + + +class WazuhCentralComponents: + + @staticmethod + def install_aio(inventory_path, wazuh_version) -> None: + """ + Installs Wazuh Central Components AIO in the host + + Args: + inventory_path (str): host's inventory path + wazuh_version (str): major.minor.patch + + """ + wazuh_version = '.'.join(wazuh_version.split('.')[:2]) + os_name = HostInformation.get_os_name_from_inventory(inventory_path) + + if 'debian' in os_name: + commands = [ + f"wget https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" + ] + + else: + commands = [ + f"curl -sO https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" + ] + + logger.info(f'Installing Wazuh AIO in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') + Executor.execute_commands(inventory_path, commands) + + + @staticmethod + def uninstall_aio(inventory_path) -> None: + """ + Uninstall Wazuh Central Components AIO in the host + + Args: + inventory_paths (str): hosts' inventory path + """ + + commands = ['bash wazuh-install.sh --uninstall --ignore-check'] + + logger.info(f'Uninstalling Wazuh AIO in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') + Executor.execute_commands(inventory_path, commands) + + + @staticmethod + def _install_aio_callback(wazuh_params, host_params): + WazuhCentralComponents.install_aio(host_params, wazuh_params['wazuh_version']) + + + @staticmethod + def _uninstall_aio_callback(host_params): + WazuhCentralComponents.uninstall_aio(host_params) + + + @staticmethod + def perform_action_and_scan(host_params, action_callback) -> dict: + """ + Takes scans using filters, the callback action and compares the result + + Args: + host_params (str): host parameters + callback (cb): callback (action) + + Returns: + result (dict): comparison brief + + """ + result = CheckFiles.perform_action_and_scan(host_params, action_callback) + os_name = HostInformation.get_os_name_from_inventory(host_params) + logger.info(f'Applying filters in checkfiles in {HostInformation.get_os_name_and_version_from_inventory(host_params)}') + + if 'debian' in os_name: + filter_data = { + '/boot': {'added': [], 'removed': [], 'modified': ['grubenv']}, + '/usr/bin': { + 'added': [ + 'unattended-upgrade', 'gapplication', 'add-apt-repository', 'gpg-wks-server', 'pkexec', 'gpgsplit', + 'watchgnupg', 'pinentry-curses', 'gpg-zip', 'gsettings', 'gpg-agent', 'gresource', 'gdbus', + 'gpg-connect-agent', 'gpgconf', 'gpgparsemail', 'lspgpot', 'pkaction', 'pkttyagent', 'pkmon', + 'dirmngr', 'kbxutil', 'migrate-pubring-from-classic-gpg', 'gpgcompose', 'pkcheck', 'gpgsm', 'gio', + 'pkcon', 'gpgtar', 'dirmngr-client', 'gpg', 'filebeat', 'gawk', 'curl', 'update-mime-database', + 'dh_installxmlcatalogs', 'appstreamcli', 'lspgpot', 'symcryptrun' + ], + 'removed': ['filebeat'], + 'modified': [] + }, + '/root': {'added': ['trustdb.gpg', 'lesshst'], 'removed': ['filebeat'], 'modified': []}, + '/usr/sbin': { + 'added': [ + 'update-catalog', 'applygnupgdefaults', 'addgnupghome', 'install-sgmlcatalog', 'update-xmlcatalog' + ], + 'removed': [], + 'modified': [] + } + } + else: + filter_data = { + '/boot': { + 'added': ['grub2', 'loader', 'vmlinuz', 'System.map', 'config-', 'initramfs'], + 'removed': [], + 'modified': ['grubenv'] + }, + '/usr/bin': {'added': ['filebeat'], 'removed': ['filebeat'], 'modified': []}, + '/root': {'added': ['trustdb.gpg', 'lesshst'], 'removed': [], 'modified': ['.rnd']}, + '/usr/sbin': {'added': [], 'removed': [], 'modified': []} + } + + # Use of filters + for directory, changes in result.items(): + if directory in filter_data: + for change, files in changes.items(): + if change in filter_data[directory]: + result[directory][change] = [file for file in files if file.split('/')[-1] not in filter_data[directory][change]] + + return result + + @staticmethod + def perform_install_and_scan_for_aio(host_params, wazuh_params) -> None: + """ + Coordinates the action of install the Wazuh AIO and compares the checkfiles + + Args: + host_params (str): host parameters + wazuh_params (str): wazuh parameters + + """ + action_callback = lambda: WazuhCentralComponents._install_aio_callback(wazuh_params, host_params) + result = WazuhCentralComponents.perform_action_and_scan(host_params, action_callback) + logger.info(f'Pre and post install checkfile comparison in {HostInformation.get_os_name_and_version_from_inventory(host_params)}: {result}') + WazuhCentralComponents.assert_results(result) + + + @staticmethod + def perform_uninstall_and_scan_for_aio(host_params) -> None: + """ + Coordinates the action of uninstall the Wazuh AIO and compares the checkfiles + + Args: + host_params (str): host parameters + wazuh_params (str): wazuh parameters + + """ + action_callback = lambda: WazuhCentralComponents._uninstall_aio_callback(host_params) + result = WazuhCentralComponents.perform_action_and_scan(host_params, action_callback) + logger.info(f'Pre and post uninstall checkfile comparison in {HostInformation.get_os_name_and_version_from_inventory(host_params)}: {result}') + WazuhCentralComponents.assert_results(result) + + + @staticmethod + def assert_results(result) -> None: + """ + Gets the status of an agent given its name. + + Args: + result (dict): result of comparison between pre and post action scan + + """ + categories = ['/root', '/usr/bin', '/usr/sbin', '/boot'] + actions = ['added', 'modified', 'removed'] + # Testing the results + for category in categories: + for action in actions: + assert result[category][action] == [], logger.error(f'{result[category][action]} was found in: {category} {action}') \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/deployability/modules/testing/tests/helpers/filebeat.py b/deployability/modules/testing/tests/helpers/filebeat.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/deployability/modules/testing/tests/helpers/generic.py b/deployability/modules/testing/tests/helpers/generic.py index 7c989028bf..4fd9e29beb 100644 --- a/deployability/modules/testing/tests/helpers/generic.py +++ b/deployability/modules/testing/tests/helpers/generic.py @@ -94,6 +94,8 @@ def get_linux_distribution(inventory_path) -> str: os_name = re.search(r'/manager-linux-([^-]+)-', inventory_path).group(1) elif 'agent' in inventory_path: os_name = re.search(r'/agent-linux-([^-]+)-', inventory_path).group(1) + elif 'central_components' in inventory_path: + os_name = re.search(r'/central_components-linux-([^-]+)-', inventory_path).group(1) if os_name == 'ubuntu' or os_name == 'debian': linux_distribution = 'deb' @@ -118,6 +120,8 @@ def get_os_name_from_inventory(inventory_path) -> str: os_name = re.search(r'/manager-linux-([^-]+)-', inventory_path).group(1) elif 'agent' in inventory_path: os_name = re.search(r'/agent-linux-([^-]+)-', inventory_path).group(1) + elif 'central_components' in inventory_path: + os_name = re.search(r'/central_components-linux-([^-]+)-', inventory_path).group(1) return os_name @@ -136,6 +140,8 @@ def get_os_name_and_version_from_inventory(inventory_path) -> tuple: match = re.search(r'/manager-linux-([^-]+)-([^-]+)-', inventory_path) elif 'agent' in inventory_path: match = re.search(r'/agent-linux-([^-]+)-([^-]+)-', inventory_path) + elif 'central_components' in inventory_path: + match = re.search(r'/central_components-linux-([^-]+)-([^-]+)-', inventory_path) if match: os_name = match.group(1) version = match.group(2) @@ -149,6 +155,8 @@ def get_os_version_from_inventory(inventory_path) -> str: os_version = re.search(r".*?/manager-linux-.*?-(.*?)-.*?/inventory.yaml", inventory_path).group(1) elif 'agent' in inventory_path: os_version = re.search(r".*?/agent-linux-.*?-(.*?)-.*?/inventory.yaml", inventory_path).group(1) + elif 'central_components' in inventory_path: + os_version = re.search(r".*?/central_components-linux-.*?-(.*?)-.*?/inventory.yaml", inventory_path).group(1) return os_version else: return None @@ -542,7 +550,7 @@ def get_component_status(inventory_path, host_role) -> str: Returns: str: Role status """ - logger.info(f'Getting status of {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') + logger.info(f'Getting status of {host_role} in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') return Executor.execute_command(inventory_path, f'systemctl status {host_role}') diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/deployability/modules/testing/tests/helpers/manager.py b/deployability/modules/testing/tests/helpers/manager.py index 2ac8811ab7..95d15b200b 100644 --- a/deployability/modules/testing/tests/helpers/manager.py +++ b/deployability/modules/testing/tests/helpers/manager.py @@ -119,8 +119,8 @@ def perform_action_and_scan(manager_params, action_callback) -> dict: Takes scans using filters, the callback action and compares the result Args: - agent_params (str): agent parameters - callbak (cb): callback (action) + manager_params (str): manager parameters + callback (cb): callback (action) Returns: result (dict): comparison brief @@ -182,6 +182,7 @@ def perform_install_and_scan_for_manager(manager_params, manager_name, wazuh_par Args: manager_params (str): manager parameters + manager_name (str): manager name wazuh_params (str): wazuh parameters """ @@ -198,7 +199,6 @@ def perform_uninstall_and_scan_for_manager(manager_params) -> None: Args: manager_params (str): manager parameters - wazuh_params (str): wazuh parameters """ action_callback = lambda: WazuhManager._uninstall_manager_callback(manager_params) @@ -210,7 +210,7 @@ def perform_uninstall_and_scan_for_manager(manager_params) -> None: @staticmethod def assert_results(result) -> None: """ - Gets the status of an agent given its name. + Assert status of checkfiles Args: result (dict): result of comparison between pre and post action scan diff --git a/deployability/modules/testing/tests/helpers/utils.py b/deployability/modules/testing/tests/helpers/utils.py index aea456c151..8322a444ac 100644 --- a/deployability/modules/testing/tests/helpers/utils.py +++ b/deployability/modules/testing/tests/helpers/utils.py @@ -29,6 +29,8 @@ def check_inventory_connection(inventory_path, attempts=10, sleep=30) -> bool: match = re.search(r'/manager-linux-([^-]+)-([^-]+)-', inventory_path) elif 'agent' in inventory_path: match = re.search(r'/agent-linux-([^-]+)-([^-]+)-', inventory_path) + elif 'central_components' in inventory_path: + match = re.search(r'/central_components-([^-]+)-([^-]+)-', inventory_path) if match: os_name = match.group(1)+ '-' + match.group(2) logger.info(f'Checking connection to {os_name}') diff --git a/deployability/modules/testing/tests/test_central_components/__init__.py b/deployability/modules/testing/tests/test_central_components/__init__.py new file mode 100644 index 0000000000..184c7ae281 --- /dev/null +++ b/deployability/modules/testing/tests/test_central_components/__init__.py @@ -0,0 +1,6 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 + +from ..helpers.generic import HostConfiguration, CheckFiles, HostInformation, GeneralComponentActions +from ..helpers.manager import WazuhManager diff --git a/deployability/modules/testing/tests/test_central_components/test_install.py b/deployability/modules/testing/tests/test_central_components/test_install.py new file mode 100644 index 0000000000..e716033f00 --- /dev/null +++ b/deployability/modules/testing/tests/test_central_components/test_install.py @@ -0,0 +1,95 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 + +import pytest + +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.central import WazuhCentralComponents +from modules.testing.utils import logger +from ..helpers.utils import Utils + + +@pytest.fixture(scope="module", autouse=True) +def wazuh_params(request): + wazuh_version = request.config.getoption('--wazuh_version') + wazuh_revision = request.config.getoption('--wazuh_revision') + dependencies = request.config.getoption('--dependencies') + targets = request.config.getoption('--targets') + + return { + 'wazuh_version': wazuh_version, + 'wazuh_revision': wazuh_revision, + 'dependencies': dependencies, + 'targets': targets + } + + +@pytest.fixture(scope="module", autouse=True) +def setup_test_environment(wazuh_params): + targets = wazuh_params['targets'] + # Clean the string and split it into key-value pairs + targets = targets.replace(' ', '') + targets = targets.replace(' ', '') + pairs = [pair.strip() for pair in targets.strip('{}').split(',')] + targets_dict = dict(pair.split(':') for pair in pairs) + + wazuh_params['master'] = targets_dict.get('wazuh-1') + wazuh_params['workers'] = [value for key, value in targets_dict.items() if key.startswith('wazuh-') and key != 'wazuh-1'] + wazuh_params['indexers'] = [value for key, value in targets_dict.items() if key.startswith('node-')] + wazuh_params['dashboard'] = targets_dict.get('dashboard', wazuh_params['master']) + + # If there are no indexers, we choose wazuh-1 by default + if not wazuh_params['indexers']: + wazuh_params['indexers'].append(wazuh_params['master']) + + wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} + +def test_installation(wazuh_params): + # Disabling firewall for all managers + for manager_name, manager_params in wazuh_params['managers'].items(): + Utils.check_inventory_connection(manager_params) + HostConfiguration.disable_firewall(manager_params) + + # Certs create and scp from master to worker + HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers']) + + # Install central components and perform checkfile testing + for manager_name, manager_params in wazuh_params['managers'].items(): + WazuhCentralComponents.perform_install_and_scan_for_aio(manager_params, wazuh_params) + + # Validation of directory of the components + for manager in wazuh_params['managers'].values(): + assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') + + +def test_component_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') + for indexer_params in wazuh_params['indexers']: + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + + +def test_manager_version(wazuh_params): + for manager in wazuh_params['managers'].values(): + manager_status = GeneralComponentActions.get_component_version(manager) + assert wazuh_params['wazuh_version'] in manager_status, logger.error(f"The version {HostInformation.get_os_name_and_version_from_inventory(manager)} is not {wazuh_params['wazuh_version']} by using commands") + wazuh_api = WazuhAPI(wazuh_params['master']) + assert wazuh_params['wazuh_version'] in WazuhManager.get_manager_version(wazuh_api), logger.error(f"The version {HostInformation.get_os_name_and_version_from_inventory(manager)} is not {wazuh_params['wazuh_version']} in the API") + + +def test_manager_revision(wazuh_params): + for manager in wazuh_params['managers'].values(): + manager_status = GeneralComponentActions.get_component_revision(manager) + assert wazuh_params['wazuh_revision'] in manager_status, logger.error(f"The revision {HostInformation.get_os_name_and_version_from_inventory(manager)} is not {wazuh_params['wazuh_revision']} by using commands") + wazuh_api = WazuhAPI(wazuh_params['master']) + assert wazuh_params['wazuh_revision'] in str(WazuhManager.get_manager_revision(wazuh_api)), logger.error(f"The revision {HostInformation.get_os_name_and_version_from_inventory(manager)} is not {wazuh_params['wazuh_revision']} in the API") + + +def test_manager_installed_directory(wazuh_params): + for manager in wazuh_params['managers'].values(): + assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') diff --git a/deployability/modules/testing/tests/test_central_components/test_restart.py b/deployability/modules/testing/tests/test_central_components/test_restart.py new file mode 100644 index 0000000000..2294b955f6 --- /dev/null +++ b/deployability/modules/testing/tests/test_central_components/test_restart.py @@ -0,0 +1,60 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 + +import pytest + +from ..helpers.generic import HostInformation, GeneralComponentActions +from modules.testing.utils import logger + + +@pytest.fixture(scope="module", autouse=True) +def wazuh_params(request): + wazuh_version = request.config.getoption('--wazuh_version') + wazuh_revision = request.config.getoption('--wazuh_revision') + dependencies = request.config.getoption('--dependencies') + targets = request.config.getoption('--targets') + + return { + 'wazuh_version': wazuh_version, + 'wazuh_revision': wazuh_revision, + 'dependencies': dependencies, + 'targets': targets + } + + +@pytest.fixture(scope="module", autouse=True) +def setup_test_environment(wazuh_params): + targets = wazuh_params['targets'] + # Clean the string and split it into key-value pairs + targets = targets.replace(' ', '') + targets = targets.replace(' ', '') + pairs = [pair.strip() for pair in targets.strip('{}').split(',')] + targets_dict = dict(pair.split(':') for pair in pairs) + + wazuh_params['master'] = targets_dict.get('wazuh-1') + wazuh_params['workers'] = [value for key, value in targets_dict.items() if key.startswith('wazuh-') and key != 'wazuh-1'] + wazuh_params['indexers'] = [value for key, value in targets_dict.items() if key.startswith('node-')] + wazuh_params['dashboard'] = targets_dict.get('dashboard', wazuh_params['master']) + + # If there are no indexers, we choose wazuh-1 by default + if not wazuh_params['indexers']: + wazuh_params['indexers'].append(wazuh_params['master']) + + wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} + +def test_restart(wazuh_params): + GeneralComponentActions.component_restart(wazuh_params['master'], 'wazuh-manager') + + for indexer_params in wazuh_params['indexers']: + GeneralComponentActions.component_restart(indexer_params, 'wazuh-indexer') + + GeneralComponentActions.component_restart(wazuh_params['dashboard'], 'wazuh-dashboard') + GeneralComponentActions.component_restart(wazuh_params['master'], 'filebeat') + + + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') + for indexer_params in wazuh_params['indexers']: + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') diff --git a/deployability/modules/testing/tests/test_central_components/test_stop.py b/deployability/modules/testing/tests/test_central_components/test_stop.py new file mode 100644 index 0000000000..4c1552162a --- /dev/null +++ b/deployability/modules/testing/tests/test_central_components/test_stop.py @@ -0,0 +1,68 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 + +import pytest + +from ..helpers.generic import HostInformation, GeneralComponentActions +from modules.testing.utils import logger + + +@pytest.fixture(scope="module", autouse=True) +def wazuh_params(request): + wazuh_version = request.config.getoption('--wazuh_version') + wazuh_revision = request.config.getoption('--wazuh_revision') + dependencies = request.config.getoption('--dependencies') + targets = request.config.getoption('--targets') + + params = { + 'wazuh_version': wazuh_version, + 'wazuh_revision': wazuh_revision, + 'dependencies': dependencies, + 'targets': targets + } + yield params + logger.info('Restoring Central Component status') + GeneralComponentActions.component_restart(params['master'], 'wazuh-manager') + + for indexer_params in params['indexers']: + GeneralComponentActions.component_restart(indexer_params, 'wazuh-indexer') + + GeneralComponentActions.component_restart(params['dashboard'], 'wazuh-dashboard') + GeneralComponentActions.component_restart(params['master'], 'filebeat') + + +@pytest.fixture(scope="module", autouse=True) +def setup_test_environment(wazuh_params): + targets = wazuh_params['targets'] + # Clean the string and split it into key-value pairs + targets = targets.replace(' ', '') + targets = targets.replace(' ', '') + pairs = [pair.strip() for pair in targets.strip('{}').split(',')] + targets_dict = dict(pair.split(':') for pair in pairs) + + wazuh_params['master'] = targets_dict.get('wazuh-1') + wazuh_params['workers'] = [value for key, value in targets_dict.items() if key.startswith('wazuh-') and key != 'wazuh-1'] + wazuh_params['indexers'] = [value for key, value in targets_dict.items() if key.startswith('node-')] + wazuh_params['dashboard'] = targets_dict.get('dashboard', wazuh_params['master']) + + # If there are no indexers, we choose wazuh-1 by default + if not wazuh_params['indexers']: + wazuh_params['indexers'].append(wazuh_params['master']) + + wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} + +def test_stop(wazuh_params): + GeneralComponentActions.component_stop(wazuh_params['master'], 'wazuh-manager') + + for indexer_params in wazuh_params['indexers']: + GeneralComponentActions.component_stop(indexer_params, 'wazuh-indexer') + + GeneralComponentActions.component_stop(wazuh_params['dashboard'], 'wazuh-dashboard') + GeneralComponentActions.component_stop(wazuh_params['master'], 'filebeat') + + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') + for indexer_params in wazuh_params['indexers']: + assert 'inactive' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') diff --git a/deployability/modules/testing/tests/test_central_components/test_uninstall.py b/deployability/modules/testing/tests/test_central_components/test_uninstall.py new file mode 100644 index 0000000000..ea048e7f89 --- /dev/null +++ b/deployability/modules/testing/tests/test_central_components/test_uninstall.py @@ -0,0 +1,61 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 + +import pytest + +from ..helpers.constants import WAZUH_ROOT +from ..helpers.generic import HostInformation, GeneralComponentActions +from ..helpers.manager import WazuhManager +from ..helpers.central import WazuhCentralComponents +from modules.testing.utils import logger + + +@pytest.fixture(scope="module", autouse=True) +def wazuh_params(request): + wazuh_version = request.config.getoption('--wazuh_version') + wazuh_revision = request.config.getoption('--wazuh_revision') + dependencies = request.config.getoption('--dependencies') + targets = request.config.getoption('--targets') + + return { + 'wazuh_version': wazuh_version, + 'wazuh_revision': wazuh_revision, + 'dependencies': dependencies, + 'targets': targets + } + + +@pytest.fixture(scope="module", autouse=True) +def setup_test_environment(wazuh_params): + targets = wazuh_params['targets'] + # Clean the string and split it into key-value pairs + targets = targets.replace(' ', '') + targets = targets.replace(' ', '') + pairs = [pair.strip() for pair in targets.strip('{}').split(',')] + targets_dict = dict(pair.split(':') for pair in pairs) + + wazuh_params['master'] = targets_dict.get('wazuh-1') + wazuh_params['workers'] = [value for key, value in targets_dict.items() if key.startswith('wazuh-') and key != 'wazuh-1'] + wazuh_params['indexers'] = [value for key, value in targets_dict.items() if key.startswith('node-')] + wazuh_params['dashboard'] = targets_dict.get('dashboard', wazuh_params['master']) + + # If there are no indexers, we choose wazuh-1 by default + if not wazuh_params['indexers']: + wazuh_params['indexers'].append(wazuh_params['master']) + + wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} + + +def test_uninstall(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') + for indexer_params in wazuh_params['indexers']: + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + + WazuhCentralComponents.perform_uninstall_and_scan_for_aio(wazuh_params['master']) + + +def test_component_uninstalled_directory(wazuh_params): + assert not HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f'In {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} {WAZUH_ROOT} is still present') diff --git a/deployability/modules/testing/tests/test_manager/test_stop.py b/deployability/modules/testing/tests/test_manager/test_stop.py index 4b31594c43..4ea12029d3 100644 --- a/deployability/modules/testing/tests/test_manager/test_stop.py +++ b/deployability/modules/testing/tests/test_manager/test_stop.py @@ -22,6 +22,7 @@ def wazuh_params(request): 'targets': targets } yield params + logger.info('Restoring Manager status') for worker in params['workers']: GeneralComponentActions.component_restart(worker, 'wazuh-manager') diff --git a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml new file mode 100644 index 0000000000..4e86f1f70e --- /dev/null +++ b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml @@ -0,0 +1,62 @@ +version: 0.1 +description: This workflow is used to test manager deployment for DDT1 PoC +variables: + central_components-os: + - linux-ubuntu-20.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-8-amd64 + #- linux-debian-10-amd64 + #- linux-debian-11-amd64 + #- linux-debian-12-amd64 + infra-provider: aws + working-dir: /tmp/dtt1-poc + +tasks: + # Unique central components allocate task + - task: "allocate-central_components-{central_components}" + description: "Allocate resources for the central_components." + do: + this: process + with: + path: python3 + args: + - modules/allocation/main.py + - action: create + - provider: "{infra-provider}" + - size: large + - composite-name: "{central_components}" + - inventory-output: "{working-dir}/central_components-{central_components}/inventory.yaml" + - track-output: "{working-dir}/central_components-{central_components}/track.yaml" + - label-termination-date: "1d" + - label-team: "qa" + on-error: "abort-all" + foreach: + - variable: central_components-os + as: central_components + + # Generic manager test task + - task: "run-central_components-{central_components}-tests" + description: "Run tests install for the central_components." + do: + this: process + with: + path: python3 + args: + - modules/testing/main.py + - targets: + - wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml" + - tests: "install,restart,stop,uninstall" + - component: "central_components" + - wazuh-version: "4.7.3" + - wazuh-revision: "40714" + - live: "True" + on-error: "abort-all" + foreach: + - variable: central_components-os + as: central_components \ No newline at end of file diff --git a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml new file mode 100644 index 0000000000..cc163a5f82 --- /dev/null +++ b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml @@ -0,0 +1,60 @@ +version: 0.1 +description: This workflow is used to test manager deployment for DDT1 PoC +variables: + central_components-os: + - linux-ubuntu-20.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-8-amd64 + #- linux-debian-10-amd64 + #- linux-debian-11-amd64 + #- linux-debian-12-amd64 + infra-provider: vagrant + working-dir: /tmp/dtt1-poc + +tasks: + # Unique central components allocate task + - task: "allocate-central_components-{central_components}" + description: "Allocate resources for the central_components." + do: + this: process + with: + path: python3 + args: + - modules/allocation/main.py + - action: create + - provider: "{infra-provider}" + - size: large + - composite-name: "{central_components}" + - inventory-output: "{working-dir}/central_components-{central_components}/inventory.yaml" + - track-output: "{working-dir}/central_components-{central_components}/track.yaml" + on-error: "abort-all" + foreach: + - variable: central_components-os + as: central_components + + # Generic manager test task + - task: "run-central_components-{central_components}-tests" + description: "Run tests install for the central_components." + do: + this: process + with: + path: python3 + args: + - modules/testing/main.py + - targets: + - wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml" + - tests: "install,stop,restart,uninstall" + - component: "central_components" + - wazuh-version: "4.7.3" + - wazuh-revision: "40714" + - live: "True" + on-error: "abort-all" + foreach: + - variable: central_components-os + as: central_components \ No newline at end of file From 587dd763739dd279ea7fa82e5743b1585215fba2 Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 24 Apr 2024 19:01:02 +0200 Subject: [PATCH 2/9] enhancement(#5219): Preparing additional dashboard and indexer validations --- .../testing/tests/helpers/dashboard.py | 71 +++++++++++++++++++ .../modules/testing/tests/helpers/executor.py | 24 ++++++- .../modules/testing/tests/helpers/filebeat.py | 0 .../modules/testing/tests/helpers/indexer.py | 52 ++++++++++++++ .../test_central_components/test_install.py | 21 +++++- .../dtt1-central_components-poc-vagrant.yaml | 29 +++++--- .../dtt1-central_components-poc-vagrant.yaml | 24 +++---- 7 files changed, 195 insertions(+), 26 deletions(-) delete mode 100644 deployability/modules/testing/tests/helpers/filebeat.py diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py index e69de29bb2..08dd1e61b9 100644 --- a/deployability/modules/testing/tests/helpers/dashboard.py +++ b/deployability/modules/testing/tests/helpers/dashboard.py @@ -0,0 +1,71 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# 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 Executor, WazuhAPI +from .generic import HostInformation, CheckFiles +from modules.testing.utils import logger +from .utils import Utils + + +class WazuhDashboard: + + @staticmethod + def get_dashboard_version(inventory_path) -> str: + """ + Returns dashboard version + + Args: + inventory_path (str): host's inventory path + """ + + return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-dashboard/VERSION') + + + @staticmethod + def isDashboard_active(inventory_path) -> bool: + """ + Returns True/False depending if the dashboard is active or not + + Args: + inventory_path (str): host's inventory path + """ + + return '200' in Executor.execute_command(inventory_path, 'curl -Is -k https://localhost/app/login?nextUrl=%2F | head -n 1') + + + @staticmethod + def isDashboardKeystore_working(inventory_path) -> bool: + """ + Returns True/False depending if the dashboard keystore is active or not + + Args: + inventory_path (str): host's inventory path + """ + + return 'No such file or directory' not in Executor.execute_command(inventory_path, '/usr/share/wazuh-dashboard/bin/opensearch-dashboards-keystore list --allow-root') + + + @staticmethod + def areIndexes_working(wazuh_api: WazuhAPI) -> str: + """ + Function to get the status of an agent given its name. + + Args: + - agents_data (list): List of dictioconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaanaries conaaaaa. + - agent_name (str): Name of the agent whoseconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaa status is to be obtained. + + Returns: + - str: Status of the agent if found in the daconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaa, otherwise returns None. + """ + logger.error(wazuh_api.api_url) + logger.error(wazuh_api.password) + logger.error(wazuh_api.username) + response = requests.get(f"{wazuh_api.api_url}/_cat/indices/?pretty", auth=(wazuh_api.username, wazuh_api.password), verify=False) + + + return response \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/executor.py b/deployability/modules/testing/tests/helpers/executor.py index 6d204d6ba8..07b1e39894 100644 --- a/deployability/modules/testing/tests/helpers/executor.py +++ b/deployability/modules/testing/tests/helpers/executor.py @@ -50,10 +50,13 @@ def execute_commands(inventory_path, commands=[]) -> dict: class WazuhAPI: - def __init__(self, inventory_path): + def __init__(self, inventory_path, component=None): self.inventory_path = inventory_path self.api_url = None self.headers = None + self.component = component + self.username = None + self.password = None urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) self._authenticate() @@ -80,8 +83,25 @@ def _authenticate(self): token = json.loads(requests.post(login_url, headers=login_headers, verify=False).content.decode())['data']['token'] - self.api_url = f'https://{host}:{port}' self.headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {token}' } + + self.api_url = f'https://{host}:{port}' + + if self.component == 'dashboard': + self.username = 'admin' + file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt' + if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): + Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') + self.password = Executor.execute_command(self.inventory_path, "grep indexer_password wazuh-install-files/wazuh-passwords.txt | head -n 1 | awk '{print $NF}'").replace("'","").replace("\n","") + self.api_url = f'https://localhost' + + if self.component == 'indexer': + self.username = 'admin' + file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt' + if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): + Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') + self.password = Executor.execute_command(self.inventory_path, "").replace("'","").replace("\n","") + self.api_url = f'https://localhost:9200' \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/filebeat.py b/deployability/modules/testing/tests/helpers/filebeat.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index e69de29bb2..f8475ac9eb 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -0,0 +1,52 @@ +# Copyright (C) 2015, Wazuh Inc. +# Created by Wazuh, Inc. . +# 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 Executor, WazuhAPI +from .generic import HostInformation, CheckFiles +from modules.testing.utils import logger +from .utils import Utils + + +class WazuhIndexer: + + @staticmethod + def get_indexer_version(inventory_path) -> str: + """ + Returns indexer version + + Args: + inventory_path (str): host's inventory path + """ + + return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION') + + + @staticmethod + def areIndexer_internalUsers_complete(inventory_path) -> bool: + """ + Returns True/False depending on the existance of all the expected internal users + + Args: + inventory_path (str): host's inventory path + """ + + users_to_check = [ + 'admin', + 'kibanaserver', + 'kibanaro', + 'logstash', + 'readall', + 'snapshotrestore' + ] + report_of_users = Executor.execute_command(inventory_path, "cat /etc/wazuh-indexer/opensearch-security/internal_users.yml | grep '^[a-z]'") + for user in users_to_check: + if user not in report_of_users: + + return False + + return True \ No newline at end of file diff --git a/deployability/modules/testing/tests/test_central_components/test_install.py b/deployability/modules/testing/tests/test_central_components/test_install.py index e716033f00..7262eed8e2 100644 --- a/deployability/modules/testing/tests/test_central_components/test_install.py +++ b/deployability/modules/testing/tests/test_central_components/test_install.py @@ -8,6 +8,8 @@ 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 @@ -48,7 +50,23 @@ def setup_test_environment(wazuh_params): wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} -def test_installation(wazuh_params): + +def test_parametros(wazuh_params): + #logger.error(WazuhDashboard.get_dashboard_version(wazuh_params['dashboard'])) + #for indexer_params in wazuh_params['indexers']: + # logger.error(WazuhIndexer.get_indexer_version(indexer_params)) + + #logger.error(WazuhDashboard.isDashboard_active(wazuh_params['dashboard'])) + + + #logger.error(WazuhDashboard.isDashboardKeystore_working(wazuh_params['dashboard'])) + #for indexer_params in wazuh_params['indexers']: + # logger.error(WazuhIndexer.areIndexer_internalUsers_complete(indexer_params)) + + wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') + logger.error(WazuhDashboard.areIndexes_working(wazuh_api)) + +""" def test_installation(wazuh_params): # Disabling firewall for all managers for manager_name, manager_params in wazuh_params['managers'].items(): Utils.check_inventory_connection(manager_params) @@ -93,3 +111,4 @@ def test_manager_revision(wazuh_params): def test_manager_installed_directory(wazuh_params): for manager in wazuh_params['managers'].values(): assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') + """ \ No newline at end of file diff --git a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml index 4e86f1f70e..268a7bd8da 100644 --- a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml @@ -3,17 +3,16 @@ description: This workflow is used to test manager deployment for DDT1 PoC variables: central_components-os: - linux-ubuntu-20.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-8-amd64 - #- linux-debian-10-amd64 - #- linux-debian-11-amd64 - #- linux-debian-12-amd64 + - linux-ubuntu-22.04-amd64 + - linux-amazon-2-amd64 + - linux-redhat-7-amd64 + - linux-redhat-8-amd64 + - linux-redhat-9-amd64 + - linux-centos-7-amd64 + - linux-centos-8-amd64 + - linux-debian-10-amd64 + - linux-debian-11-amd64 + - linux-debian-12-amd64 infra-provider: aws working-dir: /tmp/dtt1-poc @@ -39,6 +38,14 @@ tasks: foreach: - variable: central_components-os as: central_components + cleanup: + this: process + with: + path: python3 + args: + - modules/allocation/main.py + - action: delete + - track-output: "{working-dir}/central_components-{central_components-os}/track.yaml" # Generic manager test task - task: "run-central_components-{central_components}-tests" diff --git a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml index cc163a5f82..d59383c00d 100644 --- a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml @@ -3,17 +3,17 @@ description: This workflow is used to test manager deployment for DDT1 PoC variables: central_components-os: - linux-ubuntu-20.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-8-amd64 - #- linux-debian-10-amd64 - #- linux-debian-11-amd64 - #- linux-debian-12-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-8-amd64 + - linux-debian-10-amd64 + - linux-debian-11-amd64 + - linux-debian-12-amd64 infra-provider: vagrant working-dir: /tmp/dtt1-poc @@ -49,7 +49,7 @@ tasks: - modules/testing/main.py - targets: - wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml" - - tests: "install,stop,restart,uninstall" + - tests: "install" - component: "central_components" - wazuh-version: "4.7.3" - wazuh-revision: "40714" From f7670109fbb82a61cea7b3e162a4c5023c30db5a Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 25 Apr 2024 18:00:27 +0200 Subject: [PATCH 3/9] enhancement(#5219): Adding port tests --- .../testing/tests/helpers/dashboard.py | 66 ++++++++++--- .../modules/testing/tests/helpers/executor.py | 34 +++---- .../modules/testing/tests/helpers/indexer.py | 77 +++++++++++++-- .../modules/testing/tests/helpers/manager.py | 77 +++++++++++++++ .../test_central_components/test_install.py | 96 ++++++++++++++----- .../test_central_components/test_restart.py | 40 +++++++- .../test_central_components/test_stop.py | 40 +++++++- .../test_central_components/test_uninstall.py | 25 ++++- 8 files changed, 381 insertions(+), 74 deletions(-) diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py index 08dd1e61b9..6b13a1f609 100644 --- a/deployability/modules/testing/tests/helpers/dashboard.py +++ b/deployability/modules/testing/tests/helpers/dashboard.py @@ -4,6 +4,8 @@ import requests import socket +import json +import time from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT from .executor import Executor, WazuhAPI @@ -21,9 +23,12 @@ def get_dashboard_version(inventory_path) -> str: Args: inventory_path (str): host's inventory path + + Returns: + - str: Version of the dashboard. """ - return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-dashboard/VERSION') + return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-dashboard/VERSION').strip() @staticmethod @@ -33,6 +38,9 @@ def isDashboard_active(inventory_path) -> bool: Args: inventory_path (str): host's inventory path + + Returns: + - bool: Status of the dashboard. """ return '200' in Executor.execute_command(inventory_path, 'curl -Is -k https://localhost/app/login?nextUrl=%2F | head -n 1') @@ -45,27 +53,57 @@ def isDashboardKeystore_working(inventory_path) -> bool: Args: inventory_path (str): host's inventory path + + Returns: + - bool: Status of the dashboard keystore. """ return 'No such file or directory' not in Executor.execute_command(inventory_path, '/usr/share/wazuh-dashboard/bin/opensearch-dashboards-keystore list --allow-root') @staticmethod - def areIndexes_working(wazuh_api: WazuhAPI) -> str: + def areDashboardNodes_working(wazuh_api: WazuhAPI) -> str: """ - Function to get the status of an agent given its name. - - Args: - - agents_data (list): List of dictioconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaanaries conaaaaa. - - agent_name (str): Name of the agent whoseconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaa status is to be obtained. - + Returns True/False depending the status of Dashboard nodes + Returns: - - str: Status of the agent if found in the daconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaconaaaaaa, otherwise returns None. + - bool: True/False depending on the status. """ - logger.error(wazuh_api.api_url) - logger.error(wazuh_api.password) - logger.error(wazuh_api.username) - response = requests.get(f"{wazuh_api.api_url}/_cat/indices/?pretty", auth=(wazuh_api.username, wazuh_api.password), verify=False) + response = requests.get(f"{wazuh_api.api_url}/api/status", auth=(wazuh_api.username, wazuh_api.password), verify=False) + result = True + if response.status_code == 200: + for status in json.loads((response.text))['status']['statuses']: + if status['state'] == 'green' or status['state'] == 'yellow': + result = True + else: + result = False + return result - return response \ No newline at end of file + else: + logger.error(f'The dashboard API returned: {response.status_code}') + + @staticmethod + def isDashboard_port_opened(inventory_path, wait=10, cycles=10): + """ + Check if dashboard port is open + + Args: + inventory_path (str): Dashboard inventory. + + Returns: + str: Os name. + """ + wait_cycles = 0 + while wait_cycles < cycles: + ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":443"').strip().split('\n') + for port in ports: + if 'ESTAB' in port or 'LISTEN' in port: + continue + else: + time.sleep(wait) + wait_cycles += 1 + break + else: + return True + return False \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/executor.py b/deployability/modules/testing/tests/helpers/executor.py index 07b1e39894..9b7279cb3d 100644 --- a/deployability/modules/testing/tests/helpers/executor.py +++ b/deployability/modules/testing/tests/helpers/executor.py @@ -60,19 +60,19 @@ def __init__(self, inventory_path, component=None): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) self._authenticate() + def _extract_password(self, file_path, keyword): + if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): + Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') + return Executor.execute_command(self.inventory_path, f"grep {keyword} {file_path} | head -n 1 | awk '{{print $NF}}'").replace("'", "").replace("\n", "") + def _authenticate(self): with open(self.inventory_path, 'r') as yaml_file: inventory_data = yaml.safe_load(yaml_file) user = 'wazuh' - - #----Patch issue https://github.com/wazuh/wazuh-packages/issues/2883------------- - file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt' - if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): - Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') - password = Executor.execute_command(self.inventory_path, "grep api_password wazuh-install-files/wazuh-passwords.txt | head -n 1 | awk '{print $NF}'").replace("'","").replace("\n","") - #-------------------------------------------------------------------------------- - + file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n", "") + '/wazuh-install-files/wazuh-passwords.txt' + password = self._extract_password(file_path, 'api_password') + login_endpoint = 'security/user/authenticate' host = inventory_data.get('ansible_host') port = '55000' @@ -90,18 +90,8 @@ def _authenticate(self): self.api_url = f'https://{host}:{port}' - if self.component == 'dashboard': - self.username = 'admin' - file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt' - if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): - Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') - self.password = Executor.execute_command(self.inventory_path, "grep indexer_password wazuh-install-files/wazuh-passwords.txt | head -n 1 | awk '{print $NF}'").replace("'","").replace("\n","") - self.api_url = f'https://localhost' - - if self.component == 'indexer': + if self.component == 'dashboard' or self.component == 'indexer': self.username = 'admin' - file_path = Executor.execute_command(self.inventory_path, 'pwd').replace("\n","") + '/wazuh-install-files/wazuh-passwords.txt' - if not 'true' in Executor.execute_command(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"'): - Executor.execute_command(self.inventory_path, 'tar -xvf wazuh-install-files.tar') - self.password = Executor.execute_command(self.inventory_path, "").replace("'","").replace("\n","") - self.api_url = f'https://localhost:9200' \ No newline at end of file + password = self._extract_password(file_path, 'indexer_password') + self.password = password + self.api_url = f'https://{host}' if self.component == 'dashboard' else f'https://127.0.0.1:9200' \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index f8475ac9eb..1c21cbdab4 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -2,15 +2,10 @@ # Created by Wazuh, Inc. . # This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2 -import requests -import socket +import time -from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT from .executor import Executor, WazuhAPI -from .generic import HostInformation, CheckFiles from modules.testing.utils import logger -from .utils import Utils - class WazuhIndexer: @@ -21,9 +16,12 @@ def get_indexer_version(inventory_path) -> str: Args: inventory_path (str): host's inventory path + + Returns: + - str: Version of the indexer. """ - return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION') + return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION').strip() @staticmethod @@ -33,6 +31,9 @@ def areIndexer_internalUsers_complete(inventory_path) -> bool: Args: inventory_path (str): host's inventory path + + Returns: + - bool: True/False depending on the status. """ users_to_check = [ @@ -49,4 +50,64 @@ def areIndexer_internalUsers_complete(inventory_path) -> bool: return False - return True \ No newline at end of file + return True + + + @staticmethod + def areIndexes_working(wazuh_api: WazuhAPI, inventory_path) -> bool: + """ + Returns True/False depending on the working status of the indexes + + Args: + inventory_path (str): host's inventory path + + Returns: + - bool: True/False depending on the status. + """ + indexes = Executor.execute_command(inventory_path, f"curl -k -u {wazuh_api.username}:{wazuh_api.password} {wazuh_api.api_url}/_cat/indices/?pretty").strip().split('\n') + for index in indexes: + if 'red' not in index: + + return True + return False + + + @staticmethod + def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: + """ + Returns True/False depending on the status of the indexer Cluster + + Args: + inventory_path (str): host's inventory path + + Returns: + - bool: True/False depending on the status. + """ + response = Executor.execute_command(inventory_path, f"curl -k -u {wazuh_api.username}:{wazuh_api.password} {wazuh_api.api_url}/_cat/health") + return 'green' in response + + + @staticmethod + def isIndexer_port_opened(inventory_path, wait=0, cycles=10): + """ + Check if indexer port is open + + Args: + inventory_path (str): Indexer inventory. + + Returns: + str: Os name. + """ + wait_cycles = 0 + while wait_cycles < cycles: + ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":9200"').strip().split('\n') + for port in ports: + if 'ESTAB' in port or 'LISTEN' in port: + continue + else: + time.sleep(wait) + wait_cycles += 1 + break + else: + return True + return False \ No newline at end of file diff --git a/deployability/modules/testing/tests/helpers/manager.py b/deployability/modules/testing/tests/helpers/manager.py index 95d15b200b..b21b12bed9 100644 --- a/deployability/modules/testing/tests/helpers/manager.py +++ b/deployability/modules/testing/tests/helpers/manager.py @@ -4,6 +4,7 @@ import requests import socket +import time from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT from .executor import Executor, WazuhAPI @@ -224,6 +225,82 @@ def assert_results(result) -> None: assert result[category][action] == [], logger.error(f'{result[category][action]} was found in: {category}{action}') + @staticmethod + def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=10) -> bool: + """ + Check if Manager API port is open + + Args: + inventory_path (str): Manager inventory. + + Returns: + bool: True if port is opened. + """ + wait_cycles = 0 + while wait_cycles < cycles: + ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":55000"').strip().split('\n') + for port in ports: + if 'ESTAB' in port or 'LISTEN' in port: + continue + else: + time.sleep(wait) + wait_cycles += 1 + break + else: + return True + return False + + @staticmethod + def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=10) -> bool: + """ + Check if Wazuh Manager Agent port is open + + Args: + inventory_path (str): Manager inventory. + + Returns: + bool: True if port is opened. + """ + wait_cycles = 0 + while wait_cycles < cycles: + ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":1514"').strip().split('\n') + for port in ports: + if 'ESTAB' in port or 'LISTEN' in port: + continue + else: + time.sleep(wait) + wait_cycles += 1 + break + else: + return True + return False + + @staticmethod + def isWazuhAgent_enrollment_port_opened(inventory_path, wait=10, cycles=10) -> bool: + """ + Check if Wazuh Manager Agent enrollment port is open + + Args: + inventory_path (str): Manager inventory. + + Returns: + bool: True if port is opened. + """ + wait_cycles = 0 + while wait_cycles < cycles: + ports = Executor.execute_command(inventory_path, 'ss -t -a -n | grep ":443"').strip().split('\n') + for port in ports: + if 'ESTAB' in port or 'LISTEN' in port: + continue + else: + time.sleep(wait) + wait_cycles += 1 + break + else: + return True + return False + + @staticmethod def get_cluster_info(inventory_path) -> None: """ diff --git a/deployability/modules/testing/tests/test_central_components/test_install.py b/deployability/modules/testing/tests/test_central_components/test_install.py index 7262eed8e2..a4147a9f42 100644 --- a/deployability/modules/testing/tests/test_central_components/test_install.py +++ b/deployability/modules/testing/tests/test_central_components/test_install.py @@ -51,22 +51,7 @@ def setup_test_environment(wazuh_params): wazuh_params['managers'] = {key: value for key, value in targets_dict.items() if key.startswith('wazuh-')} -def test_parametros(wazuh_params): - #logger.error(WazuhDashboard.get_dashboard_version(wazuh_params['dashboard'])) - #for indexer_params in wazuh_params['indexers']: - # logger.error(WazuhIndexer.get_indexer_version(indexer_params)) - - #logger.error(WazuhDashboard.isDashboard_active(wazuh_params['dashboard'])) - - - #logger.error(WazuhDashboard.isDashboardKeystore_working(wazuh_params['dashboard'])) - #for indexer_params in wazuh_params['indexers']: - # logger.error(WazuhIndexer.areIndexer_internalUsers_complete(indexer_params)) - - wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') - logger.error(WazuhDashboard.areIndexes_working(wazuh_api)) - -""" def test_installation(wazuh_params): +def test_installation(wazuh_params): # Disabling firewall for all managers for manager_name, manager_params in wazuh_params['managers'].items(): Utils.check_inventory_connection(manager_params) @@ -84,13 +69,8 @@ def test_parametros(wazuh_params): assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') -def test_component_status(wazuh_params): +def test_manager_status(wazuh_params): assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') - for indexer_params in wazuh_params['indexers']: - assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') - def test_manager_version(wazuh_params): for manager in wazuh_params['managers'].values(): @@ -111,4 +91,74 @@ def test_manager_revision(wazuh_params): def test_manager_installed_directory(wazuh_params): for manager in wazuh_params['managers'].values(): assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') - """ \ No newline at end of file + + +def test_manager_API_port(wazuh_params): + assert WazuhManager.isWazuhAPI_port_opened(wazuh_params['master']), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_manager_agent_port(wazuh_params): + assert WazuhManager.isWazuhAgent_port_opened(wazuh_params['master']), logger.error(f"The manage-agent port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_manager_agent_enrollment_port(wazuh_params): + assert WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master']), logger.error(f"The manager-enrollment port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_dashboard_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") + wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') + assert WazuhDashboard.isDashboard_active(wazuh_params['dashboard']), logger.error(f"The dashboard is not active in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + + +def test_dashboard_version(wazuh_params): + assert wazuh_params['wazuh_version'] == WazuhDashboard.get_dashboard_version(wazuh_params['dashboard']), logger.error(f"There is dismatch in dashboard version in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + + +def test_dashboard_nodes(wazuh_params): + wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') + assert WazuhDashboard.areDashboardNodes_working(wazuh_api), logger.error(f"There is a problem in a dashboard node in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + + +def test_dashboard_keystore(wazuh_params): + assert WazuhDashboard.isDashboardKeystore_working(wazuh_params['dashboard']), logger.error(f"There is a problem in the dashboard keystore in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + + +def test_dashboard_port(wazuh_params): + assert WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard']), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") + + +def test_indexer_status(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + + +def test_indexer_clusters_status(wazuh_params): + for indexer_params in wazuh_params['indexers']: + wazuh_api = WazuhAPI(indexer_params, component='indexer') + assert WazuhIndexer.isIndexCluster_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a indexer cluster in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + + +def test_indexer_indexes(wazuh_params): + for indexer_params in wazuh_params['indexers']: + wazuh_api = WazuhAPI(indexer_params, component='indexer') + assert WazuhIndexer.areIndexes_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a indexer index in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + + +def test_indexer_internalUsers(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert WazuhIndexer.areIndexer_internalUsers_complete(indexer_params), logger.error(f'There is a problem in a indexer internal user in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + + +def test_indexer_version(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert wazuh_params['wazuh_version'] == WazuhIndexer.get_indexer_version(indexer_params), logger.error(f'There is dismatch in indexer version in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + + +def test_indexer_port(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert WazuhIndexer.isIndexer_port_opened(indexer_params), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed") + + +def test_filebeat_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") diff --git a/deployability/modules/testing/tests/test_central_components/test_restart.py b/deployability/modules/testing/tests/test_central_components/test_restart.py index 2294b955f6..4a66ef2d3e 100644 --- a/deployability/modules/testing/tests/test_central_components/test_restart.py +++ b/deployability/modules/testing/tests/test_central_components/test_restart.py @@ -5,6 +5,9 @@ import pytest 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 @@ -53,8 +56,39 @@ def test_restart(wazuh_params): GeneralComponentActions.component_restart(wazuh_params['master'], 'filebeat') - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') +def test_manager_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + + +def test_dashboard_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") + + +def test_indexer_status(wazuh_params): for indexer_params in wazuh_params['indexers']: assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + + +def test_filebeat_status(wazuh_params): + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + + +def test_manager_API_port(wazuh_params): + assert WazuhManager.isWazuhAPI_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_manager_agent_port(wazuh_params): + assert WazuhManager.isWazuhAgent_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_manager_agent_enrollment_port(wazuh_params): + assert WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + + +def test_dashboard_port(wazuh_params): + assert WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard']),logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") + + +def test_indexer_port(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert WazuhIndexer.isIndexer_port_opened(indexer_params),logger.error(f'Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed') diff --git a/deployability/modules/testing/tests/test_central_components/test_stop.py b/deployability/modules/testing/tests/test_central_components/test_stop.py index 4c1552162a..8e7da4fbd0 100644 --- a/deployability/modules/testing/tests/test_central_components/test_stop.py +++ b/deployability/modules/testing/tests/test_central_components/test_stop.py @@ -5,6 +5,9 @@ import pytest 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 @@ -61,8 +64,39 @@ def test_stop(wazuh_params): GeneralComponentActions.component_stop(wazuh_params['dashboard'], 'wazuh-dashboard') GeneralComponentActions.component_stop(wazuh_params['master'], 'filebeat') - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f'The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["dashboard"])} is not active') +def test_manager_status(wazuh_params): + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + + +def test_dashboard_status(wazuh_params): + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") + + +def test_indexer_status(wazuh_params): for indexer_params in wazuh_params['indexers']: assert 'inactive' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + + +def test_filebeat_status(wazuh_params): + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + + +def test_manager_API_port(wazuh_params): + assert not WazuhManager.isWazuhAPI_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_manager_agent_port(wazuh_params): + assert not WazuhManager.isWazuhAgent_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_manager_agent_enrollment_port(wazuh_params): + assert not WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_dashboard_port(wazuh_params): + assert not WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") + + +def test_indexer_port(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert not WazuhIndexer.isIndexer_port_opened(indexer_params, cycles=1, wait=1), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") diff --git a/deployability/modules/testing/tests/test_central_components/test_uninstall.py b/deployability/modules/testing/tests/test_central_components/test_uninstall.py index ea048e7f89..c833b91418 100644 --- a/deployability/modules/testing/tests/test_central_components/test_uninstall.py +++ b/deployability/modules/testing/tests/test_central_components/test_uninstall.py @@ -7,6 +7,8 @@ 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 @@ -58,4 +60,25 @@ def test_uninstall(wazuh_params): def test_component_uninstalled_directory(wazuh_params): - assert not HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f'In {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} {WAZUH_ROOT} is still present') + assert not HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f"In {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} {WAZUH_ROOT} is still present") + + +def test_manager_API_port(wazuh_params): + assert not WazuhManager.isWazuhAPI_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_manager_agent_port(wazuh_params): + assert not WazuhManager.isWazuhAgent_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_manager_agent_enrollment_port(wazuh_params): + assert not WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + + +def test_dashboard_port(wazuh_params): + assert not WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") + + +def test_indexer_port(wazuh_params): + for indexer_params in wazuh_params['indexers']: + assert not WazuhIndexer.isIndexer_port_opened(indexer_params, cycles=1, wait=1), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") From 3992e5add61a3f4b2b3325e2f280b1ef1cb11540 Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 25 Apr 2024 18:05:12 +0200 Subject: [PATCH 4/9] enhancement(#5219): Fixing white spaces --- deployability/modules/testing/tests/helpers/central.py | 2 +- deployability/modules/testing/tests/helpers/dashboard.py | 2 +- deployability/modules/testing/tests/helpers/executor.py | 2 +- deployability/modules/testing/tests/helpers/indexer.py | 2 +- .../aws/dtt1-central_components-poc-vagrant.yaml | 2 +- .../vagrant/dtt1-central_components-poc-vagrant.yaml | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deployability/modules/testing/tests/helpers/central.py b/deployability/modules/testing/tests/helpers/central.py index 3cc37dcbbc..c5d7821532 100644 --- a/deployability/modules/testing/tests/helpers/central.py +++ b/deployability/modules/testing/tests/helpers/central.py @@ -174,4 +174,4 @@ def assert_results(result) -> None: # Testing the results for category in categories: for action in actions: - assert result[category][action] == [], logger.error(f'{result[category][action]} was found in: {category} {action}') \ No newline at end of file + assert result[category][action] == [], logger.error(f'{result[category][action]} was found in: {category} {action}') diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py index 6b13a1f609..b3161910df 100644 --- a/deployability/modules/testing/tests/helpers/dashboard.py +++ b/deployability/modules/testing/tests/helpers/dashboard.py @@ -106,4 +106,4 @@ def isDashboard_port_opened(inventory_path, wait=10, cycles=10): break else: return True - return False \ No newline at end of file + return False diff --git a/deployability/modules/testing/tests/helpers/executor.py b/deployability/modules/testing/tests/helpers/executor.py index 9b7279cb3d..f53d4871ad 100644 --- a/deployability/modules/testing/tests/helpers/executor.py +++ b/deployability/modules/testing/tests/helpers/executor.py @@ -94,4 +94,4 @@ def _authenticate(self): self.username = 'admin' password = self._extract_password(file_path, 'indexer_password') self.password = password - self.api_url = f'https://{host}' if self.component == 'dashboard' else f'https://127.0.0.1:9200' \ No newline at end of file + self.api_url = f'https://{host}' if self.component == 'dashboard' else f'https://127.0.0.1:9200' diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index 1c21cbdab4..12744cb9aa 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -110,4 +110,4 @@ def isIndexer_port_opened(inventory_path, wait=0, cycles=10): break else: return True - return False \ No newline at end of file + return False diff --git a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml index 268a7bd8da..0d02f3b3d4 100644 --- a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml @@ -66,4 +66,4 @@ tasks: on-error: "abort-all" foreach: - variable: central_components-os - as: central_components \ No newline at end of file + as: central_components diff --git a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml index d59383c00d..51d49d748a 100644 --- a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml @@ -49,7 +49,7 @@ tasks: - modules/testing/main.py - targets: - wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml" - - tests: "install" + - tests: "install,restart,stop,uninstall" - component: "central_components" - wazuh-version: "4.7.3" - wazuh-revision: "40714" @@ -57,4 +57,4 @@ tasks: on-error: "abort-all" foreach: - variable: central_components-os - as: central_components \ No newline at end of file + as: central_components From 57a71ded9b50e4cdcf11515f8067ecdeec6f58cb Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 25 Apr 2024 18:32:33 +0200 Subject: [PATCH 5/9] enhancement(#5219): Fixing wait time in indexer port scan --- deployability/modules/testing/tests/helpers/indexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index 12744cb9aa..c865098ca2 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -88,7 +88,7 @@ def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: @staticmethod - def isIndexer_port_opened(inventory_path, wait=0, cycles=10): + def isIndexer_port_opened(inventory_path, wait=10, cycles=10): """ Check if indexer port is open From d7edbac7e49d2cce13fd3078d24ac497e04abc4b Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 26 Apr 2024 11:24:22 +0200 Subject: [PATCH 6/9] enhancement(#5219): Cycles and wait adjustments --- deployability/modules/testing/tests/helpers/central.py | 2 +- deployability/modules/testing/tests/helpers/dashboard.py | 2 +- deployability/modules/testing/tests/helpers/indexer.py | 2 +- deployability/modules/testing/tests/helpers/manager.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deployability/modules/testing/tests/helpers/central.py b/deployability/modules/testing/tests/helpers/central.py index c5d7821532..331916cce2 100644 --- a/deployability/modules/testing/tests/helpers/central.py +++ b/deployability/modules/testing/tests/helpers/central.py @@ -98,7 +98,7 @@ def perform_action_and_scan(host_params, action_callback) -> dict: 'removed': ['filebeat'], 'modified': [] }, - '/root': {'added': ['trustdb.gpg', 'lesshst'], 'removed': ['filebeat'], 'modified': []}, + '/root': {'added': ['trustdb.gpg', 'lesshst', 'ssh'], 'removed': ['filebeat'], 'modified': []}, '/usr/sbin': { 'added': [ 'update-catalog', 'applygnupgdefaults', 'addgnupghome', 'install-sgmlcatalog', 'update-xmlcatalog' diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py index b3161910df..d99449284c 100644 --- a/deployability/modules/testing/tests/helpers/dashboard.py +++ b/deployability/modules/testing/tests/helpers/dashboard.py @@ -84,7 +84,7 @@ def areDashboardNodes_working(wazuh_api: WazuhAPI) -> str: logger.error(f'The dashboard API returned: {response.status_code}') @staticmethod - def isDashboard_port_opened(inventory_path, wait=10, cycles=10): + def isDashboard_port_opened(inventory_path, wait=10, cycles=50): """ Check if dashboard port is open diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index c865098ca2..5073cc7d5a 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -88,7 +88,7 @@ def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: @staticmethod - def isIndexer_port_opened(inventory_path, wait=10, cycles=10): + def isIndexer_port_opened(inventory_path, wait=10, cycles=50) -> bool: """ Check if indexer port is open diff --git a/deployability/modules/testing/tests/helpers/manager.py b/deployability/modules/testing/tests/helpers/manager.py index b21b12bed9..b7f4d7e5d1 100644 --- a/deployability/modules/testing/tests/helpers/manager.py +++ b/deployability/modules/testing/tests/helpers/manager.py @@ -226,7 +226,7 @@ def assert_results(result) -> None: @staticmethod - def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=10) -> bool: + def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=50) -> bool: """ Check if Manager API port is open @@ -251,7 +251,7 @@ def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=10) -> bool: return False @staticmethod - def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=10) -> bool: + def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=50) -> bool: """ Check if Wazuh Manager Agent port is open @@ -276,7 +276,7 @@ def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=10) -> bool: return False @staticmethod - def isWazuhAgent_enrollment_port_opened(inventory_path, wait=10, cycles=10) -> bool: + def isWazuhAgent_enrollment_port_opened(inventory_path, wait=10, cycles=50) -> bool: """ Check if Wazuh Manager Agent enrollment port is open From 8d3aa5d0be7c41bff8d5f6966ad7ba61b1bf8d6f Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 29 Apr 2024 12:54:49 +0200 Subject: [PATCH 7/9] fix(#5219): Fixing example file name after review --- ...ents-poc-vagrant.yaml => dtt1-central_components-poc-aws.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename deployability/modules/workflow_engine/examples/central_components/aws/{dtt1-central_components-poc-vagrant.yaml => dtt1-central_components-poc-aws.yaml} (100%) diff --git a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml similarity index 100% rename from deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-vagrant.yaml rename to deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml From a7cf33982b3c20fb4e7b5d2848e5000fd654ea80 Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 2 May 2024 11:12:13 +0200 Subject: [PATCH 8/9] fix(#5219): Fixes after review --- .../modules/testing/tests/helpers/central.py | 10 +++++----- .../modules/testing/tests/helpers/generic.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/deployability/modules/testing/tests/helpers/central.py b/deployability/modules/testing/tests/helpers/central.py index 331916cce2..e16a35438c 100644 --- a/deployability/modules/testing/tests/helpers/central.py +++ b/deployability/modules/testing/tests/helpers/central.py @@ -17,7 +17,7 @@ class WazuhCentralComponents: @staticmethod def install_aio(inventory_path, wazuh_version) -> None: """ - Installs Wazuh Central Components AIO in the host + Installs Wazuh central components (AIO) in the host Args: inventory_path (str): host's inventory path @@ -27,16 +27,16 @@ def install_aio(inventory_path, wazuh_version) -> None: wazuh_version = '.'.join(wazuh_version.split('.')[:2]) os_name = HostInformation.get_os_name_from_inventory(inventory_path) - if 'debian' in os_name: + if 'curl' in Executor.execute_command(inventory_path, 'which curl'): commands = [ - f"wget https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" + f"curl -sO https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" ] - else: commands = [ - f"curl -sO https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" + f"wget https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" ] + logger.info(f'Installing Wazuh AIO in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') Executor.execute_commands(inventory_path, commands) diff --git a/deployability/modules/testing/tests/helpers/generic.py b/deployability/modules/testing/tests/helpers/generic.py index 2ea82cc771..a07063935c 100644 --- a/deployability/modules/testing/tests/helpers/generic.py +++ b/deployability/modules/testing/tests/helpers/generic.py @@ -274,6 +274,18 @@ def get_client_keys(inventory_path) -> list[dict]: clients.append(client_info) return clients + @staticmethod + def has_curl(inventory_path) -> bool: + """ + Returns yes in case that curl is installed in Linux/macOS. + + Args: + inventory_path (str): host's inventory path + + Returns: + bool: True/False. + """ + return 'curl' in Executor.execute_command(inventory_path, 'which curl') class HostConfiguration: From 7c1d2270fe036e068551866cd700baa9e1b5a2ea Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 2 May 2024 12:38:07 +0200 Subject: [PATCH 9/9] fix(#5219): Fixes after review PEP 8 naming --- .../modules/testing/tests/helpers/central.py | 12 +++---- .../testing/tests/helpers/dashboard.py | 30 ++++++++-------- .../modules/testing/tests/helpers/indexer.py | 25 ++++++-------- .../modules/testing/tests/helpers/manager.py | 16 ++++----- .../test_central_components/test_install.py | 34 +++++++++---------- .../test_central_components/test_restart.py | 20 +++++------ .../test_central_components/test_stop.py | 22 ++++++------ .../test_central_components/test_uninstall.py | 12 +++---- .../agent/aws/test-agent-complete-macOs.yaml | 2 +- .../agent/aws/test-agent-complete.yaml | 2 +- .../aws/test-agent-restart-ins-prov.yaml | 2 +- .../agent/aws/test-agent-stop-ins-prov.yaml | 2 +- .../aws/test-agent-uninstall-ins-prov.yaml | 2 +- .../agent/vagrant/test-agent-complete-1.yaml | 2 +- .../agent/vagrant/test-agent-complete-2.yaml | 2 +- .../vagrant/test-agent-complete-macOs.yaml | 2 +- .../test-agent-restart-ins-prov-1.yaml | 2 +- .../test-agent-restart-ins-prov-2.yaml | 2 +- .../vagrant/test-agent-stop-ins-prov-1.yaml | 2 +- .../vagrant/test-agent-stop-ins-prov-2.yaml | 2 +- .../test-agent-uninstall-ins-prov-1.yaml | 2 +- .../test-agent-uninstall-ins-prov-2.yaml | 2 +- .../aws/dtt1-central_components-poc-aws.yaml | 2 +- .../dtt1-central_components-poc-vagrant.yaml | 2 +- 24 files changed, 100 insertions(+), 103 deletions(-) diff --git a/deployability/modules/testing/tests/helpers/central.py b/deployability/modules/testing/tests/helpers/central.py index e16a35438c..d2a7032cd4 100644 --- a/deployability/modules/testing/tests/helpers/central.py +++ b/deployability/modules/testing/tests/helpers/central.py @@ -27,7 +27,7 @@ def install_aio(inventory_path, wazuh_version) -> None: wazuh_version = '.'.join(wazuh_version.split('.')[:2]) os_name = HostInformation.get_os_name_from_inventory(inventory_path) - if 'curl' in Executor.execute_command(inventory_path, 'which curl'): + if HostInformation.has_curl(inventory_path): commands = [ f"curl -sO https://packages.wazuh.com/{wazuh_version}/wazuh-install.sh && sudo bash ./wazuh-install.sh -a --ignore-check" ] @@ -37,14 +37,14 @@ def install_aio(inventory_path, wazuh_version) -> None: ] - logger.info(f'Installing Wazuh AIO in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') + logger.info(f'Installing Wazuh central components (AIO) in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') Executor.execute_commands(inventory_path, commands) @staticmethod def uninstall_aio(inventory_path) -> None: """ - Uninstall Wazuh Central Components AIO in the host + Uninstall Wazuh Central Components (AIO) in the host Args: inventory_paths (str): hosts' inventory path @@ -52,7 +52,7 @@ def uninstall_aio(inventory_path) -> None: commands = ['bash wazuh-install.sh --uninstall --ignore-check'] - logger.info(f'Uninstalling Wazuh AIO in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') + logger.info(f'Uninstalling Wazuh central components (AIO) in {HostInformation.get_os_name_and_version_from_inventory(inventory_path)}') Executor.execute_commands(inventory_path, commands) @@ -131,7 +131,7 @@ def perform_action_and_scan(host_params, action_callback) -> dict: @staticmethod def perform_install_and_scan_for_aio(host_params, wazuh_params) -> None: """ - Coordinates the action of install the Wazuh AIO and compares the checkfiles + Coordinates the action of install the Wazuh central components (AIO) and compares the checkfiles Args: host_params (str): host parameters @@ -147,7 +147,7 @@ def perform_install_and_scan_for_aio(host_params, wazuh_params) -> None: @staticmethod def perform_uninstall_and_scan_for_aio(host_params) -> None: """ - Coordinates the action of uninstall the Wazuh AIO and compares the checkfiles + Coordinates the action of uninstall the Wazuh central components (AIO) and compares the checkfiles Args: host_params (str): host parameters diff --git a/deployability/modules/testing/tests/helpers/dashboard.py b/deployability/modules/testing/tests/helpers/dashboard.py index d99449284c..a2fab36467 100644 --- a/deployability/modules/testing/tests/helpers/dashboard.py +++ b/deployability/modules/testing/tests/helpers/dashboard.py @@ -19,52 +19,52 @@ class WazuhDashboard: @staticmethod def get_dashboard_version(inventory_path) -> str: """ - Returns dashboard version + Returns Wazuh dashboard version Args: inventory_path (str): host's inventory path Returns: - - str: Version of the dashboard. + - str: Version of the Wazuh dashboard. """ return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-dashboard/VERSION').strip() @staticmethod - def isDashboard_active(inventory_path) -> bool: + def is_dashboard_active(inventory_path) -> bool: """ - Returns True/False depending if the dashboard is active or not + Returns True/False depending if the dashboard service is active or not Args: inventory_path (str): host's inventory path Returns: - - bool: Status of the dashboard. + - bool: Status of the Wazuh dashboard service. """ return '200' in Executor.execute_command(inventory_path, 'curl -Is -k https://localhost/app/login?nextUrl=%2F | head -n 1') @staticmethod - def isDashboardKeystore_working(inventory_path) -> bool: + def is_dashboard_keystore_working(inventory_path) -> bool: """ - Returns True/False depending if the dashboard keystore is active or not + Returns True/False depending if the Wazuh dashboard keystore is active or not Args: inventory_path (str): host's inventory path Returns: - - bool: Status of the dashboard keystore. + - bool: Status of the Wazuh dashboard keystore. """ return 'No such file or directory' not in Executor.execute_command(inventory_path, '/usr/share/wazuh-dashboard/bin/opensearch-dashboards-keystore list --allow-root') @staticmethod - def areDashboardNodes_working(wazuh_api: WazuhAPI) -> str: + def are_dashboard_nodes_working(wazuh_api: WazuhAPI) -> str: """ - Returns True/False depending the status of Dashboard nodes + Returns True/False depending the status of Wazuh dashboard nodes Returns: - bool: True/False depending on the status. @@ -81,18 +81,18 @@ def areDashboardNodes_working(wazuh_api: WazuhAPI) -> str: return result else: - logger.error(f'The dashboard API returned: {response.status_code}') + logger.error(f'The Wazuh dashboard API returned: {response.status_code}') @staticmethod - def isDashboard_port_opened(inventory_path, wait=10, cycles=50): + def is_dashboard_port_open(inventory_path, wait=10, cycles=50): """ - Check if dashboard port is open + Check if the Wazuh dashboard port is open Args: - inventory_path (str): Dashboard inventory. + inventory_path (str): Wazuh dashboard inventory. Returns: - str: Os name. + str: OS name. """ wait_cycles = 0 while wait_cycles < cycles: diff --git a/deployability/modules/testing/tests/helpers/indexer.py b/deployability/modules/testing/tests/helpers/indexer.py index 5073cc7d5a..a200df027b 100644 --- a/deployability/modules/testing/tests/helpers/indexer.py +++ b/deployability/modules/testing/tests/helpers/indexer.py @@ -12,20 +12,20 @@ class WazuhIndexer: @staticmethod def get_indexer_version(inventory_path) -> str: """ - Returns indexer version + Returns the Wazuh indexer version Args: inventory_path (str): host's inventory path Returns: - - str: Version of the indexer. + - str: Version of the Wazuh indexer. """ return Executor.execute_command(inventory_path,'cat /usr/share/wazuh-indexer/VERSION').strip() @staticmethod - def areIndexer_internalUsers_complete(inventory_path) -> bool: + def are_indexer_internal_users_complete(inventory_path) -> bool: """ Returns True/False depending on the existance of all the expected internal users @@ -47,16 +47,14 @@ def areIndexer_internalUsers_complete(inventory_path) -> bool: report_of_users = Executor.execute_command(inventory_path, "cat /etc/wazuh-indexer/opensearch-security/internal_users.yml | grep '^[a-z]'") for user in users_to_check: if user not in report_of_users: - return False - return True @staticmethod - def areIndexes_working(wazuh_api: WazuhAPI, inventory_path) -> bool: + def are_indexes_working(wazuh_api: WazuhAPI, inventory_path) -> bool: """ - Returns True/False depending on the working status of the indexes + Returns True/False depending on the working status of the Wazuh indexes Args: inventory_path (str): host's inventory path @@ -67,15 +65,14 @@ def areIndexes_working(wazuh_api: WazuhAPI, inventory_path) -> bool: indexes = Executor.execute_command(inventory_path, f"curl -k -u {wazuh_api.username}:{wazuh_api.password} {wazuh_api.api_url}/_cat/indices/?pretty").strip().split('\n') for index in indexes: if 'red' not in index: - return True return False @staticmethod - def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: + def is_index_cluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: """ - Returns True/False depending on the status of the indexer Cluster + Returns True/False depending on the status of the Wazuh indexer cluster Args: inventory_path (str): host's inventory path @@ -88,15 +85,15 @@ def isIndexCluster_working(wazuh_api: WazuhAPI, inventory_path) -> bool: @staticmethod - def isIndexer_port_opened(inventory_path, wait=10, cycles=50) -> bool: + def is_indexer_port_open(inventory_path, wait=10, cycles=50) -> bool: """ - Check if indexer port is open + Check if the Wazuh indexer port is open Args: - inventory_path (str): Indexer inventory. + inventory_path (str): Wazuh indexer inventory. Returns: - str: Os name. + str: OS name. """ wait_cycles = 0 while wait_cycles < cycles: diff --git a/deployability/modules/testing/tests/helpers/manager.py b/deployability/modules/testing/tests/helpers/manager.py index b7f4d7e5d1..2863185a9f 100644 --- a/deployability/modules/testing/tests/helpers/manager.py +++ b/deployability/modules/testing/tests/helpers/manager.py @@ -226,12 +226,12 @@ def assert_results(result) -> None: @staticmethod - def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=50) -> bool: + def is_wazuh_api_port_open(inventory_path, wait=10, cycles=50) -> bool: """ - Check if Manager API port is open + Check if the Wazuh manager API port is open Args: - inventory_path (str): Manager inventory. + inventory_path (str): Wazuh manager inventory. Returns: bool: True if port is opened. @@ -251,9 +251,9 @@ def isWazuhAPI_port_opened(inventory_path, wait=10, cycles=50) -> bool: return False @staticmethod - def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=50) -> bool: + def is_wazuh_agent_port_open(inventory_path, wait=10, cycles=50) -> bool: """ - Check if Wazuh Manager Agent port is open + Check if the Wazuh manager port is open Args: inventory_path (str): Manager inventory. @@ -276,9 +276,9 @@ def isWazuhAgent_port_opened(inventory_path, wait=10, cycles=50) -> bool: return False @staticmethod - def isWazuhAgent_enrollment_port_opened(inventory_path, wait=10, cycles=50) -> bool: + def is_wazuh_agent_enrollment_port_open(inventory_path, wait=10, cycles=50) -> bool: """ - Check if Wazuh Manager Agent enrollment port is open + Check if Wazuh manager's agent enrollment port is open Args: inventory_path (str): Manager inventory. @@ -319,7 +319,7 @@ def get_cluster_info(inventory_path) -> None: @staticmethod def get_agent_control_info(inventory_path) -> None: """ - Returns the Agent information from the manager + Returns the Wazuh agent information from the Wazuh manager Args: inventory_path: host's inventory path diff --git a/deployability/modules/testing/tests/test_central_components/test_install.py b/deployability/modules/testing/tests/test_central_components/test_install.py index a4147a9f42..f3654d7617 100644 --- a/deployability/modules/testing/tests/test_central_components/test_install.py +++ b/deployability/modules/testing/tests/test_central_components/test_install.py @@ -70,7 +70,7 @@ def test_installation(wazuh_params): def test_manager_status(wazuh_params): - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f'The Wazuh manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active') def test_manager_version(wazuh_params): for manager in wazuh_params['managers'].values(): @@ -93,72 +93,72 @@ def test_manager_installed_directory(wazuh_params): assert HostInformation.dir_exists(manager, WAZUH_ROOT), logger.error(f'The {WAZUH_ROOT} is not present in {HostInformation.get_os_name_and_version_from_inventory(manager)}') -def test_manager_API_port(wazuh_params): - assert WazuhManager.isWazuhAPI_port_opened(wazuh_params['master']), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") +def test_manager_api_port(wazuh_params): + assert WazuhManager.is_wazuh_api_port_open(wazuh_params['master']), logger.error(f"The Wazuh manager's API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_manager_agent_port(wazuh_params): - assert WazuhManager.isWazuhAgent_port_opened(wazuh_params['master']), logger.error(f"The manage-agent port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + assert WazuhManager.is_wazuh_agent_port_open(wazuh_params['master']), logger.error(f"The Wazuh manager port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_manager_agent_enrollment_port(wazuh_params): - assert WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master']), logger.error(f"The manager-enrollment port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + assert WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master']), logger.error(f"The Wazuh manager agent enrollment port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_dashboard_status(wazuh_params): assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') - assert WazuhDashboard.isDashboard_active(wazuh_params['dashboard']), logger.error(f"The dashboard is not active in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + assert WazuhDashboard.is_dashboard_active(wazuh_params['dashboard']), logger.error(f"The Wazuh dashboard is not active in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") def test_dashboard_version(wazuh_params): - assert wazuh_params['wazuh_version'] == WazuhDashboard.get_dashboard_version(wazuh_params['dashboard']), logger.error(f"There is dismatch in dashboard version in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + assert wazuh_params['wazuh_version'] == WazuhDashboard.get_dashboard_version(wazuh_params['dashboard']), logger.error(f"There is dismatch in the Wazuh dashboard version in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") def test_dashboard_nodes(wazuh_params): wazuh_api = WazuhAPI(wazuh_params['dashboard'], component='dashboard') - assert WazuhDashboard.areDashboardNodes_working(wazuh_api), logger.error(f"There is a problem in a dashboard node in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + assert WazuhDashboard.are_dashboard_nodes_working(wazuh_api), logger.error(f"There is a problem in the Wazuh dashboard node in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") def test_dashboard_keystore(wazuh_params): - assert WazuhDashboard.isDashboardKeystore_working(wazuh_params['dashboard']), logger.error(f"There is a problem in the dashboard keystore in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") + assert WazuhDashboard.is_dashboard_keystore_working(wazuh_params['dashboard']), logger.error(f"There is a problem in the Wazuh dashboard keystore in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])}") def test_dashboard_port(wazuh_params): - assert WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard']), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") + assert WazuhDashboard.is_dashboard_port_open(wazuh_params['dashboard']), logger.error(f"The Wazuh dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") def test_indexer_status(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The Wazuh indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') def test_indexer_clusters_status(wazuh_params): for indexer_params in wazuh_params['indexers']: wazuh_api = WazuhAPI(indexer_params, component='indexer') - assert WazuhIndexer.isIndexCluster_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a indexer cluster in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + assert WazuhIndexer.is_index_cluster_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a Wazuh indexer cluster in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') def test_indexer_indexes(wazuh_params): for indexer_params in wazuh_params['indexers']: wazuh_api = WazuhAPI(indexer_params, component='indexer') - assert WazuhIndexer.areIndexes_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a indexer index in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + assert WazuhIndexer.are_indexes_working(wazuh_api, indexer_params), logger.error(f'There is a problem in a Wazuh indexer index in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') def test_indexer_internalUsers(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert WazuhIndexer.areIndexer_internalUsers_complete(indexer_params), logger.error(f'There is a problem in a indexer internal user in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + assert WazuhIndexer.are_indexer_internal_users_complete(indexer_params), logger.error(f'There is a problem in a Wazuh indexer internal user in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') def test_indexer_version(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert wazuh_params['wazuh_version'] == WazuhIndexer.get_indexer_version(indexer_params), logger.error(f'There is dismatch in indexer version in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') + assert wazuh_params['wazuh_version'] == WazuhIndexer.get_indexer_version(indexer_params), logger.error(f'There is dismatch in Wazuh indexer version in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)}') def test_indexer_port(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert WazuhIndexer.isIndexer_port_opened(indexer_params), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed") + assert WazuhIndexer.is_indexer_port_open(indexer_params), logger.error(f"Some Wazuh indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed") def test_filebeat_status(wazuh_params): - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The Filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") diff --git a/deployability/modules/testing/tests/test_central_components/test_restart.py b/deployability/modules/testing/tests/test_central_components/test_restart.py index 4a66ef2d3e..0400043b31 100644 --- a/deployability/modules/testing/tests/test_central_components/test_restart.py +++ b/deployability/modules/testing/tests/test_central_components/test_restart.py @@ -57,38 +57,38 @@ def test_restart(wazuh_params): def test_manager_status(wazuh_params): - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The Wazuh manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") def test_dashboard_status(wazuh_params): - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The Wazuh dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") def test_indexer_status(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The Wazuh indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') def test_filebeat_status(wazuh_params): - assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The Filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") -def test_manager_API_port(wazuh_params): - assert WazuhManager.isWazuhAPI_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") +def test_manager_api_port(wazuh_params): + assert WazuhManager.is_wazuh_api_port_open(wazuh_params['master']),logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_manager_agent_port(wazuh_params): - assert WazuhManager.isWazuhAgent_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + assert WazuhManager.is_wazuh_agent_port_open(wazuh_params['master']),logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_manager_agent_enrollment_port(wazuh_params): - assert WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master']),logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") + assert WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master']),logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is closed") def test_dashboard_port(wazuh_params): - assert WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard']),logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") + assert WazuhDashboard.is_dashboard_port_open(wazuh_params['dashboard']),logger.error(f"The Wazuh dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is closed") def test_indexer_port(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert WazuhIndexer.isIndexer_port_opened(indexer_params),logger.error(f'Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed') + assert WazuhIndexer.is_indexer_port_open(indexer_params),logger.error(f'Some Wazuh indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is closed') diff --git a/deployability/modules/testing/tests/test_central_components/test_stop.py b/deployability/modules/testing/tests/test_central_components/test_stop.py index 8e7da4fbd0..218dbbb762 100644 --- a/deployability/modules/testing/tests/test_central_components/test_stop.py +++ b/deployability/modules/testing/tests/test_central_components/test_stop.py @@ -25,7 +25,7 @@ def wazuh_params(request): 'targets': targets } yield params - logger.info('Restoring Central Component status') + logger.info('Restoring Wazuh central components statuses') GeneralComponentActions.component_restart(params['master'], 'wazuh-manager') for indexer_params in params['indexers']: @@ -65,38 +65,38 @@ def test_stop(wazuh_params): GeneralComponentActions.component_stop(wazuh_params['master'], 'filebeat') def test_manager_status(wazuh_params): - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'wazuh-manager'), logger.error(f"The Wazuh manager in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") def test_dashboard_status(wazuh_params): - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['dashboard'], 'wazuh-dashboard'), logger.error(f"The Wazuh dashboard in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is not active") def test_indexer_status(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert 'inactive' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') + assert 'inactive' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The Wazuh indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active') def test_filebeat_status(wazuh_params): - assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") + assert 'inactive' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f"The Filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is not active") -def test_manager_API_port(wazuh_params): - assert not WazuhManager.isWazuhAPI_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") +def test_manager_api_port(wazuh_params): + assert not WazuhManager.is_wazuh_api_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_manager_agent_port(wazuh_params): - assert not WazuhManager.isWazuhAgent_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + assert not WazuhManager.is_wazuh_agent_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_manager_agent_enrollment_port(wazuh_params): - assert not WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + assert not WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_dashboard_port(wazuh_params): - assert not WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") + assert not WazuhDashboard.is_dashboard_port_open(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The Wazuh dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") def test_indexer_port(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert not WazuhIndexer.isIndexer_port_opened(indexer_params, cycles=1, wait=1), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") + assert not WazuhIndexer.is_indexer_port_open(indexer_params, cycles=1, wait=1), logger.error(f"Some Wazuh indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") diff --git a/deployability/modules/testing/tests/test_central_components/test_uninstall.py b/deployability/modules/testing/tests/test_central_components/test_uninstall.py index c833b91418..5d5370533b 100644 --- a/deployability/modules/testing/tests/test_central_components/test_uninstall.py +++ b/deployability/modules/testing/tests/test_central_components/test_uninstall.py @@ -63,22 +63,22 @@ def test_component_uninstalled_directory(wazuh_params): assert not HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f"In {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} {WAZUH_ROOT} is still present") -def test_manager_API_port(wazuh_params): - assert not WazuhManager.isWazuhAPI_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") +def test_manager_api_port(wazuh_params): + assert not WazuhManager.is_wazuh_api_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_manager_agent_port(wazuh_params): - assert not WazuhManager.isWazuhAgent_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + assert not WazuhManager.is_wazuh_agent_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_manager_agent_enrollment_port(wazuh_params): - assert not WazuhManager.isWazuhAgent_enrollment_port_opened(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") + assert not WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active") def test_dashboard_port(wazuh_params): - assert not WazuhDashboard.isDashboard_port_opened(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") + assert not WazuhDashboard.is_dashboard_port_open(wazuh_params['dashboard'], cycles=1, wait=1), logger.error(f"The Wazuh dashboard port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['dashboard'])} is still active") def test_indexer_port(wazuh_params): for indexer_params in wazuh_params['indexers']: - assert not WazuhIndexer.isIndexer_port_opened(indexer_params, cycles=1, wait=1), logger.error(f"Some indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") + assert not WazuhIndexer.is_indexer_port_open(indexer_params, cycles=1, wait=1), logger.error(f"Some Wazuh indexer port in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is still active") diff --git a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete-macOs.yaml b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete-macOs.yaml index 2ae2d26e5f..1db2fb91cc 100755 --- a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete-macOs.yaml +++ b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete-macOs.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test agents' deployment for DDT1 PoC +description: This workflow is used to test agents deployment for DDT1 PoC variables: agent-os: # Run one at a time as there are limitations on the number of hosts (Inform @dev-devops-team about your usage, dedicated hosts) diff --git a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete.yaml b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete.yaml index d9d581b111..8c21f1e8f4 100755 --- a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete.yaml +++ b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-complete.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test agents' deployment for DDT1 PoC +description: This workflow is used to test agents deployment for DDT1 PoC variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-restart-ins-prov.yaml b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-restart-ins-prov.yaml index b7002c02c6..cd12531247 100755 --- a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-restart-ins-prov.yaml +++ b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-restart-ins-prov.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent restart with provisioning agents' with provision module +description: Test agent restart with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-stop-ins-prov.yaml b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-stop-ins-prov.yaml index 0e97045f32..c01800b3f5 100755 --- a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-stop-ins-prov.yaml +++ b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-stop-ins-prov.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent restart with provisioning agents' with provision module +description: Test agent restart with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-uninstall-ins-prov.yaml b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-uninstall-ins-prov.yaml index 90c6145862..4cc042b41e 100755 --- a/deployability/modules/workflow_engine/examples/agent/aws/test-agent-uninstall-ins-prov.yaml +++ b/deployability/modules/workflow_engine/examples/agent/aws/test-agent-uninstall-ins-prov.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent restart with provisioning agents' with provision module +description: Test agent restart with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-1.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-1.yaml index 0d1780775e..1b10763219 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-1.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-1.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test agents' deployment for DDT1 PoC +description: This workflow is used to test agents deployment for DDT1 PoC variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-2.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-2.yaml index 2af6a19463..db0299dbb1 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-2.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-2.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test agents' deployment for DDT1 PoC +description: This workflow is used to test agents deployment for DDT1 PoC variables: agent-os: - linux-centos-7-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-macOs.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-macOs.yaml index d1e35d3e71..e5dbe718c9 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-macOs.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-complete-macOs.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test agents' deployment for DDT1 PoC +description: This workflow is used to test agents deployment for DDT1 PoC variables: agent-os: # Run one at a time as there are limitations on the number of hosts diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-1.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-1.yaml index dea050edb9..7a41aa7c4f 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-1.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-1.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent restart with provisioning agents' with provision module +description: Test agent restart with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-2.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-2.yaml index 7b7a3b03f0..7c36f9c872 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-2.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-restart-ins-prov-2.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent restart with provisioning agents' with provision module +description: Test agent restart with provisioning agents with provision module variables: agent-os: - linux-centos-7-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-1.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-1.yaml index 8a7c959ca4..1f2330125b 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-1.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-1.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent stop with provisioning agents' with provision module +description: Test agent stop with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-2.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-2.yaml index 1e58fd2593..b09c24c05e 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-2.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-stop-ins-prov-2.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent stop with provisioning agents' with provision module +description: Test agent stop with provisioning agents with provision module variables: agent-os: - linux-centos-7-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-1.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-1.yaml index 91e83fdce7..cb2dff4cb3 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-1.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-1.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent uninstall with provisioning agents' with provision module +description: Test agent uninstall with provisioning agents with provision module variables: agent-os: - linux-ubuntu-18.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-2.yaml b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-2.yaml index 13a7db7c09..be28e87d6b 100755 --- a/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-2.yaml +++ b/deployability/modules/workflow_engine/examples/agent/vagrant/test-agent-uninstall-ins-prov-2.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: Test agent uninstall with provisioning agents' with provision module +description: Test agent uninstall with provisioning agents with provision module variables: agent-os: - linux-centos-7-amd64 diff --git a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml index 0d02f3b3d4..4f210e8b92 100644 --- a/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/aws/dtt1-central_components-poc-aws.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test manager deployment for DDT1 PoC +description: This workflow is used to test the Wazuh manager deployment for DDT1 PoC variables: central_components-os: - linux-ubuntu-20.04-amd64 diff --git a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml index 51d49d748a..165032ca53 100644 --- a/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml +++ b/deployability/modules/workflow_engine/examples/central_components/vagrant/dtt1-central_components-poc-vagrant.yaml @@ -1,5 +1,5 @@ version: 0.1 -description: This workflow is used to test manager deployment for DDT1 PoC +description: This workflow is used to test the Wazuh manager deployment for DDT1 PoC variables: central_components-os: - linux-ubuntu-20.04-amd64