Skip to content

Commit

Permalink
refactor(#2947): Move analysisd fixtures to integration conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
jmv74211 committed Sep 12, 2022
1 parent 5ac7de7 commit e8d08af
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 53 deletions.
37 changes: 37 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from wazuh_testing import mocking
from wazuh_testing.db_interface.agent_db import update_os_info
from wazuh_testing.db_interface.global_db import get_system, modify_system
from wazuh_testing.tools.run_simulator import simulate_agent,syslog_simulator


if sys.platform == 'win32':
Expand Down Expand Up @@ -1188,3 +1189,39 @@ def create_file(new_file_path):
yield

remove_file(new_file_path)


@pytest.fixture(scope='function')
def simulate_agent_function(request):
"""Fixture to run the script simulate_agent.py"""
simulate_agent(request.param)

yield


@pytest.fixture(scope='session')
def load_wazuh_basic_configuration():
"""Load a new basic configuration to the manager"""
# Load ossec.conf with all disabled settings
minimal_configuration = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'all_disabled_ossec.conf')

# Make a backup from current configuration
backup_ossec_configuration = get_wazuh_conf()

# Write new configuration
with open(minimal_configuration, 'r') as file:
lines = file.readlines()
write_wazuh_conf(lines)

yield

# Restore the ossec.conf backup
write_wazuh_conf(backup_ossec_configuration)


@pytest.fixture(scope='function')
def syslog_simulator_function(request):
"""Fixture to run the script syslog_simulator.py"""
syslog_simulator(request.param)

yield
52 changes: 1 addition & 51 deletions tests/integration/test_analysisd/test_eps/conftest.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
# Copyright (C) 2015-2021, Wazuh Inc.
# Created by Wazuh, Inc. <[email protected]>.
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2
import os
import pytest

from wazuh_testing.tools.services import control_service
from wazuh_testing.tools import configuration
from wazuh_testing.tools.run_simulator import simulate_agent,syslog_simulator


@pytest.fixture(scope='function')
def set_wazuh_configuration_analysisd(configuration, set_wazuh_configuration, configure_local_internal_options_eps):
"""Set wazuh configuration
Args:
configuration (dict): Configuration template data to write in the ossec.conf.
set_wazuh_configuration (fixture): Set the wazuh configuration according to the configuration data.
configure_local_internal_options_eps (fixture): Set the local_internal_options.conf file.
"""
yield


@pytest.fixture(scope='function')
def simulate_agent_function(request):
"""Fixture to run the script simulate_agent.py"""
simulate_agent(request.param)

yield


@pytest.fixture(scope='function')
def configure_wazuh_one_thread():
def configure_analysisd_one_thread():
"""Fixture to configure the local internal options file to work with one thread."""
local_internal_options = {'analysisd.event_threads': '1', 'analysisd.syscheck_threads': '1',
'analysisd.syscollector_threads': '1', 'analysisd.rootcheck_threads': '1',
Expand All @@ -48,30 +25,3 @@ def configure_wazuh_one_thread():

# Backup the old local internal options cofiguration
configuration.set_wazuh_local_internal_options(backup_local_internal_options)


@pytest.fixture(scope='session')
def load_wazuh_basic_configuration():
"""Load a new basic configuration to the manager"""
# Reference paths
DATA_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
CONFIGURATIONS_PATH = os.path.join(DATA_PATH, 'wazuh_basic_configuration')
configurations_path = os.path.join(CONFIGURATIONS_PATH, 'ossec.conf')

backup_ossec_configuration = configuration.get_wazuh_conf()

with open(configurations_path, 'r') as file:
lines = file.readlines()
configuration.write_wazuh_conf(lines)

yield

configuration.write_wazuh_conf(backup_ossec_configuration)


@pytest.fixture(scope='function')
def syslog_simulator_function(request):
"""Fixture to run the script syslog_simulator.py"""
syslog_simulator(request.param)

yield
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
@pytest.mark.parametrize('configure_local_internal_options_module', local_internal_configuration_t1, indirect=True)
@pytest.mark.parametrize('syslog_simulator_function', [params_process_old_events_one_thread], indirect=True)
def test_process_old_events_one_thread(configuration, metadata, load_wazuh_basic_configuration,
configure_local_internal_options_module, configure_wazuh_one_thread,
configure_local_internal_options_module, configure_analysisd_one_thread,
truncate_monitored_files, restart_wazuh_daemon_function,
syslog_simulator_function):
'''
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_process_old_events_one_thread(configuration, metadata, load_wazuh_basic
- set_wazuh_configuration_analysisd:
type: fixture
brief: Set the wazuh configuration according to the configuration data.
- configure_wazuh_one_thread:
- configure_analysisd_one_thread:
type: fixture
brief: Set the wazuh internal option configuration according to the configuration data.
- truncate_monitored_files:
Expand Down

0 comments on commit e8d08af

Please sign in to comment.