From 328e43fe674d16e90c162d1bd6cfb2fd463de012 Mon Sep 17 00:00:00 2001 From: Dmitriy Zayakin Date: Mon, 22 Jan 2024 14:14:10 +0300 Subject: [PATCH] [#162] Refactor frostfs-cli functional Signed-off-by: Dmitriy Zayakin --- src/frostfs_testlib/cli/frostfs_cli/container.py | 8 +------- src/frostfs_testlib/cli/frostfs_cli/object.py | 6 ++---- src/frostfs_testlib/defaults.py | 2 +- src/frostfs_testlib/resources/cli.py | 2 +- src/frostfs_testlib/steps/cli/container.py | 7 +++---- src/frostfs_testlib/steps/cli/object.py | 13 +++++++------ src/frostfs_testlib/storage/constants.py | 1 + .../storage/dataclasses/node_base.py | 15 +++++++++++++-- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/frostfs_testlib/cli/frostfs_cli/container.py b/src/frostfs_testlib/cli/frostfs_cli/container.py index 5ea8ba8..374c880 100644 --- a/src/frostfs_testlib/cli/frostfs_cli/container.py +++ b/src/frostfs_testlib/cli/frostfs_cli/container.py @@ -65,7 +65,6 @@ class FrostfsCliContainer(CliCommand): ttl: Optional[int] = None, xhdr: Optional[dict] = None, force: bool = False, - timeout: Optional[str] = None, ) -> CommandResult: """ Delete an existing container. @@ -81,7 +80,6 @@ class FrostfsCliContainer(CliCommand): ttl: TTL value in request meta header (default 2). wallet: WIF (NEP-2) string or path to the wallet or binary key. xhdr: Dict with request X-Headers. - timeout: Timeout for the operation (default 15s). Returns: Command's result. @@ -298,9 +296,5 @@ class FrostfsCliContainer(CliCommand): return self._execute( f"container nodes {from_str}", - **{ - param: value - for param, value in locals().items() - if param not in ["self", "from_file", "from_str"] - }, + **{param: value for param, value in locals().items() if param not in ["self", "from_file", "from_str"]}, ) diff --git a/src/frostfs_testlib/cli/frostfs_cli/object.py b/src/frostfs_testlib/cli/frostfs_cli/object.py index 476af68..0e4654b 100644 --- a/src/frostfs_testlib/cli/frostfs_cli/object.py +++ b/src/frostfs_testlib/cli/frostfs_cli/object.py @@ -124,9 +124,7 @@ class FrostfsCliObject(CliCommand): """ return self._execute( "object hash", - **{ - param: value for param, value in locals().items() if param not in ["self", "params"] - }, + **{param: value for param, value in locals().items() if param not in ["self", "params"]}, ) def head( @@ -355,8 +353,8 @@ class FrostfsCliObject(CliCommand): def nodes( self, rpc_endpoint: str, - wallet: str, cid: str, + wallet: Optional[str] = None, address: Optional[str] = None, bearer: Optional[str] = None, generate_key: Optional = None, diff --git a/src/frostfs_testlib/defaults.py b/src/frostfs_testlib/defaults.py index 687fbd6..22097be 100644 --- a/src/frostfs_testlib/defaults.py +++ b/src/frostfs_testlib/defaults.py @@ -1,5 +1,5 @@ class Options: - DEFAULT_SHELL_TIMEOUT = 90 + DEFAULT_SHELL_TIMEOUT = 120 @staticmethod def get_default_shell_timeout(): diff --git a/src/frostfs_testlib/resources/cli.py b/src/frostfs_testlib/resources/cli.py index 5f7d468..06a9832 100644 --- a/src/frostfs_testlib/resources/cli.py +++ b/src/frostfs_testlib/resources/cli.py @@ -9,4 +9,4 @@ FROSTFS_ADM_EXEC = os.getenv("FROSTFS_ADM_EXEC", "frostfs-adm") # Config for frostfs-adm utility. Optional if tests are running against devenv FROSTFS_ADM_CONFIG_PATH = os.getenv("FROSTFS_ADM_CONFIG_PATH") -CLI_DEFAULT_TIMEOUT = os.getenv("CLI_DEFAULT_TIMEOUT", None) +CLI_DEFAULT_TIMEOUT = os.getenv("CLI_DEFAULT_TIMEOUT", "100s") diff --git a/src/frostfs_testlib/steps/cli/container.py b/src/frostfs_testlib/steps/cli/container.py index b3afd88..3cc3f35 100644 --- a/src/frostfs_testlib/steps/cli/container.py +++ b/src/frostfs_testlib/steps/cli/container.py @@ -1,11 +1,12 @@ import json import logging import re -import requests from dataclasses import dataclass from time import sleep from typing import Optional, Union +import requests + from frostfs_testlib import reporter from frostfs_testlib.cli import FrostfsCli from frostfs_testlib.resources.cli import CLI_DEFAULT_TIMEOUT, FROSTFS_CLI_EXEC @@ -291,18 +292,17 @@ def delete_container( force: bool = False, session_token: Optional[str] = None, await_mode: bool = False, - timeout: Optional[str] = CLI_DEFAULT_TIMEOUT, ) -> None: """ A wrapper for `frostfs-cli container delete` call. Args: + await_mode: Block execution until container is removed. wallet (str): path to a wallet on whose behalf we delete the container cid (str): ID of the container to delete shell: executor for cli command endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key force (bool): do not check whether container contains locks and remove immediately session_token: a path to session token file - timeout: Timeout for the operation. This function doesn't return anything. """ @@ -314,7 +314,6 @@ def delete_container( force=force, session=session_token, await_mode=await_mode, - timeout=timeout, ) diff --git a/src/frostfs_testlib/steps/cli/object.py b/src/frostfs_testlib/steps/cli/object.py index 803524a..610b76a 100644 --- a/src/frostfs_testlib/steps/cli/object.py +++ b/src/frostfs_testlib/steps/cli/object.py @@ -732,23 +732,24 @@ def neo_go_query_height(shell: Shell, endpoint: str) -> dict: @reporter.step("Search object nodes") def get_object_nodes( cluster: Cluster, - wallet: str, cid: str, oid: str, - shell: Shell, - endpoint: str, + alive_node: ClusterNode, bearer: str = "", xhdr: Optional[dict] = None, is_direct: bool = False, verify_presence_all: bool = False, - wallet_config: Optional[str] = None, timeout: Optional[str] = CLI_DEFAULT_TIMEOUT, ) -> list[ClusterNode]: - cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or DEFAULT_WALLET_CONFIG) + shell = alive_node.host.get_shell() + endpoint = alive_node.storage_node.get_rpc_endpoint() + wallet = alive_node.storage_node.get_remote_wallet_path() + wallet_config = alive_node.storage_node.get_remote_wallet_config_path() + + cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config) result_object_nodes = cli.object.nodes( rpc_endpoint=endpoint, - wallet=wallet, cid=cid, oid=oid, bearer=bearer, diff --git a/src/frostfs_testlib/storage/constants.py b/src/frostfs_testlib/storage/constants.py index 710262a..5b9d694 100644 --- a/src/frostfs_testlib/storage/constants.py +++ b/src/frostfs_testlib/storage/constants.py @@ -9,6 +9,7 @@ class ConfigAttributes: LOGGER_CONFIG_PATH = "logger_config_path" LOCAL_WALLET_PATH = "local_wallet_path" LOCAL_WALLET_CONFIG = "local_wallet_config_path" + REMOTE_WALLET_CONFIG = "remote_wallet_config_path" ENDPOINT_DATA_0 = "endpoint_data0" ENDPOINT_DATA_1 = "endpoint_data1" ENDPOINT_INTERNAL = "endpoint_internal0" diff --git a/src/frostfs_testlib/storage/dataclasses/node_base.py b/src/frostfs_testlib/storage/dataclasses/node_base.py index bf36665..72b12a9 100644 --- a/src/frostfs_testlib/storage/dataclasses/node_base.py +++ b/src/frostfs_testlib/storage/dataclasses/node_base.py @@ -114,6 +114,14 @@ class NodeBase(HumanReadableABC): ConfigAttributes.CONFIG_PATH, ) + def get_remote_wallet_config_path(self) -> str: + """ + Returns node config file path located on remote host + """ + return self._get_attribute( + ConfigAttributes.REMOTE_WALLET_CONFIG, + ) + def get_wallet_config_path(self) -> str: return self._get_attribute( ConfigAttributes.LOCAL_WALLET_CONFIG, @@ -125,8 +133,11 @@ class NodeBase(HumanReadableABC): Returns config path for logger located on remote host """ config_attributes = self.host.get_service_config(self.name) - return self._get_attribute( - ConfigAttributes.LOGGER_CONFIG_PATH) if ConfigAttributes.LOGGER_CONFIG_PATH in config_attributes.attributes else None + return ( + self._get_attribute(ConfigAttributes.LOGGER_CONFIG_PATH) + if ConfigAttributes.LOGGER_CONFIG_PATH in config_attributes.attributes + else None + ) @property def config_dir(self) -> str: