2022-07-05 07:18:37 +00:00
|
|
|
import logging
|
2022-07-05 10:17:36 +00:00
|
|
|
import os
|
2022-12-05 22:31:45 +00:00
|
|
|
import random
|
2022-07-05 07:18:37 +00:00
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-07-05 10:17:36 +00:00
|
|
|
from epoch import get_epoch, tick_epoch
|
2022-10-11 08:18:08 +00:00
|
|
|
from file_helper import generate_file, get_file_hash
|
2022-12-07 12:38:56 +00:00
|
|
|
from python_keywords.container import create_container
|
2022-09-15 09:46:45 +00:00
|
|
|
from python_keywords.http_gate import (
|
|
|
|
get_via_http_curl,
|
|
|
|
get_via_http_gate,
|
|
|
|
get_via_http_gate_by_attribute,
|
|
|
|
get_via_zip_http_gate,
|
|
|
|
upload_via_http_gate,
|
|
|
|
upload_via_http_gate_curl,
|
|
|
|
)
|
2022-12-05 22:31:45 +00:00
|
|
|
from python_keywords.neofs_verbs import get_object, put_object_to_random_node
|
2022-07-05 07:18:37 +00:00
|
|
|
from python_keywords.storage_policy import get_nodes_without_object
|
2022-07-27 10:42:29 +00:00
|
|
|
from utility import wait_for_gc_pass_on_storage_nodes
|
2022-07-12 09:59:19 +00:00
|
|
|
from wellknown_acl import PUBLIC_ACL
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
from steps.cluster_test_base import ClusterTestBase
|
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-10-06 07:31:47 +00:00
|
|
|
OBJECT_NOT_FOUND_ERROR = "not found"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-21 13:52:49 +00:00
|
|
|
# For some reason object uploaded via http gateway is not immediately available for downloading
|
|
|
|
# Until this issue is resolved we are waiting for some time before attempting to read an object
|
2022-07-27 10:42:29 +00:00
|
|
|
# TODO: remove after https://github.com/nspcc-dev/neofs-http-gw/issues/176 is fixed
|
2022-07-21 13:52:49 +00:00
|
|
|
OBJECT_UPLOAD_DELAY = 10
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
|
|
|
|
@allure.link(
|
|
|
|
"https://github.com/nspcc-dev/neofs-http-gw#neofs-http-gateway", name="neofs-http-gateway"
|
|
|
|
)
|
|
|
|
@allure.link("https://github.com/nspcc-dev/neofs-http-gw#uploading", name="uploading")
|
|
|
|
@allure.link("https://github.com/nspcc-dev/neofs-http-gw#downloading", name="downloading")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
2022-07-05 07:18:37 +00:00
|
|
|
@pytest.mark.http_gate
|
2022-12-05 22:31:45 +00:00
|
|
|
class TestHttpGate(ClusterTestBase):
|
2022-11-22 11:25:14 +00:00
|
|
|
PLACEMENT_RULE_1 = "REP 1 IN X CBF 1 SELECT 1 FROM * AS X"
|
|
|
|
PLACEMENT_RULE_2 = "REP 2 IN X CBF 2 SELECT 2 FROM * AS X"
|
2022-07-12 09:59:19 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="class", autouse=True)
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("[Class/Autouse]: Prepare wallet and deposit")
|
2022-12-05 22:31:45 +00:00
|
|
|
def prepare_wallet(self, default_wallet):
|
|
|
|
TestHttpGate.wallet = default_wallet
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("Test Put over gRPC, Get over HTTP")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_put_grpc_get_http(self, complex_object_size, simple_object_size):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
|
|
|
Test that object can be put using gRPC interface and get using HTTP.
|
|
|
|
|
|
|
|
Steps:
|
|
|
|
1. Create simple and large objects.
|
|
|
|
2. Put objects using gRPC (neofs-cli).
|
|
|
|
3. Download objects using HTTP gate (https://github.com/nspcc-dev/neofs-http-gw#downloading).
|
|
|
|
4. Get objects using gRPC (neofs-cli).
|
|
|
|
5. Compare hashes for got objects.
|
|
|
|
6. Compare hashes for got and original objects.
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
Hashes must be the same.
|
|
|
|
"""
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_1,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path_simple, file_path_large = generate_file(simple_object_size), generate_file(
|
|
|
|
complex_object_size
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using gRPC"):
|
2022-12-05 22:31:45 +00:00
|
|
|
oid_simple = put_object_to_random_node(
|
|
|
|
wallet=self.wallet,
|
|
|
|
path=file_path_simple,
|
|
|
|
cid=cid,
|
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-05 22:31:45 +00:00
|
|
|
oid_large = put_object_to_random_node(
|
|
|
|
wallet=self.wallet,
|
|
|
|
path=file_path_large,
|
|
|
|
cid=cid,
|
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
for oid, file_path in ((oid_simple, file_path_simple), (oid_large, file_path_large)):
|
2022-12-05 22:31:45 +00:00
|
|
|
self.get_object_and_verify_hashes(oid, file_path, self.wallet, cid)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.link("https://github.com/nspcc-dev/neofs-http-gw#uploading", name="uploading")
|
|
|
|
@allure.link("https://github.com/nspcc-dev/neofs-http-gw#downloading", name="downloading")
|
|
|
|
@allure.title("Test Put over HTTP, Get over HTTP")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.smoke
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_put_http_get_http(self, complex_object_size, simple_object_size):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
|
|
|
Test that object can be put and get using HTTP interface.
|
|
|
|
|
|
|
|
Steps:
|
|
|
|
1. Create simple and large objects.
|
|
|
|
2. Upload objects using HTTP (https://github.com/nspcc-dev/neofs-http-gw#uploading).
|
|
|
|
3. Download objects using HTTP gate (https://github.com/nspcc-dev/neofs-http-gw#downloading).
|
|
|
|
4. Compare hashes for got and original objects.
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
Hashes must be the same.
|
|
|
|
"""
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path_simple, file_path_large = generate_file(simple_object_size), generate_file(
|
|
|
|
complex_object_size
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using HTTP"):
|
2022-12-05 22:31:45 +00:00
|
|
|
oid_simple = upload_via_http_gate(
|
|
|
|
cid=cid, path=file_path_simple, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
|
|
|
oid_large = upload_via_http_gate(
|
|
|
|
cid=cid, path=file_path_large, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
for oid, file_path in ((oid_simple, file_path_simple), (oid_large, file_path_large)):
|
2022-12-05 22:31:45 +00:00
|
|
|
self.get_object_and_verify_hashes(oid, file_path, self.wallet, cid)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.link(
|
|
|
|
"https://github.com/nspcc-dev/neofs-http-gw#by-attributes", name="download by attributes"
|
|
|
|
)
|
|
|
|
@allure.title("Test Put over HTTP, Get over HTTP with headers")
|
2022-07-12 09:59:19 +00:00
|
|
|
@pytest.mark.parametrize(
|
2022-09-15 09:46:45 +00:00
|
|
|
"attributes",
|
2022-07-12 09:59:19 +00:00
|
|
|
[
|
2022-09-15 09:46:45 +00:00
|
|
|
{"fileName": "simple_obj_filename"},
|
|
|
|
{"file-Name": "simple obj filename"},
|
|
|
|
{"cat%jpeg": "cat%jpeg"},
|
2022-07-12 09:59:19 +00:00
|
|
|
],
|
2022-09-15 09:46:45 +00:00
|
|
|
ids=["simple", "hyphen", "percent"],
|
2022-07-12 09:59:19 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_put_http_get_http_with_headers(self, attributes: dict, simple_object_size):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
|
|
|
Test that object can be downloaded using different attributes in HTTP header.
|
|
|
|
|
|
|
|
Steps:
|
|
|
|
1. Create simple and large objects.
|
|
|
|
2. Upload objects using HTTP with particular attributes in the header.
|
|
|
|
3. Download objects by attributes using HTTP gate (https://github.com/nspcc-dev/neofs-http-gw#by-attributes).
|
|
|
|
4. Compare hashes for got and original objects.
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
Hashes must be the same.
|
|
|
|
"""
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path = generate_file(simple_object_size)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using HTTP with attribute"):
|
2022-07-12 09:59:19 +00:00
|
|
|
headers = self._attr_into_header(attributes)
|
2022-12-05 22:31:45 +00:00
|
|
|
oid = upload_via_http_gate(
|
|
|
|
cid=cid,
|
|
|
|
path=file_path,
|
|
|
|
headers=headers,
|
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-21 13:52:49 +00:00
|
|
|
sleep(OBJECT_UPLOAD_DELAY)
|
|
|
|
|
2022-07-12 09:59:19 +00:00
|
|
|
self.get_object_by_attr_and_verify_hashes(oid, file_path, cid, attributes)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("Test Expiration-Epoch in HTTP header")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_expiration_epoch_in_http(self, simple_object_size):
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = self.cluster.default_rpc_endpoint
|
|
|
|
http_endpoint = self.cluster.default_http_gate_endpoint
|
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path = generate_file(simple_object_size)
|
2022-07-05 07:18:37 +00:00
|
|
|
oids = []
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
curr_epoch = get_epoch(self.shell, self.cluster)
|
2022-07-05 07:18:37 +00:00
|
|
|
epochs = (curr_epoch, curr_epoch + 1, curr_epoch + 2, curr_epoch + 100)
|
|
|
|
|
|
|
|
for epoch in epochs:
|
2022-09-15 09:46:45 +00:00
|
|
|
headers = {"X-Attribute-Neofs-Expiration-Epoch": str(epoch)}
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using HTTP with attribute Expiration-Epoch"):
|
2022-12-05 22:31:45 +00:00
|
|
|
oids.append(
|
|
|
|
upload_via_http_gate(
|
|
|
|
cid=cid, path=file_path, headers=headers, endpoint=http_endpoint
|
|
|
|
)
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
assert len(oids) == len(epochs), "Expected all objects have been put successfully"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("All objects can be get"):
|
2022-07-05 07:18:37 +00:00
|
|
|
for oid in oids:
|
2022-12-05 22:31:45 +00:00
|
|
|
get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
for expired_objects, not_expired_objects in [(oids[:1], oids[1:]), (oids[:2], oids[2:])]:
|
2022-12-05 22:31:45 +00:00
|
|
|
tick_epoch(self.shell, self.cluster)
|
2022-07-21 13:52:49 +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-05 07:18:37 +00:00
|
|
|
|
|
|
|
for oid in expired_objects:
|
2022-07-12 09:59:19 +00:00
|
|
|
self.try_to_get_object_and_expect_error(
|
2022-09-15 09:46:45 +00:00
|
|
|
cid=cid, oid=oid, error_pattern=OBJECT_NOT_FOUND_ERROR
|
2022-07-12 09:59:19 +00:00
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Other objects can be get"):
|
2022-07-05 07:18:37 +00:00
|
|
|
for oid in not_expired_objects:
|
2022-12-05 22:31:45 +00:00
|
|
|
get_via_http_gate(cid=cid, oid=oid, endpoint=http_endpoint)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("Test Zip in HTTP header")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_zip_in_http(self, complex_object_size, simple_object_size):
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path_simple, file_path_large = generate_file(simple_object_size), generate_file(
|
|
|
|
complex_object_size
|
|
|
|
)
|
2022-09-15 09:46:45 +00:00
|
|
|
common_prefix = "my_files"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
headers1 = {"X-Attribute-FilePath": f"{common_prefix}/file1"}
|
|
|
|
headers2 = {"X-Attribute-FilePath": f"{common_prefix}/file2"}
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
upload_via_http_gate(
|
|
|
|
cid=cid,
|
|
|
|
path=file_path_simple,
|
|
|
|
headers=headers1,
|
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
)
|
|
|
|
upload_via_http_gate(
|
|
|
|
cid=cid,
|
|
|
|
path=file_path_large,
|
|
|
|
headers=headers2,
|
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-21 13:52:49 +00:00
|
|
|
sleep(OBJECT_UPLOAD_DELAY)
|
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
dir_path = get_via_zip_http_gate(
|
|
|
|
cid=cid, prefix=common_prefix, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Verify hashes"):
|
|
|
|
assert get_file_hash(f"{dir_path}/file1") == get_file_hash(file_path_simple)
|
|
|
|
assert get_file_hash(f"{dir_path}/file2") == get_file_hash(file_path_large)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
@pytest.mark.long
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("Test Put over HTTP/Curl, Get over HTTP/Curl for large object")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_put_http_get_http_large_file(self, complex_object_size):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
2022-11-10 05:27:52 +00:00
|
|
|
This test checks upload and download using curl with 'large' object.
|
|
|
|
Large is object with size up to 20Mb.
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-07-05 10:17:36 +00:00
|
|
|
|
2022-12-07 12:38:56 +00:00
|
|
|
obj_size = int(os.getenv("BIG_OBJ_SIZE", complex_object_size))
|
2022-07-05 10:17:36 +00:00
|
|
|
file_path = generate_file(obj_size)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using HTTP"):
|
2022-12-05 22:31:45 +00:00
|
|
|
oid_gate = upload_via_http_gate(
|
|
|
|
cid=cid, path=file_path, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
|
|
|
oid_curl = upload_via_http_gate_curl(
|
|
|
|
cid=cid,
|
|
|
|
filepath=file_path,
|
|
|
|
large_object=True,
|
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-12-05 22:31:45 +00:00
|
|
|
self.get_object_and_verify_hashes(oid_gate, file_path, self.wallet, cid)
|
2022-10-13 16:13:45 +00:00
|
|
|
self.get_object_and_verify_hashes(
|
|
|
|
oid_curl,
|
|
|
|
file_path,
|
|
|
|
self.wallet,
|
|
|
|
cid,
|
|
|
|
object_getter=get_via_http_curl,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.title("Test Put/Get over HTTP using Curl utility")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_put_http_get_http_curl(self, complex_object_size, simple_object_size):
|
2022-07-05 07:18:37 +00:00
|
|
|
"""
|
|
|
|
Test checks upload and download over HTTP using curl utility.
|
|
|
|
"""
|
2022-10-13 18:53:44 +00:00
|
|
|
cid = create_container(
|
2022-12-05 22:31:45 +00:00
|
|
|
self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE_2,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path_simple, file_path_large = generate_file(simple_object_size), generate_file(
|
|
|
|
complex_object_size
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
with allure.step("Put objects using curl utility"):
|
2022-12-05 22:31:45 +00:00
|
|
|
oid_simple = upload_via_http_gate_curl(
|
|
|
|
cid=cid, filepath=file_path_simple, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
|
|
|
oid_large = upload_via_http_gate_curl(
|
|
|
|
cid=cid, filepath=file_path_large, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
for oid, file_path in ((oid_simple, file_path_simple), (oid_large, file_path_large)):
|
2022-10-13 16:13:45 +00:00
|
|
|
self.get_object_and_verify_hashes(
|
|
|
|
oid,
|
|
|
|
file_path,
|
|
|
|
self.wallet,
|
|
|
|
cid,
|
|
|
|
object_getter=get_via_http_curl,
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.step("Try to get object and expect error")
|
2022-12-05 22:31:45 +00:00
|
|
|
def try_to_get_object_and_expect_error(self, cid: str, oid: str, error_pattern: str) -> None:
|
2022-07-05 07:18:37 +00:00
|
|
|
try:
|
2022-12-05 22:31:45 +00:00
|
|
|
get_via_http_gate(cid=cid, oid=oid, endpoint=self.cluster.default_http_gate_endpoint)
|
2022-09-15 09:46:45 +00:00
|
|
|
raise AssertionError(f"Expected error on getting object with cid: {cid}")
|
2022-07-05 07:18:37 +00:00
|
|
|
except Exception as err:
|
2022-10-06 07:31:47 +00:00
|
|
|
match = error_pattern.casefold() in str(err).casefold()
|
|
|
|
assert match, f"Expected {err} to match {error_pattern}"
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.step("Verify object can be get using HTTP header attribute")
|
2022-10-03 08:16:27 +00:00
|
|
|
def get_object_by_attr_and_verify_hashes(
|
2022-12-05 22:31:45 +00:00
|
|
|
self, oid: str, file_name: str, cid: str, attrs: dict
|
2022-10-03 08:16:27 +00:00
|
|
|
) -> None:
|
2022-12-05 22:31:45 +00:00
|
|
|
got_file_path_http = get_via_http_gate(
|
|
|
|
cid=cid, oid=oid, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
|
|
|
got_file_path_http_attr = get_via_http_gate_by_attribute(
|
|
|
|
cid=cid, attribute=attrs, endpoint=self.cluster.default_http_gate_endpoint
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
TestHttpGate._assert_hashes_are_equal(
|
|
|
|
file_name, got_file_path_http, got_file_path_http_attr
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-09-15 09:46:45 +00:00
|
|
|
@allure.step("Verify object can be get using HTTP")
|
|
|
|
def get_object_and_verify_hashes(
|
2022-12-05 22:31:45 +00:00
|
|
|
self, oid: str, file_name: str, wallet: str, cid: str, object_getter=None
|
2022-10-03 08:16:27 +00:00
|
|
|
) -> None:
|
2022-12-05 22:31:45 +00:00
|
|
|
nodes = get_nodes_without_object(
|
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
shell=self.shell,
|
|
|
|
nodes=self.cluster.storage_nodes,
|
|
|
|
)
|
|
|
|
random_node = random.choice(nodes)
|
2022-07-05 07:18:37 +00:00
|
|
|
object_getter = object_getter or get_via_http_gate
|
|
|
|
|
2022-10-13 18:53:44 +00:00
|
|
|
got_file_path = get_object(
|
2022-12-05 22:31:45 +00:00
|
|
|
wallet=wallet,
|
|
|
|
cid=cid,
|
|
|
|
oid=oid,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=random_node.get_rpc_endpoint(),
|
|
|
|
)
|
|
|
|
got_file_path_http = object_getter(
|
|
|
|
cid=cid, oid=oid, endpoint=self.cluster.default_http_gate_endpoint
|
2022-10-13 18:53:44 +00:00
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
2022-07-05 10:17:36 +00:00
|
|
|
TestHttpGate._assert_hashes_are_equal(file_name, got_file_path, got_file_path_http)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-10-03 08:16:27 +00:00
|
|
|
def _assert_hashes_are_equal(orig_file_name: str, got_file_1: str, got_file_2: str) -> None:
|
2022-09-15 09:46:45 +00:00
|
|
|
msg = "Expected hashes are equal for files {f1} and {f2}"
|
2022-07-05 07:18:37 +00:00
|
|
|
got_file_hash_http = get_file_hash(got_file_1)
|
2022-09-15 09:46:45 +00:00
|
|
|
assert get_file_hash(got_file_2) == got_file_hash_http, msg.format(
|
|
|
|
f1=got_file_2, f2=got_file_1
|
|
|
|
)
|
|
|
|
assert get_file_hash(orig_file_name) == got_file_hash_http, msg.format(
|
|
|
|
f1=orig_file_name, f2=got_file_1
|
|
|
|
)
|
2022-07-05 07:18:37 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _attr_into_header(attrs: dict) -> dict:
|
2022-09-15 09:46:45 +00:00
|
|
|
return {f"X-Attribute-{_key}": _value for _key, _value in attrs.items()}
|