2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-08-19 02:22:20 +00:00
|
|
|
from common import COMPLEX_OBJ_SIZE, SIMPLE_OBJ_SIZE
|
2022-07-12 09:59:19 +00:00
|
|
|
from container import create_container
|
2022-07-08 17:24:55 +00:00
|
|
|
from epoch import get_epoch, tick_epoch
|
2022-10-11 15:15:50 +00:00
|
|
|
from file_helper import generate_file, get_file_content, get_file_hash
|
2022-08-12 16:44:10 +00:00
|
|
|
from grpc_responses import OBJECT_ALREADY_REMOVED, OBJECT_NOT_FOUND, error_matches_status
|
2022-09-28 12:07:16 +00:00
|
|
|
from python_keywords.neofs_verbs import (
|
|
|
|
delete_object,
|
|
|
|
get_object,
|
|
|
|
get_range,
|
|
|
|
get_range_hash,
|
|
|
|
head_object,
|
|
|
|
put_object,
|
|
|
|
search_object,
|
|
|
|
)
|
2022-10-04 05:55:09 +00:00
|
|
|
from python_keywords.storage_policy import get_complex_object_copies, get_simple_object_copies
|
2022-07-14 07:33:45 +00:00
|
|
|
from tombstone import verify_head_tombstone
|
2022-10-11 15:15:50 +00:00
|
|
|
from utility import wait_for_gc_pass_on_storage_nodes
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
CLEANUP_TIMEOUT = 10
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Test native object API")
|
2022-07-05 07:18:37 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.grpc_api
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"object_size", [SIMPLE_OBJ_SIZE, COMPLEX_OBJ_SIZE], ids=["simple object", "complex object"]
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
def test_object_api(prepare_wallet_and_deposit, request, object_size):
|
|
|
|
"""
|
|
|
|
Test common gRPC API for object (put/get/head/get_range_hash/get_range/search/delete).
|
|
|
|
"""
|
2022-10-04 05:55:09 +00:00
|
|
|
allure.dynamic.title(f"Test native object API for {request.node.callspec.id}")
|
|
|
|
|
2022-07-12 09:59:19 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
cid = create_container(wallet)
|
2022-09-28 12:07:16 +00:00
|
|
|
wallet_cid = {"wallet": wallet, "cid": cid}
|
|
|
|
file_usr_header = {"key1": 1, "key2": "abc", "common_key": "common_value"}
|
|
|
|
file_usr_header_oth = {"key1": 2, "common_key": "common_value"}
|
|
|
|
common_header = {"common_key": "common_value"}
|
2022-07-08 17:24:55 +00:00
|
|
|
range_len = 10
|
2022-09-28 12:07:16 +00:00
|
|
|
range_cut = f"0:{range_len}"
|
2022-07-08 17:24:55 +00:00
|
|
|
file_path = generate_file(object_size)
|
2022-07-05 10:17:36 +00:00
|
|
|
file_hash = get_file_hash(file_path)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-10-04 05:55:09 +00:00
|
|
|
with allure.step("Check container is empty"):
|
|
|
|
search_object(**wallet_cid, expected_objects_list=[])
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-10-04 05:55:09 +00:00
|
|
|
oids = []
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Put objects"):
|
2022-07-05 10:17:36 +00:00
|
|
|
oids.append(put_object(wallet=wallet, path=file_path, cid=cid))
|
2022-08-25 10:57:55 +00:00
|
|
|
oids.append(put_object(wallet=wallet, path=file_path, cid=cid, attributes=file_usr_header))
|
2022-09-28 12:07:16 +00:00
|
|
|
oids.append(
|
|
|
|
put_object(wallet=wallet, path=file_path, cid=cid, attributes=file_usr_header_oth)
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Validate storage policy for objects"):
|
2022-07-05 07:18:37 +00:00
|
|
|
for oid_to_check in oids:
|
2022-10-04 05:55:09 +00:00
|
|
|
if object_size == SIMPLE_OBJ_SIZE:
|
|
|
|
copies = get_simple_object_copies(wallet=wallet, cid=cid, oid=oid_to_check)
|
|
|
|
else:
|
|
|
|
copies = get_complex_object_copies(wallet=wallet, cid=cid, oid=oid_to_check)
|
|
|
|
assert copies == 2, "Expected 2 copies"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Get objects and compare hashes"):
|
2022-07-05 07:18:37 +00:00
|
|
|
for oid_to_check in oids:
|
|
|
|
got_file_path = get_object(wallet=wallet, cid=cid, oid=oid_to_check)
|
|
|
|
got_file_hash = get_file_hash(got_file_path)
|
|
|
|
assert file_hash == got_file_hash
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Get range/range hash"):
|
|
|
|
range_hash = get_range_hash(**wallet_cid, oid=oids[0], bearer_token="", range_cut=range_cut)
|
|
|
|
assert (
|
|
|
|
get_file_hash(file_path, range_len) == range_hash
|
|
|
|
), f"Expected range hash to match {range_cut} slice of file payload"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
range_hash = get_range_hash(**wallet_cid, oid=oids[1], bearer_token="", range_cut=range_cut)
|
|
|
|
assert (
|
|
|
|
get_file_hash(file_path, range_len) == range_hash
|
|
|
|
), f"Expected range hash to match {range_cut} slice of file payload"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
_, range_content = get_range(**wallet_cid, oid=oids[1], bearer="", range_cut=range_cut)
|
|
|
|
assert (
|
|
|
|
get_file_content(file_path, content_len=range_len, mode="rb") == range_content
|
|
|
|
), f"Expected range content to match {range_cut} slice of file payload"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Search objects"):
|
2022-07-05 07:18:37 +00:00
|
|
|
search_object(**wallet_cid, expected_objects_list=oids)
|
|
|
|
search_object(**wallet_cid, filters=file_usr_header, expected_objects_list=oids[1:2])
|
|
|
|
search_object(**wallet_cid, filters=file_usr_header_oth, expected_objects_list=oids[2:3])
|
2022-07-08 17:24:55 +00:00
|
|
|
search_object(**wallet_cid, filters=common_header, expected_objects_list=oids[1:3])
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Head object and validate"):
|
2022-07-05 07:18:37 +00:00
|
|
|
head_object(**wallet_cid, oid=oids[0])
|
|
|
|
head_info = head_object(**wallet_cid, oid=oids[1])
|
|
|
|
check_header_is_presented(head_info, file_usr_header)
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Delete objects"):
|
2022-07-05 07:18:37 +00:00
|
|
|
tombstone_s = delete_object(**wallet_cid, oid=oids[0])
|
|
|
|
tombstone_h = delete_object(**wallet_cid, oid=oids[1])
|
|
|
|
|
|
|
|
verify_head_tombstone(wallet_path=wallet, cid=cid, oid_ts=tombstone_s, oid=oids[0])
|
|
|
|
verify_head_tombstone(wallet_path=wallet, cid=cid, oid_ts=tombstone_h, oid=oids[1])
|
|
|
|
|
|
|
|
tick_epoch()
|
|
|
|
sleep(CLEANUP_TIMEOUT)
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Get objects and check errors"):
|
2022-08-12 16:44:10 +00:00
|
|
|
get_object_and_check_error(**wallet_cid, oid=oids[0], error_pattern=OBJECT_ALREADY_REMOVED)
|
|
|
|
get_object_and_check_error(**wallet_cid, oid=oids[1], error_pattern=OBJECT_ALREADY_REMOVED)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Test object life time")
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.grpc_api
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"object_size", [SIMPLE_OBJ_SIZE, COMPLEX_OBJ_SIZE], ids=["simple object", "complex object"]
|
|
|
|
)
|
2022-07-21 15:05:34 +00:00
|
|
|
def test_object_api_lifetime(prepare_wallet_and_deposit, request, object_size):
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
Test object deleted after expiration epoch.
|
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
cid = create_container(wallet)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.dynamic.title(f"Test object life time for {request.node.callspec.id}")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
file_path = generate_file(object_size)
|
|
|
|
file_hash = get_file_hash(file_path)
|
|
|
|
epoch = get_epoch()
|
|
|
|
|
2022-08-19 02:22:20 +00:00
|
|
|
oid = put_object(wallet, file_path, cid, expire_at=epoch + 1)
|
2022-07-08 17:24:55 +00:00
|
|
|
got_file = get_object(wallet, cid, oid)
|
|
|
|
assert get_file_hash(got_file) == file_hash
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Tick two epochs"):
|
2022-07-21 12:11:59 +00:00
|
|
|
for _ in range(2):
|
2022-07-08 17:24:55 +00:00
|
|
|
tick_epoch()
|
|
|
|
|
2022-07-21 12:11:59 +00:00
|
|
|
# Wait for GC, because object with expiration is counted as alive until GC removes it
|
2022-07-27 10:42:29 +00:00
|
|
|
wait_for_gc_pass_on_storage_nodes()
|
2022-07-21 12:11:59 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Check object deleted because it expires-on epoch"):
|
2022-08-12 16:44:10 +00:00
|
|
|
with pytest.raises(Exception, match=OBJECT_NOT_FOUND):
|
2022-07-08 17:24:55 +00:00
|
|
|
get_object(wallet, cid, oid)
|
|
|
|
|
|
|
|
|
2022-08-12 16:44:10 +00:00
|
|
|
def get_object_and_check_error(wallet: str, cid: str, oid: str, error_pattern: str) -> None:
|
2022-07-05 07:18:37 +00:00
|
|
|
try:
|
|
|
|
get_object(wallet=wallet, cid=cid, oid=oid)
|
2022-09-28 12:07:16 +00:00
|
|
|
raise AssertionError(f"Expected object {oid} removed, but it is not")
|
2022-07-05 07:18:37 +00:00
|
|
|
except Exception as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
logger.info(f"Error is {err}")
|
|
|
|
assert error_matches_status(err, error_pattern), f"Expected {err} to match {error_pattern}"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_header_is_presented(head_info: dict, object_header: dict):
|
|
|
|
for key_to_check, val_to_check in object_header.items():
|
2022-09-28 12:07:16 +00:00
|
|
|
assert (
|
|
|
|
key_to_check in head_info["header"]["attributes"]
|
|
|
|
), f"Key {key_to_check} is found in {head_object}"
|
|
|
|
assert head_info["header"]["attributes"].get(key_to_check) == str(
|
|
|
|
val_to_check
|
|
|
|
), f"Value {val_to_check} is equal"
|