Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring storage: removed s3wrapper #2295

Merged
merged 28 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2c56e36
moved s3wrapper inside storage
pcrespov Apr 22, 2021
dcf49fe
removes s3wrapper dependency from simcore-skd
pcrespov Apr 26, 2021
da97eb3
removes s3wrapper dependency from web/server
pcrespov Apr 26, 2021
2ae297e
removes s3wrapper dependency from swarm-deploy
pcrespov Apr 26, 2021
cd87470
removes s3wrapper dependency from sidecar
pcrespov Apr 26, 2021
fced709
removes s3wrapper dependency from api-server
pcrespov Apr 26, 2021
08e5e1d
removes s3wrapper dependency from pytest-simcore
pcrespov Apr 26, 2021
d838092
minor fix test in storage
pcrespov Apr 26, 2021
358d4b5
adds minio in tests reqs for simcore-sdk
pcrespov Apr 26, 2021
7775720
Fixes minio in pytest-simcore
pcrespov Apr 26, 2021
00502d2
adds minio in tests reqs for sidecar
pcrespov Apr 26, 2021
726a1c9
adds minio in tests reqs for swarm-deploy
pcrespov Apr 26, 2021
8eefd5d
fixes reqs
pcrespov Apr 26, 2021
eaa4cc3
minor
pcrespov Apr 26, 2021
a1f3b78
Cleanup pytest_simcore.minio_service and some extra monkeypatch fixt…
pcrespov Apr 26, 2021
e965e81
moved to a subfolder former s3wrapper tests
pcrespov Apr 26, 2021
26645d8
adds missing pytest-plugin
pcrespov Apr 26, 2021
27da19b
fixes healtcheck in mino
pcrespov Apr 26, 2021
4283722
Fixes minio deprecated functionality
pcrespov Apr 26, 2021
54907b6
typo
pcrespov Apr 26, 2021
d1a2132
git fixes simcore-sdk requirements constraints
pcrespov Apr 26, 2021
a0fc117
minor comment
pcrespov Apr 26, 2021
73bd57b
Revert "Fixes minio deprecated functionality"
pcrespov Apr 26, 2021
cfaa8b7
upgardes minio in storage
pcrespov Apr 26, 2021
42979a6
fixes cleanup and refactors retry
pcrespov Apr 26, 2021
4f2806c
Merge branch 'master' into refactor/remove-s3wrapper
pcrespov Apr 27, 2021
14e315e
review @sanderegg: renamed s3client
pcrespov Apr 27, 2021
b6950c0
review @sanderegg: added annotations
pcrespov Apr 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"./packages/postgres-database/src",
"./packages/postgres-database/tests",
"./packages/pytest-simcore/src",
"./packages/s3wrapper/src",
"./packages/service-integration/src",
"./packages/service-library/src",
"./packages/simcore-sdk/src",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable


from copy import deepcopy
from pathlib import Path
Expand Down
92 changes: 54 additions & 38 deletions packages/pytest-simcore/src/pytest_simcore/minio_service.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import logging
import os
from copy import deepcopy
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable

# pylint:disable=unused-variable
# pylint:disable=unused-argument
# pylint:disable=redefined-outer-name
import logging
from distutils.util import strtobool
from typing import Dict
from typing import Dict, Iterator

import pytest
import tenacity
from s3wrapper.s3_client import S3Client
from minio import Minio
from tenacity import Retrying

from .helpers.utils_docker import get_ip, get_service_published_port

log = logging.getLogger(__name__)


def _ensure_remove_bucket(client: Minio, bucket_name: str):
if client.bucket_exists(bucket_name):
# remove content
objs = client.list_objects(bucket_name, prefix=None, recursive=True)
errors = client.remove_objects(bucket_name, [o.object_name for o in objs])
assert not list(errors)
# remove bucket
client.remove_bucket(bucket_name)
assert not client.bucket_exists(bucket_name)


@pytest.fixture(scope="module")
def minio_config(docker_stack: Dict, devel_environ: Dict) -> Dict[str, str]:
def minio_config(
docker_stack: Dict, devel_environ: Dict, monkeypatch_module
) -> Dict[str, str]:
assert "ops_minio" in docker_stack["services"]

config = {
Expand All @@ -32,49 +44,53 @@ def minio_config(docker_stack: Dict, devel_environ: Dict) -> Dict[str, str]:
}

# nodeports takes its configuration from env variables
old_environ = deepcopy(os.environ)
for key, value in config["client"].items():
os.environ[f"S3_{key.upper()}"] = str(value)
os.environ["S3_SECURE"] = devel_environ["S3_SECURE"]
os.environ["S3_BUCKET_NAME"] = config["bucket_name"]
monkeypatch_module.setenv(f"S3_{key.upper()}", str(value))

