diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index 52f543128d..4af28e3471 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -91,28 +91,33 @@ def get_version(): + try: + if platform.system() in ['Windows', 'win32']: + with open(os.path.join(WAZUH_PATH, 'VERSION'), 'r') as f: + version = f.read() + return version[:version.rfind('\n')] - if platform.system() in ['Windows', 'win32']: - with open(os.path.join(WAZUH_PATH, 'VERSION'), 'r') as f: - version = f.read() - return version[:version.rfind('\n')] - - else: # Linux, sunos5, darwin, aix... - return subprocess.check_output([ - f"{WAZUH_PATH}/bin/wazuh-control", "info", "-v" - ], stderr=subprocess.PIPE).decode('utf-8').rstrip() + else: # Linux, sunos5, darwin, aix... + return subprocess.check_output([ + f"{WAZUH_PATH}/bin/wazuh-control", "info", "-v" + ], stderr=subprocess.PIPE).decode('utf-8').rstrip() + except Exception: + return 'N/A' def get_service(): if platform.system() in ['Windows', 'win32']: - return 'wazuh-agent' - + service = 'wazuh-agent' else: # Linux, sunos5, darwin, aix... - service = subprocess.check_output([ - f"{WAZUH_PATH}/bin/wazuh-control", "info", "-t" - ], stderr=subprocess.PIPE).decode('utf-8').strip() - - return 'wazuh-manager' if service == 'server' else 'wazuh-agent' + try: + output = subprocess.check_output([ + f"{WAZUH_PATH}/bin/wazuh-control", "info", "-t" + ], stderr=subprocess.PIPE).decode('utf-8').strip() + service = 'wazuh-manager' if service == 'server' else 'wazuh-agent' + except Exception: + service = '' + + return service _data_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'data') diff --git a/deps/wazuh_testing/wazuh_testing/tools/utils.py b/deps/wazuh_testing/wazuh_testing/tools/utils.py index 346bfddb87..e5f22d73ee 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/utils.py +++ b/deps/wazuh_testing/wazuh_testing/tools/utils.py @@ -131,9 +131,12 @@ def get_random_string(string_length, digits=True): def get_version(): - f = open('../../version.json') - data = json.load(f) - version = data['version'] + try: + f = open('../../version.json') + data = json.load(f) + version = data['version'] + except Exception: + version = 'N/A' return version diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 258b236b52..0a394789fb 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -57,36 +57,39 @@ def get_report_files(): def pytest_collection_modifyitems(session, config, items): selected_tests = [] deselected_tests = [] - - for item in items: - supported_platforms = PLATFORMS.intersection(mark.name for mark in item.iter_markers()) - plat = sys.platform - - selected = True - if supported_platforms and plat not in supported_platforms: - selected = False - - host_type = 'agent' if 'agent' in get_service() else 'server' - supported_types = HOST_TYPES.intersection(mark.name for mark in item.iter_markers()) - if supported_types and host_type not in supported_types: - selected = False - # Consider only first mark - levels = [mark.kwargs['level'] for mark in item.iter_markers(name="tier")] - if levels and len(levels) > 0: - tiers = item.config.getoption("--tier") - if tiers is not None and levels[0] not in tiers: + print(session) + print(config) + if not global_parameters.allow_platform_deselected_tests: + for item in items: + supported_platforms = PLATFORMS.intersection(mark.name for mark in item.iter_markers()) + plat = sys.platform + + selected = True + if supported_platforms and plat not in supported_platforms: selected = False - elif item.config.getoption("--tier-minimum") > levels[0]: - selected = False - elif item.config.getoption("--tier-maximum") < levels[0]: + + host_type = 'agent' if 'agent' in get_service() else 'server' + + supported_types = HOST_TYPES.intersection(mark.name for mark in item.iter_markers()) + if supported_types and host_type not in supported_types: selected = False - if selected: - selected_tests.append(item) - else: - deselected_tests.append(item) + # Consider only first mark + levels = [mark.kwargs['level'] for mark in item.iter_markers(name="tier")] + if levels and len(levels) > 0: + tiers = item.config.getoption("--tier") + if tiers is not None and levels[0] not in tiers: + selected = False + elif item.config.getoption("--tier-minimum") > levels[0]: + selected = False + elif item.config.getoption("--tier-maximum") < levels[0]: + selected = False + if selected: + selected_tests.append(item) + else: + deselected_tests.append(item) - config.hook.pytest_deselected(items=deselected_tests) - items[:] = selected_tests + config.hook.pytest_deselected(items=deselected_tests) + items[:] = selected_tests @pytest.fixture(scope='module') @@ -253,6 +256,7 @@ def pytest_addoption(parser): parser.addoption( "--fim-database-memory", action="store_true", + default=False, help="run tests activating database memory in the syscheck configuration" ) parser.addoption( @@ -336,6 +340,12 @@ def pytest_addoption(parser): help="pass webhook url required for integratord tests." ) + parser.addoption( + "--allow-platform-deselected-tests", + action="store_true", + default=False, + help="Avoid tests deselection based on current environment" + ) def pytest_configure(config): # Register an additional marker @@ -405,6 +415,10 @@ def pytest_configure(config): if global_parameters.wpk_package_path: global_parameters.wpk_package_path = global_parameters.wpk_package_path + # Set collect test mode + global_parameters.allow_platform_deselected_tests = config.getoption("--allow-platform-deselected-tests") + + def pytest_html_results_table_header(cells): cells.insert(4, html.th('Tier', class_='sortable tier', col='tier')) @@ -1288,3 +1302,13 @@ def truncate_event_logs(): for log_file in log_files: truncate_file(log_file) + + +def pytest_deselected(items): + if not items: + return + config = items[0].session.config + reporter = config.pluginmanager.getplugin("terminalreporter") + reporter.ensure_newline() + for item in items: + reporter.line(f"deselected: {item.nodeid}", yellow=True, bold=True) \ No newline at end of file diff --git a/tests/integration/test_agentd/test_agentd_parametrized_reconnections.py b/tests/integration/test_agentd/test_agentd_parametrized_reconnections.py index 71a2e53e72..12640d9ada 100644 --- a/tests/integration/test_agentd/test_agentd_parametrized_reconnections.py +++ b/tests/integration/test_agentd/test_agentd_parametrized_reconnections.py @@ -72,8 +72,12 @@ # Marks pytestmark = [pytest.mark.linux, pytest.mark.win32, pytest.mark.tier(level=0), pytest.mark.agent] + test_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') configurations_path = os.path.join(test_data_path, 'wazuh_conf.yaml') +global timeout +timeout = '5' + params = [ # Different parameters on UDP @@ -112,6 +116,7 @@ def teardown(): remoted_server.stop() +@pytest.fixture(scope="module", autouse=True) def set_debug_mode(): """Set debug2 for agentd in local internal options file.""" if platform.system() == 'win32' or platform.system() == 'Windows': @@ -129,9 +134,6 @@ def set_debug_mode(): local_file_write.write('\n' + debug_line) -set_debug_mode() - - # fixtures @pytest.fixture(scope="module", params=configurations, ids=case_ids) def get_configuration(request): @@ -256,17 +258,15 @@ def wait_unable_to_connect(line): return line return None - -def change_timeout(new_value): +@pytest.fixture(scope="module") +def change_timeout(): """Set agent.recv_timeout for agentd in local internal options file. The above option sets the maximum number of seconds to wait for server response from the TCP client socket. - - Args: - new_value (int): Number of seconds (between 1 and 600). """ - new_timeout = 'agent.recv_timeout=' + new_value + global timeout + new_timeout = 'agent.recv_timeout=' + timeout if platform.system() == 'win32' or platform.system() == 'Windows': local_int_conf_path = os.path.join(WAZUH_PATH, 'local_internal_options.conf') else: @@ -280,9 +280,6 @@ def change_timeout(new_value): local_file_write.write('\n' + new_timeout) -change_timeout('5') - - def parse_time_from_log_line(log_line): """Create a datetime object from a date in a string. diff --git a/tests/integration/test_agentd/test_agentd_reconnection.py b/tests/integration/test_agentd/test_agentd_reconnection.py index 5a36b1c4a0..3a1f655dd6 100644 --- a/tests/integration/test_agentd/test_agentd_reconnection.py +++ b/tests/integration/test_agentd/test_agentd_reconnection.py @@ -86,18 +86,14 @@ {'PROTOCOL': 'udp'} ] -config_ids = ['tcp', 'udp'] - -configurations = load_wazuh_configurations(configurations_path, __name__, params=params, metadata=metadata) - log_monitor_paths = [] - receiver_sockets_params = [] - monitored_sockets_params = [] -receiver_sockets, monitored_sockets, log_monitors = None, None, None # Set in the fixtures +config_ids = ['tcp', 'udp'] +configurations = load_wazuh_configurations(configurations_path, __name__, params=params, metadata=metadata) +receiver_sockets, monitored_sockets, log_monitors = None, None, None # Set in the fixtures authd_server = AuthdSimulator(params[0]['SERVER_ADDRESS'], key_path=SERVER_KEY_PATH, cert_path=SERVER_CERT_PATH) global remoted_server @@ -111,7 +107,7 @@ def teardown(): if remoted_server is not None: remoted_server.stop() - +@pytest.fixture(scope="module", autouse=True) def set_debug_mode(): """Set debug2 for agentd in local internal options file.""" if platform.system() == 'win32' or platform.system() == 'Windows': @@ -130,9 +126,6 @@ def set_debug_mode(): local_file_write.write('\n' + debug_line) -set_debug_mode() - - # fixtures @pytest.fixture(scope="module", params=configurations, ids=config_ids) def get_configuration(request): diff --git a/tests/integration/test_analysisd/__init__.py b/tests/integration/test_analysisd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_analysisd/test_limit_eps/__init__.py b/tests/integration/test_analysisd/test_limit_eps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_gcloud/__init__.py b/tests/integration/test_gcloud/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_gcloud/test_configuration/__init__.py b/tests/integration/test_gcloud/test_configuration/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_gcloud/test_functionality/__init__.py b/tests/integration/test_gcloud/test_functionality/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_gcloud/test_functionality/test_interval.py b/tests/integration/test_gcloud/test_functionality/test_interval.py index 657a4dc4b0..3d5365e953 100644 --- a/tests/integration/test_gcloud/test_functionality/test_interval.py +++ b/tests/integration/test_gcloud/test_functionality/test_interval.py @@ -95,7 +95,11 @@ # Preparing -truncate_file(LOG_FILE_PATH) +@pytest.fixture(scope='module', autouse=True) +def truncate_logs(): + """Truncate the 'ossec.log' file.""" + truncate_file(LOG_FILE_PATH) + # fixtures diff --git a/tests/integration/test_gcloud/test_functionality/test_max_messages.py b/tests/integration/test_gcloud/test_functionality/test_max_messages.py index b8040a73cc..cbfd4336e1 100644 --- a/tests/integration/test_gcloud/test_functionality/test_max_messages.py +++ b/tests/integration/test_gcloud/test_functionality/test_max_messages.py @@ -102,7 +102,10 @@ # Preparing -truncate_file(LOG_FILE_PATH) +@pytest.fixture(scope='module', autouse=True) +def truncate_logs(): + """Truncate the 'ossec.log' file.""" + truncate_file(LOG_FILE_PATH) # fixtures diff --git a/tests/integration/test_gcloud/test_functionality/test_rules.py b/tests/integration/test_gcloud/test_functionality/test_rules.py index e28dcf3d32..79affa7176 100644 --- a/tests/integration/test_gcloud/test_functionality/test_rules.py +++ b/tests/integration/test_gcloud/test_functionality/test_rules.py @@ -93,7 +93,10 @@ # Preparing -truncate_file(LOG_FILE_PATH) +@pytest.fixture(scope='module', params=configurations) +def get_configuration(request): + """Get configurations from the module.""" + return request.param # fixtures diff --git a/tests/integration/test_github/__init__.py b/tests/integration/test_github/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_github/test_configuration/__init__.py b/tests/integration/test_github/test_configuration/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/test_wpk/test_wpk_agent.py b/tests/integration/test_wpk/test_wpk_agent.py index 97aa68fc18..e9c52fa795 100644 --- a/tests/integration/test_wpk/test_wpk_agent.py +++ b/tests/integration/test_wpk/test_wpk_agent.py @@ -93,26 +93,29 @@ mark_skip_agentLinux = pytest.mark.skipif(get_service() == 'wazuh-agent' and sys_platform == 'Linux', reason="It will be blocked by wazuh/wazuh#9763") -if not global_parameters.wpk_version: - raise Exception("The WPK package version must be defined by parameter. See README.md") -if global_parameters.wpk_package_path is None: - raise ValueError("The WPK package path must be defined by parameter. See README.md") - -version_to_upgrade = global_parameters.wpk_version[0] -package_path = global_parameters.wpk_package_path[0] - -_agent_version = get_version() - -error_msg = '' -ver_split = _agent_version.replace("v", "").split(".") -if int(ver_split[0]) >= 4 and int(ver_split[1]) >= 1: - error_msg = 'Could not chmod' \ - if sys_platform != "Windows" else \ - 'Error executing command' -else: - error_msg = 'err Could not chmod' \ - if sys_platform != "Windows" else \ - 'err Cannot execute installer' + +try: + version_to_upgrade = global_parameters.wpk_version[0] + package_path = global_parameters.wpk_package_path[0] + _agent_version = get_version() + + error_msg = '' + ver_split = _agent_version.replace("v", "").split(".") + if int(ver_split[0]) >= 4 and int(ver_split[1]) >= 1: + error_msg = 'Could not chmod' \ + if sys_platform != "Windows" else \ + 'Error executing command' + else: + error_msg = 'err Could not chmod' \ + if sys_platform != "Windows" else \ + 'err Cannot execute installer' +except Exception as e: + print("Error: {}".format(e)) + print("Using default values") + version_to_upgrade = 'v4.4.0' + error_msg = '' + _agent_version = 'v4.3.0' + package_path = "https://packages.wazuh.com/wpk/linux/x86_64/wazuh_agent_v4.4.0_linux_x86_64.wpk""" time_to_sleep_until_backup = 10 diff --git a/tests/integration/test_wpk/test_wpk_manager.py b/tests/integration/test_wpk/test_wpk_manager.py index c36369e4d7..bfcac57ba0 100644 --- a/tests/integration/test_wpk/test_wpk_manager.py +++ b/tests/integration/test_wpk/test_wpk_manager.py @@ -72,7 +72,7 @@ UPGRADE_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'tasks', 'upgrade') TASK_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'tasks', 'task') SERVER_ADDRESS = 'localhost' -WPK_REPOSITORY_4x = global_parameters.wpk_package_path[0] +WPK_REPOSITORY_4x = global_parameters.wpk_package_path[0] if global_parameters.wpk_package_path else 'v4.4.0' WPK_REPOSITORY_3x = 'packages.wazuh.com/wpk/' CRYPTO = "aes" CHUNK_SIZE = 16384 @@ -88,12 +88,8 @@ max_upgrade_result_status_retries = 30 -if global_parameters.wpk_version is None: - raise ValueError("The WPK package version must be defined by parameter. See README.md") -if global_parameters.wpk_package_path is None: - raise ValueError("The WPK package path must be defined by parameter. See README.md") -version_to_upgrade = global_parameters.wpk_version[0] +version_to_upgrade = global_parameters.wpk_version[0] if global_parameters.wpk_version else 'v4.4.0' MANAGER_VERSION = get_version() diff --git a/tests/integration/test_wpk/test_wpk_manager_task_states.py b/tests/integration/test_wpk/test_wpk_manager_task_states.py index 28f2fdcf6d..a84e7a87de 100644 --- a/tests/integration/test_wpk/test_wpk_manager_task_states.py +++ b/tests/integration/test_wpk/test_wpk_manager_task_states.py @@ -67,7 +67,9 @@ UPGRADE_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'tasks', 'upgrade') TASK_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'tasks', 'task') SERVER_ADDRESS = 'localhost' -WPK_REPOSITORY_4x = global_parameters.wpk_package_path[0] + +WPK_REPOSITORY_4x = global_parameters.wpk_package_path[0] if global_parameters.wpk_package_path else 'v4.4.0' + CRYPTO = "aes" CHUNK_SIZE = 16384 TASK_TIMEOUT = '15m' diff --git a/tests/performance/test_api/conftest.py b/tests/performance/test_api/conftest.py index d1324a68f2..44b58bc006 100755 --- a/tests/performance/test_api/conftest.py +++ b/tests/performance/test_api/conftest.py @@ -173,4 +173,5 @@ def pytest_collection_modifyitems(session, config, items): # Add each test_case metadata as user_properties for its item for item in items: - item.user_properties.extend([(key, value) for key, value in item.callspec.params['test_case'].items()]) + if hasattr(item, 'callspec') and 'test_case' in item.callspec.params: + item.user_properties.extend([(key, value) for key, value in item.callspec.params['test_case'].items()]) \ No newline at end of file diff --git a/tests/performance/test_cluster/conftest.py b/tests/performance/test_cluster/conftest.py index b550384c87..8847f1cad8 100644 --- a/tests/performance/test_cluster/conftest.py +++ b/tests/performance/test_cluster/conftest.py @@ -11,7 +11,7 @@ def pytest_addoption(parser): # Get command line options parser.addoption( - "--artifacts_path", + "--performance-artifacts_path", action="store", type=str, help="Path where information of all cluster nodes can be found (logs, stats CSVs, etc)." diff --git a/tests/reliability/test_cluster/test_cluster_logs/conftest.py b/tests/reliability/test_cluster/test_cluster_logs/conftest.py index faab49f847..3b56d9f860 100644 --- a/tests/reliability/test_cluster/test_cluster_logs/conftest.py +++ b/tests/reliability/test_cluster/test_cluster_logs/conftest.py @@ -11,7 +11,7 @@ def pytest_addoption(parser): # Get command line options parser.addoption( - "--artifacts_path", + "--reliability-artifacts-path", action="store", type=str, help="Path where information of all cluster nodes can be found (logs, stats CSVs, etc)."