2022-10-27 05:43:20 +00:00
|
|
|
import os
|
2022-08-25 10:57:55 +00:00
|
|
|
from dataclasses import dataclass
|
2024-03-11 16:34:54 +00:00
|
|
|
from datetime import datetime
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2024-03-11 16:34:54 +00:00
|
|
|
from frostfs_testlib.credentials.interfaces import CredentialsProvider, User
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.wellknown_acl import PUBLIC_ACL
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.shell import Shell
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.cli.container import create_container
|
|
|
|
from frostfs_testlib.steps.cli.object import put_object_to_random_node
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
|
|
|
from frostfs_testlib.storage.dataclasses.acl import EACLRole
|
|
|
|
from frostfs_testlib.storage.dataclasses.frostfs_services import InnerRing, StorageNode
|
2024-03-11 16:34:54 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
OBJECT_COUNT = 5
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Wallets:
|
2024-03-11 16:34:54 +00:00
|
|
|
wallets: dict[EACLRole, list[WalletInfo]]
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2024-03-11 16:34:54 +00:00
|
|
|
def get_wallet(self, role: EACLRole = EACLRole.USER) -> WalletInfo:
|
2022-08-25 10:57:55 +00:00
|
|
|
return self.wallets[role][0]
|
|
|
|
|
2024-03-11 16:34:54 +00:00
|
|
|
def get_wallets_list(self, role: EACLRole = EACLRole.USER) -> list[WalletInfo]:
|
2022-08-25 10:57:55 +00:00
|
|
|
return self.wallets[role]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2024-03-11 16:34:54 +00:00
|
|
|
def wallets(default_wallet: WalletInfo, credentials_provider: CredentialsProvider, cluster: Cluster) -> Wallets:
|
|
|
|
other_wallets: list = []
|
|
|
|
for _ in range(2):
|
|
|
|
user = User(f"user_{hex(int(datetime.now().timestamp() * 1000000))}")
|
|
|
|
other_wallets.append(credentials_provider.GRPC.provide(user, cluster.cluster_nodes[0]))
|
2022-10-27 05:43:20 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
ir_node: InnerRing = cluster.ir_nodes[0]
|
|
|
|
storage_node: StorageNode = cluster.storage_nodes[0]
|
2022-12-05 22:31:45 +00:00
|
|
|
|
2023-09-21 16:49:31 +00:00
|
|
|
wallets_collection = Wallets(
|
2022-09-05 12:12:56 +00:00
|
|
|
wallets={
|
2024-03-11 16:34:54 +00:00
|
|
|
EACLRole.USER: [default_wallet],
|
|
|
|
EACLRole.OTHERS: other_wallets,
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.SYSTEM: [
|
2024-03-11 16:34:54 +00:00
|
|
|
WalletInfo.from_node(ir_node),
|
|
|
|
WalletInfo.from_node(storage_node),
|
2022-09-05 12:12:56 +00:00
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2023-09-21 16:49:31 +00:00
|
|
|
for role, wallets in wallets_collection.wallets.items():
|
|
|
|
if role == EACLRole.SYSTEM:
|
|
|
|
continue
|
|
|
|
for wallet in wallets:
|
2024-03-11 16:34:54 +00:00
|
|
|
reporter.attach(wallet.path, os.path.basename(wallet.path))
|
2023-09-21 16:49:31 +00:00
|
|
|
|
|
|
|
return wallets_collection
|
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2022-09-05 12:12:56 +00:00
|
|
|
@pytest.fixture(scope="function")
|
2022-12-05 22:31:45 +00:00
|
|
|
def eacl_container_with_objects(
|
|
|
|
wallets: Wallets, client_shell: Shell, cluster: Cluster, file_path: str
|
2023-05-15 09:59:33 +00:00
|
|
|
) -> tuple[str, list[str], str]:
|
2022-08-25 10:57:55 +00:00
|
|
|
user_wallet = wallets.get_wallet()
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Create eACL public container"):
|
2022-12-05 22:31:45 +00:00
|
|
|
cid = create_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-12-05 22:31:45 +00:00
|
|
|
basic_acl=PUBLIC_ACL,
|
|
|
|
shell=client_shell,
|
|
|
|
endpoint=cluster.default_rpc_endpoint,
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Add test objects to container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
objects_oids = [
|
2022-12-05 22:31:45 +00:00
|
|
|
put_object_to_random_node(
|
2024-03-11 16:34:54 +00:00
|
|
|
user_wallet,
|
2022-09-05 12:12:56 +00:00
|
|
|
file_path,
|
|
|
|
cid,
|
|
|
|
attributes={"key1": "val1", "key": val, "key2": "abc"},
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster=cluster,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
for val in range(OBJECT_COUNT)
|
|
|
|
]
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
yield cid, objects_oids, file_path
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
# with reporter.step('Delete eACL public container'):
|
2022-08-25 10:57:55 +00:00
|
|
|
# delete_container(user_wallet, cid)
|