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

Clean environment between basic_cluster tests #4656

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@
timeout = 10


# Fixtures
@pytest.fixture(scope='module')
def delete_group():
yield
master_token = host_manager.get_api_token(test_infra_managers[0])
# Remove groups
host_manager.make_api_call(host=test_infra_managers[0], method='DELETE', token=master_token,
endpoint=f"/groups?groups_list={agent_groups}")


# Tests
@pytest.mark.parametrize("agent_host", test_infra_managers[0:2])
def test_sync_when_forced_to_change_a_group(agent_host, clean_environment):
def test_sync_when_forced_to_change_a_group(agent_host, clean_environment, delete_group):
'''
description: Check that having an agent with a group assigned,
when the change is forced with a wdb command, the new group
Expand Down Expand Up @@ -119,7 +129,7 @@ def test_sync_when_forced_to_change_a_group(agent_host, clean_environment):


# Tests
def test_force_group_change_during_sync(clean_environment):
def test_force_group_change_during_sync(clean_environment, delete_group):
'''
description: Check that having an agent with a group assigned, when the change is forced with a wdb command,
and the agent's group is changed again during the sync timeframe, the agent has the correct group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Hosts
testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2']
test_infra_agents = ['wazuh-agent2', 'wazuh-agent3']
master_host = 'wazuh-master'

inventory_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
Expand Down Expand Up @@ -54,8 +55,9 @@ def clean_cluster_logs():
# Its required to restart each node after clearing the log files
host_manager.get_host(host).ansible('command', 'service wazuh-manager restart', check=False)

