diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 41d8711339..811fb23fe2 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -121,6 +121,9 @@ def get_service(): WAZUH_SOCKETS = { 'wazuh-agentd': [], + 'wazuh-apid': [], + 'wazuh-agentlessd': [], + 'wazuh-csyslogd': [], 'wazuh-analysisd': [ ANALYSISD_ANALISIS_SOCKET_PATH, ANALYSISD_QUEUE_SOCKET_PATH @@ -130,6 +133,7 @@ def get_service(): 'wazuh-logcollector': [LOGCOLLECTOR_SOCKET_PATH], 'wazuh-monitord': [MONITORD_SOCKET_PATH], 'wazuh-remoted': [REMOTED_SOCKET_PATH], + 'wazuh-maild': [], 'wazuh-syscheckd': [SYSCHECKD_SOCKET_PATH], 'wazuh-db': [WAZUH_DB_SOCKET_PATH], 'wazuh-modulesd': [ @@ -147,6 +151,31 @@ def get_service(): AUTHD_SOCKET_PATH ] +# Wazuh daemons +LOGCOLLECTOR_DAEMON = 'wazuh-logcollector' +AGENTLESS_DAEMON = 'wazuh-agentlessd' +CSYSLOG_DAEMON = 'wazuh-csyslogd' +REMOTE_DAEMON = 'wazuh-remoted' +ANALYSISD_DAEMON = 'wazuh-analysisd' +API_DAEMON = 'wazuh-apid' +MAIL_DAEMON = 'wazuh-maild' +SYSCHECK_DAEMON = 'wazuh-syscheckd' +EXEC_DAEMON = 'wazuh-execd' +MODULES_DAEMON = 'wazuh-modulesd' +CLUSTER_DAEMON = 'wazuh-clusterd' +INTEGRATOR_DAEMON = 'wazuh-integratord' +MONITOR_DAEMON = 'wazuh-monitord' +DB_DAEMON = 'wazuh-db' +AGENT_DAEMON = 'wazuh-agentd' + + +ALL_MANAGER_DAEMONS = [LOGCOLLECTOR_DAEMON, AGENTLESS_DAEMON, CSYSLOG_DAEMON, REMOTE_DAEMON, ANALYSISD_DAEMON, + API_DAEMON, MAIL_DAEMON, SYSCHECK_DAEMON, EXEC_DAEMON, MODULES_DAEMON, CLUSTER_DAEMON, + INTEGRATOR_DAEMON, MONITOR_DAEMON, DB_DAEMON] +ALL_AGENT_DAEMONS = [AGENT_DAEMON, EXEC_DAEMON, LOGCOLLECTOR_DAEMON, SYSCHECK_DAEMON, MODULES_DAEMON] +API_DAEMONS_REQUIREMENTS = [API_DAEMON, MODULES_DAEMON, ANALYSISD_DAEMON, EXEC_DAEMON, DB_DAEMON, REMOTE_DAEMON] + + DISABLE_MONITORD_ROTATE_LOG_OPTION = {'monitord.rotate_log': '0'} REMOTED_LOCAL_INTERNAL_OPTIONS = {'remoted.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) ANALYSISD_LOCAL_INTERNAL_OPTIONS = {'analysisd.debug': '2'}.update(DISABLE_MONITORD_ROTATE_LOG_OPTION) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index cee15c37d4..3543c6769c 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -604,6 +604,77 @@ def create_file_structure_function(get_files_list): delete_file_structure(get_files_list) +@pytest.fixture(scope='module') +def daemons_handler(get_configuration, request): + """Handler of Wazuh daemons. + + It uses `daemons_handler_configuration` of each module in order to configure the behavior of the fixture. + The `daemons_handler_configuration` should be a dictionary with the following keys: + daemons (list, optional): List with every daemon to be used by the module. In case of empty a ValueError + will be raised + all_daemons (boolean): Configure to restart all wazuh services. Default `False`. + ignore_errors (boolean): Configure if errors in daemon handling should be ignored. This option is available + in order to use this fixture along with invalid configuration. Default `False` + + Args: + get_configuration (fixture): Gets the current configuration of the test. + request (fixture): Provide information on the executing test function. + """ + daemons = [] + ignore_errors = False + all_daemons = False + + try: + daemons_handler_configuration = getattr(request.module, 'daemons_handler_configuration') + if 'daemons' in daemons_handler_configuration and not all_daemons: + daemons = daemons_handler_configuration['daemons'] + if not daemons or (type(daemons) == list and len(daemons) == 0): + logger.error('Daemons list is not set') + raise ValueError + + if 'all_daemons' in daemons_handler_configuration: + logger.debug(f"Wazuh control set to {daemons_handler_configuration['all_daemons']}") + all_daemons = daemons_handler_configuration['all_daemons'] + + if 'ignore_errors' in daemons_handler_configuration: + logger.debug(f"Ignore error set to {daemons_handler_configuration['ignore_errors']}") + ignore_errors = daemons_handler_configuration['ignore_errors'] + + except AttributeError as daemon_configuration_not_set: + logger.error('daemons_handler_configuration is not set') + raise daemon_configuration_not_set + + try: + if all_daemons: + logger.debug('Restarting wazuh using wazuh-control') + # Restart daemon instead of starting due to legacy used fixture in the test suite. + control_service('restart') + else: + for daemon in daemons: + logger.debug(f"Restarting {daemon}") + # Restart daemon instead of starting due to legacy used fixture in the test suite. + control_service('restart', daemon=daemon) + + except ValueError as value_error: + logger.error(f"{str(value_error)}") + if not ignore_errors: + raise value_error + except subprocess.CalledProcessError as called_process_error: + logger.error(f"{str(called_process_error)}") + if not ignore_errors: + raise called_process_error + + yield + + if all_daemons: + logger.debug('Stopping wazuh using wazuh-control') + control_service('stop') + else: + for daemon in daemons: + logger.debug(f"Stopping {daemon}") + control_service('stop', daemon=daemon) + + @pytest.fixture(scope='function') def file_monitoring(request): """Fixture to handle the monitoring of a specified file.