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

Full Yellow Local - WazuhDB tests in 4.2 #1535

Closed
Rebits opened this issue Jul 2, 2021 · 2 comments · Fixed by #1643
Closed

Full Yellow Local - WazuhDB tests in 4.2 #1535

Rebits opened this issue Jul 2, 2021 · 2 comments · Fixed by #1643
Assignees

Comments

@Rebits
Copy link
Member

Rebits commented Jul 2, 2021

Description

This issue is part of the #1516. After the research #1493, it has been detected that wazuh_db tests do not properly autoconfigure the testing environment. These tests do not start automatically wazuh_db daemon. In an environment where the Wazuh manager has not started for the first time, these tests will fail in some cases.

Research results

Pipeline parameters

Jenkins branch QA branch
4.2 1516-4.2.0-full-green

Packages details

Type Format Architecture Version Revision Tag File name
Server rpm x86_64 4.2.0 40207 v4.2.0-rc8 wazuh-manager-4.2.0-1.1493.x86_64.rpm

In the case presented in the description, wazuh_db tests fail in the following cases:


FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: Insert commands] - AssertionErro...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: Update commands] - AssertionErro...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: Select commands] - AssertionErro...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: get-all-agents command] - Assert...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: sync-agent-info-get command] - A...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: Reset connection status] - Asser...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: get-agents-by-connection-status command]
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: disconnect-agents command] - Ass...
===================================== 8 failed, 22 passed in 26.11s =====================================

The error output obtained is:

