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

Remove workarround restart manager logtest #1507

Conversation

juliancnn
Copy link
Member

@juliancnn juliancnn commented Jun 25, 2021

Related issue
Closes #1506

Hi team!,

This PR implements 3 changes:

  • Remove workarround to restart manager in the tests: test_invalid_rule_decoders_syntax
  • Remove workarround to restart manager in the tests: test_rules_decoders_load
  • Change the debug mode of analysisd before running remove session tests, (no need to set it manually anymore, neither in jenkis).

Regards,
Julian

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

@juliancnn juliancnn self-assigned this Jun 25, 2021
@juliancnn juliancnn linked an issue Jun 25, 2021 that may be closed by this pull request
@juliancnn juliancnn force-pushed the 1506-remove-workarround-restart-manager-logtest branch from 937631c to 29dd8d3 Compare June 28, 2021 13:43
@JcabreraC
Copy link
Member

JcabreraC commented Jun 30, 2021

Test

test_invalid_decoder_syntax.py

# python3 -m pytest tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py -vvs
======================================== test session starts ========================================
platform linux -- Python 3.6.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
metadata: {'Python': '3.6.9', 'Platform': 'Linux-5.4.0-77-generic-x86_64-with-Ubuntu-18.04-bionic', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '3.1.1', 'testinfra': '5.0.0', 'metadata': '1.9.0'}}
rootdir: /home/Wazuh/wazuh-qa/tests/integration, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-1.9.0
collected 11 items                                                                                  

tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: garbage file] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: no closing XML tag] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: no existing parent] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: no existing attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: decoder with no name] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: regex attribute without order attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: regex attribute without prematch/program_name/parent attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: order attribute without regex attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: two-level order parenting] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: invalid plugin_decoder] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_decoder_syntax.py::test_invalid_decoder_syntax[Invalid decoder syntax: invalid offset] PASSED

======================================== 11 passed in 0.58s =========================================

test_invalid_rules_syntax.py

# python3 -m pytest tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py -vvs
======================================== test session starts ========================================
platform linux -- Python 3.6.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
metadata: {'Python': '3.6.9', 'Platform': 'Linux-5.4.0-77-generic-x86_64-with-Ubuntu-18.04-bionic', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '3.1.1', 'testinfra': '5.0.0', 'metadata': '1.9.0'}}
rootdir: /home/Wazuh/wazuh-qa/tests/integration, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-1.9.0
collected 15 items                                                                                  

tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: garbage file] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: no closing XML tag] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: no group] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: invalid level] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: invalid rule overwrite] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: same_* attribute without frequency and timeframe] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: invalid weekday] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: no existing if_sid rule number] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: no existing if_matched_sid rule number attribute without frequency and timeframe] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: non existing/invalid attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: no invalid rule label] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: non existing group in if_group] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: invalid values on option attribute] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: different_* attribute without frequency and timeframe] PASSED
tests/integration/test_logtest/test_invalid_rule_decoders_syntax/test_invalid_rules_syntax.py::test_invalid_rule_syntax[Invalid rules syntax: non existing decoder] PASSED

======================================== 15 passed in 6.29s =========================================

test_remove_old_sessions.py

# python3 -m pytest tests/integration/test_logtest/test_remove_old_sessions/test_remove_old_sessions.py -vvs
======================================== test session starts ========================================
platform linux -- Python 3.6.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
metadata: {'Python': '3.6.9', 'Platform': 'Linux-5.4.0-77-generic-x86_64-with-Ubuntu-18.04-bionic', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '3.1.1', 'testinfra': '5.0.0', 'metadata': '1.9.0'}}
rootdir: /home/Wazuh/wazuh-qa/tests/integration, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-1.9.0
collected 1 item                                                                                    

tests/integration/test_logtest/test_remove_old_sessions/test_remove_old_sessions.py::test_remove_old_session[get_configuration0] PASSED2021-06-30T13:11:52.1625051512


======================================== 1 passed in 53.17s =========================================

test_remove_old_session_for_inactivity.py

