Add neofs-cli control shards command

Signed-off-by: Vladimir Avdeev <v.avdeev@yadro.com>
This commit is contained in:
Vladimir Avdeev 2022-12-05 23:14:17 +03:00 committed by Vladimir Avdeev
parent 7c127d9d74
commit 647f89459d
2 changed files with 141 additions and 0 deletions

View file

@ -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)

View file

@ -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 '<host>:<port>').
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 '<host>:<port>').
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 '<host>:<port>').
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 '<host>:<port>').
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"]
},
)