Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System Tests: Module (FIM) - FIM Files Events: System test for FIM synchronization process #2536

Merged
merged 21 commits into from
Feb 22, 2022

Conversation

CamiRomero
Copy link
Contributor

@CamiRomero CamiRomero commented Feb 1, 2022

Related issue
2434

Description

While developing wazuh/wazuh#9103 we are planning to develop some system tests to check that the FIM database agent and the manager database are synchronized.

The changes made are as follows:

  • Added new script to performe query to DB - path: tests/system/scripts/system_query_db.py
  • Added new function query_db in init.py to can executed scripts to DB inside the host
  • Added tests/system/test_fim/test_synchronization/data/delete_message.ymlto check expected outputs
  • Added tests/system/test_fim/test_synchronization/data/messages.yml to check expected outputs
  • Added tests/system/test_fim/test_synchronization/data/wait_fim_scan.yml to check expected outputs
  • Added tests/system/test_fim/test_synchronization/data/agent_initializing_synchronization.yml to check expected outputs
  • Added tests/system/test_fim/test_synchronization/data/manager_initializing_synchronization.yml to check expected outputs
  • Added tests/system/test_fim/test_synchronization/test_synchronization.py to performance de test described in 2434

Configuration options

In order to run the test, first the environment located in /test/system/provisioning/one_manager_agent must be enabled with:
sudo ansible-playbook -i inventory.yml playbook.yml --extra-vars='{"wazuh_branch": "4.2"}'

Logs example

Run Results Date By Notes
R1 🟢 01/02/2022 @CamiRomero
R2 🟢 01/02/2022 @CamiRomero
R3 🟢 01/02/2022 @CamiRomero

Tests

  • Proven that tests pass when they have to pass.
  • Proven that tests fail when they have to fail.
  • Python codebase satisfies PEP-8 style style guide. pycodestyle --max-line-length=120 --show-source --show-pep8 file.py.

@CamiRomero CamiRomero changed the title 2434 fim synchronizaton agent stopped System Tests: Module (FIM) - FIM Files Events: System test for FIM synchronization process Feb 2, 2022
type: system
brief: Check that when FIM is activated, and the agent is running, the agent and manager are synchronization when
a change is performed in a monitored folder.
tier: 1
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tier: 1
tier: 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not part of this PR. I applied the change in 2443

Comment on lines 44 to 45

import pytest
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import pytest
import pytest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not part of this PR. I applied the change in #2443

Comment on lines 68 to 72
'''
The test will monitor a directory.
Finally, it will verify that the FIM event is generated
in agent and manager side.
'''
Copy link
Member

Choose a reason for hiding this comment

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

Add the comments as shown in the schema 2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was worked in PR [2443](This is not part of this PR. 2443

type: system
brief: Check that when FIM is activated, and the agent is running, the agent and manager are synchronization when
a change is performed in a monitored folder.
tier: 1
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tier: 1
tier: 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 83482

Comment on lines 78 to 80
Description: The test will monitor a directory and apply changes when agent is stopped.
Finally, it will verify that the FIM 'Synchronization' event is generated
in agent and manager side.
Copy link
Member

Choose a reason for hiding this comment

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

The synchronization is when the agent and manager are running again, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 71e04

@pytest.mark.parametrize('host', ['wazuh-agent1', 'wazuh-manager'])
@pytest.mark.parametrize('case', ['add', 'modify', 'delete'])
@pytest.mark.parametrize('folder_path', ['testdir1'])
def test_Synchronization_create_file_agent_stopped(folder_path, case, host):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_Synchronization_create_file_agent_stopped(folder_path, case, host):
def test_synchronization_create_file_agent_stopped(folder_path, case, host):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 7ae07

Comment on lines 52 to 53
testinfra_hosts = ["wazuh-manager", "wazuh-agent1"]

Copy link
Member

Choose a reason for hiding this comment

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

When do you use it?



# Hosts
testinfra_hosts = ["wazuh-manager", "wazuh-agent1"]
Copy link
Member

Choose a reason for hiding this comment

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

When do you use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 080c1


clean_logs(host_manager)

# Stop agent
Copy link
Member

Choose a reason for hiding this comment

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

There are 2 cases: the agent stops and the manager stops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 1321a

@pytest.mark.parametrize('host', ['wazuh-agent1', 'wazuh-manager'])
@pytest.mark.parametrize('case', ['add', 'modify', 'delete'])
@pytest.mark.parametrize('folder_path', ['testdir1'])
def test_Synchronization_create_file_agent_stopped(folder_path, case, host):
Copy link
Member

Choose a reason for hiding this comment

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

The name should be representative. It doesn't just create a file (it also modifies and deletes it) and, the description says that it is when the manager or agent stops (2 cases). However, the test name only talks about agent stopped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 7ae07

@Deblintrake09
Copy link
Contributor

Run Results Date By Notes
R1 🟢 02/02/2022 @Deblintrake09
R2 🟢 02/02/2022 @Deblintrake09
R3 🟢 02/02/2022 @Deblintrake09

Comment on lines 8 to 28
def create_folder_file(host_manager, folder_path):
# Create folder
host_manager.run_command('wazuh-agent1', f'mkdir {folder_path}')

# Create file
host_manager.run_command('wazuh-agent1', f'touch {folder_path}/{folder_path}.txt')


def wait_for_fim_scan_end(HostMonitor, inventory_path, messages_path, tmp_path):
HostMonitor(inventory_path=inventory_path,
messages_path=messages_path,
tmp_path=tmp_path).run()


def clean_logs(host_manager):
host_manager.clear_file(host='wazuh-manager', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))
host_manager.clear_file(host='wazuh-agent1', file_path=os.path.join(WAZUH_LOGS_PATH, 'ossec.log'))


def query_db(host_manager, script, db_path, query):
return host_manager.run_command('wazuh-manager', "python {} --db_path {} --query {}".format(script, db_path, query))
Copy link
Member

Choose a reason for hiding this comment

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

Comments are necessary for each method. Why don't you have them here?

@CamiRomero
Copy link
Contributor Author

Run Results Date By Notes
R1 🟢 03/02/2022 @CamiRomero
R2 🟢 03/02/2022 @CamiRomero
R3 🟢 03/02/2022 @CamiRomero

@Deblintrake09
Copy link
Contributor

Run Results Date By Notes
R1 🟢 03/02/2022 @Deblintrake09
R2 🟢 03/02/2022 @Deblintrake09
R3 🟢 03/02/2022 @Deblintrake09

Deblintrake09
Deblintrake09 previously approved these changes Feb 3, 2022
@CamiRomero
Copy link
Contributor Author

CamiRomero commented Feb 11, 2022

Run Results Date By Notes
R1 🟢 11/02/2022 @CamiRomero
R2 🟢 11/02/2022 @CamiRomero
R3 🟢 11/02/2022 @CamiRomero

@snaow snaow merged commit b208963 into master Feb 22, 2022
@snaow snaow deleted the 2434-fim-synchronizaton-agent-stopped branch February 22, 2022 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FIM Files Events: System test for FIM synchronization process (2)
4 participants