From 6aa44f1c64d5bcf09dbf5aff635b50116695ddc8 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 2 May 2023 15:09:36 +0200 Subject: [PATCH 01/17] feat(#3953)-group_sync_status --- .../data/test_group_sync_cases.yml | 22 +++ .../test_group_sync_status.py | 172 ++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml create mode 100644 tests/system/test_cluster/test_agent_groups/test_group_sync_status.py diff --git a/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml b/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml new file mode 100644 index 0000000000..2083c59e6a --- /dev/null +++ b/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml @@ -0,0 +1,22 @@ +- + name: 'delete_folder_master' + test_case: + host: 'wazuh-master' + group_deleted: 'group_master' + first_time_check: 'syncreq' + second_time_check: 'synced' +- + name: 'delete_folder_worker1' + test_case: + host: 'wazuh-worker1' + group_deleted: 'group_worker1' + first_time_check: 'synced' + second_time_check: 'synced' +- + name: 'delete_folder_worker2' + test_case: + host: 'wazuh-worker2' + group_deleted: 'group_worker2' + first_time_check: 'synced' + second_time_check: 'synced' + diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py new file mode 100644 index 0000000000..c94ffe74c0 --- /dev/null +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -0,0 +1,172 @@ +''' +copyright: Copyright (C) 2015-2023, Wazuh Inc. + Created by Wazuh, Inc. . + This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 +type: system +brief: Wazuh manager handles agent groups. + If a group is deleted from a master cluster, there will be an instance where the agents require a resynchronization (syncreq). + If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the group structure without the need for resynchronization. + This test suite tests the correct functioning of the mentioned use case. +tier: 0 +modules: + - enrollment +components: + - manager + - agent +daemons: + - wazuh-authd + - wazuh-agentd +os_platform: + - linux +os_version: + - Debian Buster +references: + - https://documentation.wazuh.com/current/user-manual/registering/agent-enrollment.html +''' + +import os +import pytest +import time +from wazuh_testing.tools import WAZUH_PATH +from wazuh_testing.tools.file import read_file, read_yaml +from wazuh_testing.tools.system import HostManager +from system import assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query + +pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] + +testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] +groups = ['group_master', 'group_worker1', 'group_worker2'] +agents = ['wazuh-agent1', 'wazuh-agent2'] +workers = ['wazuh-worker1', 'wazuh-worker2'] +groups_created = [] +first_time_check = "synced" +second_time_check = "synced" +network = {} + +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__)) +test_cases_yaml = read_yaml(os.path.join(local_path, 'data/test_group_sync_cases.yml')) +wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py') +agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), + '..', '..' ,'provisioning', 'enrollment_cluster', 'roles', 'agent-role', 'files', 'ossec.conf') + +def get_ip_directions(): + global network + for host in testinfra_hosts: + network[host] = host_manager.get_host_ip(host, 'eth0') + +def delete_all_groups(): + for group in groups: + delete_agent_group(testinfra_hosts[0],group,host_manager, 'api') + +def query_database(): + query = "global 'sql select group_sync_status from agent;'" + response = execute_wdb_query(query, testinfra_hosts[0], host_manager) + return response + +def first_check(): + global first_time_check + first_time_check = "synced" + s_time = 15 + for i in range(s_time): + time.sleep(0.25) + result = query_database() + if 'syncreq' in result: + first_time_check = "syncreq" + +def second_check(): + time.sleep(10) + global second_time_check + second_time_check = "synced" + result = query_database() + if 'syncreq' in result: + second_time_check = "syncreq" + +@pytest.fixture +def network_configuration(): + get_ip_directions() + for worker in workers: + old_agent_configuration = read_file(agent_conf_file) + new_configuration = old_agent_configuration.replace('
MANAGER_IP
', + f"
{network[worker][0]}
") + + host_manager.modify_file_content(host=agents[worker.index(worker)], path=f'{WAZUH_PATH}/etc/ossec.conf', + content=new_configuration) + host_manager.get_host(testinfra_hosts[0]).ansible('command', f'service wazuh-manager restart', check=False) + for agent in agents: + host_manager.get_host(agent).ansible('command', f'service wazuh-agent restart', check=False) + +@pytest.fixture +def group_creation(): + delete_all_groups() + for group in groups: + create_new_agent_group(testinfra_hosts[0], group, host_manager) + +@pytest.fixture +def agent_group_assignation(): + agent_ids = host_manager.run_command(testinfra_hosts[0], f'cut -c 1-3 {WAZUH_PATH}/etc/client.keys').split() + for group in groups: + for agent_id in agent_ids: + assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) + +@pytest.fixture +def delete_group_folder(test_case): + groups_created = host_manager.run_command(testinfra_hosts[0], f'{WAZUH_PATH}/bin/agent_groups') + if test_case['test_case']['group_deleted'] in groups_created: + host_manager.run_command(test_case['test_case']['host'], f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") + +@pytest.fixture +def wait_end_initial_syncreq(): + result = query_database() + while 'syncreq' in result: + time.sleep(1) + result = query_database() + +@pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] + for cases in test_cases_yaml]) + +def test_group_sync_status(test_case, network_configuration, + group_creation, agent_group_assignation, + wait_end_initial_syncreq, delete_group_folder): + + ''' + description: Delete a group folder in wazuh server cluster and check group_sync status in 2 times. + wazuh_min_version: 4.4.0 + parameters: + - test_case: + type: list + brief: List of tests to be performed. + - network_configuration + type: function + brief: Delete logs generally talking + - group_creation: + type: function + brief: Delete and create from zero all the groups that are going to be used for testing + - agent_group_assignation: + type: function + brief: Assign agents to groups + - wait_end_initial_syncreq: + type: function + brief: Wait until syncreqs related with the test-environment setting get neutralized + - delete_group_folder: + type: function + brief: Delete the folder-group assigned by test case (trigger) + + assertions: + - Verify that group_sync status changes according the trigger. + + input_description: Different use cases are found in the test module and include parameters. + + expected_output: + - If the group-folder is deleted from master cluster, it is expected to find a syncreq group_sync status until it gets synced. + - If the group-folder is deletef rom a worker cluster, it is expected that master cluster recreates groups without syncreq status. + ''' + #Checks + first_check() + second_check() + + #Results + assert test_case['test_case']['first_time_check'] == first_time_check + assert test_case['test_case']['second_time_check'] == second_time_check From aa1d5b10a4aae872ac83b7da5f5c33e30ad6422e Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 2 May 2023 15:23:34 +0200 Subject: [PATCH 02/17] refactor(#3953): title fixed --- .../data/test_group_sync_cases.yml | 35 ++++++++-------- .../test_group_sync_status.py | 40 +++++++++++-------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml b/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml index 2083c59e6a..1f3c69dead 100644 --- a/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml +++ b/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml @@ -1,22 +1,19 @@ -- - name: 'delete_folder_master' +--- +- name: delete_folder_master test_case: - host: 'wazuh-master' - group_deleted: 'group_master' - first_time_check: 'syncreq' - second_time_check: 'synced' -- - name: 'delete_folder_worker1' + host: wazuh-master + group_deleted: group_master + first_time_check: syncreq + second_time_check: synced +- name: delete_folder_worker1 test_case: - host: 'wazuh-worker1' - group_deleted: 'group_worker1' - first_time_check: 'synced' - second_time_check: 'synced' -- - name: 'delete_folder_worker2' + host: wazuh-worker1 + group_deleted: group_worker1 + first_time_check: synced + second_time_check: synced +- name: delete_folder_worker2 test_case: - host: 'wazuh-worker2' - group_deleted: 'group_worker2' - first_time_check: 'synced' - second_time_check: 'synced' - + host: wazuh-worker2 + group_deleted: group_worker2 + first_time_check: synced + second_time_check: synced \ No newline at end of file diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index c94ffe74c0..3035f98ca1 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -4,8 +4,10 @@ This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 type: system brief: Wazuh manager handles agent groups. - If a group is deleted from a master cluster, there will be an instance where the agents require a resynchronization (syncreq). - If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the group structure without the need for resynchronization. + If a group is deleted from a master cluster, there will be an instance where the agents require a + resynchronization (syncreq). + If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the + group structure without the need for resynchronization. This test suite tests the correct functioning of the mentioned use case. tier: 0 modules: @@ -50,16 +52,17 @@ test_cases_yaml = read_yaml(os.path.join(local_path, 'data/test_group_sync_cases.yml')) wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py') agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - '..', '..' ,'provisioning', 'enrollment_cluster', 'roles', 'agent-role', 'files', 'ossec.conf') + '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', + 'files', 'ossec.conf') def get_ip_directions(): global network for host in testinfra_hosts: network[host] = host_manager.get_host_ip(host, 'eth0') - + def delete_all_groups(): for group in groups: - delete_agent_group(testinfra_hosts[0],group,host_manager, 'api') + delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') def query_database(): query = "global 'sql select group_sync_status from agent;'" @@ -75,7 +78,7 @@ def first_check(): result = query_database() if 'syncreq' in result: first_time_check = "syncreq" - + def second_check(): time.sleep(10) global second_time_check @@ -83,7 +86,7 @@ def second_check(): result = query_database() if 'syncreq' in result: second_time_check = "syncreq" - + @pytest.fixture def network_configuration(): get_ip_directions() @@ -91,13 +94,12 @@ def network_configuration(): old_agent_configuration = read_file(agent_conf_file) new_configuration = old_agent_configuration.replace('
MANAGER_IP
', f"
{network[worker][0]}
") - host_manager.modify_file_content(host=agents[worker.index(worker)], path=f'{WAZUH_PATH}/etc/ossec.conf', content=new_configuration) host_manager.get_host(testinfra_hosts[0]).ansible('command', f'service wazuh-manager restart', check=False) for agent in agents: host_manager.get_host(agent).ansible('command', f'service wazuh-agent restart', check=False) - + @pytest.fixture def group_creation(): delete_all_groups() @@ -110,12 +112,13 @@ def agent_group_assignation(): for group in groups: for agent_id in agent_ids: assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) - + @pytest.fixture def delete_group_folder(test_case): groups_created = host_manager.run_command(testinfra_hosts[0], f'{WAZUH_PATH}/bin/agent_groups') if test_case['test_case']['group_deleted'] in groups_created: - host_manager.run_command(test_case['test_case']['host'], f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") + host_manager.run_command(test_case['test_case']['host'], + f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") @pytest.fixture def wait_end_initial_syncreq(): @@ -123,7 +126,7 @@ def wait_end_initial_syncreq(): while 'syncreq' in result: time.sleep(1) result = query_database() - + @pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] for cases in test_cases_yaml]) @@ -153,20 +156,23 @@ def test_group_sync_status(test_case, network_configuration, - delete_group_folder: type: function brief: Delete the folder-group assigned by test case (trigger) - + assertions: - Verify that group_sync status changes according the trigger. input_description: Different use cases are found in the test module and include parameters. - + expected_output: - - If the group-folder is deleted from master cluster, it is expected to find a syncreq group_sync status until it gets synced. - - If the group-folder is deletef rom a worker cluster, it is expected that master cluster recreates groups without syncreq status. + - If the group-folder is deleted from master cluster, it is expected to find a + syncreq group_sync status until it gets synced. + - If the group-folder is deletef rom a worker cluster, it is expected that master + cluster recreates groups without syncreq status. ''' #Checks first_check() second_check() - + #Results assert test_case['test_case']['first_time_check'] == first_time_check assert test_case['test_case']['second_time_check'] == second_time_check + From 6dbaaa745aa4633e54e98753e82c63acdc9294ed Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 4 May 2023 11:22:18 +0200 Subject: [PATCH 03/17] refactor(#3953): small fixes --- ...up_sync_cases.yml => cases_group_sync.yml} | 4 ++-- .../test_group_sync_status.py | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) rename tests/system/test_cluster/test_agent_groups/data/{test_group_sync_cases.yml => cases_group_sync.yml} (93%) diff --git a/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml similarity index 93% rename from tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml rename to tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml index 1f3c69dead..26f8301eca 100644 --- a/tests/system/test_cluster/test_agent_groups/data/test_group_sync_cases.yml +++ b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml @@ -1,4 +1,4 @@ ---- + - name: delete_folder_master test_case: host: wazuh-master @@ -16,4 +16,4 @@ host: wazuh-worker2 group_deleted: group_worker2 first_time_check: synced - second_time_check: synced \ No newline at end of file + second_time_check: synced diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 3035f98ca1..929965d601 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -33,6 +33,7 @@ from wazuh_testing.tools.file import read_file, read_yaml from wazuh_testing.tools.system import HostManager from system import assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query +from wazuh_testing import T_10, T_20 pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] @@ -49,7 +50,7 @@ 'provisioning', 'enrollment_cluster', 'inventory.yml') host_manager = HostManager(inventory_path) local_path = os.path.dirname(os.path.abspath(__file__)) -test_cases_yaml = read_yaml(os.path.join(local_path, 'data/test_group_sync_cases.yml')) +test_cases_yaml = read_yaml(os.path.join(local_path, 'data/cases_group_sync.yml')) wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py') agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', @@ -72,15 +73,14 @@ def query_database(): def first_check(): global first_time_check first_time_check = "synced" - s_time = 15 - for i in range(s_time): + for i in range(T_20): time.sleep(0.25) result = query_database() if 'syncreq' in result: first_time_check = "syncreq" def second_check(): - time.sleep(10) + time.sleep(T_10) global second_time_check second_time_check = "synced" result = query_database() @@ -102,9 +102,10 @@ def network_configuration(): @pytest.fixture def group_creation(): - delete_all_groups() for group in groups: create_new_agent_group(testinfra_hosts[0], group, host_manager) + yield + delete_all_groups() @pytest.fixture def agent_group_assignation(): @@ -142,19 +143,19 @@ def test_group_sync_status(test_case, network_configuration, type: list brief: List of tests to be performed. - network_configuration - type: function + type: fixture brief: Delete logs generally talking - group_creation: - type: function + type: fixture brief: Delete and create from zero all the groups that are going to be used for testing - agent_group_assignation: - type: function + type: fixture brief: Assign agents to groups - wait_end_initial_syncreq: - type: function + type: fixture brief: Wait until syncreqs related with the test-environment setting get neutralized - delete_group_folder: - type: function + type: fixture brief: Delete the folder-group assigned by test case (trigger) assertions: From d7ec119a0dfa7ad4d2e609e554787c44f6b772d3 Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 4 May 2023 13:19:19 +0200 Subject: [PATCH 04/17] refactor(#3953): Resetting after review --- .../data/cases_group_sync.yml | 3 +- .../test_group_sync_status.py | 116 +++++++----------- 2 files changed, 45 insertions(+), 74 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml index 26f8301eca..483fd58710 100644 --- a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml +++ b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml @@ -1,16 +1,17 @@ - - name: delete_folder_master test_case: host: wazuh-master group_deleted: group_master first_time_check: syncreq second_time_check: synced + - name: delete_folder_worker1 test_case: host: wazuh-worker1 group_deleted: group_worker1 first_time_check: synced second_time_check: synced + - name: delete_folder_worker2 test_case: host: wazuh-worker2 diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 929965d601..91bee557fd 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -32,9 +32,12 @@ from wazuh_testing.tools import WAZUH_PATH from wazuh_testing.tools.file import read_file, read_yaml from wazuh_testing.tools.system import HostManager -from system import assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query +from system import (get_agent_id, assign_agent_to_new_group, create_new_agent_group, + delete_agent_group, execute_wdb_query, restart_cluster) from wazuh_testing import T_10, T_20 +from system.test_cluster.test_agent_groups.common import register_agent + pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] @@ -42,9 +45,7 @@ agents = ['wazuh-agent1', 'wazuh-agent2'] workers = ['wazuh-worker1', 'wazuh-worker2'] groups_created = [] -first_time_check = "synced" -second_time_check = "synced" -network = {} + inventory_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'provisioning', 'enrollment_cluster', 'inventory.yml') @@ -56,83 +57,41 @@ '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', 'files', 'ossec.conf') -def get_ip_directions(): - global network - for host in testinfra_hosts: - network[host] = host_manager.get_host_ip(host, 'eth0') - -def delete_all_groups(): - for group in groups: - delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') - -def query_database(): - query = "global 'sql select group_sync_status from agent;'" - response = execute_wdb_query(query, testinfra_hosts[0], host_manager) - return response - -def first_check(): - global first_time_check - first_time_check = "synced" - for i in range(T_20): - time.sleep(0.25) - result = query_database() - if 'syncreq' in result: - first_time_check = "syncreq" - -def second_check(): - time.sleep(T_10) - global second_time_check - second_time_check = "synced" - result = query_database() - if 'syncreq' in result: - second_time_check = "syncreq" - @pytest.fixture -def network_configuration(): - get_ip_directions() - for worker in workers: - old_agent_configuration = read_file(agent_conf_file) - new_configuration = old_agent_configuration.replace('
MANAGER_IP
', - f"
{network[worker][0]}
") - host_manager.modify_file_content(host=agents[worker.index(worker)], path=f'{WAZUH_PATH}/etc/ossec.conf', - content=new_configuration) - host_manager.get_host(testinfra_hosts[0]).ansible('command', f'service wazuh-manager restart', check=False) - for agent in agents: - host_manager.get_host(agent).ansible('command', f'service wazuh-agent restart', check=False) - +def agent_configuration(): + restart_cluster(workers, host_manager) + @pytest.fixture -def group_creation(): +def group_creation_and_assignation(): for group in groups: create_new_agent_group(testinfra_hosts[0], group, host_manager) - yield - delete_all_groups() - -@pytest.fixture -def agent_group_assignation(): - agent_ids = host_manager.run_command(testinfra_hosts[0], f'cut -c 1-3 {WAZUH_PATH}/etc/client.keys').split() + + agent_ids = get_agent_id(host_manager).split() for group in groups: for agent_id in agent_ids: assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) + + yield + for group in groups: + delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') @pytest.fixture def delete_group_folder(test_case): - groups_created = host_manager.run_command(testinfra_hosts[0], f'{WAZUH_PATH}/bin/agent_groups') - if test_case['test_case']['group_deleted'] in groups_created: - host_manager.run_command(test_case['test_case']['host'], - f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") + host_manager.run_command(test_case['test_case']['host'], + f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") @pytest.fixture def wait_end_initial_syncreq(): - result = query_database() + query = "global 'sql select group_sync_status from agent;'" + result = execute_wdb_query(query, testinfra_hosts[0], host_manager) while 'syncreq' in result: time.sleep(1) - result = query_database() + result = execute_wdb_query(query, testinfra_hosts[0], host_manager) @pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] for cases in test_cases_yaml]) -def test_group_sync_status(test_case, network_configuration, - group_creation, agent_group_assignation, +def test_group_sync_status(test_case, agent_configuration, group_creation_and_assignation, wait_end_initial_syncreq, delete_group_folder): ''' @@ -141,16 +100,14 @@ def test_group_sync_status(test_case, network_configuration, parameters: - test_case: type: list - brief: List of tests to be performed. - - network_configuration + brief: List of tests to be performed. + - agent_configuration: type: fixture - brief: Delete logs generally talking - - group_creation: + brief: Restarting agents to be included in the network. + - group_creation_and_assignation: type: fixture - brief: Delete and create from zero all the groups that are going to be used for testing - - agent_group_assignation: - type: fixture - brief: Assign agents to groups + brief: Delete and create from zero all the groups that are going to be used for testing. + It includes group cleaning after tests. - wait_end_initial_syncreq: type: fixture brief: Wait until syncreqs related with the test-environment setting get neutralized @@ -170,10 +127,23 @@ def test_group_sync_status(test_case, network_configuration, cluster recreates groups without syncreq status. ''' #Checks - first_check() - second_check() + query = "global 'sql select group_sync_status from agent;'" + + first_time_check = "synced" + second_time_check = "synced" + for i in range(T_20): + time.sleep(0.25) + result = execute_wdb_query(query, testinfra_hosts[0], host_manager) + if 'syncreq' in result: + first_time_check = "syncreq" + + time.sleep(T_10) + + result = execute_wdb_query(query, testinfra_hosts[0], host_manager) + if 'syncreq' in result: + second_time_check = "syncreq" + #Results assert test_case['test_case']['first_time_check'] == first_time_check assert test_case['test_case']['second_time_check'] == second_time_check - From 44ba50bdd0538205c5f9e6e9f668743fa7464f72 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 5 May 2023 10:02:15 +0200 Subject: [PATCH 05/17] refactor(#3953): Indentation fix --- .../test_agent_groups/test_group_sync_status.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 91bee557fd..0855ce371b 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -46,7 +46,6 @@ workers = ['wazuh-worker1', 'wazuh-worker2'] groups_created = [] - 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) @@ -60,17 +59,17 @@ @pytest.fixture def agent_configuration(): restart_cluster(workers, host_manager) - + @pytest.fixture def group_creation_and_assignation(): for group in groups: create_new_agent_group(testinfra_hosts[0], group, host_manager) - + agent_ids = get_agent_id(host_manager).split() for group in groups: for agent_id in agent_ids: assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) - + yield for group in groups: delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') From 4eefe09c7a053274f9de25b7a722c661f576188f Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 5 May 2023 10:04:57 +0200 Subject: [PATCH 06/17] refactor(#3953): Time fix --- .../test_cluster/test_agent_groups/test_group_sync_status.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 0855ce371b..a064e4b95d 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -84,7 +84,7 @@ def wait_end_initial_syncreq(): query = "global 'sql select group_sync_status from agent;'" result = execute_wdb_query(query, testinfra_hosts[0], host_manager) while 'syncreq' in result: - time.sleep(1) + time.sleep(T_10/10) result = execute_wdb_query(query, testinfra_hosts[0], host_manager) @pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] @@ -132,7 +132,7 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as second_time_check = "synced" for i in range(T_20): - time.sleep(0.25) + time.sleep(T_10/40) result = execute_wdb_query(query, testinfra_hosts[0], host_manager) if 'syncreq' in result: first_time_check = "syncreq" From 23d4e6e5a701a9b6925be13e4ca3670e6925dac7 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 5 May 2023 14:21:58 +0200 Subject: [PATCH 07/17] refactor(#3953): Adding new Test cases --- .../data/cases_group_sync.yml | 63 +++++++++++++-- .../test_group_sync_status.py | 81 ++++++++++--------- 2 files changed, 100 insertions(+), 44 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml index 483fd58710..628d4b8919 100644 --- a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml +++ b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml @@ -1,20 +1,71 @@ -- name: delete_folder_master +- name: delete_folder_master_agent_in_group_all test_case: - host: wazuh-master + host: 'wazuh-master' + agent_in_group: all group_deleted: group_master first_time_check: syncreq second_time_check: synced -- name: delete_folder_worker1 +- name: delete_folder_worker1_agent_in_group_all test_case: - host: wazuh-worker1 + host: 'wazuh-worker1' + agent_in_group: all group_deleted: group_worker1 first_time_check: synced second_time_check: synced -- name: delete_folder_worker2 +- name: delete_folder_worker2_agent_in_group_all test_case: - host: wazuh-worker2 + host: 'wazuh-worker2' + agent_in_group: all group_deleted: group_worker2 first_time_check: synced second_time_check: synced + +- name: delete_folder_master_agent_in_group_agent1 + test_case: + host: 'wazuh-master' + agent_in_group: agent1 + group_deleted: group_master + first_time_check: syncreq + second_time_check: synced + +- name: delete_folder_worker1_in_group_agent1 + test_case: + host: 'wazuh-worker1' + agent_in_group: agent1 + group_deleted: group_worker1 + first_time_check: synced + second_time_check: synced + +- name: delete_folder_worker2_in_group_agent1 + test_case: + host: 'wazuh-worker2' + agent_in_group: agent1 + group_deleted: group_worker2 + first_time_check: synced + second_time_check: synced + +- name: delete_folder_master_agent_in_group_agent2 + test_case: + host: 'wazuh-master' + agent_in_group: agent2 + group_deleted: group_master + first_time_check: syncreq + second_time_check: synced + +- name: delete_folder_worker1_in_group_agent2 + test_case: + host: 'wazuh-worker1' + agent_in_group: agent2 + group_deleted: group_worker1 + first_time_check: synced + second_time_check: synced + +- name: delete_folder_worker2_in_group_agent2 + test_case: + host: 'wazuh-worker2' + agent_in_group: agent2 + group_deleted: group_worker2 + first_time_check: synced + second_time_check: synced \ No newline at end of file diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index a064e4b95d..7571535b99 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -26,17 +26,15 @@ - https://documentation.wazuh.com/current/user-manual/registering/agent-enrollment.html ''' +import json import os import pytest import time -from wazuh_testing.tools import WAZUH_PATH -from wazuh_testing.tools.file import read_file, read_yaml +from wazuh_testing import T_025, T_1, T_10 +from wazuh_testing.tools.file import read_yaml from wazuh_testing.tools.system import HostManager from system import (get_agent_id, assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query, restart_cluster) -from wazuh_testing import T_10, T_20 - -from system.test_cluster.test_agent_groups.common import register_agent pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] @@ -45,6 +43,7 @@ agents = ['wazuh-agent1', 'wazuh-agent2'] workers = ['wazuh-worker1', 'wazuh-worker2'] groups_created = [] +query = "global 'sql select name, group_sync_status from agent;'" inventory_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'provisioning', 'enrollment_cluster', 'inventory.yml') @@ -58,41 +57,43 @@ @pytest.fixture def agent_configuration(): - restart_cluster(workers, host_manager) + restart_cluster(agents, host_manager) @pytest.fixture -def group_creation_and_assignation(): +def group_creation_and_assignation(test_case): + agent_ids = get_agent_id(host_manager).split() for group in groups: create_new_agent_group(testinfra_hosts[0], group, host_manager) - agent_ids = get_agent_id(host_manager).split() - for group in groups: - for agent_id in agent_ids: - assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) + if test_case['test_case']['agent_in_group'] == 'all': + for group in groups: + for agent_id in agent_ids: + assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) + + if test_case['test_case']['agent_in_group'] == 'agent1': + for group in groups: + assign_agent_to_new_group(testinfra_hosts[0], group, agent_ids[0], host_manager) + + if test_case['test_case']['agent_in_group'] == 'agent2': + for group in groups: + assign_agent_to_new_group(testinfra_hosts[0], group, agent_ids[1], host_manager) yield for group in groups: delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') -@pytest.fixture -def delete_group_folder(test_case): - host_manager.run_command(test_case['test_case']['host'], - f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f") - @pytest.fixture def wait_end_initial_syncreq(): - query = "global 'sql select group_sync_status from agent;'" result = execute_wdb_query(query, testinfra_hosts[0], host_manager) while 'syncreq' in result: - time.sleep(T_10/10) + time.sleep(T_1) result = execute_wdb_query(query, testinfra_hosts[0], host_manager) @pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] for cases in test_cases_yaml]) def test_group_sync_status(test_case, agent_configuration, group_creation_and_assignation, - wait_end_initial_syncreq, delete_group_folder): - + wait_end_initial_syncreq): ''' description: Delete a group folder in wazuh server cluster and check group_sync status in 2 times. wazuh_min_version: 4.4.0 @@ -110,10 +111,7 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as - wait_end_initial_syncreq: type: fixture brief: Wait until syncreqs related with the test-environment setting get neutralized - - delete_group_folder: - type: fixture - brief: Delete the folder-group assigned by test case (trigger) - + assertions: - Verify that group_sync status changes according the trigger. @@ -125,24 +123,31 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as - If the group-folder is deletef rom a worker cluster, it is expected that master cluster recreates groups without syncreq status. ''' + #Delete group + delete_agent_group(test_case['test_case']['host'], test_case['test_case']['group_deleted'], host_manager, 'folder') + #Checks - query = "global 'sql select group_sync_status from agent;'" - - first_time_check = "synced" - second_time_check = "synced" + first_time_check = second_time_check = "synced" - for i in range(T_20): - time.sleep(T_10/40) + for i in range(T_10): + time.sleep(T_025) result = execute_wdb_query(query, testinfra_hosts[0], host_manager) - if 'syncreq' in result: - first_time_check = "syncreq" - + if test_case['test_case']['agent_in_group'] == 'all': + if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: + first_time_check = "syncreq" + if test_case['test_case']['agent_in_group'] == 'agent1': + if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'synced' == json.loads(result)[2]['group_sync_status']: + first_time_check = "syncreq" + if test_case['test_case']['agent_in_group'] == 'agent2': + if 'synced' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: + first_time_check = "syncreq" + time.sleep(T_10) - + result = execute_wdb_query(query, testinfra_hosts[0], host_manager) if 'syncreq' in result: - second_time_check = "syncreq" - + second_time_check = "syncreq" + #Results - assert test_case['test_case']['first_time_check'] == first_time_check - assert test_case['test_case']['second_time_check'] == second_time_check + assert test_case['test_case']['first_time_check'] == first_time_check + assert test_case['test_case']['second_time_check'] == second_time_check From bacd6fade3a470dc3b901bc029e9137e70c4a8ad Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 5 May 2023 14:26:05 +0200 Subject: [PATCH 08/17] refactor(#3953): Indentation fixes --- .../test_cluster/test_agent_groups/test_group_sync_status.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 7571535b99..79a34ebd30 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -135,9 +135,11 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as if test_case['test_case']['agent_in_group'] == 'all': if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: first_time_check = "syncreq" + if test_case['test_case']['agent_in_group'] == 'agent1': if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'synced' == json.loads(result)[2]['group_sync_status']: first_time_check = "syncreq" + if test_case['test_case']['agent_in_group'] == 'agent2': if 'synced' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: first_time_check = "syncreq" From 88cf3f3fae0ba72227bc07717cee0c8345f4157f Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 10 May 2023 15:42:31 +0200 Subject: [PATCH 09/17] refactor(#3953): Fixes after review --- .../data/cases_group_sync.yaml | 89 +++++++++++++++ .../data/cases_group_sync.yml | 71 ------------ .../test_group_sync_status.py | 101 +++++++++--------- 3 files changed, 140 insertions(+), 121 deletions(-) create mode 100644 tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml delete mode 100644 tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml diff --git a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml new file mode 100644 index 0000000000..44d582ea9b --- /dev/null +++ b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml @@ -0,0 +1,89 @@ +- name: delete_folder_master_agent_all + description: all agents in all groups, deleting folder group_master from wazuh-master, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-master + agent_in_group: all + group_folder_deleted: group_master + expected_first_check: syncreq + expected_second_check: synced + +- name: delete_folder_worker1_agent_all + description: all agents in all groups, deleting folder group_worker1 from wazuh-worker1, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker1 + agent_in_group: all + group_folder_deleted: group_worker1 + expected_first_check: synced + expected_second_check: synced + +- name: delete_folder_worker2_agent_all + description: all agents in all groups, deleting folder group_worker2 from wazuh-worker2, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker2 + agent_in_group: all + group_folder_deleted: group_worker2 + expected_first_check: synced + expected_second_check: synced + +- name: delete_folder_master_agent_agent1 + description: agent1 in all groups, deleting folder group_master from wazuh-master, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-master + agent_in_group: agent1 + group_folder_deleted: group_master + expected_first_check: syncreq + expected_second_check: synced + +- name: delete_folder_worker1_agent1 + description: agent1 in all groups, deleting folder group_worker1 from wazuh-worker1, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker1 + agent_in_group: agent1 + group_folder_deleted: group_worker1 + expected_first_check: synced + expected_second_check: synced + +- name: delete_folder_worker2_agent1 + description: agent1 in all groups, deleting folder group_worker2 from wazuh-worker2, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker2 + agent_in_group: agent1 + group_folder_deleted: group_worker2 + expected_first_check: synced + expected_second_check: synced + +- name: delete_folder_master_agent_agent2 + description: agent2 in all groups, deleting folder group_master from wazuh-master, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-master + agent_in_group: agent2 + group_folder_deleted: group_master + expected_first_check: syncreq + expected_second_check: synced + +- name: delete_folder_worker1_agent2 + description: agent2 in all groups, deleting folder group_worker1 from wazuh-worker1, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker1 + agent_in_group: agent2 + group_folder_deleted: group_worker1 + expected_first_check: synced + expected_second_check: synced + +- name: delete_folder_worker2_agent2 + description: agent2 in all groups, deleting folder group_worker2 from wazuh-worker2, check sync_status + configuration_parameters: null + metadata: + delete_target: wazuh-worker2 + agent_in_group: agent2 + group_folder_deleted: group_worker2 + expected_first_check: synced + expected_second_check: synced \ No newline at end of file diff --git a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml deleted file mode 100644 index 628d4b8919..0000000000 --- a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yml +++ /dev/null @@ -1,71 +0,0 @@ -- name: delete_folder_master_agent_in_group_all - test_case: - host: 'wazuh-master' - agent_in_group: all - group_deleted: group_master - first_time_check: syncreq - second_time_check: synced - -- name: delete_folder_worker1_agent_in_group_all - test_case: - host: 'wazuh-worker1' - agent_in_group: all - group_deleted: group_worker1 - first_time_check: synced - second_time_check: synced - -- name: delete_folder_worker2_agent_in_group_all - test_case: - host: 'wazuh-worker2' - agent_in_group: all - group_deleted: group_worker2 - first_time_check: synced - second_time_check: synced - -- name: delete_folder_master_agent_in_group_agent1 - test_case: - host: 'wazuh-master' - agent_in_group: agent1 - group_deleted: group_master - first_time_check: syncreq - second_time_check: synced - -- name: delete_folder_worker1_in_group_agent1 - test_case: - host: 'wazuh-worker1' - agent_in_group: agent1 - group_deleted: group_worker1 - first_time_check: synced - second_time_check: synced - -- name: delete_folder_worker2_in_group_agent1 - test_case: - host: 'wazuh-worker2' - agent_in_group: agent1 - group_deleted: group_worker2 - first_time_check: synced - second_time_check: synced - -- name: delete_folder_master_agent_in_group_agent2 - test_case: - host: 'wazuh-master' - agent_in_group: agent2 - group_deleted: group_master - first_time_check: syncreq - second_time_check: synced - -- name: delete_folder_worker1_in_group_agent2 - test_case: - host: 'wazuh-worker1' - agent_in_group: agent2 - group_deleted: group_worker1 - first_time_check: synced - second_time_check: synced - -- name: delete_folder_worker2_in_group_agent2 - test_case: - host: 'wazuh-worker2' - agent_in_group: agent2 - group_deleted: group_worker2 - first_time_check: synced - second_time_check: synced \ No newline at end of file diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 79a34ebd30..0f3e071522 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -30,12 +30,11 @@ import os import pytest import time -from wazuh_testing import T_025, T_1, T_10 -from wazuh_testing.tools.file import read_yaml +from wazuh_testing import T_025, T_1, T_5, T_10 from wazuh_testing.tools.system import HostManager from system import (get_agent_id, assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query, restart_cluster) - +from wazuh_testing.tools.configuration import get_test_cases_data pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] @@ -48,62 +47,59 @@ 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) +data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') local_path = os.path.dirname(os.path.abspath(__file__)) -test_cases_yaml = read_yaml(os.path.join(local_path, 'data/cases_group_sync.yml')) +test_cases_yaml = os.path.join(data_path, 'cases_group_sync.yaml') wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py') agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', 'files', 'ossec.conf') +t1_configuration_parameters, t1_configuration_metadata, t1_case_ids = get_test_cases_data(test_cases_yaml) -@pytest.fixture -def agent_configuration(): - restart_cluster(agents, host_manager) -@pytest.fixture -def group_creation_and_assignation(test_case): +@pytest.fixture() +def group_creation_and_assignation(metadata, target_node): + restart_cluster(agents, host_manager) agent_ids = get_agent_id(host_manager).split() for group in groups: - create_new_agent_group(testinfra_hosts[0], group, host_manager) + create_new_agent_group(target_node, group, host_manager) - if test_case['test_case']['agent_in_group'] == 'all': + if metadata['agent_in_group'] == 'agent1': for group in groups: - for agent_id in agent_ids: - assign_agent_to_new_group(testinfra_hosts[0], group, agent_id, host_manager) - - if test_case['test_case']['agent_in_group'] == 'agent1': + assign_agent_to_new_group(target_node, group, agent_ids[0], host_manager) + + elif metadata['agent_in_group'] == 'agent2': for group in groups: - assign_agent_to_new_group(testinfra_hosts[0], group, agent_ids[0], host_manager) - - if test_case['test_case']['agent_in_group'] == 'agent2': + assign_agent_to_new_group(target_node, group, agent_ids[1], host_manager) + + else: for group in groups: - assign_agent_to_new_group(testinfra_hosts[0], group, agent_ids[1], host_manager) + for agent_id in agent_ids: + assign_agent_to_new_group(target_node, group, agent_id, host_manager) yield for group in groups: delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') -@pytest.fixture + +@pytest.fixture() def wait_end_initial_syncreq(): result = execute_wdb_query(query, testinfra_hosts[0], host_manager) while 'syncreq' in result: time.sleep(T_1) result = execute_wdb_query(query, testinfra_hosts[0], host_manager) -@pytest.mark.parametrize('test_case', [cases for cases in test_cases_yaml], ids=[cases['name'] - for cases in test_cases_yaml]) -def test_group_sync_status(test_case, agent_configuration, group_creation_and_assignation, - wait_end_initial_syncreq): +@pytest.mark.parametrize('target_node', ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2']) +@pytest.mark.parametrize('metadata', t1_configuration_metadata, ids=t1_case_ids) +def test_group_sync_status(metadata, target_node, group_creation_and_assignation, wait_end_initial_syncreq): ''' description: Delete a group folder in wazuh server cluster and check group_sync status in 2 times. wazuh_min_version: 4.4.0 - parameters: + metadata: - test_case: type: list - brief: List of tests to be performed. - - agent_configuration: - type: fixture - brief: Restarting agents to be included in the network. + brief: List of tests to be performed. - group_creation_and_assignation: type: fixture brief: Delete and create from zero all the groups that are going to be used for testing. @@ -114,6 +110,7 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as assertions: - Verify that group_sync status changes according the trigger. + - Verify same conditions creating and assigning groups from all wazuh-manager clusters (Master and Workers) input_description: Different use cases are found in the test module and include parameters. @@ -123,33 +120,37 @@ def test_group_sync_status(test_case, agent_configuration, group_creation_and_as - If the group-folder is deletef rom a worker cluster, it is expected that master cluster recreates groups without syncreq status. ''' - #Delete group - delete_agent_group(test_case['test_case']['host'], test_case['test_case']['group_deleted'], host_manager, 'folder') + # Delete group folder + delete_agent_group(metadata['delete_target'], metadata['group_folder_deleted'], host_manager, 'folder') - #Checks - first_time_check = second_time_check = "synced" + # Set values + first_time_check = 'synced' + second_time_check = '' - for i in range(T_10): + # Check each 0.25 seconds/10 seconds sync_status + for _ in range(T_10): time.sleep(T_025) - result = execute_wdb_query(query, testinfra_hosts[0], host_manager) - if test_case['test_case']['agent_in_group'] == 'all': - if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: - first_time_check = "syncreq" + agent1_status = json.loads(execute_wdb_query(query, testinfra_hosts[0], host_manager))[1]['group_sync_status'] + agent2_status = json.loads(execute_wdb_query(query, testinfra_hosts[0], host_manager))[2]['group_sync_status'] - if test_case['test_case']['agent_in_group'] == 'agent1': - if 'syncreq' == json.loads(result)[1]['group_sync_status'] and 'synced' == json.loads(result)[2]['group_sync_status']: + if metadata['agent_in_group'] == 'agent1': + if 'syncreq' == agent1_status and 'synced' == agent2_status: first_time_check = "syncreq" - if test_case['test_case']['agent_in_group'] == 'agent2': - if 'synced' == json.loads(result)[1]['group_sync_status'] and 'syncreq' == json.loads(result)[2]['group_sync_status']: + elif metadata['agent_in_group'] == 'agent2': + if 'synced' == agent1_status and 'syncreq' == agent2_status: first_time_check = "syncreq" - - time.sleep(T_10) + + else: + if agent1_status == 'syncreq' and agent2_status == 'syncreq': + first_time_check = 'syncreq' + + time.sleep(T_5) + assert metadata['expected_first_check'] == first_time_check - result = execute_wdb_query(query, testinfra_hosts[0], host_manager) - if 'syncreq' in result: - second_time_check = "syncreq" + # Check after 5 seconds, sync_status + if 'syncreq' in execute_wdb_query(query, testinfra_hosts[0], host_manager): + second_time_check = 'syncreq' + else: second_time_check = 'synced' - #Results - assert test_case['test_case']['first_time_check'] == first_time_check - assert test_case['test_case']['second_time_check'] == second_time_check + assert metadata['expected_second_check'] == second_time_check From 84b5d1203839003122bb04f819a1945abcebe7ac Mon Sep 17 00:00:00 2001 From: Antonio Date: Thu, 11 May 2023 11:35:39 +0200 Subject: [PATCH 10/17] refactor(#3953): Adding register_agent() --- deps/wazuh_testing/wazuh_testing/__init__.py | 3 + .../test_group_sync_status.py | 89 +++++++++++-------- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/__init__.py b/deps/wazuh_testing/wazuh_testing/__init__.py index acb4b49b6d..08ca8d9179 100644 --- a/deps/wazuh_testing/wazuh_testing/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/__init__.py @@ -64,6 +64,9 @@ ANALYSISD_STATE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state') # Timeouts +T_025 = 0.25 +T_1 = 1 +T_3 = 3 T_5 = 5 T_10 = 10 T_20 = 20 diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 0f3e071522..cf1ca63167 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -1,14 +1,14 @@ ''' copyright: Copyright (C) 2015-2023, Wazuh Inc. - Created by Wazuh, Inc. . - This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 + Created by Wazuh, Inc. . + This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 type: system brief: Wazuh manager handles agent groups. - If a group is deleted from a master cluster, there will be an instance where the agents require a - resynchronization (syncreq). - If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the - group structure without the need for resynchronization. - This test suite tests the correct functioning of the mentioned use case. + If a group is deleted from a master cluster, there will be an instance where the agents require a + resynchronization (syncreq). + If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the + group structure without the need for resynchronization. + This test suite tests the correct functioning of the mentioned use case. tier: 0 modules: - enrollment @@ -32,14 +32,16 @@ import time from wazuh_testing import T_025, T_1, T_5, T_10 from wazuh_testing.tools.system import HostManager -from system import (get_agent_id, assign_agent_to_new_group, create_new_agent_group, - delete_agent_group, execute_wdb_query, restart_cluster) +from system import (assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query, + restart_cluster) from wazuh_testing.tools.configuration import get_test_cases_data +from system.test_cluster.test_agent_groups.common import register_agent pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] -testinfra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] +test_infra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] +test_infra_managers = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2'] +test_infra_agents = ['wazuh-agent1', 'wazuh-agent2'] groups = ['group_master', 'group_worker1', 'group_worker2'] -agents = ['wazuh-agent1', 'wazuh-agent2'] workers = ['wazuh-worker1', 'wazuh-worker2'] groups_created = [] query = "global 'sql select name, group_sync_status from agent;'" @@ -56,50 +58,65 @@ 'files', 'ossec.conf') t1_configuration_parameters, t1_configuration_metadata, t1_case_ids = get_test_cases_data(test_cases_yaml) - @pytest.fixture() def group_creation_and_assignation(metadata, target_node): - restart_cluster(agents, host_manager) - agent_ids = get_agent_id(host_manager).split() + + agent_ids = [] + for agent in test_infra_agents: + agent_ip, agent_id, agent_name, manager_ip = register_agent(agent, test_infra_hosts[0], host_manager) + time.sleep(T_025) + agent_ids.append(agent_id) + + restart_cluster(test_infra_agents, host_manager) + + time.sleep(T_1) for group in groups: create_new_agent_group(target_node, group, host_manager) - + if metadata['agent_in_group'] == 'agent1': for group in groups: assign_agent_to_new_group(target_node, group, agent_ids[0], host_manager) - + elif metadata['agent_in_group'] == 'agent2': for group in groups: assign_agent_to_new_group(target_node, group, agent_ids[1], host_manager) - + else: for group in groups: for agent_id in agent_ids: assign_agent_to_new_group(target_node, group, agent_id, host_manager) - + yield + for group in groups: - delete_agent_group(testinfra_hosts[0], group, host_manager, 'api') + delete_agent_group(test_infra_hosts[0], group, host_manager, 'api') @pytest.fixture() def wait_end_initial_syncreq(): - result = execute_wdb_query(query, testinfra_hosts[0], host_manager) + result = execute_wdb_query(query, test_infra_hosts[0], host_manager) while 'syncreq' in result: time.sleep(T_1) - result = execute_wdb_query(query, testinfra_hosts[0], host_manager) + result = execute_wdb_query(query, test_infra_hosts[0], host_manager) @pytest.mark.parametrize('target_node', ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2']) @pytest.mark.parametrize('metadata', t1_configuration_metadata, ids=t1_case_ids) -def test_group_sync_status(metadata, target_node, group_creation_and_assignation, wait_end_initial_syncreq): +def test_group_sync_status(metadata, target_node, clean_environment, group_creation_and_assignation, + wait_end_initial_syncreq): ''' description: Delete a group folder in wazuh server cluster and check group_sync status in 2 times. wazuh_min_version: 4.4.0 metadata: - - test_case: + - metadata: type: list brief: List of tests to be performed. + - target_node: + type: list + brief: List of nodes from the groups will be managed. + - clean_environment: + type: fixture + brief: Cleaning logs and resetting environment before testing. - group_creation_and_assignation: type: fixture brief: Delete and create from zero all the groups that are going to be used for testing. @@ -107,13 +124,10 @@ def test_group_sync_status(metadata, target_node, group_creation_and_assignation - wait_end_initial_syncreq: type: fixture brief: Wait until syncreqs related with the test-environment setting get neutralized - assertions: - Verify that group_sync status changes according the trigger. - Verify same conditions creating and assigning groups from all wazuh-manager clusters (Master and Workers) - input_description: Different use cases are found in the test module and include parameters. - expected_output: - If the group-folder is deleted from master cluster, it is expected to find a syncreq group_sync status until it gets synced. @@ -122,35 +136,36 @@ def test_group_sync_status(metadata, target_node, group_creation_and_assignation ''' # Delete group folder delete_agent_group(metadata['delete_target'], metadata['group_folder_deleted'], host_manager, 'folder') - + # Set values first_time_check = 'synced' second_time_check = '' - + # Check each 0.25 seconds/10 seconds sync_status for _ in range(T_10): time.sleep(T_025) - agent1_status = json.loads(execute_wdb_query(query, testinfra_hosts[0], host_manager))[1]['group_sync_status'] - agent2_status = json.loads(execute_wdb_query(query, testinfra_hosts[0], host_manager))[2]['group_sync_status'] - + agent1_status = json.loads(execute_wdb_query(query, test_infra_hosts[0], host_manager))[1]['group_sync_status'] + agent2_status = json.loads(execute_wdb_query(query, test_infra_hosts[0], host_manager))[2]['group_sync_status'] + if metadata['agent_in_group'] == 'agent1': if 'syncreq' == agent1_status and 'synced' == agent2_status: first_time_check = "syncreq" - + elif metadata['agent_in_group'] == 'agent2': if 'synced' == agent1_status and 'syncreq' == agent2_status: first_time_check = "syncreq" - + else: if agent1_status == 'syncreq' and agent2_status == 'syncreq': first_time_check = 'syncreq' - + time.sleep(T_5) + assert metadata['expected_first_check'] == first_time_check - + # Check after 5 seconds, sync_status - if 'syncreq' in execute_wdb_query(query, testinfra_hosts[0], host_manager): + if 'syncreq' in execute_wdb_query(query, test_infra_hosts[0], host_manager): second_time_check = 'syncreq' else: second_time_check = 'synced' - + assert metadata['expected_second_check'] == second_time_check From 6c2985d1a2e92877c3130604cdbe41d533b20a75 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 2 Jun 2023 16:51:58 +0200 Subject: [PATCH 11/17] refactor(#3953): Timeout handling and unnececessary wait --- .../test_agent_groups/data/cases_group_sync.yaml | 2 +- .../test_agent_groups/test_group_sync_status.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml index 44d582ea9b..fc49b89624 100644 --- a/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml +++ b/tests/system/test_cluster/test_agent_groups/data/cases_group_sync.yaml @@ -86,4 +86,4 @@ agent_in_group: agent2 group_folder_deleted: group_worker2 expected_first_check: synced - expected_second_check: synced \ No newline at end of file + expected_second_check: synced diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index cf1ca63167..ac940929f9 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -36,6 +36,7 @@ restart_cluster) from wazuh_testing.tools.configuration import get_test_cases_data from system.test_cluster.test_agent_groups.common import register_agent + pytestmark = [pytest.mark.cluster, pytest.mark.enrollment_cluster_env] test_infra_hosts = ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2', 'wazuh-agent1', 'wazuh-agent2'] @@ -64,12 +65,11 @@ def group_creation_and_assignation(metadata, target_node): agent_ids = [] for agent in test_infra_agents: agent_ip, agent_id, agent_name, manager_ip = register_agent(agent, test_infra_hosts[0], host_manager) - time.sleep(T_025) agent_ids.append(agent_id) restart_cluster(test_infra_agents, host_manager) - time.sleep(T_1) + time.sleep(T_10) for group in groups: create_new_agent_group(target_node, group, host_manager) @@ -94,9 +94,15 @@ def group_creation_and_assignation(metadata, target_node): @pytest.fixture() def wait_end_initial_syncreq(): + + time_counter = 0 result = execute_wdb_query(query, test_infra_hosts[0], host_manager) + while 'syncreq' in result: time.sleep(T_1) + time_counter += T_1 + if T_10 - time_counter == 0: + pytest.fail('Test failure due to unstable environment, syncreq does not disappear after group management') result = execute_wdb_query(query, test_infra_hosts[0], host_manager) @@ -151,7 +157,7 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat if 'syncreq' == agent1_status and 'synced' == agent2_status: first_time_check = "syncreq" - elif metadata['agent_in_group'] == 'agent2': + elif metadata['agent_in_group'] == 'agent2': if 'synced' == agent1_status and 'syncreq' == agent2_status: first_time_check = "syncreq" @@ -164,8 +170,8 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat assert metadata['expected_first_check'] == first_time_check # Check after 5 seconds, sync_status - if 'syncreq' in execute_wdb_query(query, test_infra_hosts[0], host_manager): - second_time_check = 'syncreq' + if 'syncreq' in execute_wdb_query(query, test_infra_hosts[0], host_manager): + second_time_check = 'syncreq' else: second_time_check = 'synced' assert metadata['expected_second_check'] == second_time_check From a3f65f3f0708c06db8eb69c46f969171f8e4510f Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 6 Jun 2023 16:47:26 +0200 Subject: [PATCH 12/17] refactor(#3953): Absolute timeout change --- deps/wazuh_testing/wazuh_testing/__init__.py | 6 ++---- .../test_agent_groups/test_group_sync_status.py | 7 +++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/__init__.py b/deps/wazuh_testing/wazuh_testing/__init__.py index b8084b904e..ab0c95137a 100644 --- a/deps/wazuh_testing/wazuh_testing/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/__init__.py @@ -66,13 +66,11 @@ ANALYSISD_STATE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state') # Timeouts -<<<<<<< HEAD + T_025 = 0.25 T_1 = 1 -T_3 = 3 -======= T_2 = 2 ->>>>>>> 95d6ac070917267c65c5214ef9ec07c5d97d14c8 +T_3 = 3 T_5 = 5 T_10 = 10 T_20 = 20 diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index ac940929f9..da43e16c64 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -30,6 +30,7 @@ import os import pytest import time +from time import time as current_time from wazuh_testing import T_025, T_1, T_5, T_10 from wazuh_testing.tools.system import HostManager from system import (assign_agent_to_new_group, create_new_agent_group, delete_agent_group, execute_wdb_query, @@ -94,14 +95,12 @@ def group_creation_and_assignation(metadata, target_node): @pytest.fixture() def wait_end_initial_syncreq(): - - time_counter = 0 + timeout = current_time() + T_10 result = execute_wdb_query(query, test_infra_hosts[0], host_manager) while 'syncreq' in result: time.sleep(T_1) - time_counter += T_1 - if T_10 - time_counter == 0: + if current_time() >= timeout: pytest.fail('Test failure due to unstable environment, syncreq does not disappear after group management') result = execute_wdb_query(query, test_infra_hosts[0], host_manager) From 7645a44dcf26c7d42173404d4a22704b0231835a Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 3 Jul 2023 09:56:59 +0200 Subject: [PATCH 13/17] fix(#3953): Fixes after linter --- .../test_group_sync_status.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index da43e16c64..8fcaf97b20 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -3,10 +3,10 @@ Created by Wazuh, Inc. . This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 type: system -brief: Wazuh manager handles agent groups. - If a group is deleted from a master cluster, there will be an instance where the agents require a - resynchronization (syncreq). - If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the +brief: Wazuh manager handles agent groups. + If a group is deleted from a master cluster, there will be an instance where the agents require a + resynchronization (syncreq). + If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the group structure without the need for resynchronization. This test suite tests the correct functioning of the mentioned use case. tier: 0 @@ -56,10 +56,11 @@ test_cases_yaml = os.path.join(data_path, 'cases_group_sync.yaml') wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py') agent_conf_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', + '..', '..', 'provisioning', 'enrollment_cluster', 'roles', 'agent-role', 'files', 'ossec.conf') t1_configuration_parameters, t1_configuration_metadata, t1_case_ids = get_test_cases_data(test_cases_yaml) + @pytest.fixture() def group_creation_and_assignation(metadata, target_node): @@ -107,7 +108,7 @@ def wait_end_initial_syncreq(): @pytest.mark.parametrize('target_node', ['wazuh-master', 'wazuh-worker1', 'wazuh-worker2']) @pytest.mark.parametrize('metadata', t1_configuration_metadata, ids=t1_case_ids) -def test_group_sync_status(metadata, target_node, clean_environment, group_creation_and_assignation, +def test_group_sync_status(metadata, target_node, clean_environment, group_creation_and_assignation, wait_end_initial_syncreq): ''' description: Delete a group folder in wazuh server cluster and check group_sync status in 2 times. @@ -115,10 +116,10 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat metadata: - metadata: type: list - brief: List of tests to be performed. + brief: List of tests to be performed. - target_node: type: list - brief: List of nodes from the groups will be managed. + brief: List of nodes from the groups will be managed. - clean_environment: type: fixture brief: Cleaning logs and resetting environment before testing. @@ -134,9 +135,9 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat - Verify same conditions creating and assigning groups from all wazuh-manager clusters (Master and Workers) input_description: Different use cases are found in the test module and include parameters. expected_output: - - If the group-folder is deleted from master cluster, it is expected to find a + - If the group-folder is deleted from master cluster, it is expected to find a syncreq group_sync status until it gets synced. - - If the group-folder is deletef rom a worker cluster, it is expected that master + - If the group-folder is deletef rom a worker cluster, it is expected that master cluster recreates groups without syncreq status. ''' # Delete group folder @@ -171,6 +172,7 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat # Check after 5 seconds, sync_status if 'syncreq' in execute_wdb_query(query, test_infra_hosts[0], host_manager): second_time_check = 'syncreq' - else: second_time_check = 'synced' + else: + second_time_check = 'synced' assert metadata['expected_second_check'] == second_time_check From 37488fc8451f00c652a0d5b5cb5f315b39d9caf3 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 3 Jul 2023 09:59:30 +0200 Subject: [PATCH 14/17] fix(#3953): Fixes after linter --- .../test_agent_groups/test_group_sync_status.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index 8fcaf97b20..e6f7415fcb 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -154,11 +154,11 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat agent2_status = json.loads(execute_wdb_query(query, test_infra_hosts[0], host_manager))[2]['group_sync_status'] if metadata['agent_in_group'] == 'agent1': - if 'syncreq' == agent1_status and 'synced' == agent2_status: + if 'syncreq' == agent1_status and 'synced' == agent2_status: first_time_check = "syncreq" elif metadata['agent_in_group'] == 'agent2': - if 'synced' == agent1_status and 'syncreq' == agent2_status: + if 'synced' == agent1_status and 'syncreq' == agent2_status: first_time_check = "syncreq" else: @@ -172,7 +172,7 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat # Check after 5 seconds, sync_status if 'syncreq' in execute_wdb_query(query, test_infra_hosts[0], host_manager): second_time_check = 'syncreq' - else: + else: second_time_check = 'synced' assert metadata['expected_second_check'] == second_time_check From 4251c28a26749a8923cd66f66060c95ce187ef10 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 3 Jul 2023 10:05:53 +0200 Subject: [PATCH 15/17] fix(#3953): Fixes after linter --- .../test_cluster/test_agent_groups/test_group_sync_status.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index e6f7415fcb..b55ca97465 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -155,11 +155,11 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat if metadata['agent_in_group'] == 'agent1': if 'syncreq' == agent1_status and 'synced' == agent2_status: - first_time_check = "syncreq" + first_time_check = "syncreq" elif metadata['agent_in_group'] == 'agent2': if 'synced' == agent1_status and 'syncreq' == agent2_status: - first_time_check = "syncreq" + first_time_check = "syncreq" else: if agent1_status == 'syncreq' and agent2_status == 'syncreq': From 50acf3b7b3ec18e014ea8d2fd08e422e1a92e9e8 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 3 Jul 2023 10:11:22 +0200 Subject: [PATCH 16/17] fix(#3953): Fixes after linter --- .../test_cluster/test_agent_groups/test_group_sync_status.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py index b55ca97465..51e3edd7a7 100644 --- a/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py +++ b/tests/system/test_cluster/test_agent_groups/test_group_sync_status.py @@ -154,11 +154,11 @@ def test_group_sync_status(metadata, target_node, clean_environment, group_creat agent2_status = json.loads(execute_wdb_query(query, test_infra_hosts[0], host_manager))[2]['group_sync_status'] if metadata['agent_in_group'] == 'agent1': - if 'syncreq' == agent1_status and 'synced' == agent2_status: + if 'syncreq' == agent1_status and 'synced' == agent2_status: first_time_check = "syncreq" elif metadata['agent_in_group'] == 'agent2': - if 'synced' == agent1_status and 'syncreq' == agent2_status: + if 'synced' == agent1_status and 'syncreq' == agent2_status: first_time_check = "syncreq" else: From 93d838bf5769835a2c2673544fa85195efbbedd8 Mon Sep 17 00:00:00 2001 From: Antonio Date: Wed, 6 Sep 2023 12:43:13 +0200 Subject: [PATCH 17/17] fix(#3953): Adding CHANGELOG information --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 357d7b33a2..fe27b7da02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file. Wazuh commit: TBD \ Release report: TBD +### Added +- Agent syncronization testing after group deleting ([#3953](https://github.com/wazuh/wazuh-qa/pull/4143)) \- (Tests) + ### Changed - Enable Ubuntu Vulnerability Detector E2E. ([#4252](https://github.com/wazuh/wazuh-qa/pull/4252)) \- (Tests)