diff --git a/roles/oneagent/tests/ansible/util.py b/roles/oneagent/tests/ansible/util.py deleted file mode 100644 index de51614..0000000 --- a/roles/oneagent/tests/ansible/util.py +++ /dev/null @@ -1,6 +0,0 @@ -from ansible.constants import ERROR_MESSAGES_FILE -from util.common_utils import read_yaml_file - - -def parse_error_messages_file() -> dict[str, str]: - return read_yaml_file(ERROR_MESSAGES_FILE) diff --git a/roles/oneagent/tests/conftest.py b/roles/oneagent/tests/conftest.py index 561aea9..d3093c7 100644 --- a/roles/oneagent/tests/conftest.py +++ b/roles/oneagent/tests/conftest.py @@ -8,7 +8,6 @@ from pathlib import Path import ansible.constants as AnsibleConstants -import ansible.util as AnsibleUtil from command.platform_command_wrapper import PlatformCommandWrapper from ansible.config import AnsibleConfig @@ -26,7 +25,6 @@ USER_KEY = "user" PASS_KEY = "password" -UTIL_KEY = "util" RUNNER_KEY = "runner" WRAPPER_KEY = "wrapper" CONSTANTS_KEY = "constants" @@ -188,7 +186,6 @@ def pytest_generate_tests(metafunc) -> None: wrapper = PlatformCommandWrapper(user, password) configurator = AnsibleConfig(user, password, platforms) runner = AnsibleRunner(user, password) - util = AnsibleUtil constants = AnsibleConstants if CONFIGURATOR_KEY in metafunc.fixturenames: @@ -197,9 +194,6 @@ def pytest_generate_tests(metafunc) -> None: if RUNNER_KEY in metafunc.fixturenames: metafunc.parametrize(RUNNER_KEY, [runner]) - if UTIL_KEY in metafunc.fixturenames: - metafunc.parametrize(UTIL_KEY, [util]) - if CONSTANTS_KEY in metafunc.fixturenames: metafunc.parametrize(CONSTANTS_KEY, [constants]) diff --git a/roles/oneagent/tests/test_resilience.py b/roles/oneagent/tests/test_resilience.py index 551f53d..fa8f024 100644 --- a/roles/oneagent/tests/test_resilience.py +++ b/roles/oneagent/tests/test_resilience.py @@ -3,7 +3,8 @@ import pytest -from ansible.constants import TEST_SIGNATURE_FILE +from ansible.constants import TEST_SIGNATURE_FILE, ERROR_MESSAGES_FILE, FAILED_DEPLOYMENT_EXIT_CODE, VARIABLE_PREFIX +from util.common_utils import read_yaml_file from util.test_data_types import DeploymentResult from util.test_helpers import run_deployment, set_installer_download_params, enable_for_system_family from util.constants.common_constants import InstallerVersion @@ -21,10 +22,14 @@ VERSION_LOWER_THAN_INSTALLED_KEY = "version_lower_than_installed" +def _parse_error_messages_file() -> dict[str, str]: + return read_yaml_file(ERROR_MESSAGES_FILE) + + def _prepare_test_data(constants, data: dict[str, str]) -> dict[str, str]: parsed_data = {} for key, value in data.items(): - key = key.strip().removeprefix(constants.VARIABLE_PREFIX) + key = key.strip().removeprefix(VARIABLE_PREFIX) value = value.strip().strip('"') value = value.replace("(", "\\(").replace(")", "\\)") parsed_data[key] = re.sub("%\\w", ".*", value) @@ -32,8 +37,8 @@ def _prepare_test_data(constants, data: dict[str, str]) -> dict[str, str]: @pytest.fixture -def _error_messages(util, constants) -> dict[str, str]: - return _prepare_test_data(constants, util.parse_error_messages_file()) +def _error_messages(constants) -> dict[str, str]: + return _prepare_test_data(constants, _parse_error_messages_file()) def _check_deployment_failure(results: DeploymentResult, expected_message: str, expected_code: int) -> None: @@ -46,7 +51,7 @@ def _check_deployment_failure(results: DeploymentResult, expected_message: str, assert re.search(expected_message, result.stdout + result.stderr) -def test_invalid_required_parameters(_error_messages, runner, configurator, constants): +def test_invalid_required_parameters(_error_messages, runner, configurator): logging.info("Running missing required parameters test") logging.debug("Removing required parameter - direct download scenario") @@ -56,22 +61,22 @@ def test_invalid_required_parameters(_error_messages, runner, configurator, cons _check_deployment_failure( run_deployment(runner, True), _error_messages[MISSING_REQUIRED_PARAMETERS_KEY], - constants.FAILED_DEPLOYMENT_EXIT_CODE, + FAILED_DEPLOYMENT_EXIT_CODE, ) -def test_invalid_architecture(_error_messages, runner, configurator, constants): +def test_invalid_architecture(_error_messages, runner, configurator): logging.info("Running invalid architecture test") set_installer_download_params(configurator) configurator.set_common_parameter(configurator.INSTALLER_ARCH_KEY, "unknown_arch") _check_deployment_failure( - run_deployment(runner, True), _error_messages[UNKNOWN_ARCHITECTURE_KEY], constants.FAILED_DEPLOYMENT_EXIT_CODE + run_deployment(runner, True), _error_messages[UNKNOWN_ARCHITECTURE_KEY], FAILED_DEPLOYMENT_EXIT_CODE ) -def test_missing_local_installer(_error_messages, runner, configurator, constants): +def test_missing_local_installer(_error_messages, runner, configurator): logging.info("Running missing local installer test") configurator.set_common_parameter(configurator.LOCAL_INSTALLER_KEY, "non_existing_installer") @@ -79,12 +84,12 @@ def test_missing_local_installer(_error_messages, runner, configurator, constant _check_deployment_failure( run_deployment(runner, True), _error_messages[LOCAL_INSTALLER_NOT_AVAILABLE_KEY], - constants.FAILED_DEPLOYMENT_EXIT_CODE, + FAILED_DEPLOYMENT_EXIT_CODE, ) @enable_for_system_family(family="unix") -def test_directories_contain_spaces(_error_messages, runner, configurator, constants): +def test_directories_contain_spaces(_error_messages, runner, configurator): logging.info("Running directories contain spaces test") logging.debug("Space in directory path - INSTALL_PATH scenario") @@ -95,7 +100,7 @@ def test_directories_contain_spaces(_error_messages, runner, configurator, const _check_deployment_failure( run_deployment(runner, True), _error_messages[INSTALL_DIR_CONTAINS_SPACES_KEY], - constants.FAILED_DEPLOYMENT_EXIT_CODE, + FAILED_DEPLOYMENT_EXIT_CODE, ) logging.debug("Space in directory path - download dir scenario") @@ -106,11 +111,11 @@ def test_directories_contain_spaces(_error_messages, runner, configurator, const _check_deployment_failure( run_deployment(runner, True), _error_messages[DOWNLOAD_DIR_CONTAINS_SPACES_KEY], - constants.FAILED_DEPLOYMENT_EXIT_CODE, + FAILED_DEPLOYMENT_EXIT_CODE, ) -def test_version_parameter_too_low(_error_messages, runner, configurator, constants): +def test_version_parameter_too_low(_error_messages, runner, configurator): logging.info("Running version parameter too low test") set_installer_download_params(configurator) @@ -119,11 +124,11 @@ def test_version_parameter_too_low(_error_messages, runner, configurator, consta _check_deployment_failure( run_deployment(runner, True), _error_messages[VERSION_PARAMETER_TOO_LOW_KEY], - constants.FAILED_DEPLOYMENT_EXIT_CODE, + FAILED_DEPLOYMENT_EXIT_CODE, ) -def test_multiple_install_path_arguments(_error_messages, runner, configurator, constants): +def test_multiple_install_path_arguments(_error_messages, runner, configurator): logging.info("Running multiple install path arguments test") set_installer_download_params(configurator) @@ -131,24 +136,24 @@ def test_multiple_install_path_arguments(_error_messages, runner, configurator, configurator.set_common_parameter(configurator.INSTALLER_PLATFORM_ARGS_KEY, ["INSTALL_PATH=/path2"]) _check_deployment_failure( - run_deployment(runner, True), _error_messages[MULTIPLE_INSTALL_PATH_KEY], constants.FAILED_DEPLOYMENT_EXIT_CODE + run_deployment(runner, True), _error_messages[MULTIPLE_INSTALL_PATH_KEY], FAILED_DEPLOYMENT_EXIT_CODE ) -def test_failed_download(_error_messages, runner, configurator, constants): +def test_failed_download(_error_messages, runner, configurator): logging.info("Running failed download test") set_installer_download_params(configurator) configurator.set_common_parameter(configurator.ENVIRONMENT_URL_KEY, "0.0.0.0") _check_deployment_failure( - run_deployment(runner, True), _error_messages[DOWNLOAD_FAILED_KEY], constants.FAILED_DEPLOYMENT_EXIT_CODE + run_deployment(runner, True), _error_messages[DOWNLOAD_FAILED_KEY], FAILED_DEPLOYMENT_EXIT_CODE ) # noinspection PyUnusedLocal @enable_for_system_family(family="unix") -def test_failed_signature_verification(_error_messages, runner, configurator, constants): +def test_failed_signature_verification(_error_messages, runner, configurator): logging.info("Running failed signature verification test") set_installer_download_params(configurator) @@ -158,4 +163,4 @@ def test_failed_signature_verification(_error_messages, runner, configurator, co signature.write("break signature by writing some text") universal_message = _error_messages.get(SIGNATURE_VERIFICATION_FAILED_KEY) - _check_deployment_failure(run_deployment(runner, True), universal_message, constants.FAILED_DEPLOYMENT_EXIT_CODE) + _check_deployment_failure(run_deployment(runner, True), universal_message, FAILED_DEPLOYMENT_EXIT_CODE)