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 neo3crypto==0.2.1
neo3vm==0.9.0 neo3vm==0.9.0
neo3vm-stubs==0.9.0 neo3vm-stubs==0.9.0
neofs-testlib==0.2.2 neofs-testlib==0.3.0
netaddr==0.8.0 netaddr==0.8.0
orjson==3.6.8 orjson==3.6.8
packaging==21.3 packaging==21.3

View file

@ -78,16 +78,32 @@ class TestStorageGroup:
file_path = generate_file(object_size) file_path = generate_file(object_size)
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell) oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid] 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.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.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.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") @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) oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid] objects = [oid]
self.expect_success_for_storagegroup_operations( 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.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.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") @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) oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid] objects = [oid]
self.expect_success_for_storagegroup_operations( 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.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.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") @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) oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid] objects = [oid]
self.expect_success_for_storagegroup_operations( 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 = [ eacl_deny = [
EACLRule(access=EACLAccess.DENY, role=role, operation=op) EACLRule(access=EACLAccess.DENY, role=role, operation=op)
for op in EACLOperation for op in EACLOperation
@ -146,7 +191,7 @@ class TestStorageGroup:
shell=client_shell, shell=client_shell,
) )
self.expect_failure_for_storagegroup_operations( 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( bearer_file = form_bearertoken_file(
self.main_wallet, self.main_wallet,
@ -158,7 +203,12 @@ class TestStorageGroup:
shell=client_shell, shell=client_shell,
) )
self.expect_success_for_storagegroup_operations( 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") @allure.title("Test to check Storage Group lifetime")
@ -167,21 +217,23 @@ class TestStorageGroup:
file_path = generate_file(object_size) file_path = generate_file(object_size)
oid = put_object(self.main_wallet, file_path, cid, shell=client_shell) oid = put_object(self.main_wallet, file_path, cid, shell=client_shell)
objects = [oid] 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"): with allure.step("Tick two epochs"):
for _ in range(2): for _ in range(2):
tick_epoch(shell=client_shell) tick_epoch(shell=client_shell)
with pytest.raises(Exception, match=OBJECT_NOT_FOUND): 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 @staticmethod
@allure.step("Run Storage Group Operations And Expect Success") @allure.step("Run Storage Group Operations And Expect Success")
def expect_success_for_storagegroup_operations( def expect_success_for_storagegroup_operations(
shell: Shell,
wallet: str, wallet: str,
cid: str, cid: str,
obj_list: list, obj_list: list,
object_size: int, object_size: int,
shell: Shell,
bearer: Optional[str] = None, bearer: Optional[str] = None,
): ):
""" """
@ -189,15 +241,25 @@ class TestStorageGroup:
Put, List, Get and Delete the Storage Group which contains Put, List, Get and Delete the Storage Group which contains
the Object. the Object.
""" """
storage_group = put_storagegroup(wallet, cid, obj_list, bearer) storage_group = put_storagegroup(shell, wallet, cid, obj_list, bearer)
verify_list_storage_group(wallet, cid, storage_group, bearer) verify_list_storage_group(
verify_get_storage_group(wallet, cid, storage_group, obj_list, object_size, shell, bearer) shell=shell, wallet=wallet, cid=cid, gid=storage_group, bearer=bearer
delete_storagegroup(wallet, cid, storage_group, 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 @staticmethod
@allure.step("Run Storage Group Operations And Expect Failure") @allure.step("Run Storage Group Operations And Expect Failure")
def expect_failure_for_storagegroup_operations( 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 This func verifies if the Object's owner isn't allowed to
@ -205,36 +267,43 @@ class TestStorageGroup:
the Object. the Object.
""" """
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED): 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): 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): 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): with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
delete_storagegroup(wallet, cid, storagegroup) delete_storagegroup(shell=shell, wallet=wallet, cid=cid, gid=gid)
@staticmethod @staticmethod
@allure.step("Run Storage Group Operations On Other's Behalf In RO Container") @allure.step("Run Storage Group Operations On Other's Behalf In RO Container")
def storagegroup_operations_by_other_ro_container( def storagegroup_operations_by_other_ro_container(
shell: Shell,
owner_wallet: str, owner_wallet: str,
other_wallet: str, other_wallet: str,
cid: str, cid: str,
obj_list: list, obj_list: list,
object_size: int, 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): with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED):
put_storagegroup(other_wallet, cid, obj_list) put_storagegroup(shell=shell, wallet=other_wallet, cid=cid, objects=obj_list)
verify_list_storage_group(other_wallet, cid, storage_group) verify_list_storage_group(shell=shell, wallet=other_wallet, cid=cid, gid=storage_group)
verify_get_storage_group(other_wallet, cid, storage_group, obj_list, object_size, shell) 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): 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 @staticmethod
@allure.step("Run Storage Group Operations On Systems's Behalf In RO Container") @allure.step("Run Storage Group Operations On Systems's Behalf In RO Container")
def storagegroup_operations_by_system_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 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_path=IR_WALLET_PATH,
wallet_from_password=IR_WALLET_PASS, 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): 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( verify_list_storage_group(
IR_WALLET_PATH, cid, storage_group, wallet_config=IR_WALLET_CONFIG IR_WALLET_PATH, cid, storage_group, wallet_config=IR_WALLET_CONFIG
) )
verify_get_storage_group( verify_get_storage_group(
IR_WALLET_PATH, shell=shell,
cid, wallet=IR_WALLET_PATH,
storage_group, cid=cid,
obj_list, gid=storage_group,
object_size, obj_list=obj_list,
shell, object_size=object_size,
wallet_config=IR_WALLET_CONFIG, wallet_config=IR_WALLET_CONFIG,
) )
with pytest.raises(Exception, match=OBJECT_ACCESS_DENIED): 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") @allure.title("Test balance request with wallet and address")
def test_balance_wallet_address(self, client_shell): def test_balance_wallet_address(self, client_shell):
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG) cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.accounting.balance( result = cli.accounting.balance(
wallet=self.user_wallet, wallet=self.user_wallet,
rpc_endpoint=NEOFS_ENDPOINT, rpc_endpoint=NEOFS_ENDPOINT,
address=self.address, 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") @allure.title("Test balance request with wallet only")
def test_balance_wallet(self, client_shell): def test_balance_wallet(self, client_shell):
cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG) cli = NeofsCli(client_shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT) result = cli.accounting.balance(wallet=self.user_wallet, rpc_endpoint=NEOFS_ENDPOINT)
assert int(output.stdout.rstrip()) == DEPOSIT_AMOUNT assert int(result.stdout.rstrip()) == DEPOSIT_AMOUNT
@allure.title("Test balance request with wallet and wrong address") @allure.title("Test balance request with wallet and wrong address")
def test_balance_wrong_address(self, client_shell): def test_balance_wrong_address(self, client_shell):

View file

@ -2,20 +2,13 @@ import random
import allure import allure
import pytest 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 file_helper import generate_file
from grpc_responses import SESSION_NOT_FOUND from grpc_responses import SESSION_NOT_FOUND
from neofs_testlib.shell import Shell from neofs_testlib.shell import Shell
from neofs_testlib.utils.wallet import get_last_address_from_wallet from neofs_testlib.utils.wallet import get_last_address_from_wallet
from python_keywords.container import create_container from python_keywords.container import create_container
from python_keywords.neofs_verbs import ( from python_keywords.neofs_verbs import delete_object, put_object
delete_object,
get_object,
get_range,
head_object,
put_object,
search_object,
)
from python_keywords.session_token import create_session_token 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: Steps:
1. Create a private container 1. Create a private container
2. Obj operation requests to the node which IS NOT in the container but granted with a session token 2. Obj operation requests to the node which IS NOT in the container but granted
3. Obj operation requests to the node which IS in the container and NOT granted with a session token with a session token
4. Obj operation requests to the node which IS NOT in the container and NOT 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"): 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"] noncontainer_node = NEOFS_NETMAP_DICT[noncontainer_node_name]["rpc"]
with allure.step("Create Session Token"): 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"): with allure.step("Create Private Container"):
un_locode = NEOFS_NETMAP_DICT[container_node_name]["UN-LOCODE"] 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 allure
import base58 import base58
from cli_helpers import _cmd_run
from common import ASSETS_DIR, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG from common import ASSETS_DIR, NEOFS_CLI_EXEC, NEOFS_ENDPOINT, WALLET_CONFIG
from data_formatters import get_wallet_public_key from data_formatters import get_wallet_public_key
from neofs_testlib.cli import NeofsCli from neofs_testlib.cli import NeofsCli
@ -120,14 +119,14 @@ class EACLRule:
def get_eacl(wallet_path: str, cid: str, shell: Shell) -> Optional[str]: def get_eacl(wallet_path: str, cid: str, shell: Shell) -> Optional[str]:
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG) cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
try: 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: except RuntimeError as exc:
logger.info("Extended ACL table is not set for this container") logger.info("Extended ACL table is not set for this container")
logger.info(f"Got exception while getting eacl: {exc}") logger.info(f"Got exception while getting eacl: {exc}")
return None 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 None
return output.stdout return result.stdout
@allure.title("Set extended ACL") @allure.title("Set extended ACL")
@ -208,7 +207,7 @@ def form_bearertoken_file(
json.dump(eacl_result, eacl_file, ensure_ascii=False, indent=4) json.dump(eacl_result, eacl_file, ensure_ascii=False, indent=4)
logger.info(f"Got these extended ACL records: {eacl_result}") logger.info(f"Got these extended ACL records: {eacl_result}")
sign_bearer(wif, file_path) sign_bearer(shell, wif, file_path)
return file_path return file_path
@ -235,12 +234,11 @@ def eacl_rules(access: str, verbs: list, user: str) -> list[str]:
return rules return rules
def sign_bearer(wallet_path: str, eacl_rules_file: str) -> None: def sign_bearer(shell: Shell, wallet_path: str, eacl_rules_file: str) -> None:
cmd = ( neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=WALLET_CONFIG)
f"{NEOFS_CLI_EXEC} util sign bearer-token --from {eacl_rules_file} " neofscli.util.sign_bearer_token(
f"--to {eacl_rules_file} --wallet {wallet_path} --config {WALLET_CONFIG} --json" 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") @allure.title("Wait for eACL cache expired")

View file

@ -59,7 +59,7 @@ def create_container(
""" """
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG) cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG)
output = cli.container.create( result = cli.container.create(
rpc_endpoint=NEOFS_ENDPOINT, rpc_endpoint=NEOFS_ENDPOINT,
wallet=session_wallet if session_wallet else wallet, wallet=session_wallet if session_wallet else wallet,
policy=rule, policy=rule,
@ -71,7 +71,7 @@ def create_container(
**options or {}, **options or {},
) )
cid = _parse_cid(output.stdout) cid = _parse_cid(result.stdout)
logger.info("Container created; waiting until it is persisted in the sidechain") 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 (list): list of containers
""" """
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG) 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}") logger.info(f"Containers: \n{output}")
return output.stdout.split() return result.stdout.split()
@allure.step("Get Container") @allure.step("Get Container")
@ -146,14 +146,14 @@ def get_container(
(dict, str): dict of container attributes (dict, str): dict of container attributes
""" """
cli = NeofsCli(shell, NEOFS_CLI_EXEC, WALLET_CONFIG) 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 rpc_endpoint=NEOFS_ENDPOINT, wallet=wallet, cid=cid, json_mode=json_mode
) )
if not 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() attributes = dict()
for attr in container_info["attributes"]: for attr in container_info["attributes"]:
attributes[attr["key"]] = attr["value"] 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) 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, rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet, wallet=wallet,
cid=cid, cid=cid,
@ -113,7 +113,7 @@ def get_range_hash(
) )
# cutting off output about range offset and length # cutting off output about range offset and length
return output.stdout.split(":")[1].strip() return result.stdout.split(":")[1].strip()
@allure.step("Put object") @allure.step("Put object")
@ -156,7 +156,7 @@ def put_object(
logger.info(f"---DEB:\n{NEOFS_NETMAP}") logger.info(f"---DEB:\n{NEOFS_NETMAP}")
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG) cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG)
output = cli.object.put( result = cli.object.put(
rpc_endpoint=endpoint, rpc_endpoint=endpoint,
wallet=wallet, wallet=wallet,
file=path, file=path,
@ -170,7 +170,7 @@ def put_object(
) )
# splitting CLI output to lines and taking the penultimate line # 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] oid = id_str.split(":")[1]
return oid.strip() return oid.strip()
@ -204,7 +204,7 @@ def delete_object(
(str): Tombstone ID (str): Tombstone ID
""" """
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG) 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, rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet, wallet=wallet,
cid=cid, cid=cid,
@ -214,7 +214,7 @@ def delete_object(
session=session, session=session,
) )
id_str = output.stdout.split("\n")[1] id_str = result.stdout.split("\n")[1]
tombstone = id_str.split(":")[1] tombstone = id_str.split(":")[1]
return tombstone.strip() return tombstone.strip()
@ -301,7 +301,7 @@ def search_object(
""" """
cli = NeofsCli(shell, NEOFS_CLI_EXEC, wallet_config or WALLET_CONFIG) 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, rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet, wallet=wallet,
cid=cid, cid=cid,
@ -313,7 +313,7 @@ def search_object(
session=session, 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 expected_objects_list:
if sorted(found_objects) == sorted(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) 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, rpc_endpoint=endpoint or NEOFS_ENDPOINT,
wallet=wallet, wallet=wallet,
cid=cid, cid=cid,
@ -386,18 +386,18 @@ def head_object(
) )
if not json_output: if not json_output:
return output return result
try: try:
decoded = json.loads(output.stdout) decoded = json.loads(result.stdout)
except Exception as exc: except Exception as exc:
# If we failed to parse output as JSON, the cause might be # If we failed to parse output as JSON, the cause might be
# the plain text string in the beginning of the output. # the plain text string in the beginning of the output.
# Here we cut off first string and try to parse again. # Here we cut off first string and try to parse again.
logger.info(f"failed to parse output: {exc}") logger.info(f"failed to parse output: {exc}")
logger.info("parsing output in another way") logger.info("parsing output in another way")
fst_line_idx = output.stdout.find("\n") fst_line_idx = result.stdout.find("\n")
decoded = json.loads(output.stdout[fst_line_idx:]) decoded = json.loads(result.stdout[fst_line_idx:])
# If response is Complex Object header, it has `splitId` key # If response is Complex Object header, it has `splitId` key
if "splitId" in decoded.keys(): if "splitId" in decoded.keys():

View file

@ -139,16 +139,14 @@ def transfer_gas(
the assets will be transferred to the last one. the assets will be transferred to the last one.
Args: Args:
shell: Shell instance. shell: Shell instance.
wallet_from_password: password of the wallet; it is wallet_from_password: Password of the wallet; it is required to decode the wallet
required to decode the wallet and extract its addresses and extract its addresses.
wallet_from_path: path to chain node wallet wallet_from_path: Path to chain node wallet.
address_from: the address of the wallet to transfer assets from 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_path: The path to the wallet to transfer assets to.
wallet_to_password: the password 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 address_to: The address of the wallet to transfer assets to.
amount: amount of gas to transfer amount: Amount of gas to transfer.
Returns:
(void)
""" """
address_to = address_to or get_last_address_from_wallet(wallet_to_path, wallet_to_password) 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 allure
import json_transformers 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 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 from neo3 import wallet
logger = logging.getLogger("NeoLogger") 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") @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. Create session token for an object.
Args: Args:
owner(str): user that writes the token shell: Shell instance.
session_wallet(str): the path to wallet to which we grant the owner: User that writes the token.
access via session 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: 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())) session_token = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = ( neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC)
f"{NEOFS_CLI_EXEC} session create --address {owner} -w {wallet_path} " neofscli.session.create(
f"--out {session_token} --rpc-endpoint {rpc}" rpc_endpoint=rpc_endpoint,
address=owner,
wallet=wallet_path,
wallet_password=wallet_password,
out=session_token,
) )
_run_with_passwd(cmd)
return session_token return session_token
@allure.step("Sign 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. This function signs the session token by the given wallet.
Args: Args:
session_token(str): the path to the session token file shell: Shell instance.
wlt(str): the path to the signing wallet session_token_file: The path to the session token file.
wlt: The path to the signing wallet.
Returns: 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())) signed_token_file = os.path.join(os.getcwd(), ASSETS_DIR, str(uuid.uuid4()))
cmd = ( neofscli = NeofsCli(shell=shell, neofs_cli_exec_path=NEOFS_CLI_EXEC, config_file=WALLET_CONFIG)
f"{NEOFS_CLI_EXEC} util sign session-token --from {session_token} " neofscli.util.sign_session_token(
f"-w {wlt} --to {signed_token} --config {WALLET_CONFIG}" wallet=wlt, from_file=session_token_file, to_file=signed_token_file
) )
_cmd_run(cmd) return signed_token_file
return signed_token

View file

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