2022-03-15 11:58:59 +00:00
|
|
|
import json
|
2022-09-20 15:03:52 +00:00
|
|
|
import logging
|
2022-10-18 07:11:57 +00:00
|
|
|
import os
|
2022-06-09 13:08:11 +00:00
|
|
|
import re
|
2022-03-15 11:58:59 +00:00
|
|
|
import uuid
|
2022-11-30 08:26:38 +00:00
|
|
|
from typing import Any, Optional
|
2022-03-15 11:58:59 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-03-15 11:58:59 +00:00
|
|
|
import json_transformers
|
2022-12-05 22:31:45 +00:00
|
|
|
from cluster import Cluster
|
2023-01-09 12:46:03 +00:00
|
|
|
from common import ASSETS_DIR, FROSTFS_CLI_EXEC, WALLET_CONFIG
|
|
|
|
from frostfs_testlib.cli import FrostfsCli
|
|
|
|
from frostfs_testlib.shell import Shell
|
2022-09-20 15:03:52 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
@allure.step("Get object from random node")
|
|
|
|
def get_object_from_random_node(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
write_object: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
) -> str:
|
|
|
|
"""
|
2023-01-09 12:46:03 +00:00
|
|
|
GET from FrostFS random storage node
|
2022-12-05 22:31:45 +00:00
|
|
|
|
|
|
|
Args:
|
|
|
|
wallet: wallet on whose behalf GET is done
|
|
|
|
cid: ID of Container where we get the Object from
|
|
|
|
oid: Object ID
|
|
|
|
shell: executor for cli command
|
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
|
|
|
write_object (optional, str): path to downloaded file, appends to `--file` key
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
|
|
|
no_progress(optional, bool): do not show progress bar
|
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
|
|
|
Returns:
|
|
|
|
(str): path to downloaded file
|
|
|
|
"""
|
|
|
|
endpoint = cluster.get_random_storage_rpc_endpoint()
|
|
|
|
return get_object(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
shell,
|
|
|
|
endpoint,
|
|
|
|
bearer,
|
|
|
|
write_object,
|
|
|
|
xhdr,
|
|
|
|
wallet_config,
|
|
|
|
no_progress,
|
|
|
|
session,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@allure.step("Get object from {endpoint}")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str = None,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: Optional[str] = None,
|
2022-12-05 22:31:45 +00:00
|
|
|
write_object: Optional[str] = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
) -> str:
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2023-01-09 12:46:03 +00:00
|
|
|
GET from FrostFS.
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf GET is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): Object ID
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-12-05 22:31:45 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
|
|
|
write_object: path to downloaded file, appends to `--file` key
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-19 02:22:20 +00:00
|
|
|
no_progress(optional, bool): do not show progress bar
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): path to downloaded file
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
if not write_object:
|
|
|
|
write_object = str(uuid.uuid4())
|
2022-10-18 07:11:57 +00:00
|
|
|
file_path = os.path.join(ASSETS_DIR, write_object)
|
2022-03-15 11:58:59 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-09-05 09:35:46 +00:00
|
|
|
cli.object.get(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
file=file_path,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-09-05 09:35:46 +00:00
|
|
|
no_progress=no_progress,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
return file_path
|
|
|
|
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
@allure.step("Get Range Hash from {endpoint}")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_range_hash(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
range_cut: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: Optional[str] = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2022-11-22 14:56:58 +00:00
|
|
|
session: Optional[str] = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
GETRANGEHASH of given Object.
|
|
|
|
|
|
|
|
Args:
|
2022-11-22 14:56:58 +00:00
|
|
|
wallet: wallet on whose behalf GETRANGEHASH is done
|
|
|
|
cid: ID of Container where we get the Object from
|
|
|
|
oid: Object ID
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-11-22 14:56:58 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
|
|
|
range_cut: Range to take hash from in the form offset1:length1,...,
|
2022-03-15 11:58:59 +00:00
|
|
|
value to pass to the `--range` parameter
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-11-22 14:56:58 +00:00
|
|
|
wallet_config: path to the wallet config
|
|
|
|
xhdr: Request X-Headers in form of Key=Values
|
|
|
|
session: Filepath to a JSON- or binary-encoded token of the object RANGEHASH session.
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
None
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 09:30:05 +00:00
|
|
|
result = cli.object.hash(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
range=range_cut,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-09-05 09:35:46 +00:00
|
|
|
xhdr=xhdr,
|
2022-11-22 14:56:58 +00:00
|
|
|
session=session,
|
2022-09-05 09:35:46 +00:00
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-06-06 13:47:13 +00:00
|
|
|
# cutting off output about range offset and length
|
2022-11-01 09:30:05 +00:00
|
|
|
return result.stdout.split(":")[1].strip()
|
2022-09-05 09:35:46 +00:00
|
|
|
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
@allure.step("Put object to random node")
|
|
|
|
def put_object_to_random_node(
|
|
|
|
wallet: str,
|
|
|
|
path: str,
|
|
|
|
cid: str,
|
|
|
|
shell: Shell,
|
|
|
|
cluster: Cluster,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
expire_at: Optional[int] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
PUT of given file to a random storage node.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
wallet: wallet on whose behalf PUT is done
|
|
|
|
path: path to file to be PUT
|
|
|
|
cid: ID of Container where we get the Object from
|
|
|
|
shell: executor for cli command
|
|
|
|
cluster: cluster under test
|
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
|
|
|
attributes: User attributes in form of Key1=Value1,Key2=Value2
|
|
|
|
cluster: cluster under test
|
|
|
|
wallet_config: path to the wallet config
|
|
|
|
no_progress: do not show progress bar
|
|
|
|
expire_at: Last epoch in the life of the object
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
session: path to a JSON-encoded container session token
|
|
|
|
Returns:
|
|
|
|
ID of uploaded Object
|
|
|
|
"""
|
|
|
|
|
|
|
|
endpoint = cluster.get_random_storage_rpc_endpoint()
|
|
|
|
return put_object(
|
|
|
|
wallet,
|
|
|
|
path,
|
|
|
|
cid,
|
|
|
|
shell,
|
|
|
|
endpoint,
|
|
|
|
bearer,
|
|
|
|
attributes,
|
|
|
|
xhdr,
|
|
|
|
wallet_config,
|
|
|
|
expire_at,
|
|
|
|
no_progress,
|
|
|
|
session,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@allure.step("Put object at {endpoint} in container {cid}")
|
2022-09-05 09:35:46 +00:00
|
|
|
def put_object(
|
|
|
|
wallet: str,
|
|
|
|
path: str,
|
|
|
|
cid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
bearer: Optional[str] = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
expire_at: Optional[int] = None,
|
|
|
|
no_progress: bool = True,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
PUT of given file.
|
|
|
|
|
|
|
|
Args:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet: wallet on whose behalf PUT is done
|
|
|
|
path: path to file to be PUT
|
|
|
|
cid: ID of Container where we get the Object from
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-12-05 22:31:45 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
|
|
|
attributes: User attributes in form of Key1=Value1,Key2=Value2
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet_config: path to the wallet config
|
|
|
|
no_progress: do not show progress bar
|
|
|
|
expire_at: Last epoch in the life of the object
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
session: path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): ID of uploaded Object
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 09:30:05 +00:00
|
|
|
result = cli.object.put(
|
2022-09-05 09:35:46 +00:00
|
|
|
rpc_endpoint=endpoint,
|
|
|
|
wallet=wallet,
|
|
|
|
file=path,
|
|
|
|
cid=cid,
|
|
|
|
attributes=attributes,
|
|
|
|
bearer=bearer,
|
|
|
|
expire_at=expire_at,
|
|
|
|
no_progress=no_progress,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
# splitting CLI output to lines and taking the penultimate line
|
2022-11-01 09:30:05 +00:00
|
|
|
id_str = result.stdout.strip().split("\n")[-2]
|
2022-09-05 09:35:46 +00:00
|
|
|
oid = id_str.split(":")[1]
|
2022-03-15 11:58:59 +00:00
|
|
|
return oid.strip()
|
|
|
|
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
@allure.step("Delete object {cid}/{oid} from {endpoint}")
|
2022-09-05 09:35:46 +00:00
|
|
|
def delete_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
bearer: str = "",
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
DELETE an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet: wallet on whose behalf DELETE is done
|
|
|
|
cid: ID of Container where we get the Object from
|
|
|
|
oid: ID of Object we are going to delete
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-12-05 22:31:45 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet_config: path to the wallet config
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
session: path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
(str): Tombstone ID
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-12-05 22:31:45 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 09:30:05 +00:00
|
|
|
result = cli.object.delete(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
|
|
|
|
2022-11-01 09:30:05 +00:00
|
|
|
id_str = result.stdout.split("\n")[1]
|
2022-09-05 09:35:46 +00:00
|
|
|
tombstone = id_str.split(":")[1]
|
2022-03-15 11:58:59 +00:00
|
|
|
return tombstone.strip()
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Range")
|
2022-09-05 09:35:46 +00:00
|
|
|
def get_range(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
range_cut: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str = None,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
bearer: str = "",
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
GETRANGE an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet: wallet on whose behalf GETRANGE is done
|
|
|
|
cid: ID of Container where we get the Object from
|
|
|
|
oid: ID of Object we are going to request
|
|
|
|
range_cut: range to take data from in the form offset:length
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-12-05 22:31:45 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
|
|
|
wallet_config: path to the wallet config
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
session: path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
2022-08-03 15:50:01 +00:00
|
|
|
(str, bytes) - path to the file with range content and content of this file as bytes
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-10-18 07:11:57 +00:00
|
|
|
range_file_path = os.path.join(ASSETS_DIR, str(uuid.uuid4()))
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-09-05 09:35:46 +00:00
|
|
|
cli.object.range(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
range=range_cut,
|
2022-10-18 07:11:57 +00:00
|
|
|
file=range_file_path,
|
2022-09-05 09:35:46 +00:00
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
|
|
|
|
2022-10-18 07:11:57 +00:00
|
|
|
with open(range_file_path, "rb") as file:
|
|
|
|
content = file.read()
|
|
|
|
return range_file_path, content
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
|
2022-11-25 12:44:47 +00:00
|
|
|
@allure.step("Lock Object")
|
|
|
|
def lock_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-11-25 12:44:47 +00:00
|
|
|
lifetime: Optional[int] = None,
|
|
|
|
expire_at: Optional[int] = None,
|
|
|
|
address: Optional[str] = None,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
ttl: Optional[int] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> str:
|
|
|
|
"""
|
|
|
|
Lock object in container.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
address: Address of wallet account.
|
|
|
|
bearer: File with signed JSON or binary encoded bearer token.
|
|
|
|
cid: Container ID.
|
|
|
|
oid: Object ID.
|
|
|
|
lifetime: Lock lifetime.
|
|
|
|
expire_at: Lock expiration epoch.
|
2022-12-05 22:31:45 +00:00
|
|
|
shell: executor for cli command
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-11-25 12:44:47 +00:00
|
|
|
session: Path to a JSON-encoded container session token.
|
|
|
|
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.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Lock object ID
|
|
|
|
"""
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-25 12:44:47 +00:00
|
|
|
result = cli.object.lock(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-11-25 12:44:47 +00:00
|
|
|
lifetime=lifetime,
|
|
|
|
expire_at=expire_at,
|
|
|
|
address=address,
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
ttl=ttl,
|
|
|
|
)
|
|
|
|
|
|
|
|
# splitting CLI output to lines and taking the penultimate line
|
|
|
|
id_str = result.stdout.strip().split("\n")[0]
|
|
|
|
oid = id_str.split(":")[1]
|
|
|
|
return oid.strip()
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Search object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def search_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-05 09:35:46 +00:00
|
|
|
bearer: str = "",
|
|
|
|
filters: Optional[dict] = None,
|
|
|
|
expected_objects_list: Optional[list] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
session: Optional[str] = None,
|
2022-11-01 16:11:26 +00:00
|
|
|
phy: bool = False,
|
|
|
|
root: bool = False,
|
2022-09-05 09:35:46 +00:00
|
|
|
) -> list:
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-06-06 13:47:13 +00:00
|
|
|
SEARCH an Object.
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
Args:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet: wallet on whose behalf SEARCH is done
|
|
|
|
cid: ID of Container where we get the Object from
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
2022-12-05 22:31:45 +00:00
|
|
|
bearer: path to Bearer Token file, appends to `--bearer` key
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint: FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-12-05 22:31:45 +00:00
|
|
|
filters: key=value pairs to filter Objects
|
|
|
|
expected_objects_list: a list of ObjectIDs to compare found Objects with
|
|
|
|
wallet_config: path to the wallet config
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
session: path to a JSON-encoded container session token
|
2022-11-01 16:11:26 +00:00
|
|
|
phy: Search physically stored objects.
|
|
|
|
root: Search for user objects.
|
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
2022-12-05 22:31:45 +00:00
|
|
|
list of found ObjectIDs
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 09:30:05 +00:00
|
|
|
result = cli.object.search(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
2022-09-20 15:03:52 +00:00
|
|
|
filters=[f"{filter_key} EQ {filter_val}" for filter_key, filter_val in filters.items()]
|
2022-09-05 09:35:46 +00:00
|
|
|
if filters
|
|
|
|
else None,
|
|
|
|
session=session,
|
2022-11-01 16:11:26 +00:00
|
|
|
phy=phy,
|
|
|
|
root=root,
|
2022-09-05 09:35:46 +00:00
|
|
|
)
|
|
|
|
|
2022-11-01 09:30:05 +00:00
|
|
|
found_objects = re.findall(r"(\w{43,44})", result.stdout)
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
if expected_objects_list:
|
|
|
|
if sorted(found_objects) == sorted(expected_objects_list):
|
2022-09-05 09:35:46 +00:00
|
|
|
logger.info(
|
2022-09-23 11:09:41 +00:00
|
|
|
f"Found objects list '{found_objects}' "
|
|
|
|
f"is equal for expected list '{expected_objects_list}'"
|
2022-09-05 09:35:46 +00:00
|
|
|
)
|
2022-03-15 11:58:59 +00:00
|
|
|
else:
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.warning(
|
2022-09-23 11:09:41 +00:00
|
|
|
f"Found object list {found_objects} "
|
|
|
|
f"is not equal to expected list '{expected_objects_list}'"
|
2022-09-05 09:35:46 +00:00
|
|
|
)
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
return found_objects
|
|
|
|
|
|
|
|
|
2022-11-01 16:11:26 +00:00
|
|
|
@allure.step("Get netmap netinfo")
|
|
|
|
def get_netmap_netinfo(
|
|
|
|
wallet: str,
|
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-11-01 16:11:26 +00:00
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
address: Optional[str] = None,
|
|
|
|
ttl: Optional[int] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2022-11-30 08:26:38 +00:00
|
|
|
) -> dict[str, Any]:
|
2022-11-01 16:11:26 +00:00
|
|
|
"""
|
|
|
|
Get netmap netinfo output from node
|
|
|
|
|
|
|
|
Args:
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet (str): wallet on whose behalf request is done
|
2022-11-01 16:11:26 +00:00
|
|
|
shell: executor for cli command
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint (optional, str): FrostFS endpoint to send request to, appends to `--rpc-endpoint` key
|
2022-11-01 16:11:26 +00:00
|
|
|
address: Address of wallet account
|
|
|
|
ttl: TTL value in request meta header (default 2)
|
|
|
|
wallet: Path to the wallet or binary key
|
|
|
|
xhdr: Request X-Headers in form of Key=Value
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
(dict): dict of parsed command output
|
|
|
|
"""
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 16:11:26 +00:00
|
|
|
output = cli.netmap.netinfo(
|
|
|
|
wallet=wallet,
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-11-01 16:11:26 +00:00
|
|
|
address=address,
|
|
|
|
ttl=ttl,
|
|
|
|
xhdr=xhdr,
|
|
|
|
)
|
|
|
|
|
|
|
|
settings = dict()
|
|
|
|
|
|
|
|
patterns = [
|
|
|
|
(re.compile("(.*): (\d+)"), int),
|
|
|
|
(re.compile("(.*): (false|true)"), bool),
|
|
|
|
(re.compile("(.*): (\d+\.\d+)"), float),
|
|
|
|
]
|
|
|
|
for pattern, func in patterns:
|
|
|
|
for setting, value in re.findall(pattern, output.stdout):
|
|
|
|
settings[setting.lower().strip().replace(" ", "_")] = func(value)
|
|
|
|
|
|
|
|
return settings
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Head object")
|
2022-09-05 09:35:46 +00:00
|
|
|
def head_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
bearer: str = "",
|
2022-09-05 09:35:46 +00:00
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
json_output: bool = True,
|
|
|
|
is_raw: bool = False,
|
|
|
|
is_direct: bool = False,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
session: Optional[str] = None,
|
|
|
|
):
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-03-15 11:58:59 +00:00
|
|
|
HEAD an Object.
|
|
|
|
|
|
|
|
Args:
|
2022-06-06 13:47:13 +00:00
|
|
|
wallet (str): wallet on whose behalf HEAD is done
|
2022-03-15 11:58:59 +00:00
|
|
|
cid (str): ID of Container where we get the Object from
|
|
|
|
oid (str): ObjectID to HEAD
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: executor for cli command
|
|
|
|
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
2023-01-09 12:46:03 +00:00
|
|
|
endpoint(optional, str): FrostFS endpoint to send request to
|
2022-11-01 16:11:26 +00:00
|
|
|
json_output(optional, bool): return response in JSON format or not; this flag
|
2022-03-15 11:58:59 +00:00
|
|
|
turns into `--json` key
|
|
|
|
is_raw(optional, bool): send "raw" request or not; this flag
|
|
|
|
turns into `--raw` key
|
2022-04-07 18:48:03 +00:00
|
|
|
is_direct(optional, bool): send request directly to the node or not; this flag
|
|
|
|
turns into `--ttl 1` key
|
2022-06-13 20:33:09 +00:00
|
|
|
wallet_config(optional, str): path to the wallet config
|
2022-08-25 10:57:55 +00:00
|
|
|
xhdr (optional, dict): Request X-Headers in form of Key=Value
|
2022-09-05 09:35:46 +00:00
|
|
|
session (optional, dict): path to a JSON-encoded container session token
|
2022-03-15 11:58:59 +00:00
|
|
|
Returns:
|
|
|
|
depending on the `json_output` parameter value, the function returns
|
|
|
|
(dict): HEAD response in JSON format
|
|
|
|
or
|
|
|
|
(str): HEAD response as a plain text
|
2022-06-09 13:08:11 +00:00
|
|
|
"""
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
cli = FrostfsCli(shell, FROSTFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
2022-11-01 09:30:05 +00:00
|
|
|
result = cli.object.head(
|
2022-12-05 22:31:45 +00:00
|
|
|
rpc_endpoint=endpoint,
|
2022-09-05 09:35:46 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
2022-10-13 18:53:44 +00:00
|
|
|
bearer=bearer,
|
2022-09-05 09:35:46 +00:00
|
|
|
json_mode=json_output,
|
|
|
|
raw=is_raw,
|
|
|
|
ttl=1 if is_direct else None,
|
|
|
|
xhdr=xhdr,
|
|
|
|
session=session,
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
if not json_output:
|
2022-11-01 09:30:05 +00:00
|
|
|
return result
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
try:
|
2022-11-01 09:30:05 +00:00
|
|
|
decoded = json.loads(result.stdout)
|
2022-03-15 11:58:59 +00:00
|
|
|
except Exception as exc:
|
|
|
|
# If we failed to parse output as JSON, the cause might be
|
|
|
|
# the plain text string in the beginning of the output.
|
|
|
|
# Here we cut off first string and try to parse again.
|
|
|
|
logger.info(f"failed to parse output: {exc}")
|
|
|
|
logger.info("parsing output in another way")
|
2022-11-01 09:30:05 +00:00
|
|
|
fst_line_idx = result.stdout.find("\n")
|
|
|
|
decoded = json.loads(result.stdout[fst_line_idx:])
|
2022-03-15 11:58:59 +00:00
|
|
|
|
|
|
|
# If response is Complex Object header, it has `splitId` key
|
2022-09-05 09:35:46 +00:00
|
|
|
if "splitId" in decoded.keys():
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding split header")
|
|
|
|
return json_transformers.decode_split_header(decoded)
|
|
|
|
|
|
|
|
# If response is Last or Linking Object header,
|
|
|
|
# it has `header` dictionary and non-null `split` dictionary
|
2022-09-05 09:35:46 +00:00
|
|
|
if "split" in decoded["header"].keys():
|
|
|
|
if decoded["header"]["split"]:
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding linking object")
|
|
|
|
return json_transformers.decode_linking_object(decoded)
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
if decoded["header"]["objectType"] == "STORAGE_GROUP":
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding storage group")
|
|
|
|
return json_transformers.decode_storage_group(decoded)
|
|
|
|
|
2022-09-05 09:35:46 +00:00
|
|
|
if decoded["header"]["objectType"] == "TOMBSTONE":
|
2022-06-06 13:47:13 +00:00
|
|
|
logger.info("decoding tombstone")
|
|
|
|
return json_transformers.decode_tombstone(decoded)
|
|
|
|
|
2022-03-15 11:58:59 +00:00
|
|
|
logger.info("decoding simple header")
|
|
|
|
return json_transformers.decode_simple_header(decoded)
|