forked from TrueCloudLab/frostfs-testcases
Use neofs-testlib
Signed-off-by: Vladimir Avdeev <v.avdeev@yadro.com>
This commit is contained in:
parent
31d43fbba9
commit
e63db788c5
46 changed files with 889 additions and 1992 deletions
|
@ -13,8 +13,9 @@ from typing import Optional
|
|||
|
||||
import allure
|
||||
import json_transformers
|
||||
from cli_utils import NeofsCli
|
||||
from common import ASSETS_DIR, NEOFS_ENDPOINT, NEOFS_NETMAP, WALLET_CONFIG
|
||||
from common import ASSETS_DIR, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, NEOFS_NETMAP, WALLET_CONFIG
|
||||
from neofs_testlib.cli import NeofsCli
|
||||
from neofs_testlib.shell import Shell
|
||||
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
|
||||
|
@ -24,6 +25,7 @@ def get_object(
|
|||
wallet: str,
|
||||
cid: str,
|
||||
oid: str,
|
||||
shell: Shell,
|
||||
bearer_token: Optional[str] = None,
|
||||
write_object: str = "",
|
||||
endpoint: str = "",
|
||||
|
@ -39,6 +41,7 @@ def get_object(
|
|||
wallet (str): wallet on whose behalf GET is done
|
||||
cid (str): ID of Container where we get the Object from
|
||||
oid (str): Object ID
|
||||
shell: executor for cli command
|
||||
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
write_object (optional, str): path to downloaded file, appends to `--file` key
|
||||
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
||||
|
@ -50,7 +53,6 @@ def get_object(
|
|||
(str): path to downloaded file
|
||||
"""
|
||||
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
if not write_object:
|
||||
write_object = str(uuid.uuid4())
|
||||
file_path = f"{ASSETS_DIR}/{write_object}"
|
||||
|
@ -58,7 +60,7 @@ def get_object(
|
|||
if not endpoint:
|
||||
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
|
||||
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
cli.object.get(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
|
@ -74,14 +76,14 @@ def get_object(
|
|||
return file_path
|
||||
|
||||
|
||||
# TODO: make `bearer_token` optional
|
||||
@allure.step("Get Range Hash")
|
||||
def get_range_hash(
|
||||
wallet: str,
|
||||
cid: str,
|
||||
oid: str,
|
||||
bearer_token: str,
|
||||
range_cut: str,
|
||||
shell: Shell,
|
||||
bearer_token: Optional[str] = None,
|
||||
endpoint: Optional[str] = None,
|
||||
wallet_config: Optional[str] = None,
|
||||
xhdr: Optional[dict] = None,
|
||||
|
@ -93,6 +95,7 @@ def get_range_hash(
|
|||
wallet (str): wallet on whose behalf GETRANGEHASH is done
|
||||
cid (str): ID of Container where we get the Object from
|
||||
oid (str): Object ID
|
||||
shell: executor for cli command
|
||||
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
range_cut (str): Range to take hash from in the form offset1:length1,...,
|
||||
value to pass to the `--range` parameter
|
||||
|
@ -103,8 +106,7 @@ def get_range_hash(
|
|||
None
|
||||
"""
|
||||
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
output = cli.object.hash(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
|
@ -116,7 +118,7 @@ def get_range_hash(
|
|||
)
|
||||
|
||||
# cutting off output about range offset and length
|
||||
return output.split(":")[1].strip()
|
||||
return output.stdout.split(":")[1].strip()
|
||||
|
||||
|
||||
@allure.step("Put object")
|
||||
|
@ -124,7 +126,8 @@ def put_object(
|
|||
wallet: str,
|
||||
path: str,
|
||||
cid: str,
|
||||
bearer: str = "",
|
||||
shell: Shell,
|
||||
bearer: Optional[str] = None,
|
||||
attributes: Optional[dict] = None,
|
||||
xhdr: Optional[dict] = None,
|
||||
endpoint: Optional[str] = None,
|
||||
|
@ -140,6 +143,7 @@ def put_object(
|
|||
wallet (str): wallet on whose behalf PUT is done
|
||||
path (str): path to file to be PUT
|
||||
cid (str): ID of Container where we get the Object from
|
||||
shell: executor for cli command
|
||||
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
attributes (optional, str): User attributes in form of Key1=Value1,Key2=Value2
|
||||
endpoint(optional, str): NeoFS endpoint to send request to
|
||||
|
@ -151,13 +155,12 @@ def put_object(
|
|||
Returns:
|
||||
(str): ID of uploaded Object
|
||||
"""
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
if not endpoint:
|
||||
endpoint = random.sample(NEOFS_NETMAP, 1)[0]
|
||||
if not endpoint:
|
||||
logger.info(f"---DEB:\n{NEOFS_NETMAP}")
|
||||
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
output = cli.object.put(
|
||||
rpc_endpoint=endpoint,
|
||||
wallet=wallet,
|
||||
|
@ -172,7 +175,7 @@ def put_object(
|
|||
)
|
||||
|
||||
# splitting CLI output to lines and taking the penultimate line
|
||||
id_str = output.strip().split("\n")[-2]
|
||||
id_str = output.stdout.strip().split("\n")[-2]
|
||||
oid = id_str.split(":")[1]
|
||||
return oid.strip()
|
||||
|
||||
|
@ -182,6 +185,7 @@ def delete_object(
|
|||
wallet: str,
|
||||
cid: str,
|
||||
oid: str,
|
||||
shell: Shell,
|
||||
endpoint: Optional[str] = None,
|
||||
bearer: str = "",
|
||||
wallet_config: Optional[str] = None,
|
||||
|
@ -195,6 +199,7 @@ def delete_object(
|
|||
wallet (str): wallet on whose behalf DELETE is done
|
||||
cid (str): ID of Container where we get the Object from
|
||||
oid (str): ID of Object we are going to delete
|
||||
shell: executor for cli command
|
||||
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
||||
wallet_config(optional, str): path to the wallet config
|
||||
|
@ -203,8 +208,7 @@ def delete_object(
|
|||
Returns:
|
||||
(str): Tombstone ID
|
||||
"""
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
output = cli.object.delete(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
|
@ -215,7 +219,7 @@ def delete_object(
|
|||
session=session,
|
||||
)
|
||||
|
||||
id_str = output.split("\n")[1]
|
||||
id_str = output.stdout.split("\n")[1]
|
||||
tombstone = id_str.split(":")[1]
|
||||
return tombstone.strip()
|
||||
|
||||
|
@ -226,6 +230,7 @@ def get_range(
|
|||
cid: str,
|
||||
oid: str,
|
||||
range_cut: str,
|
||||
shell: Shell,
|
||||
endpoint: Optional[str] = None,
|
||||
wallet_config: Optional[str] = None,
|
||||
bearer: str = "",
|
||||
|
@ -240,6 +245,7 @@ def get_range(
|
|||
cid (str): ID of Container where we get the Object from
|
||||
oid (str): ID of Object we are going to request
|
||||
range_cut (str): range to take data from in the form offset:length
|
||||
shell: executor for cli command
|
||||
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
||||
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
wallet_config(optional, str): path to the wallet config
|
||||
|
@ -248,10 +254,9 @@ def get_range(
|
|||
Returns:
|
||||
(str, bytes) - path to the file with range content and content of this file as bytes
|
||||
"""
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
range_file = f"{ASSETS_DIR}/{uuid.uuid4()}"
|
||||
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
cli.object.range(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
|
@ -273,6 +278,7 @@ def get_range(
|
|||
def search_object(
|
||||
wallet: str,
|
||||
cid: str,
|
||||
shell: Shell,
|
||||
bearer: str = "",
|
||||
endpoint: Optional[str] = None,
|
||||
filters: Optional[dict] = None,
|
||||
|
@ -287,6 +293,7 @@ def search_object(
|
|||
Args:
|
||||
wallet (str): wallet on whose behalf SEARCH is done
|
||||
cid (str): ID of Container where we get the Object from
|
||||
shell: executor for cli command
|
||||
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
endpoint (optional, str): NeoFS endpoint to send request to, appends to `--rpc-endpoint` key
|
||||
filters (optional, dict): key=value pairs to filter Objects
|
||||
|
@ -298,8 +305,7 @@ def search_object(
|
|||
(list): list of found ObjectIDs
|
||||
"""
|
||||
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
output = cli.object.search(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
|
@ -312,7 +318,7 @@ def search_object(
|
|||
session=session,
|
||||
)
|
||||
|
||||
found_objects = re.findall(r"(\w{43,44})", output)
|
||||
found_objects = re.findall(r"(\w{43,44})", output.stdout)
|
||||
|
||||
if expected_objects_list:
|
||||
if sorted(found_objects) == sorted(expected_objects_list):
|
||||
|
@ -334,7 +340,8 @@ def head_object(
|
|||
wallet: str,
|
||||
cid: str,
|
||||
oid: str,
|
||||
bearer_token: str = "",
|
||||
shell: Shell,
|
||||
bearer: str = "",
|
||||
xhdr: Optional[dict] = None,
|
||||
endpoint: Optional[str] = None,
|
||||
json_output: bool = True,
|
||||
|
@ -350,7 +357,8 @@ def head_object(
|
|||
wallet (str): wallet on whose behalf HEAD is done
|
||||
cid (str): ID of Container where we get the Object from
|
||||
oid (str): ObjectID to HEAD
|
||||
bearer_token (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
shell: executor for cli command
|
||||
bearer (optional, str): path to Bearer Token file, appends to `--bearer` key
|
||||
endpoint(optional, str): NeoFS endpoint to send request to
|
||||
json_output(optional, bool): return reponse in JSON format or not; this flag
|
||||
turns into `--json` key
|
||||
|
@ -368,14 +376,13 @@ def head_object(
|
|||
(str): HEAD response as a plain text
|
||||
"""
|
||||
|
||||
wallet_config = wallet_config or WALLET_CONFIG
|
||||
cli = NeofsCli(config=wallet_config)
|
||||
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
|
||||
output = cli.object.head(
|
||||
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
|
||||
wallet=wallet,
|
||||
cid=cid,
|
||||
oid=oid,
|
||||
bearer=bearer_token,
|
||||
bearer=bearer,
|
||||
json_mode=json_output,
|
||||
raw=is_raw,
|
||||
ttl=1 if is_direct else None,
|
||||
|
@ -387,15 +394,15 @@ def head_object(
|
|||
return output
|
||||
|
||||
try:
|
||||
decoded = json.loads(output)
|
||||
decoded = json.loads(output.stdout)
|
||||
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")
|
||||
fst_line_idx = output.find("\n")
|
||||
decoded = json.loads(output[fst_line_idx:])
|
||||
fst_line_idx = output.stdout.find("\n")
|
||||
decoded = json.loads(output.stdout[fst_line_idx:])
|
||||
|
||||
# If response is Complex Object header, it has `splitId` key
|
||||
if "splitId" in decoded.keys():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue