-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
tests/system/test_cluster/test_agent_files_deletion/data/messages_restart.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
wazuh-master: | ||
- regex: ".*Agent key generated for agent.*" | ||
path: "/var/ossec/logs/ossec.log" | ||
timeout: 60 | ||
- regex: '.*Worker wazuh-worker1.*Integrity check.*Finished in.*' | ||
path: "/var/ossec/logs/cluster.log" | ||
timeout: 60 | ||
- regex: '.*Worker wazuh-worker2.*Integrity check.*Finished in.*' | ||
path: "/var/ossec/logs/cluster.log" | ||
timeout: 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,22 @@ | |
# Created by Wazuh, Inc. <[email protected]>. | ||
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
|
||
import os | ||
from os.path import join, dirname, abspath | ||
from time import sleep | ||
|
||
import pytest | ||
|
||
from wazuh_testing.tools import WAZUH_PATH | ||
from wazuh_testing.tools import WAZUH_PATH, WAZUH_LOGS_PATH | ||
from wazuh_testing.tools.monitoring import HostMonitor | ||
from wazuh_testing.tools.system import HostManager | ||
|
||
master_host = 'wazuh-master' | ||
worker_host = 'wazuh-worker2' | ||
agent_host = 'wazuh-agent3' | ||
local_path = os.path.dirname(os.path.abspath(__file__)) | ||
restart_messages_path = os.path.join(local_path, 'data/messages_restart.yml') | ||
integrity_messages_path = os.path.join(local_path, 'data/messages_integrity.yml') | ||
tmp_path = os.path.join(local_path, 'tmp') | ||
managers_hosts = [master_host, worker_host] | ||
inventory_path = join(dirname(dirname(dirname(abspath(__file__)))), 'provisioning', 'basic_cluster', 'inventory.yml') | ||
host_manager = HostManager(inventory_path) | ||
|
@@ -32,11 +37,18 @@ def register_agent(): | |
"""Restart the removed agent to trigger auto-enrollment.""" | ||
yield | ||
host_manager.get_host(agent_host).ansible('command', f'service wazuh-agent restart', check=False) | ||
sleep(15) | ||
|
||
# Wait until the agent is reconnected | ||
HostMonitor(inventory_path=inventory_path, messages_path=restart_messages_path, tmp_path=tmp_path).run() | ||
|
||
|
||
def test_agent_files_deletion(register_agent): | ||
"""Check that when an agent is deleted, all its related files in managers are also removed.""" | ||
# Clean ossec.log and cluster.log | ||
host_manager.clear_file(host='wazuh-master', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log')) | ||
host_manager.clear_file(host='wazuh-master', file_path=os.path.join(WAZUH_LOGS_PATH, 'cluster.log')) | ||
host_manager.control_service(host='wazuh-master', service='wazuh', state="restarted") | ||
|
||
# Get the current ID and name of the agent that is reporting to worker_host. | ||
master_token = host_manager.get_api_token(master_host) | ||
response = host_manager.make_api_call(host=master_host, method='GET', token=master_token, | ||
|
@@ -59,7 +71,6 @@ def test_agent_files_deletion(register_agent): | |
f'{file["path"].format(id=agent_id, name=agent_name)}' | ||
|
||
# Check that agent information exists in global.db | ||
sleep(time_to_sync) | ||
for host in managers_hosts: | ||
for query in db_queries: | ||
result = host_manager.run_command( | ||
|
@@ -74,6 +85,7 @@ def test_agent_files_deletion(register_agent): | |
assert response['status'] == 200, f'Failed when trying to remove agent {agent_id}: {response}' | ||
|
||
# Wait until information is synced to all workers | ||
HostMonitor(inventory_path=inventory_path, messages_path=integrity_messages_path, tmp_path=tmp_path).run() | ||
sleep(time_to_sync) | ||
|
||
# Check that agent-related files where removed from each node. | ||
|