Skip to content

Commit

Permalink
Change after review
Browse files Browse the repository at this point in the history
  • Loading branch information
yanazaeva committed Dec 10, 2021
1 parent bc71c05 commit bca0a10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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.
Expand Down

0 comments on commit bca0a10

Please sign in to comment.