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

IT - WDB - 2532- Test sync_agent_groups_get WDB command #2626

Merged
merged 13 commits into from
Mar 7, 2022

Conversation

CamiRomero
Copy link
Contributor

@CamiRomero CamiRomero commented Mar 2, 2022

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.

Related issues #2532 #10771 (Wazuh)

Cases for sync_agent_groups_get command:

  • Condition
    - 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
    - set_synced in True
    - set_synced with invalidad value - boolean
    - Test set_synced with invalidad value - string
  • Get globlal hash
    - get_global_hash in true
    - get_global_hash in false
    - get_global_hash with invalid value
  • Agentregistration delta
    - '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
    - last_id - by default
    - last_id - obtain from second group
    - last_id - with not exist id
    - last_id - with negative value

Configuration options

OS Version Branch Type
Centos 4.4.0 dev-10771-agent-groups-files-to-wazuh-db Manager

Local Internal Options: No Local Internal Options used



Tests Results

Test Path Os/Type Execution Type Results Date By
test_wazuh_db/test_sync_agent_groups_get Manager Local 🟢🟢🟢 02/03/2022 @CamiRomero
test_wazuh_db/test_sync_agent_groups_get Manager Jenkins 🟢 🟢 🟢 02/03/2022 @CamiRomero

Required

  • 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.
  • Python codebase is documented following the Google Style for Python docstrings.
  • The test is documented in wazuh-qa/docs.

@CamiRomero CamiRomero self-assigned this Mar 2, 2022
@Deblintrake09 Deblintrake09 changed the title IT - WDB - 2532- Test sync_agent_groups_get WDB comman IT - WDB - 2532- Test sync_agent_groups_get WDB command Mar 2, 2022
@@ -167,6 +169,28 @@ def clean_agents_from_db():
raise Exception('Unable to clean agents')


def clean_groups_from_db():
"""
Clean groups from DB
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
Clean groups from DB
Clean groups table from global.db

try:
query_wdb(command)
except Exception:
raise Exception('Unable to clean groups')
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
raise Exception('Unable to clean groups')
raise Exception('Unable to clean groups table.')


def clean_belongs():
"""
Clean belong DB
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
Clean belong DB
Clean belong table from global.db

try:
query_wdb(command)
except Exception:
raise Exception('Unable to clean belongs')
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
raise Exception('Unable to clean belongs')
raise Exception('Unable to clean belongs table.')

Comment on lines 209 to 210
def insert_agent_into_group(amount):
for i in range(amount):
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 insert_agent_into_group(amount):
for i in range(amount):
def insert_agent_into_group(total_agents):
for i in range(total_agents):

Comment on lines 60 to 61
with open(messages_file) as f:
module_tests.append((yaml.safe_load(f), messages_file.split('_')[0]))
Copy link
Member

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():
Copy link
Member

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():
Copy link
Member

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.

Copy link
Contributor Author

@CamiRomero CamiRomero Mar 4, 2022

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

Copy link
Member

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.

Comment on lines 43 to 51
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
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 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

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 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]
Copy link
Member

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?

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 aa349

Copy link
Member

@damarisg damarisg left a comment

Choose a reason for hiding this comment

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

Tests Results

Test Path Os/Type Execution Type Results Date By
test_wazuhdb/test_sync_agent_groups_get Manager Jenkins 🟢🟢🟢 07/03/2022 Seyla

@damarisg damarisg merged commit a4bd8d3 into 2532-wazuh-db-commands Mar 7, 2022
@damarisg damarisg deleted the sync-agent-groups-get branch March 7, 2022 12:11
@damarisg damarisg linked an issue Mar 9, 2022 that may be closed by this pull request
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.

IT - Wazuh DB (T0): Successful behavior of wazuh DB commands
2 participants