Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking the agent status in wazuh-manager when it is closed gracefullyv2 #4146

Merged
merged 22 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
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)

### Changed

- Enable Ubuntu Vulnerability Detector E2E. ([#4252](https://github.com/wazuh/wazuh-qa/pull/4252)) \- (Tests)
Expand Down
70 changes: 35 additions & 35 deletions deps/wazuh_testing/wazuh_testing/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
'''
copyright: Copyright (C) 2015-2023, Wazuh Inc.
Created by Wazuh, Inc. <info@wazuh.com>.
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. <info@wazuh.com>.
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
4 changes: 4 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
89 changes: 89 additions & 0 deletions tests/system/test_shutdown_message/test_shutdown_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'''
copyright: Copyright (C) 2015-2023, Wazuh Inc.
Created by Wazuh, Inc. <info@wazuh.com>.
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