python3 -m pytest tests/integration/test_logtest/test_remove_old_sessions/test_remove_old_session_for_inactivity.py -vvs
======================================== test session starts ========================================
platform linux -- Python 3.6.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
metadata: {'Python': '3.6.9', 'Platform': 'Linux-5.4.0-77-generic-x86_64-with-Ubuntu-18.04-bionic', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '3.1.1', 'testinfra': '5.0.0', 'metadata': '1.9.0'}}
rootdir: /home/Wazuh/wazuh-qa/tests/integration, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-1.9.0
collected 1 item                                                                                    

tests/integration/test_logtest/test_remove_old_sessions/test_remove_old_session_for_inactivity.py::test_remove_old_session_for_inactivity[get_configuration0] PASSED2021-06-30T12:28:37.1625048917


======================================== 1 passed in 57.67s =========================================

@nmkoremblum nmkoremblum force-pushed the 1506-remove-workarround-restart-manager-logtest branch 7 times, most recently from 164fb53 to e9d2e23 Compare July 1, 2021 19:11
@juliancnn
Copy link
Member Author

LGTM!!

nmkoremblum
nmkoremblum previously approved these changes Jul 1, 2021
Copy link
Contributor

@nmkoremblum nmkoremblum left a comment

Choose a reason for hiding this comment

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

👍

@JcabreraC
Copy link
Member

LGTM !

JcabreraC
JcabreraC previously approved these changes Jul 5, 2021
Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

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

GJ, but some changes are required.

Comment on lines 38 to 41
@pytest.fixture(scope='module')
def get_local_internal_options():
"""Get configurations from the module."""
return local_internal_options
Copy link
Member

Choose a reason for hiding this comment

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

Use configure_local_internal_options_module fixture, instead. Otherwise , local_internal_options dictionary will be useless. You should rebase this branch to add that fixture.

Suggested change
@pytest.fixture(scope='module')
def get_local_internal_options():
"""Get configurations from the module."""
return local_internal_options

Comment on lines 82 to 87
def test_remove_old_session_for_inactivity(get_local_internal_options,
configure_local_internal_options,
get_configuration,
configure_environment,
restart_required_logtest_daemons,
wait_for_logtest_startup,
connect_to_sockets_function):
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_remove_old_session_for_inactivity(get_local_internal_options,
configure_local_internal_options,
get_configuration,
configure_environment,
restart_required_logtest_daemons,
wait_for_logtest_startup,
connect_to_sockets_function):
def test_remove_old_session_for_inactivity(configure_local_internal_options,
get_configuration,
configure_environment,
restart_required_logtest_daemons,
wait_for_logtest_startup,
connect_to_sockets_function):

Comment on lines 51 to 55
@pytest.fixture(scope='module')
def wait_for_logtest_startup(request):
"""Wait until logtest has begun."""
log_monitor = FileMonitor(LOG_FILE_PATH)
log_monitor.start(timeout=logtest_startup_timeout, callback=callback_logtest_started)
Copy link
Member

Choose a reason for hiding this comment

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

This is used for other logtest tests. Create a contest file for the logtest folder and adds this fixture, in order to avoid code repetition.

Comment on lines 35 to 30
@pytest.fixture(scope='module')
def get_local_internal_options():
"""Get configurations from the module."""
return local_internal_options

Copy link
Member

Choose a reason for hiding this comment

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

Same as before

wazuh_log_monitor = FileMonitor(LOG_FILE_PATH)
logtest_sock = os.path.join(os.path.join(WAZUH_PATH, 'queue', 'sockets', 'logtest'))

