-
Notifications
You must be signed in to change notification settings - Fork 65
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
[WIP] Add possibility to parameterize S3 service URL #137
Merged
pjbull
merged 5 commits into
drivendataorg:custom-s3-endpoint
from
YevheniiSemendiak:ys/parameterize_s3_endpoint
Mar 23, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4adffe6
Add possibility to parameterize S3 service URL
YevheniiSemendiak 258392b
add usage description into the docs
YevheniiSemendiak 02f7a8c
add rig for custom S3 servers
YevheniiSemendiak fc113dc
address PR review: add cods to rig, allow mock
YevheniiSemendiak 762c884
forgot to commit tests/conftest.py :)
YevheniiSemendiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,15 +51,22 @@ class CloudProviderTestRig: | |
"""Class that holds together the components needed to test a cloud implementation.""" | ||
|
||
def __init__( | ||
self, path_class: type, client_class: type, drive: str = "drive", test_dir: str = "" | ||
self, | ||
path_class: type, | ||
client_class: type, | ||
drive: str = "drive", | ||
test_dir: str = "", | ||
**client_kwargs: dict, | ||
): | ||
""" | ||
Args: | ||
path_class (type): CloudPath subclass | ||
client_class (type): Client subclass | ||
client_kwargs (dict): Kwargs, passed to instantiate the client | ||
""" | ||
self.path_class = path_class | ||
self.client_class = client_class | ||
self.client_kwargs = client_kwargs | ||
self.drive = drive | ||
self.test_dir = test_dir | ||
|
||
|
@@ -212,6 +219,63 @@ def s3_rig(request, monkeypatch, assets_dir): | |
bucket.objects.filter(Prefix=test_dir).delete() | ||
|
||
|
||
@fixture() | ||
def custom_s3_rig(request, monkeypatch, assets_dir): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a docstring that this is used for testing things like MinIO/ceph There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done here 762c884 |
||
""" | ||
Custom S3 rig used to test the integrations with non-AWS S3-compatible object storages like | ||
- MinIO (https://min.io/) | ||
- CEPH (https://ceph.io/ceph-storage/object-storage/) | ||
- others | ||
""" | ||
drive = os.getenv("CUSTOM_S3_BUCKET", "bucket") | ||
custom_endpoint_url = os.getenv("CUSTOM_S3_ENDPOINT") | ||
custom_key_id = os.getenv("CUSTOM_S3_KEY_ID") | ||
custom_secret_key = os.getenv("CUSTOM_S3_SECRET_KEY") | ||
test_dir = create_test_dir_name(request) | ||
|
||
if os.getenv("USE_LIVE_CLOUD") == "1": | ||
# Upload test assets | ||
s3 = boto3.resource( | ||
"s3", | ||
aws_access_key_id=custom_key_id, | ||
aws_secret_access_key=custom_secret_key, | ||
endpoint_url=custom_endpoint_url, | ||
) | ||
bucket = s3.Bucket(drive) | ||
test_files = [ | ||
f for f in assets_dir.glob("**/*") if f.is_file() and f.name not in UPLOAD_IGNORE_LIST | ||
] | ||
for test_file in test_files: | ||
bucket.upload_file( | ||
str(test_file), | ||
str(f"{test_dir}/{PurePosixPath(test_file.relative_to(assets_dir))}"), | ||
) | ||
else: | ||
# Mock cloud SDK | ||
monkeypatch.setattr( | ||
cloudpathlib.s3.s3client, | ||
"Session", | ||
mocked_session_class_factory(test_dir), | ||
) | ||
|
||
rig = CloudProviderTestRig( | ||
path_class=S3Path, | ||
client_class=S3Client, | ||
drive=drive, | ||
test_dir=test_dir, | ||
endpoint_url=custom_endpoint_url, | ||
aws_access_key_id=custom_key_id, | ||
aws_secret_access_key=custom_secret_key, | ||
) | ||
|
||
rig.client_class(**rig.client_kwargs).set_as_default_client() # set default client | ||
|
||
yield rig | ||
|
||
rig.client_class._default_client = None # reset default client | ||
bucket.objects.filter(Prefix=test_dir).delete() | ||
|
||
|
||
@fixture() | ||
def local_azure_rig(request, monkeypatch, assets_dir): | ||
drive = os.getenv("LIVE_AZURE_CONTAINER", "container") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might set this up to show three scenarios:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here fc113dc