diff --git a/deps/wazuh_testing/wazuh_testing/tools/utils.py b/deps/wazuh_testing/wazuh_testing/tools/utils.py index aa4bb721ba..113fd7e3ed 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/utils.py +++ b/deps/wazuh_testing/wazuh_testing/tools/utils.py @@ -1,18 +1,17 @@ -# Copyright (C) 2015-2021, Wazuh Inc. +# Copyright (C) 2015, Wazuh Inc. # Created by Wazuh, Inc. . # This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 +import ipaddress +import json import logging +import numbers import re +import socket import string -import numbers +from datetime import datetime from functools import wraps from random import randint, SystemRandom from time import sleep -from random import randint, SystemRandom, choice -import string -import json -import socket -import ipaddress def retry(exceptions, attempts=5, delay=1, delay_multiplier=2): @@ -179,3 +178,14 @@ def format_ipv6_long(ipv6_address): str: IPV6 long form """ return (ipaddress.ip_address(ipv6_address).exploded).upper() + + +def get_datetime_diff(phase_datetimes, date_format): + """Calculate the difference between two datetimes. + + Args: + phase_datetimes (list): List containing start and end datetimes. + date_format (str): Expected datetime shape. + """ + return datetime.strptime(phase_datetimes[1], date_format) - datetime.strptime(phase_datetimes[0], date_format) + diff --git a/tests/performance/test_cluster/test_cluster_performance/data/25w_50000a_thresholds.yaml b/tests/performance/test_cluster/test_cluster_performance/data/25w_50000a_thresholds.yaml index 38643e9b17..3a1c4a09ec 100644 --- a/tests/performance/test_cluster/test_cluster_performance/data/25w_50000a_thresholds.yaml +++ b/tests/performance/test_cluster/test_cluster_performance/data/25w_50000a_thresholds.yaml @@ -53,7 +53,7 @@ resources: workers: max: 47.85 mean: 9.35 - reg_cof: 0.06 + reg_cof: 0.1 FD: master: max: 160 diff --git a/tests/performance/test_cluster/test_cluster_performance/test_cluster_performance.py b/tests/performance/test_cluster/test_cluster_performance/test_cluster_performance.py index a22a417e5e..275bc385c7 100644 --- a/tests/performance/test_cluster/test_cluster_performance/test_cluster_performance.py +++ b/tests/performance/test_cluster/test_cluster_performance/test_cluster_performance.py @@ -1,8 +1,7 @@ -# Copyright (C) 2015-2021, Wazuh Inc. +# Copyright (C) 2015, Wazuh Inc. # Created by Wazuh, Inc. . # This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 -from datetime import datetime from os import listdir from os.path import join, dirname, realpath @@ -10,6 +9,7 @@ from yaml import safe_load from wazuh_testing.tools.performance.csv_parser import ClusterCSVTasksParser, ClusterCSVResourcesParser, ClusterEnvInfo +from wazuh_testing.tools.utils import get_datetime_diff test_data_path = join(dirname(realpath(__file__)), 'data') configurations = {file.replace('_thresholds.yaml', ''): safe_load(open(join(test_data_path, file))) for file in @@ -21,22 +21,12 @@ # Fixtures @pytest.fixture() def n_workers(pytestconfig): - return pytestconfig.getoption("n_workers") + return pytestconfig.getoption('n_workers') @pytest.fixture() def n_agents(pytestconfig): - return pytestconfig.getoption("n_agents") - - -# Functions -def get_datetime_diff(phase_datetimes): - """Calculate the difference between two datetimes. - - Args: - phase_datetimes (list): List containing start and end datetimes. - """ - return datetime.strptime(phase_datetimes[1], date_format) - datetime.strptime(phase_datetimes[0], date_format) + return pytestconfig.getoption('n_agents') def test_cluster_performance(artifacts_path, n_workers, n_agents): @@ -64,19 +54,19 @@ def test_cluster_performance(artifacts_path, n_workers, n_agents): try: cluster_info = ClusterEnvInfo(artifacts_path).get_all_info() except FileNotFoundError: - pytest.fail(f'Path "{artifacts_path}" could not be found or it may not follow the proper structure.') + pytest.fail(f"Path '{artifacts_path}' could not be found or it may not follow the proper structure.") if cluster_info.get('worker_nodes', 0) != int(n_workers): - pytest.fail(f'Information of {n_workers} workers was expected inside the artifacts folder, but ' - f'{cluster_info.get("worker_nodes", 0)} were found.') + pytest.fail(f"Information of {n_workers} workers was expected inside the artifacts folder, but " + f"{cluster_info.get('worker_nodes', 0)} were found.") # Calculate stats from data inside artifacts path. data = {'tasks': ClusterCSVTasksParser(artifacts_path).get_stats(), 'resources': ClusterCSVResourcesParser(artifacts_path).get_stats()} if not data['tasks'] or not data['resources']: - pytest.fail(f'Stats could not be retrieved, "{artifacts_path}" path may not exist, it is empty or it may not' - f' follow the proper structure.') + pytest.fail(f"Stats could not be retrieved, '{artifacts_path}' path may not exist, it is empty or it may not" + f" follow the proper structure.") # Compare each stat with its threshold. for data_name, data_stats in data.items(): @@ -92,16 +82,15 @@ def test_cluster_performance(artifacts_path, n_workers, n_agents): 'phase': phase}) try: - assert not exceeded_thresholds, f"Some thresholds were exceeded:\n- " + '\n- '.join( + assert not exceeded_thresholds, 'Some thresholds were exceeded:\n- ' + '\n- '.join( '{stat} {column} {value} >= {threshold} ({node}, {file}, {phase})'.format(**item) for item in exceeded_thresholds) finally: # Add useful information to report as stdout try: - print('\n') - print(f'Setup phase took {get_datetime_diff(cluster_info["phases"]["setup_phase"])}s ' - f'({cluster_info["phases"]["setup_phase"][0]} - {cluster_info["phases"]["setup_phase"][1]}).') - print(f'Stable phase took {get_datetime_diff(cluster_info["phases"]["stable_phase"])}s ' - f'({cluster_info["phases"]["stable_phase"][0]} - {cluster_info["phases"]["stable_phase"][1]}).') + print(f"\nSetup phase took {get_datetime_diff(cluster_info['phases']['setup_phase'], date_format)}s " + f"({cluster_info['phases']['setup_phase'][0]} - {cluster_info['phases']['setup_phase'][1]}).") + print(f"Stable phase took {get_datetime_diff(cluster_info['phases']['stable_phase'], date_format)}s " + f"({cluster_info['phases']['stable_phase'][0]} - {cluster_info['phases']['stable_phase'][1]}).") except KeyError: print('No information available about test phases.')