host_manager.clear_file(host='wazuh-agent3', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
host_manager.get_host('wazuh-agent3').ansible('command', 'service wazuh-agent restart', check=False)
for agent in test_infra_agents:
host_manager.clear_file(host=agent, file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
host_manager.get_host(agent).ansible('command', 'service wazuh-agent restart', check=False)


@pytest.fixture(scope='function')
Expand Down
77 changes: 77 additions & 0 deletions tests/system/test_cluster/test_agent_key_polling/data/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
wazuh-master:
description: Enable remoted key_request at master side
sections:
- section: remote
elements:
- connection:
value: secure
- port:
value: 1514
- protocol:
value: tcp
- queue_size:
value: 131072
- section: auth
elements:
- disabled:
value: 'no'
- port:
value: 1515
- use_source_ip:
value: 'yes'
- force_insert:
value: 'yes'
- force_time:
value: 0
- purge:
value: 'yes'
- use_password:
value: 'no'
- limit_maxagents:
value: 'yes'
- ciphers:
value: HIGH:!ADH:!EXP:!MD5:!RC4:!3DES:!CAMELLIA:@STRENGTH
- ssl_verify_host:
value: 'no'
- ssl_manager_cert:
value: /var/ossec/etc/sslmanager.cert
- ssl_manager_key:
value: /var/ossec/etc/sslmanager.key
- ssl_auto_negotiate:
value: 'no'
- key_request:
elements:
- enabled:
value: 'yes'
- exec_path:
value: /var/ossec/framework/python/bin/python3 /tmp/fetch_keys.py
- timeout:
value: 60
- threads:
value: 1
- queue_size:
value: 1024

wazuh-worker1:
description: Enable remoted agent_key_polling at worker side
sections:
- section: remote
elements:
- connection:
value: secure
- port:
value: 1514
- protocol:
value: tcp
- queue_size:
value: 131072

wazuh-agent2:
description: Set manager address
sections:
- section: client
elements:
- server:
elements:
- address:
value: wazuh-worker1
69 changes: 0 additions & 69 deletions tests/system/test_cluster/test_agent_key_polling/data/config.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def configure_environment(host_manager):
host_manager.move_file(host='wazuh-master',
src_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files/fetch_keys.py'),
dest_path='/tmp/fetch_keys.py')
host_manager.apply_config(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/config.yml'),
host_manager.apply_config(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/config.yaml'),
clear_files=[os.path.join(WAZUH_LOGS_PATH, 'ossec.log')],
restart_services=['wazuh'])
host_manager.add_block_to_file(host='wazuh-master', path='/var/ossec/etc/client.keys', replace='NOTVALIDKEY',
Expand All @@ -46,7 +46,7 @@ def configure_environment(host_manager):

def test_agent_key_polling():
"""Check that the agent key polling cycle works correctly. To do this, we use the messages and the hosts defined
in data/messages.yml and the hosts inventory.
in data/messages.yaml and the hosts inventory.

Parameters
----------
Expand All @@ -57,6 +57,6 @@ def test_agent_key_polling():
configure_environment(host_manager)

host_monitor = HostMonitor(inventory_path=inventory_path,
messages_path=os.path.join(actual_path, 'data/messages.yml'),
messages_path=os.path.join(actual_path, 'data/messages.yaml'),
tmp_path=os.path.join(actual_path, 'tmp'))
host_monitor.run()
17 changes: 12 additions & 5 deletions tests/system/test_multigroups/test_multigroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pytest

from system import restart_cluster, remove_cluster_agents
from wazuh_testing.tools import WAZUH_PATH
from wazuh_testing.tools.system import HostManager

Expand All @@ -21,6 +22,7 @@
test_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2']
agent_groups = {'wazuh-agent1': ['default', 'test_mg_0'],
'wazuh-agent2': ['default', 'test_mg_1']}
test_infra_agents = ['wazuh-agent1', 'wazuh-agent2']

shared_folder_path = os.path.join(WAZUH_PATH, 'etc', 'shared')
mg_folder_path = os.path.join(WAZUH_PATH, 'var', 'multigroups')
Expand Down Expand Up @@ -104,6 +106,11 @@ def delete_groups():


# Fixtures
@pytest.fixture(scope='function')
def start_agents():
"""Start agents."""
restart_cluster(test_infra_agents, host_manager)


@pytest.fixture(scope='function')
def agent_healthcheck():
Expand All @@ -122,10 +129,10 @@ def agent_healthcheck():

@pytest.fixture(scope='function')
def clean_environment():
"""Remove test groups and multigroups before and after running a test."""
delete_groups()
"""Remove test groups and multigroups after running a test."""
yield
delete_groups()
remove_cluster_agents(test_hosts[0], test_infra_agents, host_manager)


@pytest.fixture(scope='function')
Expand Down Expand Up @@ -161,7 +168,7 @@ def create_multigroups():

# Tests

def test_multigroups_not_reloaded(clean_environment, agent_healthcheck, create_multigroups):
def test_multigroups_not_reloaded(clean_environment, start_agents, agent_healthcheck, create_multigroups):
"""Check that the files are not regenerated when there are no changes.

Check and store the modification time of all group and multigroup files. Wait 10 seconds
Expand All @@ -188,7 +195,7 @@ def test_multigroups_not_reloaded(clean_environment, agent_healthcheck, create_m
agent_groups['wazuh-agent1'][1],
'default'
])
def test_multigroups_updated(clean_environment, agent_healthcheck, create_multigroups, target_group):
def test_multigroups_updated(clean_environment, start_agents, agent_healthcheck, create_multigroups, target_group):
"""Check that only the appropriate multi-groups are regenerated when a group file is created.

Check and store the modification time of all group and multigroup files. Create a new file inside
Expand Down Expand Up @@ -234,7 +241,7 @@ def test_multigroups_updated(clean_environment, agent_healthcheck, create_multig
assert mtime == host_files[host][file], f"This file changed its modification time in {host}: {file}"


def test_multigroups_deleted(clean_environment, agent_healthcheck, create_multigroups):
def test_multigroups_deleted(clean_environment, start_agents, agent_healthcheck, create_multigroups):
"""Check that multigroups are removed when expected.

Unassign an agent from their groups or delete the groups. Check that the associated multigroup disappears
Expand Down
Loading