diff --git a/CHANGELOG.md b/CHANGELOG.md index 9175b3c866..901fbf6dc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,11 @@ Wazuh commit: TBD \ Release report: TBD ### Added + +- Added tests for checking agent status upon ungraceful closure.([#4146](https://github.com/wazuh/wazuh-qa/pull/4146)) \- (Tests) - Agent syncronization testing after group deleting ([#3953](https://github.com/wazuh/wazuh-qa/pull/4143)) \- (Tests) + ### Changed - Enable Ubuntu Vulnerability Detector E2E. ([#4252](https://github.com/wazuh/wazuh-qa/pull/4252)) \- (Tests) diff --git a/deps/wazuh_testing/wazuh_testing/modules/__init__.py b/deps/wazuh_testing/wazuh_testing/modules/__init__.py index 85d695795d..acff152f70 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/modules/__init__.py @@ -1,35 +1,35 @@ -''' -copyright: Copyright (C) 2015-2023, Wazuh Inc. - Created by Wazuh, Inc. . - This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 -''' -import pytest - -# Services Variables -WAZUH_SERVICES_STOPPED = 'stopped' -WAZUH_SERVICE_PREFIX = 'wazuh' -WAZUH_SERVICES_STOP = 'stop' -WAZUH_SERVICES_START = 'start' - -# Configurations -DATA = 'data' -WAZUH_LOG_MONITOR = 'wazuh_log_monitor' - -# Marks Executions - -TIER0 = pytest.mark.tier(level=0) -TIER1 = pytest.mark.tier(level=1) -TIER2 = pytest.mark.tier(level=2) - -WINDOWS = pytest.mark.win32 -LINUX = pytest.mark.linux -MACOS = pytest.mark.darwin -SOLARIS = pytest.mark.sunos5 - -AGENT = pytest.mark.agent -SERVER = pytest.mark.server - -# Local internal options -WINDOWS_DEBUG = 'windows.debug' -SYSCHECK_DEBUG = 'syscheck.debug' -VERBOSE_DEBUG_OUTPUT = 2 +''' +copyright: Copyright (C) 2015-2023, Wazuh Inc. + Created by Wazuh, Inc. . + This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 +''' +import pytest + +# Services Variables +WAZUH_SERVICES_STOPPED = 'stopped' +WAZUH_SERVICE_PREFIX = 'wazuh' +WAZUH_SERVICES_STOP = 'stop' +WAZUH_SERVICES_START = 'start' + +# Configurations +DATA = 'data' +WAZUH_LOG_MONITOR = 'wazuh_log_monitor' + +# Marks Executions + +TIER0 = pytest.mark.tier(level=0) +TIER1 = pytest.mark.tier(level=1) +TIER2 = pytest.mark.tier(level=2) + +WINDOWS = pytest.mark.win32 +LINUX = pytest.mark.linux +MACOS = pytest.mark.darwin +SOLARIS = pytest.mark.sunos5 + +AGENT = pytest.mark.agent +SERVER = pytest.mark.server + +# Local internal options +WINDOWS_DEBUG = 'windows.debug' +SYSCHECK_DEBUG = 'syscheck.debug' +VERBOSE_DEBUG_OUTPUT = 2 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 70833dac78..08f69dbdcf 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -21,6 +21,10 @@ from wazuh_testing.logcollector import create_file_structure, delete_file_structure from wazuh_testing.tools import (PREFIX, LOG_FILE_PATH, WAZUH_CONF, get_service, ALERT_FILE_PATH, WAZUH_LOCAL_INTERNAL_OPTIONS, AGENT_CONF, AGENT_INFO_SOCKET_PATH) +from wazuh_testing.tools import ALERT_FILE_PATH, LOG_FILE_PATH, WAZUH_CONF, WAZUH_LOCAL_INTERNAL_OPTIONS, get_service +from wazuh_testing.tools import (PREFIX, LOG_FILE_PATH, WAZUH_CONF, get_service, ALERT_FILE_PATH, + WAZUH_LOCAL_INTERNAL_OPTIONS) +from wazuh_testing.tools.configuration import get_minimal_configuration, get_wazuh_conf, write_wazuh_conf from wazuh_testing.tools.file import (truncate_file, recursive_directory_creation, remove_file, copy, write_file, delete_path_recursively) from wazuh_testing.tools.monitoring import FileMonitor, QueueMonitor, SocketController, close_sockets diff --git a/tests/system/README.md b/tests/system/README.md index b5dcfad825..075376100f 100644 --- a/tests/system/README.md +++ b/tests/system/README.md @@ -134,6 +134,7 @@ required an specific testing environment located in `wazuh-qa/tests/system/provi | test_cluster/test_agent_groups/test_assign_groups_guess | enrollment_cluster | | test_cluster/test_agent_groups/test_groups_sync_default | big_cluster_40_agents | | test_cluster/test_agent_groups/test_groups_sync_time | big_cluster_40_agents | +| test_shutdown_message/test_shutdown_message | big_cluster_40_agents | ### Test structure diff --git a/tests/system/test_shutdown_message/test_shutdown_message.py b/tests/system/test_shutdown_message/test_shutdown_message.py new file mode 100644 index 0000000000..9c1903d80e --- /dev/null +++ b/tests/system/test_shutdown_message/test_shutdown_message.py @@ -0,0 +1,89 @@ +''' +copyright: Copyright (C) 2015-2023, Wazuh Inc. + Created by Wazuh, Inc. . + This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 +type: system +brief: sys +tier: 0 +modules: + - enrollment +components: + - manager + - agent +daemons: + - wazuh-authd + - wazuh-agentd +os_platform: + - linux +os_version: + - Debian Buster +references: + - https://documentation.wazuh.com/current/user-manual/registering/agent-enrollment.html +''' + +import os +import pytest +import re +import time +from wazuh_testing import T_1, T_3 +from wazuh_testing.tools import WAZUH_PATH +from wazuh_testing.tools.system import HostManager +from system import restart_cluster + +inventory_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + 'provisioning', 'big_cluster_40_agents', 'inventory.yml') +host_manager = HostManager(inventory_path) +local_path = os.path.dirname(os.path.abspath(__file__)) +agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', + 'provisioning', 'big_cluster_40_agents', 'roles', 'agent-role', 'files', 'ossec.conf') + +testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2'] +workers = ['wazuh-worker1', 'wazuh-worker2'] +agents = [] +number_agents = 40 +for number_agent in range(number_agents): + agents.append(f'wazuh-agent{number_agent+1}') + +pytestmark = [pytest.mark.cluster, pytest.mark.big_cluster_40_agents_env] + + +@pytest.fixture() +def restart_all_agents(): + restart_cluster(testinfra_hosts + agents, host_manager) + time.sleep(T_1) + + yield + restart_cluster(testinfra_hosts + agents, host_manager) + + +@pytest.fixture() +def stop_gracefully_all_agents(): + for agent in agents: + host_manager.run_command(agent, f'{WAZUH_PATH}/bin/wazuh-control stop') + + +def test_shut_down_message_gracefully_stopped_agent(restart_all_agents, stop_gracefully_all_agents): + ''' + description: Checking shutdown message when socket is closed. + wazuh_min_version: 4.6.0 + parameters: + - restart_all_agents: + type: function + brief: Restart all the agents to manipulate them after. + - stop_gracefully_all_agents: + type: function + brief: Stop agents gracefully + assertions: + - Verify that all agents status became 'Disconnected' after gracefully shutdown. + + input_description: Different use cases are found in the test module and include parameters. + + expected_output: + - Gracefully closed, it is expected to find agents 'Disconected' in agent-manager + ''' + time.sleep(T_3) + + matches = re.findall(r"Disconnected", host_manager.run_command(testinfra_hosts[0], + f'{WAZUH_PATH}/bin/agent_control -l')) + + assert len(matches) == number_agents