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) - Agent never_connected connects - default group #2665

Merged
merged 19 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 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
1 change: 1 addition & 0 deletions tests/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AGENT_STATUS_NEVER_CONNECTED = 'never_connected'
AGENT_STATUS_DISCONNECTED = 'disconnected'
AGENT_NO_GROUPS = 'Null'
AGENT_GROUPS_DEFAULT = 'default'



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""
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: Verify that the agent connects correctly to the cluster and that when it has no specific
configuration, the agent belongs to the default group.
.
tier: 0
modules:
- cluster
components:
- manager
- agent
path: /tests/system/test_cluster/test_agent_groups/test_agent_groups_default.py
Deblintrake09 marked this conversation as resolved.
Show resolved Hide resolved
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/2505
tags:
- cluster
"""
import os
import time

import pytest
Deblintrake09 marked this conversation as resolved.
Show resolved Hide resolved

from socket import timeout
from system.test_cluster.test_agent_groups.common import register_agent
from wazuh_testing.tools import WAZUH_PATH
from wazuh_testing.tools.system import HostManager
from system import (AGENT_NO_GROUPS, AGENT_STATUS_ACTIVE, AGENT_STATUS_NEVER_CONNECTED, AGENT_GROUPS_DEFAULT,
check_agent_groups, check_agent_status, restart_cluster, check_keys_file)


# Hosts
test_infra_managers = ["wazuh-master", "wazuh-worker1", "wazuh-worker2"]
test_infra_agents = ["wazuh-agent1"]

inventory_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
'provisioning', 'enrollment_cluster', 'inventory.yml')
host_manager = HostManager(inventory_path)
local_path = os.path.dirname(os.path.abspath(__file__))
tmp_path = os.path.join(local_path, 'tmp')
timeout = 5

# 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_target", test_infra_managers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is agent_target not a list and contains test_infra_manager?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parametrize requires a list of values, and test_infra_managers is a list of all manager hosts, so it is passed that way, not inside a list.

def test_agent_default_group(agent_target, clean_environment, test_infra_managers, test_infra_agents, host_manager):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the module name and the path with the new module name. Ex: test_agent_added_the_default_group.

Also, when you change it, you should change the path in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed name to test_agent_default_group_added.
Did not add to path in documentation since it was removed as requested

'''
description: Check agent enrollment process and default group assignment works as expected in a cluster enviroment.
An agent pointing to a master/worker node is registered using cli tool, and it gets assigned the default group
after it is restarted.
wazuh_min_version: 4.4.0
parameters:
- agent_target:
type: string
brief: name of the host where the agent will register
- clean_cluster_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_managers
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 the agent key file exists in all nodes.
- Verify that after registering the agent appears as never_connected in all nodes.
- Verify that after registering and before starting the agent, it has no groups assigned.
- Verify that after registering the agent appears as active in all nodes.
- Verify that after registering and after starting the agent, it has the default group assigned.
expected_output:
- f"{agent_id} {agent_name} {agent_ip} never_connected"
- f'{agent_id} {agent_name} {agent_ip} active'
Deblintrake09 marked this conversation as resolved.
Show resolved Hide resolved
'''

agent_ip, agent_id, agent_name, manager_ip = register_agent(test_infra_agents[0],agent_target, host_manager)
Deblintrake09 marked this conversation as resolved.
Show resolved Hide resolved


# Check that agent status is never-connected in cluster
time.sleep(timeout)
check_agent_status(agent_id, agent_name, agent_ip, AGENT_STATUS_NEVER_CONNECTED, host_manager, test_infra_managers)


Deblintrake09 marked this conversation as resolved.
Show resolved Hide resolved
# Check that agent has no group assigned
check_agent_groups(agent_id, AGENT_NO_GROUPS, test_infra_managers, host_manager)

# Check that agent has client key file
for host in test_infra_agents + test_infra_managers:
assert check_keys_file(host, host_manager)

# Start the enrollment process by restarting cluster
restart_cluster(test_infra_agents, host_manager)
time.sleep(timeout)

# Check if the agent is active in master and workers
check_agent_status(agent_id, agent_name, agent_ip, AGENT_STATUS_ACTIVE, host_manager, test_infra_managers)

# Check that agent has group set to default
check_agent_groups(agent_id, AGENT_GROUPS_DEFAULT, test_infra_managers, host_manager)