2022-12-08 13:03:27 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-10-24 07:38:44 +00:00
|
|
|
from frostfs_testlib.s3 import AwsCliClient, S3ClientWrapper
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.cli.object import put_object_to_random_node
|
|
|
|
from frostfs_testlib.steps.http.http_gate import (
|
2023-10-24 07:38:44 +00:00
|
|
|
assert_hashes_are_equal,
|
2022-12-08 13:03:27 +00:00
|
|
|
get_object_by_attr_and_verify_hashes,
|
2023-10-24 07:38:44 +00:00
|
|
|
get_via_http_gate,
|
2022-12-08 13:03:27 +00:00
|
|
|
try_to_get_object_via_passed_request_and_expect_error,
|
2023-05-15 09:59:33 +00:00
|
|
|
verify_object_hash,
|
2022-12-08 13:03:27 +00:00
|
|
|
)
|
2023-10-24 07:38:44 +00:00
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
2024-11-26 16:42:53 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.testing.cluster_test_base import ClusterTestBase
|
2024-11-26 16:42:53 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import TestFile
|
|
|
|
|
|
|
|
from ....helpers.container_request import REP_2_1_4_PUBLIC, requires_container
|
2022-12-08 13:03:27 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
|
|
|
|
|
2024-10-11 09:30:23 +00:00
|
|
|
@pytest.mark.nightly
|
2022-12-08 13:03:27 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.http_gate
|
|
|
|
class Test_http_object(ClusterTestBase):
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put over gRPC, Get over HTTP with attributes (obj_size={object_size})")
|
2024-11-26 16:42:53 +00:00
|
|
|
@requires_container(REP_2_1_4_PUBLIC)
|
|
|
|
def test_object_put_get_attributes(self, default_wallet: WalletInfo, container: str, test_file: TestFile):
|
2022-12-08 13:03:27 +00:00
|
|
|
"""
|
2023-10-24 07:38:44 +00:00
|
|
|
Test that object can be put using gRPC interface and got using HTTP.
|
2022-12-08 13:03:27 +00:00
|
|
|
|
|
|
|
Steps:
|
2023-10-24 07:38:44 +00:00
|
|
|
1. Create an object;
|
|
|
|
2. Put object(s) using gRPC (frostfs-cli) with attributes [--attributes chapter1=peace,chapter2=war];
|
2023-11-15 09:21:26 +00:00
|
|
|
3. Download the object using HTTP gate (https://git.frostfs.info/TrueCloudLab/frostfs-http-gw#downloading);
|
2023-10-24 07:38:44 +00:00
|
|
|
4. Compare hashes of the original and the downloaded object;
|
|
|
|
5. [Negative] Try to the get the object with the specified attributes and `get` request: [get/$CID/chapter1/peace];
|
|
|
|
6. Download the object with the specified attributes and `get_by_attribute` request: [get_by_attribute/$CID/chapter1/peace];
|
|
|
|
7. Compare hashes of the original and the downloaded object;
|
|
|
|
8. [Negative] Try to the get the object via `get_by_attribute` request: [get_by_attribute/$CID/$OID];
|
2022-12-08 13:03:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
Hashes must be the same.
|
|
|
|
"""
|
2023-03-14 09:21:40 +00:00
|
|
|
|
2022-12-08 13:03:27 +00:00
|
|
|
# List of Key=Value attributes
|
|
|
|
obj_key1 = "chapter1"
|
|
|
|
obj_value1 = "peace"
|
|
|
|
obj_key2 = "chapter2"
|
|
|
|
obj_value2 = "war"
|
|
|
|
|
|
|
|
# Prepare for grpc PUT request
|
|
|
|
key_value1 = obj_key1 + "=" + obj_value1
|
|
|
|
key_value2 = obj_key2 + "=" + obj_value2
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put objects using gRPC [--attributes chapter1=peace,chapter2=war]"):
|
2022-12-08 13:03:27 +00:00
|
|
|
oid = put_object_to_random_node(
|
2024-11-26 16:42:53 +00:00
|
|
|
wallet=default_wallet,
|
|
|
|
path=test_file.path,
|
|
|
|
cid=container,
|
2022-12-08 13:03:27 +00:00
|
|
|
shell=self.shell,
|
|
|
|
cluster=self.cluster,
|
|
|
|
attributes=f"{key_value1},{key_value2}",
|
|
|
|
)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get object and verify hashes [ get/$CID/$OID ]"):
|
2023-05-15 09:59:33 +00:00
|
|
|
verify_object_hash(
|
2022-12-08 13:03:27 +00:00
|
|
|
oid=oid,
|
2024-11-26 16:42:53 +00:00
|
|
|
file_name=test_file.path,
|
|
|
|
wallet=default_wallet,
|
|
|
|
cid=container,
|
2022-12-08 13:03:27 +00:00
|
|
|
shell=self.shell,
|
|
|
|
nodes=self.cluster.storage_nodes,
|
2024-02-14 13:20:06 +00:00
|
|
|
request_node=self.cluster.cluster_nodes[0],
|
2022-12-08 13:03:27 +00:00
|
|
|
)
|
2023-10-24 07:38:44 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("[Negative] try to get object: [get/$CID/chapter1/peace]"):
|
2022-12-08 13:03:27 +00:00
|
|
|
attrs = {obj_key1: obj_value1, obj_key2: obj_value2}
|
2024-11-26 16:42:53 +00:00
|
|
|
request = f"/get/{container}/{obj_key1}/{obj_value1}"
|
2022-12-08 13:03:27 +00:00
|
|
|
expected_err_msg = "Failed to get object via HTTP gate:"
|
|
|
|
try_to_get_object_via_passed_request_and_expect_error(
|
2024-11-26 16:42:53 +00:00
|
|
|
cid=container,
|
2022-12-08 13:03:27 +00:00
|
|
|
oid=oid,
|
2024-02-14 13:20:06 +00:00
|
|
|
node=self.cluster.cluster_nodes[0],
|
2022-12-08 13:03:27 +00:00
|
|
|
error_pattern=expected_err_msg,
|
|
|
|
http_request_path=request,
|
|
|
|
attrs=attrs,
|
|
|
|
)
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Download the object with attribute [get_by_attribute/$CID/chapter1/peace]"):
|
2022-12-08 13:03:27 +00:00
|
|
|
get_object_by_attr_and_verify_hashes(
|
|
|
|
oid=oid,
|
2024-11-26 16:42:53 +00:00
|
|
|
file_name=test_file.path,
|
|
|
|
cid=container,
|
2022-12-08 13:03:27 +00:00
|
|
|
attrs=attrs,
|
2024-02-14 13:20:06 +00:00
|
|
|
node=self.cluster.cluster_nodes[0],
|
2022-12-08 13:03:27 +00:00
|
|
|
)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("[Negative] try to get object: get_by_attribute/$CID/$OID"):
|
2024-11-26 16:42:53 +00:00
|
|
|
request = f"/get_by_attribute/{container}/{oid}"
|
2022-12-08 13:03:27 +00:00
|
|
|
try_to_get_object_via_passed_request_and_expect_error(
|
2024-11-26 16:42:53 +00:00
|
|
|
cid=container,
|
2022-12-08 13:03:27 +00:00
|
|
|
oid=oid,
|
2024-02-14 13:20:06 +00:00
|
|
|
node=self.cluster.cluster_nodes[0],
|
2022-12-08 13:03:27 +00:00
|
|
|
error_pattern=expected_err_msg,
|
|
|
|
http_request_path=request,
|
|
|
|
)
|
2023-10-24 07:38:44 +00:00
|
|
|
|
2024-08-08 10:33:35 +00:00
|
|
|
@allure.title("Put over s3, Get over HTTP with bucket name and key (object_size={object_size})")
|
2023-10-24 07:38:44 +00:00
|
|
|
@pytest.mark.parametrize("s3_client", [AwsCliClient], indirect=True)
|
2024-11-26 16:42:53 +00:00
|
|
|
def test_object_put_get_bucketname_key(self, test_file: TestFile, s3_client: S3ClientWrapper):
|
2023-10-24 07:38:44 +00:00
|
|
|
"""
|
|
|
|
Test that object can be put using s3-gateway interface and got via HTTP with bucket name and object key.
|
|
|
|
|
|
|
|
Steps:
|
|
|
|
1. Create an object;
|
|
|
|
2. Create a bucket via s3;
|
|
|
|
3. Put the object via s3;
|
|
|
|
4. Download the object using HTTP gate with the bucket name and the object key;
|
|
|
|
5. Compare hashes of the original and the downloaded objects;
|
|
|
|
|
|
|
|
Expected result:
|
|
|
|
Hashes must be the same.
|
|
|
|
"""
|
|
|
|
|
2024-11-26 16:42:53 +00:00
|
|
|
object_key = s3_helper.object_key_from_file_path(test_file.path)
|
2023-10-24 07:38:44 +00:00
|
|
|
bucket = s3_client.create_bucket(acl="public-read-write")
|
2024-11-26 16:42:53 +00:00
|
|
|
s3_client.put_object(bucket=bucket, filepath=test_file.path, key=object_key)
|
2023-10-24 07:38:44 +00:00
|
|
|
obj_s3 = s3_client.get_object(bucket=bucket, key=object_key)
|
|
|
|
|
|
|
|
request = f"/get/{bucket}/{object_key}"
|
|
|
|
obj_http = get_via_http_gate(
|
|
|
|
cid=None,
|
|
|
|
oid=None,
|
2024-02-14 13:20:06 +00:00
|
|
|
node=self.cluster.cluster_nodes[0],
|
2023-10-24 07:38:44 +00:00
|
|
|
request_path=request,
|
|
|
|
)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Verify hashes"):
|
2024-11-26 16:42:53 +00:00
|
|
|
assert_hashes_are_equal(test_file.path, obj_http, obj_s3)
|