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

System Test: Module (WAZUH-DB) - Sync of agents registered on nodes after seconds #2761

Merged
merged 9 commits into from
Apr 11, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Release report: TBD

### Added

- Add System test cluster sync group with 40 agents ([#2761](https:/wazuh/wazuh-qa/pull/2761))
- Add System test - 40 agents cluster syncs group ([#2764](https:/wazuh/wazuh-qa/pull/2764))
- Add `qa-docs` `v0.1`([#2649](https:/wazuh/wazuh-qa/pull/2649))
- Add `qa-ctl` `v0.3.1`([#2649](https:/wazuh/wazuh-qa/pull/2649))
Expand Down
1 change: 1 addition & 0 deletions tests/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def check_agent_groups(agent_id, group_to_check, hosts_list, host_manager):
assert group_to_check in group_data, f"Did not recieve expected agent group: {group_to_check} in data \
{str(group_data)}"


# Check the expected group is in the group data for the agent in db
def check_agent_groups_db(query, group_to_check, host, host_manager):
group_data = host_manager.run_command(host, f"python3 {WAZUH_PATH}/bin/wdb-query.py global \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
'''
copyright: Copyright (C) 2015-2022, Wazuh Inc.
Created by Wazuh, Inc. <[email protected]>.
This program is free software; you can redistribute it and/or modify it under the terms of GPLv2
type: system
brief: These tests check that when a cluster has a series of agents registered and connecting one after the other,
and it is unable to do a Sync, that after a expected time, a Sync is forced and the DB is Synched.
tier: 2
modules:
- cluster
components:
- manager
- agent
daemons:
- wazuh-db
- wazuh-clusterd
os_platform:
- linux
os_version:
- Arch Linux
- Amazon Linux 2
- Amazon Linux 1
- CentOS 8
- CentOS 7
- CentOS 6
- Ubuntu Focal
- Ubuntu Bionic
- Ubuntu Xenial
- Ubuntu Trusty
- Debian Buster
- Debian Stretch
- Debian Jessie
- Debian Wheezy
- Red Hat 8
- Red Hat 7
- Red Hat 6
references:
- https:/wazuh/wazuh-qa/issues/2514
tags:
- wazuh-db
'''
import os
import time

import pytest
from wazuh_testing.tools import WAZUH_PATH
from wazuh_testing.tools.system import HostManager
from system import check_agent_groups
from system.test_cluster.test_agent_groups.common import register_agent


# Hosts
test_infra_managers = ["wazuh-master", "wazuh-worker1", "wazuh-worker2"]
agents_in_cluster = 40
test_infra_agents = []
for x in range(agents_in_cluster):
test_infra_agents.append("wazuh-agent" + str(x+1))

inventory_path = os.path.join(os.path.dirname(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__))
test_time = 800
sync_delay = 40


# Tests
@pytest.mark.parametrize("test_infra_managers", [test_infra_managers])
@pytest.mark.parametrize("test_infra_agents", [test_infra_agents])
@pytest.mark.parametrize("host_manager", [host_manager])
@pytest.mark.parametrize("agent_host", test_infra_managers[0:2])
def test_agent_groups_sync_default(agent_host, clean_environment, test_infra_managers, test_infra_agents,
host_manager):
'''
description: Check that after a long time when the manager has been unable to synchronize de databases, because
new agents are being continually added, database synchronization is forced and the expected information is in
all nodes after the expected sync time. For this, an agent is restarted and connects to the agent every roughly 10
seconds, during 400 seconds. After all agents have been registered, it is checked that the wazuhDB has been synched
in all the cluster nodes.
wazuh_min_version: 4.4.0
parameters:
CamiRomero marked this conversation as resolved.
Show resolved Hide resolved
- agent_host:
type: List
brief: Name of the host where the agent will register in each case.
- clean_enviroment:
type: Fixture
brief: Reset the wazuh log files at the start of the test. Remove all registered agents from master.
- test_infra_managers
type: List
brief: List of manager hosts in enviroment.
- test_infra_agents
type: List
brief: List of agent hosts in enviroment.
- host_manager
type: HostManager object
brief: Handles connection the enviroment's hosts.
assertions:
- Verify that after registering and after starting the agent, the agent has the default group is assigned.
- Assert that all Agents have been restarted
expected_output:
- The 'Agent_name' with ID 'Agent_id' belongs to groups: 'group_name'.
'''

# Register agents in manager
agent_data = []
for index, agent in enumerate(test_infra_agents):
data = register_agent(agent, agent_host, host_manager)
agent_data.append(data)

# get the time before all the process is started
end_time = time.time() + test_time
active_agent = 0
while time.time() < end_time:
if active_agent < agents_in_cluster:
host_manager.run_command(test_infra_agents[active_agent], f'{WAZUH_PATH}/bin/wazuh-control start')
active_agent = active_agent + 1

assert active_agent == agents_in_cluster, f"Unable to restart all agents in the expected time. \
Agents restarted: {active_agent}"

time.sleep(sync_delay)

# Check that agent has the expected group assigned in all nodes
for agent in agent_data:
check_agent_groups(agent[1], "default", test_infra_managers, host_manager)