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

Add unittests for agent_upgrade script #12873

Conversation

Selutario
Copy link
Member

Related issue
Closes #12813

Description

This PR adds unit tests for the framework/scripts/agent_upgrade.py module. Some changes were also applied on the module itself to achieve a higher coverage.

Tests

python3.9 -m pytest framework/scripts/tests/test_agent_upgrade.py -xvv --cov
============================================================================================ test session starts ============================================================================================
platform linux -- Python 3.9.5, pytest-7.0.1, pluggy-1.0.0 -- /home/selu/venv/3.9-unittest-env/bin/python3.9
cachedir: .pytest_cache
rootdir: /home/selu/Git/wazuh/framework
plugins: anyio-3.5.0, asyncio-0.18.1, aiohttp-1.0.4, cov-3.0.0
asyncio: mode=auto
collected 15 items                                                                                                                                                                                          

framework/scripts/tests/test_agent_upgrade.py::test_signal_handler PASSED                                                                                                                             [  6%]
framework/scripts/tests/test_agent_upgrade.py::test_get_script_arguments PASSED                                                                                                                       [ 13%]
framework/scripts/tests/test_agent_upgrade.py::test_list_outdated[api_response0-1] PASSED                                                                                                             [ 20%]
framework/scripts/tests/test_agent_upgrade.py::test_list_outdated[api_response1-0] PASSED                                                                                                             [ 26%]
framework/scripts/tests/test_agent_upgrade.py::test_get_agents_versions PASSED                                                                                                                        [ 33%]
framework/scripts/tests/test_agent_upgrade.py::test_create_command PASSED                                                                                                                             [ 40%]
framework/scripts/tests/test_agent_upgrade.py::test_send_command PASSED                                                                                                                               [ 46%]
framework/scripts/tests/test_agent_upgrade.py::test_print_result[agents_versions0-failed_agents0-\nUpgraded agents:\n\tAgent 001 upgraded: 4.2.0 -> 4.3.0\n\nFailed upgrades:\n\tAgent 001 status: test_error\n] PASSED [ 53%]
framework/scripts/tests/test_agent_upgrade.py::test_print_result[agents_versions1-failed_agents1-] PASSED                                                                                             [ 60%]
framework/scripts/tests/test_agent_upgrade.py::test_print_result[agents_versions2-failed_agents2-\nUpgraded agents:\n\tAgent 001 upgraded: 4.2.0 -> 4.3.0\n] PASSED                                   [ 66%]
framework/scripts/tests/test_agent_upgrade.py::test_print_result[agents_versions3-failed_agents3-\nFailed upgrades:\n\tAgent 001 status: test_error\n] PASSED                                         [ 73%]
framework/scripts/tests/test_agent_upgrade.py::test_check_status[True] PASSED                                                                                                                         [ 80%]
framework/scripts/tests/test_agent_upgrade.py::test_check_status[False] PASSED                                                                                                                        [ 86%]
framework/scripts/tests/test_agent_upgrade.py::test_main PASSED                                                                                                                                       [ 93%]
framework/scripts/tests/test_agent_upgrade.py::test_main_ko PASSED                                                                                                                                    [100%]

============================================================================================= warnings summary ==============================================================================================
../../venv/3.9-unittest-env/lib/python3.9/site-packages/pytest_aiohttp/plugin.py:28
  /home/selu/venv/3.9-unittest-env/lib/python3.9/site-packages/pytest_aiohttp/plugin.py:28: DeprecationWarning: The 'asyncio_mode' is 'legacy', switching to 'auto' for the sake of pytest-aiohttp backward compatibility. Please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

----------- coverage: platform linux, python 3.9.5-final-0 -----------
Name                                            Stmts   Miss  Cover
-------------------------------------------------------------------
[...]
framework/scripts/agent_upgrade.py                115      6    95%
[...]


======================================================================================= 15 passed, 1 warning in 1.42s =======================================================================================

@Selutario Selutario self-assigned this Mar 28, 2022
@Selutario Selutario changed the base branch from master to feature/12811-add-unit-tests-for-cli March 28, 2022 09:01
@Selutario Selutario changed the title Feature/12813 agent upgrade unittests Add unittests for agent_upgrade script Mar 28, 2022
@Selutario Selutario force-pushed the feature/12813-agent-upgrade-unittests branch from d48da5b to b78ec33 Compare March 31, 2022 10:43
@davidjiglesias davidjiglesias merged commit 1f27e7a into feature/12811-add-unit-tests-for-cli Apr 7, 2022
@davidjiglesias davidjiglesias deleted the feature/12813-agent-upgrade-unittests branch April 7, 2022 10:59
AdriiiPRodri pushed a commit that referenced this pull request Apr 29, 2022
* Add unittests for agent_upgrade module

* Optimize imports

* Use RBAC bypasser
AdriiiPRodri pushed a commit that referenced this pull request May 9, 2022
* Add unittests for agent_upgrade module

* Optimize imports

* Use RBAC bypasser
AdriiiPRodri pushed a commit that referenced this pull request May 11, 2022
* Add unittests for agent_upgrade module

* Optimize imports

* Use RBAC bypasser
AdriiiPRodri pushed a commit that referenced this pull request May 16, 2022
* Add unittests for agent_upgrade module

* Optimize imports

* Use RBAC bypasser
davidjiglesias pushed a commit that referenced this pull request May 17, 2022
* Add '__init__.py'

* Change wazuh-logtest and wazuh-clusterd script names (#12926)

* Change wazuh-clusterd and wazuh-logtest names

* Add provisional name change for logtest and clusterd

* Remove __init__ binary

* Add 'wazuh-logtest' unittest (#13042)

* Add unittests for wazuh_clusterd.py (#13027)

* Refactor wazuh-clusterd code

* Add wazuh_clusterd unittests

* Improve DAPI unittest

* Add unittests for `agent_upgrade` script (#12873)

* Add unittests for agent_upgrade module

* Optimize imports

* Use RBAC bypasser

* Add unittests for agent-groups script

* Fix agent_upgrade CLI test

* Remove unused mock

* Fix test_wazuh_clusterd

* Fixed bug caused by the chain execution of framework unit tests

* Added a unittest for 'cluster_control.py'

* Use the 'headers' variable

* Fix unittests after agent-groups merge

Co-authored-by: yanazaeva <yana.zaeva@wazuh.com>
Co-authored-by: yanazaeva <67015786+yanazaeva@users.noreply.github.com>
Co-authored-by: José Luis López Sánchez <joseluis.lopez@wazuh.com>
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.

Create unit test for agent_upgrade.py
3 participants