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

@ -35,7 +35,7 @@ neo-mamba==0.10.0
neo3crypto==0.2.1
neo3vm==0.9.0
neo3vm-stubs==0.9.0
neofs-testlib==0.2.2
neofs-testlib==0.3.0
netaddr==0.8.0
orjson==3.6.8
packaging==21.3

View file

@ -78,16 +78,32 @@ class TestStorageGroup:
file_path = generate_file(object_size)
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid]
storage_group = put_storagegroup(self.main_wallet, cid, objects)
storage_group = put_storagegroup(
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
objects=objects)
self.expect_success_for_storagegroup_operations(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
self.expect_failure_for_storagegroup_operations(
self.other_wallet, cid, objects, storage_group
shell=client_shell,
wallet=self.other_wallet,
cid=cid,
obj_list=objects,
gid=storage_group,
)
self.storagegroup_operations_by_system_ro_container(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
@allure.title("Test Storage Group in Public Container")
@ -97,13 +113,25 @@ class TestStorageGroup:
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid]
self.expect_success_for_storagegroup_operations(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
self.expect_success_for_storagegroup_operations(
self.other_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.other_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
self.storagegroup_operations_by_system_ro_container(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
@allure.title("Test Storage Group in Read-Only Container")
@ -113,13 +141,26 @@ class TestStorageGroup:
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid]
self.expect_success_for_storagegroup_operations(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
self.storagegroup_operations_by_other_ro_container(
self.main_wallet, self.other_wallet, cid, objects, object_size, client_shell
shell=client_shell,
owner_wallet=self.main_wallet,
other_wallet=self.other_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
self.storagegroup_operations_by_system_ro_container(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
@allure.title("Test Storage Group with Bearer Allow")
@ -131,9 +172,13 @@ class TestStorageGroup:
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid]
self.expect_success_for_storagegroup_operations(
self.main_wallet, cid, objects, object_size, client_shell
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
)
storage_group = put_storagegroup(self.main_wallet, cid, objects)
storage_group = put_storagegroup(client_shell, self.main_wallet, cid, objects)
eacl_deny = [
EACLRule(access=EACLAccess.DENY, role=role, operation=op)
for op in EACLOperation
@ -146,7 +191,7 @@ class TestStorageGroup:
shell=client_shell,
)
self.expect_failure_for_storagegroup_operations(
self.main_wallet, cid, objects, storage_group
client_shell, self.main_wallet, cid, objects, storage_group
)
bearer_file = form_bearertoken_file(
self.main_wallet,
@ -158,7 +203,12 @@ class TestStorageGroup:
shell=client_shell,
)
self.expect_success_for_storagegroup_operations(
self.main_wallet, cid, objects, object_size, client_shell, bearer_file
shell=client_shell,
wallet=self.main_wallet,
cid=cid,
obj_list=objects,
object_size=object_size,
bearer=bearer_file,
)
@allure.title("Test to check Storage Group lifetime")
@ -167,21 +217,23 @@ class TestStorageGroup:
file_path = generate_file(object_size)
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid]
storage_group = put_storagegroup(self.main_wallet, cid, objects, lifetime="1")
storage_group = put_storagegroup(client_shell, self.main_wallet, cid, objects, lifetime=1)
with allure.step("Tick two epochs"):
for _ in range(2):
tick_epoch(shell=client_shell)
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
get_storagegroup(self.main_wallet, cid, storage_group)
get_storagegroup(
shell=client_shell, wallet=self.main_wallet, cid=cid, gid=storage_group
)
@staticmethod
@allure.step("Run Storage Group Operations And Expect Success")
def expect_success_for_storagegroup_operations(
shell: Shell,
wallet: str,
cid: str,
obj_list: list,
object_size: int,
shell: Shell,
bearer: Optional[str] = None,
):
"""
@ -189,15 +241,25 @@ class TestStorageGroup:
Put, List, Get and Delete the Storage Group which contains
the Object.
"""
storage_group = put_storagegroup(wallet, cid, obj_list, bearer)
verify_list_storage_group(wallet, cid, storage_group, bearer)
verify_get_storage_group(wallet, cid, storage_group, obj_list, object_size, shell, bearer)
delete_storagegroup(wallet, cid, storage_group, bearer)
storage_group = put_storagegroup(shell, wallet, cid, obj_list, bearer)
verify_list_storage_group(
shell=shell, wallet=wallet, cid=cid, gid=storage_group, bearer=bearer
)
verify_get_storage_group(
shell=shell,
wallet=wallet,
cid=cid,
gid=storage_group,
obj_list=obj_list,
object_size=object_size,
bearer=bearer,
)
delete_storagegroup(shell=shell, wallet=wallet, cid=cid, gid=storage_group, bearer=bearer)
@staticmethod
@allure.step("Run Storage Group Operations And Expect Failure")
def expect_failure_for_storagegroup_operations(
wallet: str, cid: str, obj_list: list, storagegroup: str
shell: Shell, wallet: str, cid: str, obj_list: list, gid: str
):
"""
This func verifies if the Object's owner isn't allowed to
@ -205,36 +267,43 @@ class TestStorageGroup:
the Object.
"""
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
put_storagegroup(wallet, cid, obj_list)
put_storagegroup(shell=shell, wallet=wallet, cid=cid, objects=obj_list)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
list_storagegroup(wallet, cid)
list_storagegroup(shell=shell, wallet=wallet, cid=cid)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
get_storagegroup(wallet, cid, storagegroup)
get_storagegroup(shell=shell, wallet=wallet, cid=cid, gid=gid)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
delete_storagegroup(wallet, cid, storagegroup)
delete_storagegroup(shell=shell, wallet=wallet, cid=cid, gid=gid)
@staticmethod
@allure.step("Run Storage Group Operations On Other's Behalf In RO Container")
def storagegroup_operations_by_other_ro_container(
shell: Shell,
owner_wallet: str,
other_wallet: str,
cid: str,
obj_list: list,
object_size: int,
shell: Shell,
):
storage_group = put_storagegroup(owner_wallet, cid, obj_list)
storage_group = put_storagegroup(shell, owner_wallet, cid, obj_list)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
put_storagegroup(other_wallet, cid, obj_list)
verify_list_storage_group(other_wallet, cid, storage_group)
verify_get_storage_group(other_wallet, cid, storage_group, obj_list, object_size, shell)
put_storagegroup(shell=shell, wallet=other_wallet, cid=cid, objects=obj_list)
verify_list_storage_group(shell=shell, wallet=other_wallet, cid=cid, gid=storage_group)
verify_get_storage_group(
shell=shell,
wallet=other_wallet,
cid=cid,
gid=storage_group,
obj_list=obj_list,
object_size=object_size,
)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
delete_storagegroup(other_wallet, cid, storage_group)
delete_storagegroup(shell=shell, wallet=other_wallet, cid=cid, gid=storage_group)
@staticmethod
@allure.step("Run Storage Group Operations On Systems's Behalf In RO Container")
def storagegroup_operations_by_system_ro_container(
wallet: str, cid: str, obj_list: list, object_size: int, shell: Shell
shell: Shell, wallet: str, cid: str, obj_list: list, object_size: int
):
"""
In this func we create a Storage Group on Inner Ring's key behalf
@ -255,20 +324,26 @@ class TestStorageGroup:
wallet_from_path=IR_WALLET_PATH,
wallet_from_password=IR_WALLET_PASS,
)
storage_group = put_storagegroup(wallet, cid, obj_list)
storage_group = put_storagegroup(shell, wallet, cid, obj_list)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
put_storagegroup(IR_WALLET_PATH, cid, obj_list, wallet_config=IR_WALLET_CONFIG)
put_storagegroup(shell, IR_WALLET_PATH, cid, obj_list, wallet_config=IR_WALLET_CONFIG)
verify_list_storage_group(
IR_WALLET_PATH, cid, storage_group, wallet_config=IR_WALLET_CONFIG
)
verify_get_storage_group(
IR_WALLET_PATH,
cid,
storage_group,
obj_list,
object_size,
shell,
shell=shell,
wallet=IR_WALLET_PATH,
cid=cid,
gid=storage_group,
obj_list=obj_list,
object_size=object_size,
wallet_config=IR_WALLET_CONFIG,
)
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
delete_storagegroup(IR_WALLET_PATH, cid, storage_group, wallet_config=IR_WALLET_CONFIG)
delete_storagegroup(
shell=shell,
wallet=IR_WALLET_PATH,
cid=cid,
gid=storage_group,
wallet_config=IR_WALLET_CONFIG,
)

View file

@ -27,18 +27,18 @@ class TestBalanceAccounting:
@allure.title("Test balance request with wallet and address")
def test_balance_wallet_address(self, client_shell):
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.accounting.balance(
result = cli.accounting.balance(
wallet=self.user_wallet,
rpc_endpoint=NEOFS_ENDPOINT,
address=self.address,
)
assert int(output.stdout.rstrip()) == DEPOSIT_AMOUNT
assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
@allure.title("Test balance request with wallet only")
def test_balance_wallet(self, client_shell):
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT)
assert int(output.stdout.rstrip()) == DEPOSIT_AMOUNT
result = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT)
assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
@allure.title("Test balance request with wallet and wrong address")
def test_balance_wrong_address(self, client_shell):

View file

@ -2,20 +2,13 @@ import random
import allure
import pytest
from common import COMPLEX_OBJ_SIZE, NEOFS_NETMAP_DICT, SIMPLE_OBJ_SIZE
from common import COMPLEX_OBJ_SIZE, NEOFS_NETMAP_DICT, SIMPLE_OBJ_SIZE, WALLET_PASS
from file_helper import generate_file
from grpc_responses import SESSION_NOT_FOUND
from neofs_testlib.shell import Shell
from neofs_testlib.utils.wallet import get_last_address_from_wallet
from python_keywords.container import create_container
from python_keywords.neofs_verbs import (
delete_object,
get_object,
get_range,
head_object,
put_object,
search_object,
)
from python_keywords.neofs_verbs import delete_object, put_object
from python_keywords.session_token import create_session_token
@ -32,9 +25,12 @@ def test_object_session_token(prepare_wallet_and_deposit, client_shell: Shell, o
Steps:
1. Create a private container
2. Obj operation requests to the node which IS NOT in the container but granted with a session token
3. Obj operation requests to the node which IS in the container and NOT granted with a session token
4. Obj operation requests to the node which IS NOT in the container and NOT granted with a session token
2. Obj operation requests to the node which IS NOT in the container but granted
with a session token
3. Obj operation requests to the node which IS in the container and NOT granted
with a session token
4. Obj operation requests to the node which IS NOT in the container and NOT granted
with a session token
"""
with allure.step("Init wallet"):
@ -52,7 +48,13 @@ def test_object_session_token(prepare_wallet_and_deposit, client_shell: Shell, o
noncontainer_node = NEOFS_NETMAP_DICT[noncontainer_node_name]["rpc"]
with allure.step("Create Session Token"):
session_token = create_session_token(address, wallet, rpc=session_token_node)
session_token = create_session_token(
shell=client_shell,
owner=address,
wallet_path=wallet,
wallet_password=WALLET_PASS,
rpc_endpoint=session_token_node,
)
with allure.step("Create Private Container"):
un_locode = NEOFS_NETMAP_DICT[container_node_name]["UN-LOCODE"]

View file

@ -10,7 +10,6 @@ from typing import Any, Dict, List, Optional, Union
import allure
import base58
from cli_helpers import _cmd_run
from common import ASSETS_DIR, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG
from data_formatters import get_wallet_public_key
from neofs_testlib.cli import NeofsCli
@ -120,14 +119,14 @@ class EACLRule:
def get_eacl(wallet_path: str, cid: str, shell: Shell) -> Optional[str]:
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
try:
output = cli.container.get_eacl(wallet=wallet_path, rpc_endpoint=NEOFS_ENDPOINT, cid=cid)
result = cli.container.get_eacl(wallet=wallet_path, rpc_endpoint=NEOFS_ENDPOINT, cid=cid)
except RuntimeError as exc:
logger.info("Extended ACL table is not set for this container")
logger.info(f"Got exception while getting eacl: {exc}")
return None
if "extended ACL table is not set for this container" in output.stdout:
if "extended ACL table is not set for this container" in result.stdout:
return None
return output.stdout
return result.stdout
@allure.title("Set extended ACL")
@ -208,7 +207,7 @@ def form_bearertoken_file(
json.dump(eacl_result, eacl_file, ensure_ascii=False, indent=4)
logger.info(f"Got these extended ACL records: {eacl_result}")
sign_bearer(wif, file_path)
sign_bearer(shell, wif, file_path)
return file_path
@ -235,12 +234,11 @@ def eacl_rules(access: str, verbs: list, user: str) -> list[str]:
return rules
def sign_bearer(wallet_path: str, eacl_rules_file: str) -> None:
cmd = (
f"{NEOFS_CLI_EXEC} util sign bearer-token --from {eacl_rules_file} "
f"--to {eacl_rules_file} --wallet {wallet_path} --config {WALLET_CONFIG} --json"
def sign_bearer(shell: Shell, wallet_path: str, eacl_rules_file: str) -> None:
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=WALLET_CONFIG)
neofscli.util.sign_bearer_token(
wallet=wallet_path, from_file=eacl_rules_file, to_file=eacl_rules_file, json=True
)
_cmd_run(cmd)
@allure.title("Wait for eACL cache expired")

View file

@ -59,7 +59,7 @@ def create_container(
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.container.create(
result = cli.container.create(
rpc_endpoint=NEOFS_ENDPOINT,
wallet=session_wallet if session_wallet else wallet,
policy=rule,
@ -71,7 +71,7 @@ def create_container(
**options or {},
)
cid = _parse_cid(output.stdout)
cid = _parse_cid(result.stdout)
logger.info("Container created; waiting until it is persisted in the sidechain")
@ -122,9 +122,9 @@ def list_containers(wallet: str, shell: Shell) -> list[str]:
(list): list of containers
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.container.list(rpc_endpoint=NEOFS_ENDPOINT, wallet=wallet)
result = cli.container.list(rpc_endpoint=NEOFS_ENDPOINT, wallet=wallet)
logger.info(f"Containers: \n{output}")
return output.stdout.split()
return result.stdout.split()
@allure.step("Get Container")
@ -146,14 +146,14 @@ def get_container(
(dict, str): dict of container attributes
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.container.get(
result = cli.container.get(
rpc_endpoint=NEOFS_ENDPOINT, wallet=wallet, cid=cid, json_mode=json_mode
)
if not json_mode:
return output.stdout
return result.stdout
container_info = json.loads(output.stdout)
container_info = json.loads(result.stdout)
attributes = dict()
for attr in container_info["attributes"]:
attributes[attr["key"]] = attr["value"]

View file

@ -102,7 +102,7 @@ def get_range_hash(
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.hash(
result = cli.object.hash(
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet,
cid=cid,
@ -113,7 +113,7 @@ def get_range_hash(
)
# cutting off output about range offset and length
return output.stdout.split(":")[1].strip()
return result.stdout.split(":")[1].strip()
@allure.step("Put object")
@ -156,7 +156,7 @@ def put_object(
logger.info(f"---DEB:\n{NEOFS_NETMAP}")
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.put(
result = cli.object.put(
rpc_endpoint=endpoint,
wallet=wallet,
file=path,
@ -170,7 +170,7 @@ def put_object(
)
# splitting CLI output to lines and taking the penultimate line
id_str = output.stdout.strip().split("\n")[-2]
id_str = result.stdout.strip().split("\n")[-2]
oid = id_str.split(":")[1]
return oid.strip()
@ -204,7 +204,7 @@ def delete_object(
(str): Tombstone ID
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.delete(
result = cli.object.delete(
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet,
cid=cid,
@ -214,7 +214,7 @@ def delete_object(
session=session,
)
id_str = output.stdout.split("\n")[1]
id_str = result.stdout.split("\n")[1]
tombstone = id_str.split(":")[1]
return tombstone.strip()
@ -301,7 +301,7 @@ def search_object(
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.search(
result = cli.object.search(
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet,
cid=cid,
@ -313,7 +313,7 @@ def search_object(
session=session,
)
found_objects = re.findall(r"(\w{43,44})", output.stdout)
found_objects = re.findall(r"(\w{43,44})", result.stdout)
if expected_objects_list:
if sorted(found_objects) == sorted(expected_objects_list):
@ -372,7 +372,7 @@ def head_object(
"""
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.head(
result = cli.object.head(
rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet,
cid=cid,
@ -386,18 +386,18 @@ def head_object(
)
if not json_output:
return output
return result
try:
decoded = json.loads(output.stdout)
decoded = json.loads(result.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.stdout.find("\n")
decoded = json.loads(output.stdout[fst_line_idx:])
fst_line_idx = result.stdout.find("\n")
decoded = json.loads(result.stdout[fst_line_idx:])
# If response is Complex Object header, it has `splitId` key
if "splitId" in decoded.keys():

View file

@ -139,16 +139,14 @@ def transfer_gas(
the assets will be transferred to the last one.
Args:
shell: Shell instance.
wallet_from_password: password of the wallet; it is
required to decode the wallet and extract its addresses
wallet_from_path: path to chain node wallet
address_from: the address of the wallet to transfer assets from
wallet_to_path: the path to the wallet to transfer assets to
wallet_to_password: the password to the wallet to transfer assets to
address_to: the address of the wallet to transfer assets to
amount: amount of gas to transfer
Returns:
(void)
wallet_from_password: Password of the wallet; it is required to decode the wallet
and extract its addresses.
wallet_from_path: Path to chain node wallet.
address_from: The address of the wallet to transfer assets from.
wallet_to_path: The path to the wallet to transfer assets to.
wallet_to_password: The password to the wallet to transfer assets to.
address_to: The address of the wallet to transfer assets to.
amount: Amount of gas to transfer.
"""
address_to = address_to or get_last_address_from_wallet(wallet_to_path, wallet_to_password)

View file

@ -6,8 +6,9 @@ import uuid
import allure
import json_transformers
from cli_helpers import _cmd_run, _run_with_passwd
from common import ASSETS_DIR, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG
from neofs_testlib.cli import NeofsCli
from neofs_testlib.shell import Shell
from neo3 import wallet
logger = logging.getLogger("NeoLogger")
@ -70,39 +71,52 @@ def generate_session_token(owner: str, session_wallet: str, cid: str = "") -> st
@allure.step("Create Session Token")
def create_session_token(owner: str, wallet_path: str, rpc: str = NEOFS_ENDPOINT):
def create_session_token(
shell: Shell,
owner: str,
wallet_path: str,
wallet_password: str,
rpc_endpoint: str = NEOFS_ENDPOINT,
) -> str:
"""
Create session token for an object.
Args:
owner(str): user that writes the token
session_wallet(str): the path to wallet to which we grant the
access via session token
shell: Shell instance.
owner: User that writes the token.
wallet_path: The path to wallet to which we grant the access via session token.
wallet_password: Wallet password.
rpc_endpoint: Remote node address (as 'multiaddr' or '<host>:<port>').
Returns:
(str): the path to the generated session token file
The path to the generated session token file.
"""
session_token = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = (
f"{NEOFS_CLI_EXEC} session create --address {owner} -w {wallet_path} "
f"--out {session_token} --rpc-endpoint {rpc}"
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC)
neofscli.session.create(
rpc_endpoint=rpc_endpoint,
address=owner,
wallet=wallet_path,
wallet_password=wallet_password,
out=session_token,
)
_run_with_passwd(cmd)
return session_token
@allure.step("Sign Session Token")
def sign_session_token(session_token: str, wlt: str):
def sign_session_token(shell: Shell, session_token_file: str, wlt: str) -> str:
"""
This function signs the session token by the given wallet.
Args:
session_token(str): the path to the session token file
wlt(str): the path to the signing wallet
shell: Shell instance.
session_token_file: The path to the session token file.
wlt: The path to the signing wallet.
Returns:
(str): the path to the signed token
The path to the signed token.
"""
signed_token = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = (
f"{NEOFS_CLI_EXEC} util sign session-token --from {session_token} "
f"-w {wlt} --to {signed_token} --config {WALLET_CONFIG}"
signed_token_file = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=WALLET_CONFIG)
neofscli.util.sign_session_token(
wallet=wlt, from_file=session_token_file, to_file=signed_token_file
)
_cmd_run(cmd)
return signed_token
return signed_token_file

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