2022-05-06 09:53:02 +00:00
|
|
|
"""
|
|
|
|
This module contains keywords for work with Storage Groups.
|
|
|
|
It contains wrappers for `neofs-cli storagegroup` verbs.
|
|
|
|
"""
|
2022-08-17 13:10:02 +00:00
|
|
|
import logging
|
2022-05-06 09:53:02 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
import allure
|
2022-06-09 13:08:11 +00:00
|
|
|
from cli_helpers import _cmd_run
|
2022-09-28 12:07:16 +00:00
|
|
|
from common import COMPLEX_OBJ_SIZE, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, SIMPLE_OBJ_SIZE, WALLET_CONFIG
|
2022-08-17 13:10:02 +00:00
|
|
|
from complex_object_actions import get_link_object
|
2022-10-14 16:56:15 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
2022-08-17 13:10:02 +00:00
|
|
|
from neofs_verbs import head_object
|
2022-06-13 20:33:09 +00:00
|
|
|
|
2022-09-06 10:23:53 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
|
|
|
|
@allure.step("Put Storagegroup")
|
2022-08-17 13:10:02 +00:00
|
|
|
def put_storagegroup(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
objects: list,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: str = "",
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config: str = WALLET_CONFIG,
|
|
|
|
lifetime: str = "10",
|
|
|
|
):
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
2022-08-17 13:10:02 +00:00
|
|
|
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
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer (optional, str): path to Bearer token file
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config (optional, str): path to neofs-cli config file
|
|
|
|
Returns:
|
|
|
|
(str): Object ID of created Storage Group
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
|
|
|
cmd = (
|
2022-08-17 13:10:02 +00:00
|
|
|
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
|
|
|
|
f"--wallet {wallet} --config {wallet_config} "
|
|
|
|
f"storagegroup put --cid {cid} --lifetime {lifetime} "
|
2022-05-06 09:53:02 +00:00
|
|
|
f'--members {",".join(objects)} '
|
2022-10-18 10:39:39 +00:00
|
|
|
f'{"--bearer " + bearer if bearer else ""}'
|
2022-05-06 09:53:02 +00:00
|
|
|
)
|
|
|
|
output = _cmd_run(cmd)
|
2022-08-17 13:10:02 +00:00
|
|
|
oid = output.split("\n")[1].split(": ")[1]
|
2022-05-06 09:53:02 +00:00
|
|
|
return oid
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("List Storagegroup")
|
2022-10-19 06:26:14 +00:00
|
|
|
def list_storagegroup(wallet: str, cid: str, bearer: str = "", wallet_config: str = WALLET_CONFIG):
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
2022-08-17 13:10:02 +00:00
|
|
|
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
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer (optional, str): path to Bearer token file
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config (optional, str): path to neofs-cli config file
|
|
|
|
Returns:
|
|
|
|
(list): Object IDs of found Storage Groups
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
|
|
|
cmd = (
|
2022-08-17 13:10:02 +00:00
|
|
|
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
|
|
|
|
f"--wallet {wallet} --config {wallet_config} storagegroup list "
|
2022-10-18 10:39:39 +00:00
|
|
|
f'--cid {cid} {"--bearer " + bearer if bearer else ""}'
|
2022-05-06 09:53:02 +00:00
|
|
|
)
|
|
|
|
output = _cmd_run(cmd)
|
|
|
|
# throwing off the first string of output
|
2022-08-17 13:10:02 +00:00
|
|
|
found_objects = output.split("\n")[1:]
|
2022-05-06 09:53:02 +00:00
|
|
|
return found_objects
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Get Storagegroup")
|
2022-08-17 13:10:02 +00:00
|
|
|
def get_storagegroup(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: str = "",
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config: str = WALLET_CONFIG,
|
|
|
|
):
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
2022-08-17 13:10:02 +00:00
|
|
|
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
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer (optional, str): path to Bearer token file
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config (optional, str): path to neofs-cli config file
|
|
|
|
Returns:
|
|
|
|
(dict): detailed information on the Storage Group
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
cmd = (
|
2022-08-17 13:10:02 +00:00
|
|
|
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
|
|
|
|
f"--wallet {wallet} --config {wallet_config} "
|
|
|
|
f"storagegroup get --cid {cid} --id {oid} "
|
2022-10-18 10:39:39 +00:00
|
|
|
f'{"--bearer " + bearer if bearer else ""}'
|
2022-05-06 09:53:02 +00:00
|
|
|
)
|
|
|
|
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.
|
2022-08-17 13:10:02 +00:00
|
|
|
strings = output.strip().split("\n")
|
2022-05-06 09:53:02 +00:00
|
|
|
# first three strings go to `data`;
|
|
|
|
# skip the 'Members:' string;
|
|
|
|
# the rest of strings go to `members`
|
|
|
|
data, members = strings[:3], strings[3:]
|
|
|
|
sg_dict = {}
|
|
|
|
for i in data:
|
2022-08-17 13:10:02 +00:00
|
|
|
key, val = i.split(": ")
|
2022-05-06 09:53:02 +00:00
|
|
|
sg_dict[key] = val
|
2022-08-17 13:10:02 +00:00
|
|
|
sg_dict["Members"] = []
|
2022-05-06 09:53:02 +00:00
|
|
|
for member in members[1:]:
|
2022-08-17 13:10:02 +00:00
|
|
|
sg_dict["Members"].append(member.strip())
|
2022-05-06 09:53:02 +00:00
|
|
|
return sg_dict
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Delete Storagegroup")
|
2022-08-17 13:10:02 +00:00
|
|
|
def delete_storagegroup(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer: str = "",
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config: str = WALLET_CONFIG,
|
|
|
|
):
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
2022-08-17 13:10:02 +00:00
|
|
|
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
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer (optional, str): path to Bearer token file
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config (optional, str): path to neofs-cli config file
|
|
|
|
Returns:
|
|
|
|
(str): Tombstone ID of the deleted Storage Group
|
2022-05-06 09:53:02 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
cmd = (
|
2022-08-17 13:10:02 +00:00
|
|
|
f"{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} "
|
|
|
|
f"--wallet {wallet} --config {wallet_config} "
|
|
|
|
f"storagegroup delete --cid {cid} --id {oid} "
|
2022-10-18 10:39:39 +00:00
|
|
|
f'{"--bearer " + bearer if bearer else ""}'
|
2022-05-06 09:53:02 +00:00
|
|
|
)
|
|
|
|
output = _cmd_run(cmd)
|
2022-08-17 13:10:02 +00:00
|
|
|
tombstone_id = output.strip().split("\n")[1].split(": ")[1]
|
2022-05-06 09:53:02 +00:00
|
|
|
return tombstone_id
|
2022-08-17 13:10:02 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Verify list operation over Storagegroup")
|
2022-08-17 13:10:02 +00:00
|
|
|
def verify_list_storage_group(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
storagegroup: str,
|
|
|
|
bearer: str = None,
|
|
|
|
wallet_config: str = WALLET_CONFIG,
|
|
|
|
):
|
2022-10-19 06:26:14 +00:00
|
|
|
storage_groups = list_storagegroup(wallet, cid, bearer=bearer, wallet_config=wallet_config)
|
2022-09-06 10:23:53 +00:00
|
|
|
assert storagegroup in storage_groups
|
2022-08-17 13:10:02 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Verify get operation over Storagegroup")
|
2022-08-17 13:10:02 +00:00
|
|
|
def verify_get_storage_group(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
storagegroup: str,
|
|
|
|
obj_list: list,
|
|
|
|
object_size: int,
|
2022-10-14 16:56:15 +00:00
|
|
|
shell: Shell,
|
2022-08-17 13:10:02 +00:00
|
|
|
bearer: str = None,
|
|
|
|
wallet_config: str = WALLET_CONFIG,
|
|
|
|
):
|
|
|
|
obj_parts = []
|
|
|
|
if object_size == COMPLEX_OBJ_SIZE:
|
|
|
|
for obj in obj_list:
|
|
|
|
link_oid = get_link_object(
|
2022-10-18 10:39:39 +00:00
|
|
|
wallet, cid, obj, shell=shell, bearer=bearer, wallet_config=wallet_config
|
2022-08-17 13:10:02 +00:00
|
|
|
)
|
|
|
|
obj_head = head_object(
|
2022-10-19 14:22:54 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=link_oid,
|
2022-10-19 06:26:14 +00:00
|
|
|
shell=shell,
|
2022-08-17 13:10:02 +00:00
|
|
|
is_raw=True,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-08-17 13:10:02 +00:00
|
|
|
wallet_config=wallet_config,
|
|
|
|
)
|
|
|
|
obj_parts = obj_head["header"]["split"]["children"]
|
|
|
|
|
|
|
|
obj_num = len(obj_list)
|
|
|
|
storagegroup_data = get_storagegroup(
|
2022-10-18 10:39:39 +00:00
|
|
|
wallet, cid, storagegroup, bearer=bearer, wallet_config=wallet_config
|
2022-08-17 13:10:02 +00:00
|
|
|
)
|
|
|
|
if object_size == SIMPLE_OBJ_SIZE:
|
|
|
|
exp_size = SIMPLE_OBJ_SIZE * obj_num
|
|
|
|
assert int(storagegroup_data["Group size"]) == exp_size
|
|
|
|
assert storagegroup_data["Members"] == obj_list
|
|
|
|
else:
|
|
|
|
exp_size = COMPLEX_OBJ_SIZE * obj_num
|
|
|
|
assert int(storagegroup_data["Group size"]) == exp_size
|
|
|
|
assert storagegroup_data["Members"] == obj_parts
|