Switch storagegroup and session_token tests to testlib library

Signed-off-by: Vladimir Avdeev <v.avdeev@yadro.com>
This commit is contained in:
Vladimir Avdeev 2022-11-01 12:30:05 +03:00 committed by Vladimir Avdeev
parent c9e42a7a0a
commit bf71f3250d
10 changed files with 301 additions and 190 deletions

View file

@ -3,11 +3,12 @@
It contains wrappers for `neofs-cli storagegroup` verbs.
"""
import logging
from typing import Optional
import allure
from cli_helpers import _cmd_run
from common import COMPLEX_OBJ_SIZE, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, SIMPLE_OBJ_SIZE, WALLET_CONFIG
from complex_object_actions import get_link_object
from neofs_testlib.cli import NeofsCli
from neofs_testlib.shell import Shell
from neofs_verbs import head_object
@ -16,95 +17,108 @@ logger = logging.getLogger("NeoLogger")
@allure.step("Put Storagegroup")
def put_storagegroup(
shell: Shell,
wallet: str,
cid: str,
objects: list,
bearer: str = "",
bearer: Optional[str] = None,
wallet_config: str = WALLET_CONFIG,
lifetime: str = "10",
):
lifetime: int = 10,
) -> str:
"""
Wrapper for `neofs-cli storagegroup put`. Before the SG is created,
neofs-cli performs HEAD on `objects`, so this verb must be allowed
for `wallet` in `cid`.
Args:
wallet (str): path to wallet on whose behalf the SG is created
cid (str): ID of Container to put SG to
objects (list): list of Object IDs to include into the SG
bearer (optional, str): path to Bearer token file
wallet_config (optional, str): path to neofs-cli config file
shell: Shell instance.
wallet: Path to wallet on whose behalf the SG is created.
cid: ID of Container to put SG to.
lifetime: Storage group lifetime in epochs.
objects: List of Object IDs to include into the SG.
bearer: Path to Bearer token file.
wallet_config: Path to neofs-cli config file.
Returns:
(str): Object ID of created Storage Group
Object ID of created Storage Group.
"""
cmd = (
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
f"--wallet {wallet} --config {wallet_config} "
f"storagegroup put --cid {cid} --lifetime {lifetime} "
f'--members {",".join(objects)} '
f'{"--bearer " + bearer if bearer else ""}'
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=wallet_config)
result = neofscli.storagegroup.put(
wallet=wallet,
cid=cid,
lifetime=lifetime,
members=objects,
bearer=bearer,
rpc_endpoint=NEOFS_ENDPOINT,
)
output = _cmd_run(cmd)
oid = output.split("\n")[1].split(": ")[1]
return oid
gid = result.stdout.split("\n")[1].split(": ")[1]
return gid
@allure.step("List Storagegroup")
def list_storagegroup(wallet: str, cid: str, bearer: str = "", wallet_config: str = WALLET_CONFIG):
def list_storagegroup(
shell: Shell,
wallet: str,
cid: str,
bearer: Optional[str] = None,
wallet_config: str = WALLET_CONFIG,
) -> list:
"""
Wrapper for `neofs-cli storagegroup list`. This operation
requires SEARCH allowed for `wallet` in `cid`.
Args:
wallet (str): path to wallet on whose behalf the SGs are
listed in the container
cid (str): ID of Container to list
bearer (optional, str): path to Bearer token file
wallet_config (optional, str): path to neofs-cli config file
shell: Shell instance.
wallet: Path to wallet on whose behalf the SGs are listed in the container
cid: ID of Container to list.
bearer: Path to Bearer token file.
wallet_config: Path to neofs-cli config file.
Returns:
(list): Object IDs of found Storage Groups
Object IDs of found Storage Groups.
"""
cmd = (
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
f"--wallet {wallet} --config {wallet_config} storagegroup list "
f'--cid {cid} {"--bearer " + bearer if bearer else ""}'
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=wallet_config)
result = neofscli.storagegroup.list(
wallet=wallet,
cid=cid,
bearer=bearer,
rpc_endpoint=NEOFS_ENDPOINT,
)
output = _cmd_run(cmd)
# throwing off the first string of output
found_objects = output.split("\n")[1:]
found_objects = result.stdout.split("\n")[1:]
return found_objects
@allure.step("Get Storagegroup")
def get_storagegroup(
shell: Shell,
wallet: str,
cid: str,
oid: str,
gid: str,
bearer: str = "",
wallet_config: str = WALLET_CONFIG,
):
) -> dict:
"""
Wrapper for `neofs-cli storagegroup get`.
Args:
wallet (str): path to wallet on whose behalf the SG is got
cid (str): ID of Container where SG is stored
oid (str): ID of the Storage Group
bearer (optional, str): path to Bearer token file
wallet_config (optional, str): path to neofs-cli config file
shell: Shell instance.
wallet: Path to wallet on whose behalf the SG is got.
cid: ID of Container where SG is stored.
gid: ID of the Storage Group.
bearer: Path to Bearer token file.
wallet_config: Path to neofs-cli config file.
Returns:
(dict): detailed information on the Storage Group
Detailed information on the Storage Group.
"""
cmd = (
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
f"--wallet {wallet} --config {wallet_config} "
f"storagegroup get --cid {cid} --id {oid} "
f'{"--bearer " + bearer if bearer else ""}'
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=wallet_config)
result = neofscli.storagegroup.get(
wallet=wallet,
cid=cid,
bearer=bearer,
id=gid,
rpc_endpoint=NEOFS_ENDPOINT,
)
output = _cmd_run(cmd)
# TODO: temporary solution for parsing output. Needs to be replaced with
# JSON parsing when https://github.com/nspcc-dev/neofs-node/issues/1355
# is done.
strings = output.strip().split("\n")
strings = result.stdout.strip().split("\n")
# first three strings go to `data`;
# skip the 'Members:' string;
# the rest of strings go to `members`
@ -121,55 +135,60 @@ def get_storagegroup(
@allure.step("Delete Storagegroup")
def delete_storagegroup(
shell: Shell,
wallet: str,
cid: str,
oid: str,
gid: str,
bearer: str = "",
wallet_config: str = WALLET_CONFIG,
):
) -> str:
"""
Wrapper for `neofs-cli storagegroup delete`.
Args:
wallet (str): path to wallet on whose behalf the SG is deleted
cid (str): ID of Container where SG is stored
oid (str): ID of the Storage Group
bearer (optional, str): path to Bearer token file
wallet_config (optional, str): path to neofs-cli config file
shell: Shell instance.
wallet: Path to wallet on whose behalf the SG is deleted.
cid: ID of Container where SG is stored.
gid: ID of the Storage Group.
bearer: Path to Bearer token file.
wallet_config: Path to neofs-cli config file.
Returns:
(str): Tombstone ID of the deleted Storage Group
Tombstone ID of the deleted Storage Group.
"""
cmd = (
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
f"--wallet {wallet} --config {wallet_config} "
f"storagegroup delete --cid {cid} --id {oid} "
f'{"--bearer " + bearer if bearer else ""}'
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=wallet_config)
result = neofscli.storagegroup.delete(
wallet=wallet,
cid=cid,
bearer=bearer,
id=gid,
rpc_endpoint=NEOFS_ENDPOINT,
)
output = _cmd_run(cmd)
tombstone_id = output.strip().split("\n")[1].split(": ")[1]
tombstone_id = result.stdout.strip().split("\n")[1].split(": ")[1]
return tombstone_id
@allure.step("Verify list operation over Storagegroup")
def verify_list_storage_group(
shell: Shell,
wallet: str,
cid: str,
storagegroup: str,
gid: str,
bearer: str = None,
wallet_config: str = WALLET_CONFIG,
):
storage_groups = list_storagegroup(wallet, cid, bearer=bearer, wallet_config=wallet_config)
assert storagegroup in storage_groups
storage_groups = list_storagegroup(
shell=shell, wallet=wallet, cid=cid, bearer=bearer, wallet_config=wallet_config
)
assert gid in storage_groups
@allure.step("Verify get operation over Storagegroup")
def verify_get_storage_group(
shell: Shell,
wallet: str,
cid: str,
storagegroup: str,
gid: str,
obj_list: list,
object_size: int,
shell: Shell,
bearer: str = None,
wallet_config: str = WALLET_CONFIG,
):
@ -192,7 +211,12 @@ def verify_get_storage_group(
obj_num = len(obj_list)
storagegroup_data = get_storagegroup(
wallet, cid, storagegroup, bearer=bearer, wallet_config=wallet_config
shell=shell,
wallet=wallet,
cid=cid,
gid=gid,
bearer=bearer,
wallet_config=wallet_config,
)
if object_size == SIMPLE_OBJ_SIZE:
exp_size = SIMPLE_OBJ_SIZE * obj_num