From d12d08963a4b61d2b614e766490c881a6b372a86 Mon Sep 17 00:00:00 2001 From: Maxim Lapan Date: Wed, 19 Jun 2024 12:34:24 +0200 Subject: [PATCH] Experimental refactor [run aws tests] --- .../sme_language_container_deployer.py | 5 ++++ .../build_language_container_fixture.py | 30 ++++++++++++------- tests/ci_tests/utils/parameters.py | 15 ++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/exasol_sagemaker_extension/deployment/sme_language_container_deployer.py b/exasol_sagemaker_extension/deployment/sme_language_container_deployer.py index fbc7d91..24baf19 100644 --- a/exasol_sagemaker_extension/deployment/sme_language_container_deployer.py +++ b/exasol_sagemaker_extension/deployment/sme_language_container_deployer.py @@ -1,6 +1,7 @@ from typing import Optional from pathlib import Path from exasol.python_extension_common.deployment.language_container_deployer import LanguageContainerDeployer +import exasol.bucketfs as bfs class SmeLanguageContainerDeployer(LanguageContainerDeployer): @@ -17,6 +18,10 @@ def download_from_github_and_run(self, version: str, alter_system=alter_system, allow_override=allow_override, wait_for_completion=wait_for_completion) + @property + def bfs_path(self) -> bfs.path.PathLike: + return self._bucketfs_path + def run(self, container_file: Optional[Path] = None, bucket_file_path: Optional[str] = None, alter_system: bool = True, diff --git a/tests/ci_tests/fixtures/build_language_container_fixture.py b/tests/ci_tests/fixtures/build_language_container_fixture.py index 2d3241f..858e7d1 100644 --- a/tests/ci_tests/fixtures/build_language_container_fixture.py +++ b/tests/ci_tests/fixtures/build_language_container_fixture.py @@ -2,14 +2,18 @@ import pytest import subprocess +from typing import Tuple from pathlib import Path +import pyexasol import exasol_bucketfs_utils_python.upload as bfsupload from exasol_bucketfs_utils_python.bucket_config import BucketConfig from exasol_bucketfs_utils_python.bucketfs_config import BucketFSConfig from exasol_bucketfs_utils_python.bucketfs_connection_config import \ BucketFSConnectionConfig -from tests.ci_tests.utils.parameters import db_params +from exasol_sagemaker_extension.deployment.sme_language_container_deployer import SmeLanguageContainerDeployer + +from tests.ci_tests.utils.parameters import db_params, get_bfs_root_path def find_script(script_name: str): @@ -27,7 +31,7 @@ def find_script(script_name: str): @pytest.fixture(scope="session") -def language_container(): +def language_container() -> Tuple[Path, str]: script_dir = find_script("build_language_container.sh") completed_process = subprocess.run( [script_dir], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -46,11 +50,7 @@ def language_container(): container_path = \ [line for line in lines if line.startswith(container_path_selector)][0] container_path = container_path[len(container_path_selector):] - - return { - "container_path": container_path, - "alter_session": alter_session - } + return Path(container_path), alter_session @pytest.fixture(scope="session") @@ -85,7 +85,17 @@ def upload_language_container(language_container, db_conn): return alter_session +@pytest.fixture +def container_deployer(language_container, db_conn: pyexasol.ExaConnection) -> SmeLanguageContainerDeployer: + deployer = SmeLanguageContainerDeployer( + pyexasol_connection=db_conn, + language_alias='PYTHON3_TEST', + bucketfs_path=get_bfs_root_path(), + ) + return deployer + + @pytest.fixture(scope="session") -def register_language_container(upload_language_container, db_conn): - alter_session = upload_language_container - db_conn.execute(f"ALTER SYSTEM SET SCRIPT_LANGUAGES='{alter_session}'") +def register_language_container(language_container, container_deployer: SmeLanguageContainerDeployer, db_conn): + container_path, _ = language_container + container_deployer.run(container_path, alter_system=True) diff --git a/tests/ci_tests/utils/parameters.py b/tests/ci_tests/utils/parameters.py index c50ec73..bfee260 100644 --- a/tests/ci_tests/utils/parameters.py +++ b/tests/ci_tests/utils/parameters.py @@ -1,4 +1,6 @@ from collections import namedtuple +import exasol.bucketfs as bfs + POLLING_INTERVAL = 5 * 60 # seconds TIMEOUT = 90 * 60 # seconds @@ -41,3 +43,16 @@ def get_db_params(): db_params = get_db_params() + + +def get_bfs_root_path() -> bfs.path.PathLike: + root_path = bfs.path.build_path( + backend="onprem", + url=f"http://{db_params.host}:{db_params.port}", + username="w", + password="write", + bucket_name="bfsdefault", + verify=False, + ) + + return root_path \ No newline at end of file