2024-11-16 11:33:56 +00:00
|
|
|
import json
|
|
|
|
import time
|
|
|
|
|
|
|
|
from frostfs_testlib import reporter
|
|
|
|
from frostfs_testlib.cli.frostfs_cli.cli import FrostfsCli
|
|
|
|
from frostfs_testlib.resources.common import MORPH_BLOCK_TIME
|
|
|
|
from frostfs_testlib.shell.interfaces import Shell
|
|
|
|
from frostfs_testlib.steps.cli.container import create_container, search_nodes_with_container
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
|
|
|
from frostfs_testlib.storage.dataclasses import ape
|
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
2024-11-20 14:11:04 +00:00
|
|
|
from frostfs_testlib.testing.parallel import parallel
|
2024-11-16 11:33:56 +00:00
|
|
|
from frostfs_testlib.utils import datetime_utils
|
|
|
|
|
2024-11-20 14:11:04 +00:00
|
|
|
from .container_request import ContainerRequest, MultipleContainersRequest
|
2024-11-16 11:33:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_container_with_ape(
|
2024-11-20 14:11:04 +00:00
|
|
|
container_request: ContainerRequest,
|
|
|
|
frostfs_cli: FrostfsCli,
|
|
|
|
wallet: WalletInfo,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
endpoint: str,
|
|
|
|
) -> str:
|
2024-11-16 11:33:56 +00:00
|
|
|
with reporter.step("Create container"):
|
2024-11-20 14:11:04 +00:00
|
|
|
cid = _create_container_by_spec(container_request, wallet, shell, cluster, endpoint)
|
2024-11-16 11:33:56 +00:00
|
|
|
|
2024-11-20 14:11:04 +00:00
|
|
|
if container_request.ape_rules:
|
|
|
|
with reporter.step("Apply APE rules for container"):
|
|
|
|
_apply_ape_rules(cid, frostfs_cli, endpoint, container_request.ape_rules)
|
2024-11-16 11:33:56 +00:00
|
|
|
|
2024-11-20 14:11:04 +00:00
|
|
|
with reporter.step("Wait for one block"):
|
|
|
|
time.sleep(datetime_utils.parse_time(MORPH_BLOCK_TIME))
|
2024-11-16 11:33:56 +00:00
|
|
|
|
|
|
|
with reporter.step("Search nodes holding the container"):
|
|
|
|
container_holder_nodes = search_nodes_with_container(wallet, cid, shell, cluster.default_rpc_endpoint, cluster)
|
|
|
|
report_data = {node.id: node.host_ip for node in container_holder_nodes}
|
|
|
|
|
|
|
|
reporter.attach(json.dumps(report_data, indent=2), "container_nodes.json")
|
|
|
|
|
|
|
|
return cid
|
|
|
|
|
|
|
|
|
2024-11-20 14:11:04 +00:00
|
|
|
@reporter.step("Create multiple containers with APE")
|
|
|
|
def create_containers_with_ape(
|
|
|
|
frostfs_cli: FrostfsCli,
|
|
|
|
wallet: WalletInfo,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
endpoint: str,
|
|
|
|
multiple_containers_request: MultipleContainersRequest,
|
|
|
|
) -> list[str]:
|
|
|
|
cids_futures = parallel(create_container_with_ape, multiple_containers_request, frostfs_cli, wallet, shell, cluster, endpoint)
|
|
|
|
return [future.result() for future in cids_futures]
|
|
|
|
|
|
|
|
|
2024-11-16 11:33:56 +00:00
|
|
|
@reporter.step("Create container by spec {container_request}")
|
|
|
|
def _create_container_by_spec(
|
2024-11-20 14:11:04 +00:00
|
|
|
container_request: ContainerRequest,
|
|
|
|
wallet: WalletInfo,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
endpoint: str,
|
2024-11-16 11:33:56 +00:00
|
|
|
) -> str:
|
2024-12-17 10:57:06 +00:00
|
|
|
return create_container(
|
|
|
|
wallet,
|
|
|
|
shell,
|
|
|
|
endpoint,
|
|
|
|
container_request.parsed_rule(cluster),
|
|
|
|
wait_for_creation=False,
|
|
|
|
nns_zone=container_request.ns_zone,
|
|
|
|
nns_name=container_request.ns_name,
|
|
|
|
)
|
2024-11-16 11:33:56 +00:00
|
|
|
|
|
|
|
|
2024-11-20 14:11:04 +00:00
|
|
|
def _apply_ape_rules(cid: str, frostfs_cli: FrostfsCli, endpoint: str, ape_rules: list[ape.Rule]):
|
2024-11-16 11:33:56 +00:00
|
|
|
for ape_rule in ape_rules:
|
|
|
|
rule_str = ape_rule.as_string()
|
|
|
|
with reporter.step(f"Apply APE rule '{rule_str}' for container {cid}"):
|
|
|
|
frostfs_cli.ape_manager.add(
|
|
|
|
endpoint,
|
|
|
|
ape_rule.chain_id,
|
|
|
|
target_name=cid,
|
|
|
|
target_type="container",
|
|
|
|
rule=rule_str,
|
|
|
|
)
|