diff --git a/CHANGELOG.md b/CHANGELOG.md index 331a45be58..2f40443e6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. ### Fixed +- Fix unexpected warnings in E2E vulnerability detection tests ([#5711](https://github.com/wazuh/wazuh-qa/pull/5711)) \- (Framework + Tests) - Grafana package used for `upgrade_package_nonvulnerable_to_vulnerable` case is vulnerable ([#5719](https://github.com/wazuh/wazuh-qa/pull/5719)) \- (Tests) - Increase results windows in E2E Vulnerability detection ([#5712](https://github.com/wazuh/wazuh-qa/pull/5712/)) \- (Framework + Tests) diff --git a/deps/wazuh_testing/wazuh_testing/end_to_end/check_validators.py b/deps/wazuh_testing/wazuh_testing/end_to_end/check_validators.py index 21abfa06c5..4081220665 100644 --- a/deps/wazuh_testing/wazuh_testing/end_to_end/check_validators.py +++ b/deps/wazuh_testing/wazuh_testing/end_to_end/check_validators.py @@ -159,6 +159,6 @@ def equals_but_not_empty(x, y): empty = lambda x: len(x) == 0 no_errors = lambda x: all( - not any(x[host][level] for level in ["ERROR", "CRITICAL", "WARNING"]) + not any(x[host][level] for level in ['ERROR', 'CRITICAL']) for host in x ) diff --git a/deps/wazuh_testing/wazuh_testing/end_to_end/logs.py b/deps/wazuh_testing/wazuh_testing/end_to_end/logs.py index 3369e3313e..875e0539ca 100644 --- a/deps/wazuh_testing/wazuh_testing/end_to_end/logs.py +++ b/deps/wazuh_testing/wazuh_testing/end_to_end/logs.py @@ -67,27 +67,31 @@ def get_hosts_logs(host_manager: HostManager, host_group: str = 'all') -> Dict[s def check_errors_in_environment(host_manager: HostManager, greater_than_timestamp: str = '', - expected_errors: List[str] = None) -> dict: - """Check if there are errors in the environment + expected_errors: List[str] = None, + error_levels=None) -> dict: + """Check if there are errors in the environment. Args: host_manager (HostManager): An instance of the HostManager class. greater_than_timestamp (str): Timestamp to filter the logs expected_errors (List): List of expected errors. Default None + error_levels (List): List of the error levels to check. Default None. Returns: dict: Errors found in the environment """ - - error_level_to_search = ['ERROR', 'CRITICAL', 'WARNING'] - expected_errors = expected_errors or [] + default_error_levels = ['ERROR', 'WARNING', 'CRITICAL'] + if not expected_errors: + expected_errors = [] + if not error_levels: + error_levels = default_error_levels environment_logs = get_hosts_logs(host_manager) environment_level_logs = {} for host, environment_log in environment_logs.items(): environment_level_logs[host] = {} - for level in error_level_to_search: + for level in error_levels: environment_level_logs[host][level] = [] regex = re.compile(fr'((\d{{4}}\/\d{{2}}\/\d{{2}} \d{{2}}:\d{{2}}:\d{{2}}) (.+): ({level}):(.*))') diff --git a/provisioning/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_custom_packages.yml b/provisioning/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_custom_packages.yml index d5f120a24a..20e56a60fa 100644 --- a/provisioning/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_custom_packages.yml +++ b/provisioning/roles/wazuh/ansible-wazuh-manager/tasks/installation_from_custom_packages.yml @@ -6,27 +6,39 @@ state: present when: - wazuh_custom_packages_installation_manager_enabled + register: wazuh_manager_installation + retries: 4 + delay: 30 + until: wazuh_manager_installation is succeeded when: - ansible_os_family|lower == "debian" - block: - - name: Install Wazuh Manager from .rpm packages | yum - yum: - name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}" - state: present - when: - - wazuh_custom_packages_installation_manager_enabled - - not (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") - - not (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8") + - name: Install Wazuh Manager from .rpm packages | yum + yum: + name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}" + state: present + when: + - wazuh_custom_packages_installation_manager_enabled + - not (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") + - not (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8") + register: wazuh_manager_installation_yum + retries: 4 + delay: 30 + until: wazuh_manager_installation_yum is succeeded - - name: Install Wazuh Manager from .rpm packages | dnf - dnf: - name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}" - state: present - disable_gpg_check: True - when: - - wazuh_custom_packages_installation_manager_enabled - - (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") or - (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8") + - name: Install Wazuh Manager from .rpm packages | dnf + dnf: + name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}" + state: present + disable_gpg_check: True + when: + - wazuh_custom_packages_installation_manager_enabled + - (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") or + (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8") + register: wazuh_manager_installation_dnf + retries: 4 + delay: 30 + until: wazuh_manager_installation_dnf is succeeded when: - - ansible_os_family|lower == "redhat" \ No newline at end of file + - ansible_os_family|lower == "redhat" diff --git a/tests/end_to_end/test_vulnerability_detector/test_vulnerability_detector.py b/tests/end_to_end/test_vulnerability_detector/test_vulnerability_detector.py index e769ac515a..9da3e16345 100644 --- a/tests/end_to_end/test_vulnerability_detector/test_vulnerability_detector.py +++ b/tests/end_to_end/test_vulnerability_detector/test_vulnerability_detector.py @@ -83,6 +83,8 @@ FIRST_SCAN_TIME = None FIRST_SCAN_VULNERABILITIES_INDEX = {} AGENT_REGISTRATION_TIMEOUT = 15 +TIMEOUT_START_MANAGER = 60 +TESTS_UNEXPECTED_ERRORS_LEVELS = ['ERROR', 'CRITICAL'] VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS = [ r"Invalid ID \d{3} for the source", @@ -184,6 +186,9 @@ def configure_vulnerability_detection_test_environment( host_manager, vulnerability_detection_previously_enabled ) + # Wait for 1 minute to ensure all managers have fully started + time.sleep(TIMEOUT_START_MANAGER) + start_agent_and_wait_until_connected(host_manager) if not vulnerability_detection_previously_enabled: @@ -380,7 +385,7 @@ def test_first_syscollector_scan( logging.critical("Checking for errors in the environment") unexpected_errors = check_errors_in_environment( - host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS + host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS ) test_result.validate_check( @@ -533,7 +538,7 @@ def test_syscollector_second_scan( unexpected_errors = check_errors_in_environment( host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, - greater_than_timestamp=get_timestamp + greater_than_timestamp=get_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS ) test_result.validate_check( @@ -760,7 +765,7 @@ def test_install_vulnerable_package_when_agent_down(self, host_manager, request, errors_environment = check_errors_in_environment( host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, - greater_than_timestamp=test_timestamp + greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS ) test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)]) @@ -887,7 +892,7 @@ def test_change_agent_manager(self, permutate_agents_managers, request, precondi errors_environment = check_errors_in_environment( host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, - greater_than_timestamp=test_timestamp + greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS ) test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)]) @@ -1018,7 +1023,7 @@ def test_vulnerability_detector_scans_cases(self, request, preconditions, body, errors_environment = check_errors_in_environment( host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, - greater_than_timestamp=test_timestamp + greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS ) test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)])