storage group operations moved from neofs.py; storage group tests

refactored

Signed-off-by: anastasia prasolova <anastasia@nspcc.ru>
This commit is contained in:
anastasia prasolova 2022-05-06 12:53:02 +03:00 committed by Anastasia Prasolova
parent 48730d8f7a
commit d940fe9573
14 changed files with 389 additions and 379 deletions

View file

@ -21,13 +21,14 @@ ROBOT_AUTO_KEYWORDS = False
@keyword('Get Link Object')
def get_link_object(wallet: str, cid: str, oid: str):
def get_link_object(wallet: str, cid: str, oid: str, bearer_token: str=""):
"""
Args:
wallet (str): path to the wallet on whose behalf the Storage Nodes
are requested
cid (str): Container ID which stores the Large Object
oid (str): Large Object ID
bearer_token (optional, str): path to Bearer token file
Returns:
(str): Link Object ID
When no Link Object ID is found after all Storage Nodes polling,
@ -38,7 +39,8 @@ def get_link_object(wallet: str, cid: str, oid: str):
resp = neofs_verbs.head_object(wallet, cid, oid,
endpoint=node,
is_raw=True,
is_direct=True)
is_direct=True,
bearer_token=bearer_token)
if resp['link']:
return resp['link']
except Exception:

View file

@ -264,90 +264,6 @@ def find_in_nodes_Log(line: str, nodes_logs_time: dict):
return 1
@keyword('Put Storagegroup')
def put_storagegroup(wallet: str, cid: str, bearer_token: str="", *oid_list):
cmd_oid_line = ",".join(oid_list)
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} --config {WALLET_PASS} '
f'storagegroup put --cid {cid} --members {cmd_oid_line} {bearer_token}'
)
output = _cmd_run(object_cmd)
oid = _parse_oid(output)
return oid
@keyword('List Storagegroup')
def list_storagegroup(wallet: str, cid: str, bearer_token: str="", *expected_list):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'--config {WALLET_PASS} storagegroup list --cid {cid} {bearer_token}'
)
output = _cmd_run(object_cmd)
found_objects = re.findall(r'(\w{43,44})', output)
if expected_list:
if sorted(found_objects) == sorted(expected_list):
logger.info(f"Found storage group list '{found_objects}' is equal for expected list '{expected_list}'")
else:
raise Exception(f"Found storage group '{found_objects}' is not equal to expected list '{expected_list}'")
return found_objects
@keyword('Get Storagegroup')
def get_storagegroup(wallet: str, cid: str, oid: str, bearer_token: str, expected_size, *expected_objects_list):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {private_key} storagegroup get --cid {cid} --id {oid} {bearer_token}'
output = _cmd_run(object_cmd)
if expected_size:
if re.search(fr'Group size: {expected_size}', output):
logger.info(f"Group size {expected_size} has been found in the output")
else:
raise Exception(f"Group size {expected_size} has not been found in the output")
found_objects = re.findall(r'\s(\w{43,44})\s', output)
if expected_objects_list:
if sorted(found_objects) == sorted(expected_objects_list):
logger.info(f"Found objects list '{found_objects}' is equal for expected list '{expected_objects_list}'")
else:
raise Exception(f"Found object list '{found_objects}' is not equal to expected list '{expected_objects_list}'")
@keyword('Delete Storagegroup')
def delete_storagegroup(wallet: str, cid: str, oid: str, bearer_token: str=""):
if bearer_token:
bearer_token = f"--bearer {bearer_token}"
object_cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} storagegroup '
f'delete --cid {cid} --config {WALLET_PASS} --id {oid} {bearer_token}'
)
output = _cmd_run(object_cmd)
m = re.search(r'Tombstone: ([a-zA-Z0-9-]+)', output)
if m.start() != m.end(): # e.g., if match found something
oid = m.group(1)
else:
raise Exception(f"no Tombstone ID was parsed from command output: \t{output}")
return oid
@keyword('Generate Session Token')
def generate_session_token(owner: str, pub_key: str, cid: str = "", wildcard: bool = False) -> str:

View file

@ -0,0 +1,126 @@
#!/usr/bin/python3
"""
This module contains keywords for work with Storage Groups.
It contains wrappers for `neofs-cli storagegroup` verbs.
"""
from cli_helpers import _cmd_run
from common import NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_PASS
from robot.api.deco import keyword
ROBOT_AUTO_KEYWORDS = False
@keyword('Put Storagegroup')
def put_storagegroup(wallet: str, cid: str, objects: list, bearer_token: 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_token (optional, str): path to Bearer token file
Returns:
(str): Object ID of created Storage Group
"""
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} '
f'--wallet {wallet} --config {WALLET_PASS} '
f'storagegroup put --cid {cid} '
f'--members {",".join(objects)} '
f'{"--bearer " + bearer_token if bearer_token else ""}'
)
output = _cmd_run(cmd)
oid = output.split('\n')[1].split(': ')[1]
return oid
@keyword('List Storagegroup')
def list_storagegroup(wallet: str, cid: str, bearer_token: str=""):
"""
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_token (optional, str): path to Bearer token file
Returns:
(list): Object IDs of found Storage Groups
"""
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} '
f'--wallet {wallet} --config {WALLET_PASS} storagegroup list '
f'--cid {cid} {"--bearer " + bearer_token if bearer_token else ""}'
)
output = _cmd_run(cmd)
# throwing off the first string of output
found_objects = output.split('\n')[1:]
return found_objects
@keyword('Get Storagegroup')
def get_storagegroup(wallet: str, cid: str, oid: str, bearer_token: str=''):
"""
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_token (optional, str): path to Bearer token file
Returns:
(dict): detailed information on the Storage Group
"""
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} '
f'--wallet {wallet} --config {WALLET_PASS} '
f'storagegroup get --cid {cid} --id {oid} '
f'{"--bearer " + bearer_token if bearer_token else ""}'
)
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')
# 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:
key, val = i.split(': ')
sg_dict[key] = val
sg_dict['Members'] = []
for member in members[1:]:
sg_dict['Members'].append(member.strip())
return sg_dict
@keyword('Delete Storagegroup')
def delete_storagegroup(wallet: str, cid: str, oid: str, bearer_token: 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_token (optional, str): path to Bearer token file
Returns:
(str): Tombstone ID of the deleted Storage Group
"""
cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} '
f'--wallet {wallet} --config {WALLET_PASS} '
f'storagegroup delete --cid {cid} --id {oid} '
f'{"--bearer " + bearer_token if bearer_token else ""}'
)
output = _cmd_run(cmd)
tombstone_id = output.strip().split('\n')[1].split(': ')[1]
return tombstone_id