local_internal_options = {'analysisd.debug': str(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
local_internal_options = {'analysisd.debug': str(1)}
local_internal_options = {'analysisd.debug': '1'}

Comment on lines 30 to 32
msg_create_session = """{"version":1, "command":"log_processing", "parameters":{
"event": "Oct 15 21:07:56 linux-agent sshd[29205]: Invalid user blimey from 18.18.18.18 port 48928",
"log_format": "syslog", "location": "master->/var/log/syslog"}}"""

Copy link
Member

Choose a reason for hiding this comment

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

Use json.dump instead

Suggested change
msg_create_session = """{"version":1, "command":"log_processing", "parameters":{
"event": "Oct 15 21:07:56 linux-agent sshd[29205]: Invalid user blimey from 18.18.18.18 port 48928",
"log_format": "syslog", "location": "master->/var/log/syslog"}}"""
create_session_data = {'version': 1, 'command': 'log_processing', 'parameters': {'event': 'Oct 15 21:07:56 linux-agent sshd[29205]: Invalid user blimey from 18.18.18.18 port 48928', 'log_format': 'syslog', 'location': 'master->/var/log/syslog'}}
msg_create_session = json.dumps(create_session_data)

@@ -22,17 +24,23 @@
configurations = load_wazuh_configurations(configurations_path, __name__)

# Variables
logtest_startup_timeout = 30
Copy link
Member

Choose a reason for hiding this comment

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

Maybe 30 seconds is too much to wait for logtest. Maybe is better to set it to '3'.

@Rebits
Copy link
Member

Rebits commented Sep 29, 2021

Other minor considerations about this PR:

  • It should be desirable to replace the not very informative error message ' Event not found' with a more precise one
           wazuh_log_monitor.start(timeout=global_parameters.default_timeout,
                                    callback=callback_session_initialized,
                                    error_message='Event not found')
  • Change test configuration file (wazuh_conf.yaml) to a more precise one
  • Use file_monitoring, master branch fixture. Tets header should be:
def test_remove_old_session(configure_local_internal_options_module,
                            get_configuration, configure_environment, file_monitoring,
                            restart_required_logtest_daemons,
                            wait_for_logtest_startup):

Also wazuh_log_monitor should be renamed to log_monitor in order to make this fixture work.

@nmkoremblum nmkoremblum force-pushed the 1433-logtest-ruleset-reload-runtime branch from 4e523d0 to fb0b3af Compare September 29, 2021 19:14
@nmkoremblum nmkoremblum changed the base branch from 1433-logtest-ruleset-reload-runtime to master September 29, 2021 19:31
@nmkoremblum nmkoremblum dismissed stale reviews from JcabreraC and themself September 29, 2021 19:31

The base branch was changed.

@nmkoremblum nmkoremblum changed the base branch from master to 1433-logtest-ruleset-reload-runtime September 29, 2021 19:31
@nmkoremblum nmkoremblum force-pushed the 1506-remove-workarround-restart-manager-logtest branch from 8b49c37 to 408f58e Compare September 29, 2021 19:38
@CamiRomero
Copy link
Contributor

Local - centos8 Manager
R1 🟢
R2 🟢
R3 🟢
Jenkins Manager
R1 🟢
R2 🟢
R3 🟢

@nmkoremblum nmkoremblum force-pushed the 1506-remove-workarround-restart-manager-logtest branch from ae5d1bb to b60930d Compare October 12, 2021 21:09
@juliamagan
Copy link
Member

juliamagan commented Oct 13, 2021

Package

Version Revision Link
4.3.0 40301 http://packages-dev.wazuh.com/warehouse/pullrequests/4.3/rpm/var/wazuh-manager-4.3.0-0.commit0a7ba8b.x86_64.rpm

Testing

Logtest

OS Local Jenkins Notes
PS1 🔴

  • 🟢: All pass
  • 🟡: Some warnings
  • 🔴: Some errors/fails
  • 🔵: In progress

@nmkoremblum nmkoremblum force-pushed the 1506-remove-workarround-restart-manager-logtest branch from e2c6429 to 22142dd Compare October 13, 2021 13:29
@Rebits Rebits closed this Oct 19, 2021
@Rebits Rebits force-pushed the 1506-remove-workarround-restart-manager-logtest branch from 6c877bd to 966476a Compare October 19, 2021 10:04
@Rebits Rebits reopened this Oct 19, 2021
@Rebits Rebits force-pushed the 1506-remove-workarround-restart-manager-logtest branch from 6c877bd to 22142dd Compare October 19, 2021 10:46
Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

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

LGTM

@Rebits Rebits merged commit 2e3a408 into 1433-logtest-ruleset-reload-runtime Oct 19, 2021
@Rebits Rebits deleted the 1506-remove-workarround-restart-manager-logtest branch October 19, 2021 11:25
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.

Remove workarround to restart manager in the logtest IT
7 participants