diff --git a/doc/changes/changes_0.5.0.md b/doc/changes/changes_0.5.0.md index 14a4d731..f10f8b97 100644 --- a/doc/changes/changes_0.5.0.md +++ b/doc/changes/changes_0.5.0.md @@ -4,6 +4,7 @@ TDB ## Features / Enhancements +- #4 Added support for listing all accessible buckets of a bucketfs service ## Bug Fixes diff --git a/exasol_bucketfs_utils_python/__init__.py b/exasol_bucketfs_utils_python/__init__.py index e69de29b..4318b4b0 100644 --- a/exasol_bucketfs_utils_python/__init__.py +++ b/exasol_bucketfs_utils_python/__init__.py @@ -0,0 +1,3 @@ +class BucketFsError(Exception): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) diff --git a/exasol_bucketfs_utils_python/buckets.py b/exasol_bucketfs_utils_python/buckets.py new file mode 100644 index 00000000..9925950e --- /dev/null +++ b/exasol_bucketfs_utils_python/buckets.py @@ -0,0 +1,32 @@ +from exasol_bucketfs_utils_python import BucketFsError +import requests +from typing import Iterator + + +def list_buckets( + base_url: str, + path: str = "", + port: int = 2580, +) -> Iterator[str]: + """ + List all buckets for a specific bucketfs service. + + The following mapping will be applied for determining the final url: {base_url}:{port}/{path} + + :param base_url: URL of the bucketfs service e.g. http://127.0.0.1. + :param path: if the service root is hidden behind a sub-path, the default "" should work in most cases. + :param port: the bucketfs service is listening on (default: 2580). + In case of error make sure the correct port is used. + + :raises BucketFsError: + + :return: all accessible buckets off the bucketfs service. + """ + url = f"{base_url}:{port}/{path}" + try: + response = requests.get(url) + response.raise_for_status() + except Exception as ex: + raise BucketFsError from ex + lines = (line for line in response.text.split("\n") if not line.isspace()) + return (line for line in lines if line != "") diff --git a/tests/build_language_container.sh b/tests/build_language_container.sh index 2180d6f8..3791b70b 100755 --- a/tests/build_language_container.sh +++ b/tests/build_language_container.sh @@ -4,6 +4,10 @@ set -euo pipefail SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" pushd "$SCRIPT_DIR" &> /dev/null +if [ -d "dist"]; then + trap 'rm "dist"/*' EXIT + rm "dist"/* || true +fi poetry build @@ -11,7 +15,7 @@ RELEASE_BUILD_STEP_DIST_DIRECTORY="./../language_container/exasol-bucketfs-utils echo "Copy" ./../dist/*.whl "$RELEASE_BUILD_STEP_DIST_DIRECTORY" mkdir "$RELEASE_BUILD_STEP_DIST_DIRECTORY" || true cp ./../dist/*.whl "$RELEASE_BUILD_STEP_DIST_DIRECTORY" -trap 'rm -rf "$RELEASE_BUILD_STEP_DIST_DIRECTORY"' EXIT +trap 'rm -rf "$RELEASE_BUILD_STEP_DIST_DIRECTORY" "../dist"' EXIT echo "Build container" ./../language_container/exaslct export --flavor-path ./../language_container/exasol-bucketfs-utils-python-container/ --output-directory ../.build_output diff --git a/tests/conftest.py b/tests/conftest.py index b0fffe62..fea799b8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,54 @@ +import pytest +from dataclasses import dataclass + + +def pytest_addoption(parser): + option = "--bucketfs-{name}" + group = parser.getgroup("bucketfs") + group.addoption( + option.format(name="port"), + type=int, + default=6666, + help="Port on which the bucketfs service ist listening (default: 6666)." + ) + group.addoption( + option.format(name="url"), + type=str, + default="http://127.0.0.1", + help="Base url used to connect to the bucketfs service (default: 'http://127.0.0.1')." + ) + group.addoption( + option.format(name="username"), + type=str, + default="w", + help="Username used to authenticate against the bucketfs service (default: 'w')." + ) + group.addoption( + option.format(name="password"), + type=str, + default="write", + help="Password used to authenticate against the bucketfs service (default: 'write')." + ) + + +@dataclass +class Config: + """Bucketfs integration test configuration""" + url: str + port: int + username: str + password: str + + +@pytest.fixture +def bucketfs_test_config(request) -> Config: + options = request.config.option + return Config( + url=options.bucketfs_url, + port=options.bucketfs_port, + username=options.bucketfs_username, + password=options.bucketfs_password + ) pytest_plugins = [ @@ -5,4 +56,4 @@ "tests.fixtures.bucketfs_location_fixture", "tests.fixtures.upload_language_container_fixture", "tests.fixtures.prepare_bucket_fixture" -] \ No newline at end of file +] diff --git a/tests/integration_tests/with_db/test_buckets.py b/tests/integration_tests/with_db/test_buckets.py new file mode 100644 index 00000000..c2eb8fd0 --- /dev/null +++ b/tests/integration_tests/with_db/test_buckets.py @@ -0,0 +1,8 @@ +from exasol_bucketfs_utils_python.buckets import list_buckets + + +def test_all_default_buckets_are_listed(bucketfs_test_config): + assert set(list(list_buckets( + base_url=bucketfs_test_config.url, + port=bucketfs_test_config.port + ))) == {'default', 'myudfs', 'jdbc_adapter'}