test_wazuh_db/test_wazuh_db.py ...............FF.FFF..FFF....                                     [100%]
=============================================== FAILURES ================================================
____________________________ test_wazuh_db_messages[global: Insert commands] ____________________________
configure_sockets_environment = None
connect_to_sockets_module = [<wazuh_testing.tools.monitoring.SocketController object at 0x7f7b39d165f8>]
test_case = [{'input': 'global delete-group TestGroup1', 'output': 'ok', 'stage': 'global delete-group previous insert'}, {'input'...lect-groups', 'output': 'ok [{"name":"default"},{"name":"TestGroup1"}]', 'stage': 'global select-groups success'}, ...]
    @pytest.mark.parametrize('test_case',
                             [case['test_case'] for module_data in module_tests for case in module_data[0]],
                             ids=[f"{module_name}: {case['name']}"
                                  for module_data, module_name in module_tests
                                  for case in module_data]
                             )
    def test_wazuh_db_messages(configure_sockets_environment, connect_to_sockets_module, test_case: list):
        """Check that every input message in wazuh-db socket generates the adequate output to wazuh-db socket
        Parameters
        ----------
        test_case : list
            List of test_case stages (dicts with input, output and stage keys).
        """
        for index, stage in enumerate(test_case):
            if 'ignore' in stage and stage['ignore'] == "yes":
                continue
            expected = stage['output']
            receiver_sockets[0].send(stage['input'], size=True)
            response = receiver_sockets[0].receive(size=True).decode()
            if 'use_regex' in stage and stage['use_regex'] == 'yes':
                match = True if regex_match(expected, response) else False
            else:
                match = (expected == response)
>           assert match, 'Failed test case stage {}: {}. Expected: {}. Response: {}' \
                .format(index + 1, stage['stage'], expected, response)
E           AssertionError: Failed test case stage 4: global find-group after insert. Expected: ok [{"id":*}]. Response: ok []
E           assert False
test_wazuh_db/test_wazuh_db.py:105: AssertionError
____________________________ test_wazuh_db_messages[global: Update commands] ____________________________

All tests should autoconfigure the testing environment in order to prevent unexpected behaviours.

@snaow snaow changed the title Full-Green - Fix autoconfiguration in WazuhDB tests in 4.2 Full-Green - WazuhDB tests in 4.2. Autoconfiguration does not work. Jul 2, 2021
@damarisg damarisg changed the title Full-Green - WazuhDB tests in 4.2. Autoconfiguration does not work. Full Yellow Local - WazuhDB tests in 4.2. Autoconfiguration does not work. Jul 5, 2021
@Rebits Rebits self-assigned this Jul 20, 2021
@Rebits
Copy link
Member Author

Rebits commented Jul 20, 2021

It has been detected that this test fails in case of the manager has already registered some agents before the test is run. This should be fixed in other to guarantee independence between tests.


test_wazuh_db/test_wazuh_db.py ...................F.F.F......                                                                                                                                               [100%]

==================================================================================================== FAILURES =====================================================================================================
_____________________________________________________________________________ test_wazuh_db_messages[global: get-all-agents command] ______________________________________________________________________________

configure_sockets_environment = None, connect_to_sockets_module = [<wazuh_testing.tools.monitoring.SocketController object at 0x7f5495e72668>]
test_case = [{'input': 'global get-all-agents last_id -1', 'output': 'ok [{"id":0},{"id":1},{"id":2}]', 'stage': 'global get-all-agents success'}]

    @pytest.mark.parametrize('test_case',
                             [case['test_case'] for module_data in module_tests for case in module_data[0]],
                             ids=[f"{module_name}: {case['name']}"
                                  for module_data, module_name in module_tests
                                  for case in module_data]
                             )
    def test_wazuh_db_messages(configure_sockets_environment, connect_to_sockets_module, test_case: list):
        """Check that every input message in wazuh-db socket generates the adequate output to wazuh-db socket
    
        Parameters
        ----------
        test_case : list
            List of test_case stages (dicts with input, output and stage keys).
        """
        for index, stage in enumerate(test_case):
            if 'ignore' in stage and stage['ignore'] == "yes":
                continue
    
            expected = stage['output']
            receiver_sockets[0].send(stage['input'], size=True)
            response = receiver_sockets[0].receive(size=True).decode()
    
            if 'use_regex' in stage and stage['use_regex'] == 'yes':
                match = True if regex_match(expected, response) else False
            else:
                match = (expected == response)
>           assert match, 'Failed test case stage {}: {}. Expected: {}. Response: {}' \
                .format(index + 1, stage['stage'], expected, response)
E           AssertionError: Failed test case stage 1: global get-all-agents success. Expected: ok [{"id":0},{"id":1},{"id":2}]. Response: ok [{"id":0},{"id":1},{"id":2},{"id":3}]
E           assert False

test_wazuh_db/test_wazuh_db.py:105: AssertionError
___________________________________________________________________________ test_wazuh_db_messages[global: sync-agent-info-set command] ___________________________________________________________________________

configure_sockets_environment = None, connect_to_sockets_module = [<wazuh_testing.tools.monitoring.SocketController object at 0x7f5495e72668>]
test_case = [{'input': 'global sync-agent-info-set [{"id":3,"name":"TestName3","ip":"0.0.0.3","os_name":"TestOsName","os_version":...,"connection_status":"never_connected"}]', 'stage': 'global get-agent-info success after sync-agent-info-set success'}]

    @pytest.mark.parametrize('test_case',
                             [case['test_case'] for module_data in module_tests for case in module_data[0]],
                             ids=[f"{module_name}: {case['name']}"
                                  for module_data, module_name in module_tests
                                  for case in module_data]
                             )
    def test_wazuh_db_messages(configure_sockets_environment, connect_to_sockets_module, test_case: list):
        """Check that every input message in wazuh-db socket generates the adequate output to wazuh-db socket
    
        Parameters
        ----------
        test_case : list
            List of test_case stages (dicts with input, output and stage keys).
        """
        for index, stage in enumerate(test_case):
            if 'ignore' in stage and stage['ignore'] == "yes":
                continue
    
            expected = stage['output']
            receiver_sockets[0].send(stage['input'], size=True)
            response = receiver_sockets[0].receive(size=True).decode()
    
            if 'use_regex' in stage and stage['use_regex'] == 'yes':
                match = True if regex_match(expected, response) else False
            else:
                match = (expected == response)
>           assert match, 'Failed test case stage {}: {}. Expected: {}. Response: {}' \
                .format(index + 1, stage['stage'], expected, response)
E           AssertionError: Failed test case stage 1: global sync-agent-info-set non-existent agent. Expected: ok. Response: err Cannot execute Global database query; NOT NULL constraint failed: agent.connection_status
E           assert False

test_wazuh_db/test_wazuh_db.py:105: AssertionError
_____________________________________________________________________________ test_wazuh_db_messages[global: Reset connection status] _____________________________________________________________________________

configure_sockets_environment = None, connect_to_sockets_module = [<wazuh_testing.tools.monitoring.SocketController object at 0x7f5495e72668>]
test_case = [{'input': 'global update-connection-status {"id":1,"connection_status":"pending","sync_status":"synced"}', 'output': ...":"active"}]', 'stage': 'global manager get-agent-info success post reset connection status', 'use_regex': 'yes'}, ...]

    @pytest.mark.parametrize('test_case',
                             [case['test_case'] for module_data in module_tests for case in module_data[0]],
                             ids=[f"{module_name}: {case['name']}"
                                  for module_data, module_name in module_tests
                                  for case in module_data]
                             )
    def test_wazuh_db_messages(configure_sockets_environment, connect_to_sockets_module, test_case: list):
        """Check that every input message in wazuh-db socket generates the adequate output to wazuh-db socket
    
        Parameters
        ----------
        test_case : list
            List of test_case stages (dicts with input, output and stage keys).
        """
        for index, stage in enumerate(test_case):
            if 'ignore' in stage and stage['ignore'] == "yes":
                continue
    
            expected = stage['output']
            receiver_sockets[0].send(stage['input'], size=True)
            response = receiver_sockets[0].receive(size=True).decode()
    
            if 'use_regex' in stage and stage['use_regex'] == 'yes':
                match = True if regex_match(expected, response) else False
            else:
                match = (expected == response)
>           assert match, 'Failed test case stage {}: {}. Expected: {}. Response: {}' \
                .format(index + 1, stage['stage'], expected, response)
E           AssertionError: Failed test case stage 9: global agent get-agent-info success post reset connection status. Expected: ok [{"id":3,"name":"TestName3","ip":"0.0.0.3","register_ip":"0.0.0.3","internal_key":"TopSecret","os_name":"TestOsName","os_version":"TestOsVersion","os_major":"TestOsMajor","os_minor":"TestOsMinor","os_codename":"TestOsCodeName","os_build":"TestOsBuild","os_platform":"TestOsPlatfor","os_uname":"TestOsUname","os_arch":"TestOsArch","config_sum":"TestConfigSum","merged_sum":"TestMergedSum","manager_host":"TestManagerHost","node_name":"TestNodeName","date_add":1599223378,"last_keepalive":200,"sync_status":"syncreq","connection_status":"disconnected"}]. Response: ok [{"id":3,"name":"1-b42dc306-debian7","ip":"10.0.2.15","register_ip":"any","internal_key":"71cf956218f4e5c839d538a6ed09ce81b9152e7b4e19132984ee19fac988ebda","os_name":"Debian GNU/Linux","os_version":"7","os_major":"7","os_codename":"wheezy","os_platform":"debian","os_uname":"Linux |agent-debian7 |3.16.0-9-amd64 |#1 SMP Debian 3.16.68-1 (2019-05-22) |x86_64","os_arch":"x86_64","version":"Wazuh v3.12.0","config_sum":"ab73af41699f13fdd81903b5f23d8d00","merged_sum":"2c45c95db2954d2c7d0ea533f09e81a5","manager_host":"centos1","node_name":"node01","date_add":1626728461,"last_keepalive":1626728531,"group":"default","sync_status":"syncreq","connection_status":"disconnected"}]
E           assert False

test_wazuh_db/test_wazuh_db.py:105: AssertionError
============================================================================================= short test summary info =============================================================================================
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: get-all-agents command] - AssertionError: Failed test case stage 1: global get-all-agents success. Expected: ok [{"id":0},{"id":1},{"id":2...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: sync-agent-info-set command] - AssertionError: Failed test case stage 1: global sync-agent-info-set non-existent agent. Expected: ok. Resp...
FAILED test_wazuh_db/test_wazuh_db.py::test_wazuh_db_messages[global: Reset connection status] - AssertionError: Failed test case stage 9: global agent get-agent-info success post reset connection status. Exp...
========================================================================================== 3 failed, 27 passed in 34.14s ==========================================================================================

@snaow snaow changed the title Full Yellow Local - WazuhDB tests in 4.2. Autoconfiguration does not work. Full Yellow Local - WazuhDB tests in 4.2. Aug 9, 2021
@snaow snaow changed the title Full Yellow Local - WazuhDB tests in 4.2. Full Yellow Local - WazuhDB tests in 4.2 Aug 9, 2021
@snaow
Copy link
Contributor

snaow commented Aug 17, 2021

Closed by #1643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants