2022-08-25 10:57:55 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.cli import CLI_DEFAULT_TIMEOUT
|
2024-10-02 12:30:39 +00:00
|
|
|
from frostfs_testlib.resources.error_patterns import OBJECT_ACCESS_DENIED
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.shell import Shell
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.cli.object import (
|
2022-09-28 12:07:16 +00:00
|
|
|
delete_object,
|
2022-12-05 22:31:45 +00:00
|
|
|
get_object_from_random_node,
|
2022-09-28 12:07:16 +00:00
|
|
|
get_range,
|
|
|
|
get_range_hash,
|
|
|
|
head_object,
|
2022-12-05 22:31:45 +00:00
|
|
|
put_object_to_random_node,
|
2022-09-28 12:07:16 +00:00
|
|
|
search_object,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
2024-03-11 16:34:54 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils import string_utils
|
|
|
|
from frostfs_testlib.utils.file_utils import get_file_hash
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
OPERATION_ERROR_TYPE = RuntimeError
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try get object from container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-12-05 22:31:45 +00:00
|
|
|
got_file_path = get_object_from_random_node(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-10-13 16:13:45 +00:00
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster=cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
assert get_file_hash(file_name) == get_file_hash(got_file_path)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_put_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try put object to container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-12-05 22:31:45 +00:00
|
|
|
put_object_to_random_node(
|
2022-09-28 12:07:16 +00:00
|
|
|
wallet,
|
|
|
|
file_name,
|
|
|
|
cid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
attributes=attributes,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster=cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-08-07 14:29:46 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_delete_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try delete object from container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-10-13 18:53:44 +00:00
|
|
|
delete_object(
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
|
|
|
endpoint=endpoint,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_head_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout: Optional[str] = CLI_DEFAULT_TIMEOUT,
|
2022-09-28 12:07:16 +00:00
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try get head of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
head_object(
|
2022-10-13 18:53:44 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint=endpoint,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout=timeout,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_range_of_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout: Optional[str] = CLI_DEFAULT_TIMEOUT,
|
2022-09-28 12:07:16 +00:00
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try get range of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
get_range(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer=bearer,
|
|
|
|
range_cut="0:10",
|
|
|
|
xhdr=xhdr,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint=endpoint,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout=timeout,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_range_hash_of_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout: Optional[str] = CLI_DEFAULT_TIMEOUT,
|
2022-09-28 12:07:16 +00:00
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try get range hash of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
get_range_hash(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
2022-10-18 10:39:39 +00:00
|
|
|
bearer=bearer,
|
2022-09-28 12:07:16 +00:00
|
|
|
range_cut="0:10",
|
|
|
|
xhdr=xhdr,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint=endpoint,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout=timeout,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_search_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint: str,
|
2022-09-28 12:07:16 +00:00
|
|
|
oid: Optional[str] = None,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout: Optional[str] = CLI_DEFAULT_TIMEOUT,
|
2022-09-28 12:07:16 +00:00
|
|
|
) -> bool:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try search object in container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-10-13 18:53:44 +00:00
|
|
|
oids = search_object(
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
|
|
|
endpoint=endpoint,
|
2023-03-09 11:41:38 +00:00
|
|
|
timeout=timeout,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2024-10-02 12:30:39 +00:00
|
|
|
assert string_utils.is_str_match_pattern(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
if oid:
|
|
|
|
return oid in oids
|
|
|
|
return True
|