2022-12-06 16:23:21 +00:00
|
|
|
import json
|
2022-12-08 20:34:29 +00:00
|
|
|
import pathlib
|
2022-12-06 16:23:21 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.cli import FrostfsCli
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.cli import CLI_DEFAULT_TIMEOUT
|
|
|
|
from frostfs_testlib.resources.common import DEFAULT_WALLET_CONFIG
|
|
|
|
from frostfs_testlib.storage.cluster import Cluster, StorageNode
|
2023-12-21 07:44:35 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.shard import Shard
|
2022-12-08 20:34:29 +00:00
|
|
|
|
2022-12-06 16:23:21 +00:00
|
|
|
|
|
|
|
@pytest.mark.shard
|
|
|
|
class TestControlShard:
|
|
|
|
@staticmethod
|
2022-12-08 20:34:29 +00:00
|
|
|
def get_shards_from_config(node: StorageNode) -> list[Shard]:
|
2023-10-02 06:59:01 +00:00
|
|
|
config_file = node.get_shard_config_path()
|
2022-12-08 20:34:29 +00:00
|
|
|
file_type = pathlib.Path(config_file).suffix
|
|
|
|
|
|
|
|
parser_method = {
|
2023-12-21 07:44:35 +00:00
|
|
|
".env": node.get_shards_from_env,
|
|
|
|
".yaml": node.get_shards,
|
|
|
|
".yml": node.get_shards,
|
2022-12-08 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
2023-12-21 07:44:35 +00:00
|
|
|
shards = parser_method[file_type]()
|
2022-12-08 20:34:29 +00:00
|
|
|
return shards
|
2022-12-06 16:23:21 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-12-08 20:34:29 +00:00
|
|
|
def get_shards_from_cli(node: StorageNode) -> list[Shard]:
|
|
|
|
wallet_path = node.get_remote_wallet_path()
|
|
|
|
wallet_password = node.get_wallet_password()
|
|
|
|
control_endpoint = node.get_control_endpoint()
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli_config = node.host.get_cli_config("frostfs-cli")
|
2022-12-06 16:23:21 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
cli = FrostfsCli(node.host.get_shell(), cli_config.exec_path, DEFAULT_WALLET_CONFIG)
|
2022-12-06 16:23:21 +00:00
|
|
|
result = cli.shards.list(
|
|
|
|
endpoint=control_endpoint,
|
|
|
|
wallet=wallet_path,
|
|
|
|
wallet_password=wallet_password,
|
|
|
|
json_mode=True,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout=CLI_DEFAULT_TIMEOUT,
|
2022-12-06 16:23:21 +00:00
|
|
|
)
|
2022-12-08 20:34:29 +00:00
|
|
|
return [Shard.from_object(shard) for shard in json.loads(result.stdout.split(">", 1)[1])]
|
2022-12-06 16:23:21 +00:00
|
|
|
|
|
|
|
@allure.title("All shards are available")
|
2022-12-08 20:34:29 +00:00
|
|
|
def test_control_shard(self, cluster: Cluster):
|
|
|
|
for storage_node in cluster.storage_nodes:
|
|
|
|
shards_from_config = self.get_shards_from_config(storage_node)
|
|
|
|
shards_from_cli = self.get_shards_from_cli(storage_node)
|
2023-12-21 07:44:35 +00:00
|
|
|
|
2022-12-06 16:23:21 +00:00
|
|
|
assert set(shards_from_config) == set(shards_from_cli)
|