2022-08-25 10:57:55 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import allure
|
2023-02-17 15:12:11 +00:00
|
|
|
from frostfs_testlib.resources.common import OBJECT_ACCESS_DENIED
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.shell import Shell
|
2023-02-19 23:58:07 +00:00
|
|
|
from frostfs_testlib.utils import string_utils
|
2023-02-27 16:54:27 +00:00
|
|
|
|
|
|
|
from pytest_tests.helpers.cluster import Cluster
|
|
|
|
from pytest_tests.helpers.file_helper import get_file_hash
|
|
|
|
from pytest_tests.helpers.frostfs_verbs 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-03-09 11:41:38 +00:00
|
|
|
from pytest_tests.resources.common import CLI_DEFAULT_TIMEOUT
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
OPERATION_ERROR_TYPE = RuntimeError
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_object(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
2023-02-27 17:28:56 +00:00
|
|
|
with allure.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
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.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,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
2023-02-27 17:28:56 +00:00
|
|
|
with allure.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,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: 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:
|
|
|
|
with allure.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,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: 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:
|
|
|
|
with allure.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",
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: 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:
|
|
|
|
with allure.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",
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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(
|
|
|
|
wallet: str,
|
|
|
|
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,
|
|
|
|
wallet_config: 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:
|
|
|
|
with allure.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,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
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:
|
2023-02-19 23:58:07 +00:00
|
|
|
assert string_utils.is_str_match_pattern(
|
2022-09-28 12:07:16 +00:00
|
|
|
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
|