[#206] Overhaul credentials work

Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
Andrey Berezin 2024-03-11 19:34:54 +03:00
parent 6af5ad9de5
commit b61dd7b39c
27 changed files with 384 additions and 494 deletions

View file

@ -1,9 +1,11 @@
import logging
import re
from datetime import datetime
import allure
import pytest
from frostfs_testlib import reporter
from frostfs_testlib.credentials.interfaces import CredentialsProvider, User
from frostfs_testlib.resources.common import STORAGE_GC_TIME
from frostfs_testlib.resources.error_patterns import (
LIFETIME_REQUIRED,
@ -25,7 +27,7 @@ from frostfs_testlib.steps.storage_policy import get_nodes_with_object
from frostfs_testlib.storage.cluster import Cluster
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
from frostfs_testlib.storage.dataclasses.storage_object_info import LockObjectInfo, StorageObjectInfo
from frostfs_testlib.storage.dataclasses.wallet import WalletFactory, WalletInfo
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
from frostfs_testlib.testing.test_control import expect_not_raises, wait_for_success
from frostfs_testlib.utils import datetime_utils
@ -38,26 +40,20 @@ FIXTURE_LOCK_LIFETIME = 5
FIXTURE_OBJECT_LIFETIME = 10
@pytest.fixture(
scope="module",
)
def user_wallet(wallet_factory: WalletFactory):
@pytest.fixture(scope="module")
def user_wallet(credentials_provider: CredentialsProvider, cluster: Cluster) -> WalletInfo:
with reporter.step("Create user wallet with container"):
wallet_file = wallet_factory.create_wallet()
return wallet_file
user = User(f"user_{hex(int(datetime.now().timestamp() * 1000000))}")
return credentials_provider.GRPC.provide(user, cluster.cluster_nodes[0])
@pytest.fixture(
scope="module",
)
@pytest.fixture(scope="module")
def user_container(user_wallet: WalletInfo, client_shell: Shell, cluster: Cluster):
container_id = create_container(user_wallet.path, shell=client_shell, endpoint=cluster.default_rpc_endpoint)
container_id = create_container(user_wallet, shell=client_shell, endpoint=cluster.default_rpc_endpoint)
return StorageContainer(StorageContainerInfo(container_id, user_wallet), client_shell, cluster)
@pytest.fixture(
scope="module",
)
@pytest.fixture(scope="module")
def locked_storage_object(
user_container: StorageContainer,
client_shell: Shell,
@ -75,7 +71,7 @@ def locked_storage_object(
object_size.value, expire_at=current_epoch + FIXTURE_OBJECT_LIFETIME
)
lock_object_id = lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
client_shell,
@ -98,7 +94,7 @@ def locked_storage_object(
tick_epoch(client_shell, cluster)
try:
delete_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
client_shell,
@ -113,10 +109,10 @@ def locked_storage_object(
@wait_for_success(datetime_utils.parse_time(STORAGE_GC_TIME))
def check_object_not_found(wallet_file_path: str, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
def check_object_not_found(wallet: WalletInfo, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
head_object(
wallet_file_path,
wallet,
cid,
oid,
shell,
@ -124,10 +120,10 @@ def check_object_not_found(wallet_file_path: str, cid: str, oid: str, shell: She
)
def verify_object_available(wallet_file_path: str, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
def verify_object_available(wallet: WalletInfo, cid: str, oid: str, shell: Shell, rpc_endpoint: str):
with expect_not_raises():
head_object(
wallet_file_path,
wallet,
cid,
oid,
shell,
@ -150,7 +146,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
object_size.value, expire_at=current_epoch + FIXTURE_OBJECT_LIFETIME
)
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -170,7 +166,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
"""
with pytest.raises(Exception, match=OBJECT_IS_LOCKED):
delete_object(
locked_storage_object.wallet_file_path,
locked_storage_object.wallet,
locked_storage_object.cid,
locked_storage_object.oid,
self.shell,
@ -189,7 +185,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
"""
lock_object = locked_storage_object.locks[0]
wallet_path = locked_storage_object.wallet_file_path
wallet_path = locked_storage_object.wallet
with pytest.raises(Exception, match=LOCK_OBJECT_REMOVAL):
delete_object(
@ -212,7 +208,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
"""
lock_object_info = locked_storage_object.locks[0]
wallet_path = locked_storage_object.wallet_file_path
wallet_path = locked_storage_object.wallet
with pytest.raises(Exception, match=LOCK_NON_REGULAR_OBJECT):
lock_object(
@ -252,7 +248,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
"""
lock_object_info = locked_storage_object.locks[0]
wallet_path = locked_storage_object.wallet_file_path
wallet_path = locked_storage_object.wallet
with pytest.raises(Exception, match=expected_error):
lock_object(
@ -281,7 +277,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Lock object for couple epochs"):
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -289,7 +285,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
lifetime=2,
)
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -303,7 +299,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
wait_for_gc_pass_on_storage_nodes()
with expect_not_raises():
head_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -313,7 +309,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Wait for object to be deleted after third epoch"):
self.tick_epoch()
check_object_not_found(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -338,7 +334,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
storage_objects.append(user_container.generate_object(object_size.value, expire_at=current_epoch + 5))
lock_object(
storage_objects[0].wallet_file_path,
storage_objects[0].wallet,
storage_objects[0].cid,
",".join([storage_object.oid for storage_object in storage_objects]),
self.shell,
@ -350,7 +346,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step(f"Try to delete object {storage_object.oid}"):
with pytest.raises(Exception, match=OBJECT_IS_LOCKED):
delete_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -384,7 +380,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
match=LOCK_OBJECT_EXPIRATION.format(expiration_epoch=expiration_epoch, current_epoch=current_epoch),
):
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -408,7 +404,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
storage_object = user_container.generate_object(object_size.value, expire_at=current_epoch + 5)
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -419,7 +415,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
self.tick_epochs(2)
with expect_not_raises():
delete_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -442,7 +438,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
storage_object = user_container.generate_object(object_size.value, expire_at=current_epoch + 5)
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -454,7 +450,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with expect_not_raises():
delete_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -481,7 +477,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step(f"Try to delete chunk object {chunk_object_id}"):
with pytest.raises(Exception, match=OBJECT_IS_LOCKED):
delete_object(
locked_storage_object.wallet_file_path,
locked_storage_object.wallet,
locked_storage_object.cid,
chunk_object_id,
self.shell,
@ -498,7 +494,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
)
def test_link_object_of_locked_complex_object_can_be_dropped(self, new_locked_storage_object: StorageObjectInfo):
link_object_id = get_link_object(
new_locked_storage_object.wallet_file_path,
new_locked_storage_object.wallet,
new_locked_storage_object.cid,
new_locked_storage_object.oid,
self.shell,
@ -569,7 +565,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
"""
link_object_id = get_link_object(
locked_storage_object.wallet_file_path,
locked_storage_object.wallet,
locked_storage_object.cid,
locked_storage_object.oid,
self.shell,
@ -579,7 +575,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step(f"Try to delete link object {link_object_id}"):
with pytest.raises(Exception, match=OBJECT_IS_LOCKED):
delete_object(
locked_storage_object.wallet_file_path,
locked_storage_object.wallet,
locked_storage_object.cid,
link_object_id,
self.shell,
@ -597,7 +593,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Apply first lock to object for 3 epochs"):
lock_object_id_0 = lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -609,7 +605,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Check first lock is still available"):
verify_object_available(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
lock_object_id_0,
self.shell,
@ -618,7 +614,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Apply second lock to object for 3 more epochs"):
lock_object_id_1 = lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -630,7 +626,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Verify first lock is expired and removed"):
check_object_not_found(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
lock_object_id_0,
self.shell,
@ -639,7 +635,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Verify second lock is still available"):
verify_object_available(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
lock_object_id_1,
self.shell,
@ -648,7 +644,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Apply third lock to object for 3 more epochs"):
lock_object(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -659,7 +655,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Verify object is deleted after all locks are expired"):
self.tick_epochs(4)
check_object_not_found(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -687,7 +683,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step("Lock objects for 4 epochs"):
lock_object(
storage_objects[0].wallet_file_path,
storage_objects[0].wallet,
storage_objects[0].cid,
",".join([storage_object.oid for storage_object in storage_objects]),
self.shell,
@ -701,7 +697,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
with reporter.step(f"Check objects at epoch {current_epoch + epoch_i + 2}"):
for storage_object in storage_objects:
verify_object_available(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,
@ -712,7 +708,7 @@ class TestObjectLockWithGrpc(ClusterTestBase):
self.tick_epoch()
for storage_object in storage_objects:
check_object_not_found(
storage_object.wallet_file_path,
storage_object.wallet,
storage_object.cid,
storage_object.oid,
self.shell,