monkeypatch_module.setenv("S3_SECURE", devel_environ["S3_SECURE"])
monkeypatch_module.setenv("S3_BUCKET_NAME", config["bucket_name"])

yield config
# restore environ
os.environ = old_environ
return config


@pytest.fixture(scope="module")
def minio_service(minio_config: Dict[str, str]) -> S3Client:
assert wait_till_minio_responsive(minio_config)
def minio_service(minio_config: Dict[str, str]) -> Iterator[Minio]:

client = Minio(**minio_config["client"])

for attempt in Retrying(
wait=tenacity.wait_fixed(5),
stop=tenacity.stop_after_attempt(60),
before_sleep=tenacity.before_sleep_log(log, logging.WARNING),
reraise=True,
):
with attempt:
# TODO: improve as https://docs.min.io/docs/minio-monitoring-guide.html
if not client.bucket_exists("pytest"):
client.make_bucket("pytest")
client.remove_bucket("pytest")

client = S3Client(**minio_config["client"])
assert client.create_bucket(minio_config["bucket_name"])
bucket_name = minio_config["bucket_name"]

yield client
# cleans up in case a failing tests left this bucket
_ensure_remove_bucket(client, bucket_name)

assert client.remove_bucket(minio_config["bucket_name"], delete_contents=True)
client.make_bucket(bucket_name)
assert client.bucket_exists(bucket_name)

yield client

@tenacity.retry(
wait=tenacity.wait_fixed(5),
stop=tenacity.stop_after_attempt(60),
before_sleep=tenacity.before_sleep_log(log, logging.INFO),
reraise=True,
)
def wait_till_minio_responsive(minio_config: Dict[str, str]) -> bool:
"""Check if something responds to ``url`` """
client = S3Client(**minio_config["client"])
if client.create_bucket("pytest"):
client.remove_bucket("pytest")
return True
raise Exception(f"Minio not responding to {minio_config}")
# cleanup upon tear-down
_ensure_remove_bucket(client, bucket_name)


@pytest.fixture(scope="module")
def bucket(minio_config: Dict[str, str], minio_service: S3Client) -> str:
def bucket(minio_config: Dict[str, str], minio_service: Minio) -> str:
bucket_name = minio_config["bucket_name"]
minio_service.create_bucket(bucket_name, delete_contents_if_exists=True)

_ensure_remove_bucket(minio_service, bucket_name)
minio_service.make_bucket(bucket_name)

yield bucket_name

minio_service.remove_bucket(bucket_name, delete_contents=True)
_ensure_remove_bucket(minio_service, bucket_name)
29 changes: 29 additions & 0 deletions packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable

from typing import Iterator

import pytest
from _pytest.fixtures import FixtureRequest
from _pytest.monkeypatch import MonkeyPatch

# Some extras to overcome https://github.com/pytest-dev/pytest/issues/363


@pytest.fixture(scope="session")
def monkeypatch_session(request: FixtureRequest) -> Iterator[MonkeyPatch]:
assert request.scope == "session"

mpatch_session = MonkeyPatch()
yield mpatch_session
mpatch_session.undo()


@pytest.fixture(scope="module")
def monkeypatch_module(request: FixtureRequest) -> Iterator[MonkeyPatch]:
assert request.scope == "module"

mpatch_module = MonkeyPatch()
yield mpatch_module
mpatch_module.undo()
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import aiohttp
import pytest
import tenacity
from s3wrapper.s3_client import S3Client
from minio import Minio
from servicelib.minio_utils import MinioRetryPolicyUponInitialization
from yarl import URL

Expand All @@ -33,7 +33,7 @@ def storage_endpoint(docker_stack: Dict, devel_environ: Dict) -> URL:

@pytest.fixture(scope="function")
async def storage_service(
minio_service: S3Client, storage_endpoint: URL, docker_stack: Dict
minio_service: Minio, storage_endpoint: URL, docker_stack: Dict
) -> URL:
await wait_till_storage_responsive(storage_endpoint)

Expand Down
6 changes: 0 additions & 6 deletions packages/s3wrapper/requirements/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions packages/s3wrapper/requirements/_base.in

This file was deleted.

25 changes: 0 additions & 25 deletions packages/s3wrapper/requirements/_base.txt

This file was deleted.

23 changes: 0 additions & 23 deletions packages/s3wrapper/requirements/_test.in

This file was deleted.

Loading