From 647f89459d3f3996161bcf7a784e82bbfc551263 Mon Sep 17 00:00:00 2001 From: Vladimir Avdeev Date: Mon, 5 Dec 2022 23:14:17 +0300 Subject: [PATCH] Add neofs-cli control shards command Signed-off-by: Vladimir Avdeev --- src/neofs_testlib/cli/neofs_cli/cli.py | 3 + src/neofs_testlib/cli/neofs_cli/shards.py | 138 ++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/neofs_testlib/cli/neofs_cli/shards.py diff --git a/src/neofs_testlib/cli/neofs_cli/cli.py b/src/neofs_testlib/cli/neofs_cli/cli.py index d80c3e8..cfe8e5d 100644 --- a/src/neofs_testlib/cli/neofs_cli/cli.py +++ b/src/neofs_testlib/cli/neofs_cli/cli.py @@ -6,6 +6,7 @@ from neofs_testlib.cli.neofs_cli.container import NeofsCliContainer from neofs_testlib.cli.neofs_cli.netmap import NeofsCliNetmap from neofs_testlib.cli.neofs_cli.object import NeofsCliObject from neofs_testlib.cli.neofs_cli.session import NeofsCliSession +from neofs_testlib.cli.neofs_cli.shards import NeofsCliShards from neofs_testlib.cli.neofs_cli.storagegroup import NeofsCliStorageGroup from neofs_testlib.cli.neofs_cli.util import NeofsCliUtil from neofs_testlib.cli.neofs_cli.version import NeofsCliVersion @@ -19,6 +20,7 @@ class NeofsCli: netmap: Optional[NeofsCliNetmap] = None object: Optional[NeofsCliObject] = None session: Optional[NeofsCliSession] = None + shards: Optional[NeofsCliShards] = None storagegroup: Optional[NeofsCliStorageGroup] = None util: Optional[NeofsCliUtil] = None version: Optional[NeofsCliVersion] = None @@ -30,6 +32,7 @@ class NeofsCli: self.netmap = NeofsCliNetmap(shell, neofs_cli_exec_path, config=config_file) self.object = NeofsCliObject(shell, neofs_cli_exec_path, config=config_file) self.session = NeofsCliSession(shell, neofs_cli_exec_path, config=config_file) + self.shards = NeofsCliShards(shell, neofs_cli_exec_path, config=config_file) self.storagegroup = NeofsCliStorageGroup(shell, neofs_cli_exec_path, config=config_file) self.util = NeofsCliUtil(shell, neofs_cli_exec_path, config=config_file) self.version = NeofsCliVersion(shell, neofs_cli_exec_path, config=config_file) diff --git a/src/neofs_testlib/cli/neofs_cli/shards.py b/src/neofs_testlib/cli/neofs_cli/shards.py new file mode 100644 index 0000000..dd57827 --- /dev/null +++ b/src/neofs_testlib/cli/neofs_cli/shards.py @@ -0,0 +1,138 @@ +from typing import Optional + +from neofs_testlib.cli.cli_command import CliCommand +from neofs_testlib.shell import CommandResult + + +class NeofsCliShards(CliCommand): + def flush_cache( + self, + endpoint: str, + wallet: str, + wallet_password: str, + id: Optional[list[str]], + address: Optional[str] = None, + all: bool = False, + ) -> CommandResult: + """ + Flush objects from the write-cache to the main storage. + + Args: + address: Address of wallet account. + id: List of shard IDs in base58 encoding. + all: Process all shards. + endpoint: Remote node address (as 'multiaddr' or ':'). + wallet: WIF (NEP-2) string or path to the wallet or binary key. + wallet_password: Wallet password. + + Returns: + Command's result. + """ + return self._execute_with_password( + f"control shards flush-cache", + wallet_password, + **{param: value for param, value in locals().items() if param not in ["self"]}, + ) + + def set_mode( + self, + endpoint: str, + wallet: str, + wallet_password: str, + mode: str, + id: Optional[list[str]], + address: Optional[str] = None, + all: bool = False, + clear_errors: bool = False, + ) -> CommandResult: + """ + Set work mode of the shard. + + Args: + address: Address of wallet account. + id: List of shard IDs in base58 encoding. + mode: New shard mode ('degraded-read-only', 'read-only', 'read-write'). + all: Process all shards. + clear_errors: Set shard error count to 0. + endpoint: Remote node address (as 'multiaddr' or ':'). + wallet: WIF (NEP-2) string or path to the wallet or binary key. + wallet_password: Wallet password. + + Returns: + Command's result. + """ + return self._execute_with_password( + f"control shards set-mode", + wallet_password, + **{ + param: value + for param, value in locals().items() + if param not in ["self", "wallet_password"] + }, + ) + + def dump( + self, + endpoint: str, + wallet: str, + wallet_password: str, + id: str, + path: str, + address: Optional[str] = None, + no_errors: bool = False, + ) -> CommandResult: + """ + Dump objects from shard to a file. + + Args: + address: Address of wallet account. + no_errors: Skip invalid/unreadable objects. + id: Shard ID in base58 encoding. + path: File to write objects to. + endpoint: Remote node address (as 'multiaddr' or ':'). + wallet: WIF (NEP-2) string or path to the wallet or binary key. + wallet_password: Wallet password. + + Returns: + Command's result. + """ + return self._execute_with_password( + f"control shards dump", + wallet_password, + **{ + param: value + for param, value in locals().items() + if param not in ["self", "wallet_password"] + }, + ) + + def list( + self, + endpoint: str, + wallet: str, + wallet_password: str, + address: Optional[str] = None, + json_mode: bool = False, + ) -> CommandResult: + """ + List shards of the storage node. + + Args: + address: Address of wallet account. + json_mode: Print shard info as a JSON array. + endpoint: Remote node address (as 'multiaddr' or ':'). + wallet: WIF (NEP-2) string or path to the wallet or binary key. + wallet_password: Wallet password. + + Returns: + Command's result. + """ + return self._execute_with_password( + f"control shards list", + wallet_password, + **{ + param: value + for param, value in locals().items() + if param not in ["self", "wallet_password"] + }, + )