2022-11-25 12:44:47 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import allure
|
2022-12-05 22:31:45 +00:00
|
|
|
from cluster import Cluster
|
2022-11-25 12:44:47 +00:00
|
|
|
from file_helper import generate_file, get_file_hash
|
|
|
|
from neofs_testlib.shell import Shell
|
2022-12-06 15:06:39 +00:00
|
|
|
from neofs_verbs import put_object, put_object_to_random_node
|
2022-11-25 12:44:47 +00:00
|
|
|
from storage_object import StorageObjectInfo
|
|
|
|
from wallet import WalletFile
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class StorageContainerInfo:
|
|
|
|
id: str
|
|
|
|
wallet_file: WalletFile
|
|
|
|
|
|
|
|
|
|
|
|
class StorageContainer:
|
2022-12-05 22:31:45 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
storage_container_info: StorageContainerInfo,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
) -> None:
|
2022-11-25 12:44:47 +00:00
|
|
|
self.shell = shell
|
|
|
|
self.storage_container_info = storage_container_info
|
2022-12-05 22:31:45 +00:00
|
|
|
self.cluster = cluster
|
2022-11-25 12:44:47 +00:00
|
|
|
|
|
|
|
def get_id(self) -> str:
|
|
|
|
return self.storage_container_info.id
|
|
|
|
|
|
|
|
def get_wallet_path(self) -> str:
|
|
|
|
return self.storage_container_info.wallet_file.path
|
|
|
|
|
2022-12-06 15:06:39 +00:00
|
|
|
def get_wallet_config_path(self) -> str:
|
|
|
|
return self.storage_container_info.wallet_file.config_path
|
|
|
|
|
2022-11-25 12:44:47 +00:00
|
|
|
@allure.step("Generate new object and put in container")
|
2022-12-06 15:06:39 +00:00
|
|
|
def generate_object(
|
|
|
|
self,
|
|
|
|
size: int,
|
|
|
|
expire_at: Optional[int] = None,
|
|
|
|
bearer_token: Optional[str] = None,
|
|
|
|
endpoint: Optional[str] = None,
|
|
|
|
) -> StorageObjectInfo:
|
2022-11-25 12:44:47 +00:00
|
|
|
with allure.step(f"Generate object with size {size}"):
|
|
|
|
file_path = generate_file(size)
|
|
|
|
file_hash = get_file_hash(file_path)
|
|
|
|
|
|
|
|
container_id = self.get_id()
|
|
|
|
wallet_path = self.get_wallet_path()
|
2022-12-06 15:06:39 +00:00
|
|
|
wallet_config = self.get_wallet_config_path()
|
2022-11-25 12:44:47 +00:00
|
|
|
with allure.step(f"Put object with size {size} to container {container_id}"):
|
2022-12-06 15:06:39 +00:00
|
|
|
if endpoint:
|
|
|
|
object_id = put_object(
|
|
|
|
wallet=wallet_path,
|
|
|
|
path=file_path,
|
|
|
|
cid=container_id,
|
|
|
|
expire_at=expire_at,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=endpoint,
|
|
|
|
bearer=bearer_token,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
object_id = put_object_to_random_node(
|
|
|
|
wallet=wallet_path,
|
|
|
|
path=file_path,
|
|
|
|
cid=container_id,
|
|
|
|
expire_at=expire_at,
|
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
|
|
|
bearer=bearer_token,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
)
|
2022-11-25 12:44:47 +00:00
|
|
|
|
|
|
|
storage_object = StorageObjectInfo(
|
|
|
|
container_id,
|
|
|
|
object_id,
|
|
|
|
size=size,
|
|
|
|
wallet_file_path=wallet_path,
|
|
|
|
file_path=file_path,
|
|
|
|
file_hash=file_hash,
|
|
|
|
)
|
|
|
|
|
|
|
|
return storage_object
|