Skip to content

Commit

Permalink
List buckets of a bucketfs service
Browse files Browse the repository at this point in the history
* Add support for listing all accessible buckets of a bucketfs service
* Add test for listing buckets
* Update change-log

Co-authored-by: Christoph Kuhnke <[email protected]>
  • Loading branch information
Nicoretti and ckunki authored Oct 12, 2022
1 parent 44e5fd1 commit ab1d9f9
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/changes_0.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
TDB

## Features / Enhancements
- #4 Added support for listing all accessible buckets of a bucketfs service

## Bug Fixes

Expand Down
3 changes: 3 additions & 0 deletions exasol_bucketfs_utils_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BucketFsError(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
32 changes: 32 additions & 0 deletions exasol_bucketfs_utils_python/buckets.py
Original file line number Diff line number Diff line change
@@ -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 != "")
6 changes: 5 additions & 1 deletion tests/build_language_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ 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


RELEASE_BUILD_STEP_DIST_DIRECTORY="./../language_container/exasol-bucketfs-utils-python-container/flavor_base/release/dist"
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
Expand Down
53 changes: 52 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
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 = [
"tests.fixtures.build_language_container_fixture",
"tests.fixtures.bucketfs_location_fixture",
"tests.fixtures.upload_language_container_fixture",
"tests.fixtures.prepare_bucket_fixture"
]
]
8 changes: 8 additions & 0 deletions tests/integration_tests/with_db/test_buckets.py
Original file line number Diff line number Diff line change
@@ -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'}

0 comments on commit ab1d9f9

Please sign in to comment.