From bce42192c3a4978d76ec700aa7c3c35172e9b804 Mon Sep 17 00:00:00 2001 From: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> Date: Mon, 20 May 2024 10:09:41 -0300 Subject: [PATCH] Added a dummy DummyExecFactory. In case of using an external DB for the RunDbTest command, the task SpawnTestEnvironment does not return a valid `container_info` for the Database (which makes totally sense because the external db can be a None-Docker Exasol DB). However, also the using `SshExecFactory` does not work because the user/pwd are not returned from SpawnTestEnvironment. => Added a DummyExecFactory which implements the interface but does nothing and throws an exception in case the `exec` function gets invoked. --- .../lib/api/run_db_tests.py | 3 ++ .../tasks/test/test_runner_db_test_task.py | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/exasol_script_languages_container_tool/lib/api/run_db_tests.py b/exasol_script_languages_container_tool/lib/api/run_db_tests.py index e6b39193..145d61e5 100644 --- a/exasol_script_languages_container_tool/lib/api/run_db_tests.py +++ b/exasol_script_languages_container_tool/lib/api/run_db_tests.py @@ -5,6 +5,8 @@ from exasol_integration_test_docker_environment.lib.api.common import run_task, generate_root_task, \ set_docker_repository_config, set_build_config, import_build_steps, cli_function from exasol_integration_test_docker_environment.lib.base.dependency_logger_base_task import DependencyLoggerBaseTask +from exasol_integration_test_docker_environment.lib.test_environment.parameter.docker_db_test_environment_parameter import \ + DbOsAccess from exasol_script_languages_container_tool.lib.api import api_errors from exasol_script_languages_container_tool.lib.tasks.test.test_container import TestContainer, AllTestsResult @@ -126,6 +128,7 @@ def root_task_generator() -> DependencyLoggerBaseTask: reuse_database_setup=reuse_database_setup, reuse_test_container=reuse_test_container, reuse_database=reuse_database, + db_os_access=DbOsAccess[db_os_access], no_test_container_cleanup_after_success=reuse_test_container, no_test_container_cleanup_after_failure=reuse_test_container, no_database_cleanup_after_success=reuse_database, diff --git a/exasol_script_languages_container_tool/lib/tasks/test/test_runner_db_test_task.py b/exasol_script_languages_container_tool/lib/tasks/test/test_runner_db_test_task.py index fd2dc1ad..776e172d 100644 --- a/exasol_script_languages_container_tool/lib/tasks/test/test_runner_db_test_task.py +++ b/exasol_script_languages_container_tool/lib/tasks/test/test_runner_db_test_task.py @@ -2,8 +2,9 @@ from typing import Generator, Any, Dict import luigi +from docker.models.containers import ExecResult from exasol_integration_test_docker_environment.lib.base.db_os_executor import DbOsExecFactory, SshExecFactory, \ - DockerClientFactory, DockerExecFactory + DockerClientFactory, DockerExecFactory, DbOsExecutor from exasol_integration_test_docker_environment.lib.base.json_pickle_parameter import JsonPickleParameter from exasol_integration_test_docker_environment.lib.data.database_info import DatabaseInfo from exasol_integration_test_docker_environment.lib.test_environment.parameter.docker_db_test_environment_parameter import \ @@ -26,6 +27,26 @@ from exasol_integration_test_docker_environment.lib.test_environment.spawn_test_environment import SpawnTestEnvironment +class DummyExecutor(DbOsExecutor): + + def exec(self, cmd: str) -> ExecResult: + raise RuntimeError("Not supposed to be called.") + + def prepare(self): + pass + + def __enter__(self): + return self + + def __exit__(self, type_, value, traceback): + pass + + +class DummyExecFactory(DbOsExecFactory): + def executor(self) -> DbOsExecutor: + return DummyExecutor() + + class TestRunnerDBTestTask(FlavorBaseTask, SpawnTestEnvironmentParameter, RunDBTestsInTestConfigParameter): @@ -71,10 +92,13 @@ def run_task(self): self.return_object(test_results) def _executor_factory(self, database_info: DatabaseInfo) -> DbOsExecFactory: + if self.db_os_access == DbOsAccess.SSH: return SshExecFactory.from_database_info(database_info) client_factory = DockerClientFactory(timeout=100000) - return DockerExecFactory(database_info.container_info.container_name, client_factory) + if database_info.container_info is not None: + return DockerExecFactory(database_info.container_info.container_name, client_factory) + return DummyExecFactory() def upload_container(self, database_credentials: DatabaseCredentials, export_info: ExportInfo): reuse = \