2022-10-27 05:43:20 +00:00
|
|
|
import os
|
|
|
|
import uuid
|
2022-08-25 10:57:55 +00:00
|
|
|
from dataclasses import dataclass
|
2022-12-05 22:31:45 +00:00
|
|
|
from typing import Optional
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.common import DEFAULT_WALLET_CONFIG, DEFAULT_WALLET_PASS
|
|
|
|
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
|
2023-08-02 11:54:03 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
2023-02-19 23:58:07 +00:00
|
|
|
from frostfs_testlib.utils import wallet_utils
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import generate_file
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
OBJECT_COUNT = 5
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Wallet:
|
|
|
|
wallet_path: Optional[str] = None
|
|
|
|
config_path: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Wallets:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallets: dict[EACLRole, list[Wallet]]
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
def get_wallet(self, role: EACLRole = EACLRole.USER) -> Wallet:
|
|
|
|
return self.wallets[role][0]
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
def get_wallets_list(self, role: EACLRole = EACLRole.USER) -> list[Wallet]:
|
2022-08-25 10:57:55 +00:00
|
|
|
return self.wallets[role]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
2023-05-15 09:59:33 +00:00
|
|
|
def wallets(default_wallet: str, temp_directory: str, cluster: Cluster) -> Wallets:
|
2023-11-29 13:34:59 +00:00
|
|
|
other_wallets_paths = [os.path.join(temp_directory, f"{str(uuid.uuid4())}.json") for _ in range(2)]
|
2022-10-27 05:43:20 +00:00
|
|
|
for other_wallet_path in other_wallets_paths:
|
2023-05-15 09:59:33 +00:00
|
|
|
wallet_utils.init_wallet(other_wallet_path, DEFAULT_WALLET_PASS)
|
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
|
|
|
|
|
|
|
ir_wallet_path = ir_node.get_wallet_path()
|
|
|
|
ir_wallet_config = ir_node.get_wallet_config_path()
|
|
|
|
|
|
|
|
storage_wallet_path = storage_node.get_wallet_path()
|
|
|
|
storage_wallet_config = storage_node.get_wallet_config_path()
|
|
|
|
|
2023-09-21 16:49:31 +00:00
|
|
|
wallets_collection = Wallets(
|
2022-09-05 12:12:56 +00:00
|
|
|
wallets={
|
2023-05-15 09:59:33 +00:00
|
|
|
EACLRole.USER: [Wallet(wallet_path=default_wallet, config_path=DEFAULT_WALLET_CONFIG)],
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.OTHERS: [
|
2023-05-15 09:59:33 +00:00
|
|
|
Wallet(wallet_path=other_wallet_path, config_path=DEFAULT_WALLET_CONFIG)
|
2022-10-27 05:43:20 +00:00
|
|
|
for other_wallet_path in other_wallets_paths
|
2022-09-05 12:12:56 +00:00
|
|
|
],
|
|
|
|
EACLRole.SYSTEM: [
|
2022-12-05 22:31:45 +00:00
|
|
|
Wallet(wallet_path=ir_wallet_path, config_path=ir_wallet_config),
|
|
|
|
Wallet(wallet_path=storage_wallet_path, config_path=storage_wallet_config),
|
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:
|
2023-11-29 13:34:59 +00:00
|
|
|
reporter.attach(wallet.wallet_path, os.path.basename(wallet.wallet_path))
|
2023-09-21 16:49:31 +00:00
|
|
|
|
|
|
|
return wallets_collection
|
|
|
|
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2023-09-07 07:18:18 +00:00
|
|
|
@pytest.fixture()
|
2023-09-08 10:35:34 +00:00
|
|
|
def file_path(object_size: ObjectSize) -> str:
|
|
|
|
yield generate_file(object_size.value)
|
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(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
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(
|
2022-09-05 12:12:56 +00:00
|
|
|
user_wallet.wallet_path,
|
|
|
|
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)
|