-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from Aiven-Open/rominf-reorganize-tests
tests: reorganize
- Loading branch information
Showing
24 changed files
with
163 additions
and
170 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright (c) 2023 Aiven, Helsinki, Finland. https://aiven.io/ | ||
|
||
IO_BLOCK_SIZE = 2**20 # 1 MiB |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright (c) 2023 Aiven, Helsinki, Finland. https://aiven.io/ | ||
|
||
from .common.models import StorageModel | ||
from .errors import InvalidConfigurationError | ||
from .notifier.interface import Notifier | ||
from .object_storage.base import BaseTransfer | ||
from typing import Any, cast, Dict, Type | ||
|
||
STORAGE_TYPE = "storage_type" | ||
NOTIFIER_TYPE = "notifier_type" | ||
Config = Dict[str, Any] | ||
|
||
|
||
def get_class_for_transfer(obj_store: Config) -> Type[BaseTransfer[StorageModel]]: | ||
storage_type = obj_store[STORAGE_TYPE] | ||
if storage_type == "azure": | ||
from .object_storage.azure import AzureTransfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], AzureTransfer) | ||
elif storage_type == "google": | ||
from .object_storage.google import GoogleTransfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], GoogleTransfer) | ||
elif storage_type == "sftp": | ||
from .object_storage.sftp import SFTPTransfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], SFTPTransfer) | ||
elif storage_type == "local": | ||
from .object_storage.local import LocalTransfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], LocalTransfer) | ||
elif storage_type == "s3": | ||
from .object_storage.s3 import S3Transfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], S3Transfer) | ||
elif storage_type == "swift": | ||
from .object_storage.swift import SwiftTransfer | ||
|
||
return cast(Type[BaseTransfer[StorageModel]], SwiftTransfer) | ||
|
||
raise InvalidConfigurationError("unsupported storage type {0!r}".format(storage_type)) | ||
|
||
|
||
def get_class_for_notifier(notifier_config: Config) -> Type[Notifier]: | ||
notifier_type = notifier_config[NOTIFIER_TYPE] | ||
if notifier_type == "http": | ||
from .notifier.http import BackgroundHTTPNotifier | ||
|
||
return BackgroundHTTPNotifier | ||
raise InvalidConfigurationError("unsupported storage type {0!r}".format(notifier_type)) | ||
|
||
|
||
def get_notifier(notifier_config: Config) -> Notifier: | ||
notificer_class = get_class_for_notifier(notifier_config) | ||
notifier_config = notifier_config.copy() | ||
notifier_config.pop(NOTIFIER_TYPE) | ||
return notificer_class(**notifier_config) | ||
|
||
|
||
def get_transfer_model(storage_config: Config) -> StorageModel: | ||
storage_class = get_class_for_transfer(storage_config) | ||
storage_config = dict(storage_config) | ||
storage_config.pop(STORAGE_TYPE) | ||
notifier_config = storage_config.pop("notifier", None) | ||
notifier = None | ||
if notifier_config is not None: | ||
notifier = get_notifier(notifier_config) | ||
|
||
model = storage_class.config_model(**storage_config, notifier=notifier) | ||
return model | ||
|
||
|
||
def get_transfer(storage_config: Config) -> BaseTransfer[StorageModel]: | ||
storage_class = get_class_for_transfer(storage_config) | ||
model = get_transfer_model(storage_config) | ||
return storage_class.from_model(model) |
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
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 was deleted.
Oops, something went wrong.
Empty file.
File renamed without changes.
Empty file.
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
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.