-
Notifications
You must be signed in to change notification settings - Fork 32
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
IT - WDB - 2532- Test sync_agent_groups_get WDB command #2626
Conversation
@@ -167,6 +169,28 @@ def clean_agents_from_db(): | |||
raise Exception('Unable to clean agents') | |||
|
|||
|
|||
def clean_groups_from_db(): | |||
""" | |||
Clean groups from DB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean groups from DB | |
Clean groups table from global.db |
try: | ||
query_wdb(command) | ||
except Exception: | ||
raise Exception('Unable to clean groups') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise Exception('Unable to clean groups') | |
raise Exception('Unable to clean groups table.') |
|
||
def clean_belongs(): | ||
""" | ||
Clean belong DB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean belong DB | |
Clean belong table from global.db |
try: | ||
query_wdb(command) | ||
except Exception: | ||
raise Exception('Unable to clean belongs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise Exception('Unable to clean belongs') | |
raise Exception('Unable to clean belongs table.') |
def insert_agent_into_group(amount): | ||
for i in range(amount): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def insert_agent_into_group(amount): | |
for i in range(amount): | |
def insert_agent_into_group(total_agents): | |
for i in range(total_agents): |
with open(messages_file) as f: | ||
module_tests.append((yaml.safe_load(f), messages_file.split('_')[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could improve by adding a method with parameters and then calling it.
|
||
# Fixtures | ||
@pytest.fixture(scope='function') | ||
def pre_insert_agents(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a short description.
|
||
# Fixtures | ||
@pytest.fixture(scope='function') | ||
def pre_insert_agents(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused name because not only insert agents else also clean all tables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this Fixture is to insert agents and assign those agents into a group, the cleans are after a 'yield' and execute after the test to assure that the environment is clean. Maybe I can change the name to pre_insert_agents_into_group
but I think that is not necessary to consider the steps inside yield for the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! But not only insert but also remove as you mentioned, so the name should contain the words insert and remove agents. It helps to be representative of the content of the method.
import os | ||
import time | ||
import pytest | ||
import yaml | ||
import json | ||
from wazuh_testing.tools import WAZUH_PATH | ||
from wazuh_testing.wazuh_db import (query_wdb, insert_agent_into_group, clean_agents_from_db, | ||
clean_groups_from_db, clean_belongs) | ||
from wazuh_testing.tools.file import get_list_of_content_yml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import os | |
import time | |
import pytest | |
import yaml | |
import json | |
from wazuh_testing.tools import WAZUH_PATH | |
from wazuh_testing.wazuh_db import (query_wdb, insert_agent_into_group, clean_agents_from_db, | |
clean_groups_from_db, clean_belongs) | |
from wazuh_testing.tools.file import get_list_of_content_yml | |
import os | |
import time | |
import pytest | |
import yaml | |
import json | |
from wazuh_testing.tools import WAZUH_PATH | |
from wazuh_testing.wazuh_db import (query_wdb, insert_agent_into_group, clean_agents_from_db, | |
clean_groups_from_db, clean_belongs) | |
from wazuh_testing.tools.file import get_list_of_content_yml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 2c5809
from wazuh_testing.tools.file import get_list_of_content_yml | ||
|
||
# Marks | ||
pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use marks defined on deps\wazuh_testing\wazuh_testing\modules\ __init__.py
, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit aa349
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR the test suite for
sync_agent_groups_get
command is added. A total of 22 new test cases covering different modes and combinations of options.Cases for
sync_agent_groups_get
command:- sync_status with response
- sync_status without response
- all condition when agent groups are in 'sync_req'
- 'all' condition when agent groups are in 'synced'
- 'sync_status' condition when one agent groups are in 'synced'
- 'all' condition when one agent groups are in 'synced'
- Test with and invalid filter in condition
- Test without condition
- set_synced in True
- set_synced with invalidad value - boolean
- Test set_synced with invalidad value - string
- get_global_hash in true
- get_global_hash in false
- get_global_hash with invalid value
- 'agent_registration_delta' in 0 and sync_status
- 'agent_registration_delta' in 0 and all condition
- 'agent_registration_delta' with delta in 10000 and sync_status
- 'agent_registration_delta' with delta in 10000 and all
- last_id - by default
- last_id - obtain from second group
- last_id - with not exist id
- last_id - with negative value
Configuration options
Local Internal Options: No Local Internal Options used
Tests Results
Required
pycodestyle --max-line-length=120 --show-source --show-pep8 file.py
.