2022-09-19 14:22:10 +00:00
|
|
|
import os
|
2024-06-24 23:27:54 +00:00
|
|
|
import random
|
2022-12-01 08:58:05 +00:00
|
|
|
import string
|
2022-09-19 14:22:10 +00:00
|
|
|
import uuid
|
|
|
|
from datetime import datetime, timedelta
|
2023-05-15 09:59:33 +00:00
|
|
|
from typing import Literal
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
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.common import ASSETS_DIR, DEFAULT_WALLET_PASS
|
2024-06-05 10:07:07 +00:00
|
|
|
from frostfs_testlib.resources.error_patterns import S3_BUCKET_DOES_NOT_ALLOW_ACL, S3_MALFORMED_XML_REQUEST
|
|
|
|
from frostfs_testlib.resources.s3_acl_grants import PRIVATE_GRANTS
|
2023-10-31 14:51:09 +00:00
|
|
|
from frostfs_testlib.s3 import AwsCliClient, S3ClientWrapper, VersioningStatus
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
2023-08-02 11:54:03 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.testing.test_control import expect_not_raises
|
2023-03-29 16:59:14 +00:00
|
|
|
from frostfs_testlib.utils import wallet_utils
|
2024-06-18 10:00:56 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import (
|
|
|
|
TestFile,
|
|
|
|
concat_files,
|
|
|
|
generate_file,
|
|
|
|
generate_file_with_content,
|
|
|
|
get_file_hash,
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.s3_gate
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.s3_gate_object
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestS3GateObject:
|
2023-03-29 16:59:14 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def second_wallet_public_key(self):
|
|
|
|
second_wallet = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
2023-05-15 09:59:33 +00:00
|
|
|
wallet_utils.init_wallet(second_wallet, DEFAULT_WALLET_PASS)
|
|
|
|
public_key = wallet_utils.get_wallet_public_key(second_wallet, DEFAULT_WALLET_PASS)
|
2023-03-29 16:59:14 +00:00
|
|
|
yield public_key
|
|
|
|
|
2024-06-24 23:27:54 +00:00
|
|
|
@allure.title("Object API (obj_size={object_size}, s3_client={s3_client})")
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"object_size",
|
|
|
|
["simple", "complex"],
|
|
|
|
indirect=True,
|
|
|
|
)
|
|
|
|
def test_s3_api_object(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
object_size: ObjectSize,
|
|
|
|
bucket: str,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Test base S3 Object API (Put/Head/List) for simple and complex objects.
|
|
|
|
"""
|
|
|
|
with reporter.step("Prepare object to upload"):
|
|
|
|
test_file = generate_file(object_size.value)
|
|
|
|
file_name = s3_helper.object_key_from_file_path(test_file)
|
|
|
|
|
|
|
|
with reporter.step("Put object to bucket"):
|
|
|
|
s3_client.put_object(bucket, test_file)
|
|
|
|
|
|
|
|
with reporter.step("Head object from bucket"):
|
|
|
|
s3_client.head_object(bucket, file_name)
|
|
|
|
|
|
|
|
with reporter.step("Verify object in list"):
|
|
|
|
bucket_objects = s3_client.list_objects(bucket)
|
|
|
|
assert file_name in bucket_objects, f"Expected file {file_name} in objects list {bucket_objects}"
|
|
|
|
|
|
|
|
with reporter.step("Check object's attributes"):
|
|
|
|
for attrs in (["ETag"], ["ObjectSize", "StorageClass"]):
|
|
|
|
s3_client.get_object_attributes(bucket, file_name, attrs)
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
2024-06-24 23:27:54 +00:00
|
|
|
two_buckets: list[str],
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
|
|
|
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket_1, bucket_2 = two_buckets
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object into one bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket_1, file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object into the same bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects(bucket_2)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy object from first bucket into second"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path_b2 = s3_client.copy_object(bucket_1, file_name, bucket=bucket_2)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, expected_objects=bucket_1_objects)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_2, expected_objects=[copy_obj_path_b2])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check copied object has the same content"):
|
2023-05-15 09:59:33 +00:00
|
|
|
got_copied_file_b2 = s3_client.get_object(bucket_2, copy_obj_path_b2)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert get_file_hash(file_path) == get_file_hash(got_copied_file_b2), "Hashes must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete one object from first bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.remove(file_name)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, expected_objects=bucket_1_objects)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_2, expected_objects=[copy_obj_path_b2])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object into the same bucket"):
|
2022-09-19 14:22:10 +00:00
|
|
|
with pytest.raises(Exception):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.copy_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy version of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_version_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
2024-06-24 23:27:54 +00:00
|
|
|
two_buckets: list[str],
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
2023-10-31 14:51:09 +00:00
|
|
|
file_name_simple = generate_file_with_content(simple_object_size.value, content=version_1_content)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_key = os.path.basename(file_name_simple)
|
|
|
|
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket_1, bucket_2 = two_buckets
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket_1, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket_1, file_name_simple)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [obj_key]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, [obj_key])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object into the same bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket_2, VersioningStatus.ENABLED)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy object from first bucket into second"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path_b2 = s3_client.copy_object(bucket_1, obj_key, bucket=bucket_2)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, expected_objects=bucket_1_objects)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_2, expected_objects=[copy_obj_path_b2])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete one object from first bucket and check object in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.remove(obj_key)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, expected_objects=bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object into the same bucket"):
|
2022-09-19 14:22:10 +00:00
|
|
|
with pytest.raises(Exception):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.copy_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy with acl (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_copy_acl(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2024-06-05 10:07:07 +00:00
|
|
|
file_path = generate_file_with_content(simple_object_size.value)
|
|
|
|
file_name = os.path.basename(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2024-06-05 10:07:07 +00:00
|
|
|
with reporter.step("Put object into bucket"):
|
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [file_name])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2024-06-05 10:07:07 +00:00
|
|
|
with reporter.step("[NEGATIVE] Copy object with public-read-write ACL"):
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
copy_path = s3_client.copy_object(bucket, file_name, acl="public-read-write")
|
|
|
|
|
|
|
|
with reporter.step("Copy object with private ACL"):
|
|
|
|
copy_path = s3_client.copy_object(bucket, file_name, acl="private")
|
|
|
|
object_grants = s3_client.get_object_acl(bucket, copy_path)
|
|
|
|
s3_helper.verify_acl_permissions(object_grants, PRIVATE_GRANTS)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object with metadata (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_copy_metadate(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path, metadata=object_metadata)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert obj_head.get("Metadata") == object_metadata, f"Metadata must be {object_metadata}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object with metadata"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name, metadata_directive="COPY")
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert obj_head.get("Metadata") == object_metadata, f"Metadata must be {object_metadata}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object with new metadata"):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata_1 = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
file_name,
|
|
|
|
metadata_directive="REPLACE",
|
|
|
|
metadata=object_metadata_1,
|
|
|
|
)
|
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert obj_head.get("Metadata") == object_metadata_1, f"Metadata must be {object_metadata_1}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object with tagging (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_copy_tagging(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_tagging = [(f"{uuid.uuid4()}", f"{uuid.uuid4()}")]
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_simple = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name_simple]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
s3_client.put_object_tagging(bucket, file_name_simple, tags=object_tagging)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name_simple]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object without tag"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name_simple)
|
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": key, "Value": value} for key, value in object_tagging]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object with tag"):
|
2023-10-31 14:51:09 +00:00
|
|
|
copy_obj_path_1 = s3_client.copy_object(bucket, file_name_simple, tagging_directive="COPY")
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": key, "Value": value} for key, value in object_tagging]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Copy one object with new tag"):
|
2022-09-19 14:22:10 +00:00
|
|
|
tag_key = "tag1"
|
|
|
|
tag_value = uuid.uuid4()
|
|
|
|
new_tag = f"{tag_key}={tag_value}"
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
file_name_simple,
|
|
|
|
tagging_directive="REPLACE",
|
|
|
|
tagging=new_tag,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": tag_key, "Value": str(tag_value)}]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete version of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_delete_versioning(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
|
|
|
complex_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
2023-10-31 14:51:09 +00:00
|
|
|
file_name_simple = generate_file_with_content(simple_object_size.value, content=version_1_content)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_simple)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_simple)
|
2024-06-18 10:00:56 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, file_name_simple, version_2_content)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == obj_key}
|
2022-09-19 14:22:10 +00:00
|
|
|
assert obj_versions == {
|
|
|
|
version_id_1,
|
|
|
|
version_id_2,
|
2023-03-29 16:59:14 +00:00
|
|
|
}, f"Object should have versions: {version_id_1, version_id_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete 1 version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key, version_id=version_id_1)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == obj_key}
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_versions == {version_id_2}, f"Object should have versions: {version_id_2}"
|
2023-05-24 14:20:25 +00:00
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete second version of object"):
|
2024-06-18 10:00:56 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key, version_id_2)
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == obj_key}
|
2022-09-19 14:22:10 +00:00
|
|
|
assert not obj_versions, "Expected object not found"
|
2023-05-24 14:20:25 +00:00
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put new object into bucket"):
|
2024-06-18 10:00:56 +00:00
|
|
|
file_name_complex = generate_file(complex_object_size.value)
|
|
|
|
obj_key = os.path.basename(file_name_complex)
|
|
|
|
s3_client.put_object(bucket, file_name_complex)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete last object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key)
|
|
|
|
versions = s3_client.list_objects_versions(bucket, True)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert versions.get("DeleteMarkers", None), "Expected delete Marker"
|
|
|
|
assert "DeleteMarker" in delete_obj.keys(), "Expected delete Marker"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Bulk delete version of object (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_bulk_delete_versioning(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
|
|
|
version_3_content = "Version 3"
|
|
|
|
version_4_content = "Version 4"
|
2023-10-31 14:51:09 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, content=version_1_content)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_1)
|
2024-06-18 10:00:56 +00:00
|
|
|
file_name_2 = generate_file_with_content(simple_object_size.value, file_name_1, version_2_content)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_2)
|
2024-06-18 10:00:56 +00:00
|
|
|
file_name_3 = generate_file_with_content(simple_object_size.value, file_name_1, version_3_content)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_3 = s3_client.put_object(bucket, file_name_3)
|
2024-06-18 10:00:56 +00:00
|
|
|
file_name_4 = generate_file_with_content(simple_object_size.value, file_name_1, version_4_content)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_4 = s3_client.put_object(bucket, file_name_4)
|
2022-09-19 14:22:10 +00:00
|
|
|
version_ids = {version_id_1, version_id_2, version_id_3, version_id_4}
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == obj_key}
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_versions == version_ids, f"Object should have versions: {version_ids}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete two objects from bucket one by one"):
|
2024-06-24 23:27:54 +00:00
|
|
|
version_to_delete_b1 = random.sample([version_id_1, version_id_2, version_id_3, version_id_4], k=2)
|
2022-09-19 14:22:10 +00:00
|
|
|
version_to_save = list(set(version_ids) - set(version_to_delete_b1))
|
|
|
|
for ver in version_to_delete_b1:
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket, obj_key, ver)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = [version.get("VersionId") for version in versions if version.get("Key") == obj_key]
|
|
|
|
assert obj_versions.sort() == version_to_save.sort(), f"Object should have versions: {version_to_save}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Get versions of object (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_get_versioning(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
2023-10-31 14:51:09 +00:00
|
|
|
file_name_simple = generate_file_with_content(simple_object_size.value, content=version_1_content)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_simple)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_simple)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_1 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_simple, content=version_2_content
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1 = s3_client.get_object(bucket, obj_key, version_id_1, full_output=True)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert object_1.get("VersionId") == version_id_1, f"Get object with version {version_id_1}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2 = s3_client.get_object(bucket, obj_key, version_id_2, full_output=True)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert object_2.get("VersionId") == version_id_2, f"Get object with version {version_id_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, obj_key, full_output=True)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert object_3.get("VersionId") == version_id_2, f"Get object with version {version_id_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Get range (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_get_range(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
file_hash = get_file_hash(file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_path)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, file_path=file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_1 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[0, int(complex_object_size.value / 3)],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(complex_object_size.value / 3) + 1,
|
|
|
|
2 * int(complex_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
2 * int(complex_object_size.value / 3) + 1,
|
|
|
|
complex_object_size.value,
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file = concat_files([object_1_part_1, object_1_part_2, object_1_part_3])
|
|
|
|
assert get_file_hash(con_file) == file_hash, "Hashes must be the same"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_1 = s3_client.get_object(
|
2022-12-07 12:38:56 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[0, int(simple_object_size.value / 3)],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(simple_object_size.value / 3) + 1,
|
|
|
|
2 * int(simple_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[2 * int(simple_object_size.value / 3) + 1, simple_object_size.value],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file_1 = concat_files([object_2_part_1, object_2_part_2, object_2_part_3])
|
2023-10-31 14:51:09 +00:00
|
|
|
assert get_file_hash(con_file_1) == get_file_hash(file_name_1), "Hashes must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_1 = s3_client.get_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
bucket, file_name, object_range=[0, int(simple_object_size.value / 3)]
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(simple_object_size.value / 3) + 1,
|
|
|
|
2 * int(simple_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[2 * int(simple_object_size.value / 3) + 1, simple_object_size.value],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file = concat_files([object_3_part_1, object_3_part_2, object_3_part_3])
|
|
|
|
assert get_file_hash(con_file) == get_file_hash(file_name_1), "Hashes must be the same"
|
|
|
|
|
2023-04-05 16:02:42 +00:00
|
|
|
def copy_extend_list(self, original_list: list[str], n: int) -> list[str]:
|
|
|
|
"""Extend the list with own elements up to n elements"""
|
|
|
|
multiplier = n // len(original_list)
|
|
|
|
result_list = original_list.copy()
|
|
|
|
result_list = result_list * multiplier
|
|
|
|
for i in range(n - len(result_list)):
|
|
|
|
result_list.append(result_list[i])
|
|
|
|
|
|
|
|
return result_list
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Bulk deletion is limited to 1000 objects (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_bulk_deletion_limit(
|
2023-09-08 10:35:34 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-09-08 10:35:34 +00:00
|
|
|
objects_in_bucket = []
|
|
|
|
objects_count = 3
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Put {objects_count} into bucket"):
|
2023-09-08 10:35:34 +00:00
|
|
|
for _ in range(objects_count):
|
|
|
|
file_path = generate_file(simple_object_size.value)
|
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
|
|
|
objects_in_bucket.append(file_name)
|
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
|
2023-04-05 16:02:42 +00:00
|
|
|
# Extend deletion list to 1001 elements with same keys for test speed
|
|
|
|
objects_to_delete = self.copy_extend_list(objects_in_bucket, 1001)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Send delete request with 1001 objects and expect error"):
|
2023-04-05 16:02:42 +00:00
|
|
|
with pytest.raises(Exception, match=S3_MALFORMED_XML_REQUEST):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_objects(bucket, objects_to_delete)
|
2023-04-05 16:02:42 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Send delete request with 1000 objects without error"):
|
2023-04-05 16:02:42 +00:00
|
|
|
with expect_not_raises():
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_objects(bucket, objects_to_delete[:1000])
|
2023-04-05 16:02:42 +00:00
|
|
|
|
2023-11-08 16:13:32 +00:00
|
|
|
@allure.title("Object head is unloaded with the correct version (s3_client={s3_client})")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.smoke
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_head_object(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_path, metadata=object_metadata)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, file_path=file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get head of first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
response = s3_client.head_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert "LastModified" in response, "Expected LastModified field"
|
|
|
|
assert "ETag" in response, "Expected ETag field"
|
|
|
|
assert response.get("Metadata") == {}, "Expected Metadata empty"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert response.get("VersionId") == version_id_2, f"Expected VersionId is {version_id_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
assert response.get("ContentLength") != 0, "Expected ContentLength is not zero"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get head ob first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
response = s3_client.head_object(bucket, file_name, version_id=version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert "LastModified" in response, "Expected LastModified field"
|
|
|
|
assert "ETag" in response, "Expected ETag field"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert response.get("Metadata") == object_metadata, f"Expected Metadata is {object_metadata}"
|
|
|
|
assert response.get("VersionId") == version_id_1, f"Expected VersionId is {version_id_1}"
|
2022-09-19 14:22:10 +00:00
|
|
|
assert response.get("ContentLength") != 0, "Expected ContentLength is not zero"
|
|
|
|
|
2023-10-31 14:51:09 +00:00
|
|
|
@allure.title("List of objects with version (method_version={list_type}, s3_client={s3_client})")
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("list_type", ["v1", "v2"])
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_list_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
list_type: str,
|
|
|
|
bucket: str,
|
|
|
|
complex_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_2 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_2 = s3_helper.object_key_from_file_path(file_path_2)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1)
|
|
|
|
s3_client.put_object(bucket, file_path_2)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get list of object"):
|
2022-09-19 14:22:10 +00:00
|
|
|
if list_type == "v1":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj = s3_client.list_objects(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
elif list_type == "v2":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj = s3_client.list_objects_v2(bucket)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert len(list_obj) == 2, "bucket should have 2 objects"
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
list_obj.sort() == [file_name, file_name_2].sort()
|
2023-03-29 16:59:14 +00:00
|
|
|
), f"bucket should have object key {file_name, file_name_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
if list_type == "v1":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj_1 = s3_client.list_objects(bucket, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
elif list_type == "v2":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj_1 = s3_client.list_objects_v2(bucket, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
contents = list_obj_1.get("Contents", [])
|
2023-03-29 16:59:14 +00:00
|
|
|
assert len(contents) == 1, "bucket should have only 1 object"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert contents[0].get("Key") == file_name_2, f"bucket should have object key {file_name_2}"
|
2023-03-29 16:59:14 +00:00
|
|
|
assert "DeleteMarker" in delete_obj.keys(), "Expected delete Marker"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_object(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
object_1_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_1 = "tag1"
|
|
|
|
tag_value_1 = uuid.uuid4()
|
|
|
|
tag_1 = f"{tag_key_1}={tag_value_1}"
|
|
|
|
object_2_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_2 = "tag2"
|
|
|
|
tag_value_2 = uuid.uuid4()
|
|
|
|
tag_2 = f"{tag_key_2}={tag_value_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.SUSPENDED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put first object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1, metadata=object_1_metadata, tagging=tag_1)
|
|
|
|
obj_head = s3_client.head_object(bucket, file_name)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head.get("Metadata") == object_1_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert got_tags == [{"Key": tag_key_1, "Value": str(tag_value_1)}], "Tags must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Rewrite file into bucket"):
|
2023-10-31 14:51:09 +00:00
|
|
|
file_path_2 = generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_2, metadata=object_2_metadata, tagging=tag_2)
|
|
|
|
obj_head = s3_client.head_object(bucket, file_name)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head.get("Metadata") == object_2_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_1 = s3_client.get_object_tagging(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_1, f"Expected tags, got {got_tags_1}"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert got_tags_1 == [{"Key": tag_key_2, "Value": str(tag_value_2)}], "Tags must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_3 = generate_file(complex_object_size.value)
|
2022-09-19 14:22:10 +00:00
|
|
|
file_hash = get_file_hash(file_path_3)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_3 = s3_helper.object_key_from_file_path(file_path_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
object_3_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_3 = "tag3"
|
|
|
|
tag_value_3 = uuid.uuid4()
|
|
|
|
tag_3 = f"{tag_key_3}={tag_value_3}"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put third object into bucket"):
|
2023-10-31 14:51:09 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_path_3, metadata=object_3_metadata, tagging=tag_3)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head_3 = s3_client.head_object(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert obj_head_3.get("Metadata") == object_3_metadata, "Matadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_3 = s3_client.get_object_tagging(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_3, f"Expected tags, got {got_tags_3}"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert got_tags_3 == [{"Key": tag_key_3, "Value": str(tag_value_3)}], "Tags must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put new version of file into bucket"):
|
2023-10-31 14:51:09 +00:00
|
|
|
file_path_4 = generate_file_with_content(simple_object_size.value, file_path=file_path_3)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_path_4)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == file_name_3}
|
2022-09-19 14:22:10 +00:00
|
|
|
assert obj_versions == {
|
|
|
|
version_id_1,
|
|
|
|
version_id_2,
|
2023-03-29 16:59:14 +00:00
|
|
|
}, f"Object should have versions: {version_id_1, version_id_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_4 = s3_client.get_object_tagging(bucket, file_name_3)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert not got_tags_4, "No tags expected"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, file_name_3, full_output=True)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert object_3.get("VersionId") == version_id_2, f"get object with version {version_id_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_4) == get_file_hash(object_3), "Hashes must be the same"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_4 = s3_client.get_object(bucket, file_name_3, version_id_1, full_output=True)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert object_4.get("VersionId") == version_id_1, f"get object with version {version_id_1}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_4 = s3_client.get_object(bucket, file_name_3, version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert file_hash == get_file_hash(object_4), "Hashes must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head_3 = s3_client.head_object(bucket, file_name_3, version_id_1)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head_3.get("Metadata") == object_3_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_3 = s3_client.get_object_tagging(bucket, file_name_3, version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_3, f"Expected tags, got {got_tags_3}"
|
2023-10-31 14:51:09 +00:00
|
|
|
assert got_tags_3 == [{"Key": tag_key_3, "Value": str(tag_value_3)}], "Tags must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object with ACL (versioning={bucket_versioning}, s3_client={s3_client})")
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("bucket_versioning", ["ENABLED", "SUSPENDED"])
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_s3_put_object_acl(
|
|
|
|
self,
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket_versioning: Literal["ENABLED", "SUSPENDED"],
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
second_wallet_public_key: str,
|
2022-12-07 12:38:56 +00:00
|
|
|
):
|
2024-06-05 10:07:07 +00:00
|
|
|
file_path = generate_file(complex_object_size.value)
|
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus[bucket_versioning])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object with acl private"):
|
2024-06-05 10:07:07 +00:00
|
|
|
s3_client.put_object(bucket, file_path, acl="private")
|
|
|
|
object_grants = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.verify_acl_permissions(object_grants, PRIVATE_GRANTS)
|
|
|
|
object = s3_client.get_object(bucket, file_name)
|
|
|
|
assert get_file_hash(file_path) == get_file_hash(object), "Hashes must be the same"
|
|
|
|
|
|
|
|
with reporter.step("[NEGATIVE] Put object with acl public-read"):
|
|
|
|
generate_file_with_content(simple_object_size.value, file_path)
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
s3_client.put_object(bucket, file_path, acl="public-read")
|
|
|
|
|
|
|
|
with reporter.step("[NEGATIVE] Put object with acl public-read-write"):
|
|
|
|
generate_file_with_content(simple_object_size.value, file_path)
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
s3_client.put_object(bucket, file_path, acl="public-read-write")
|
|
|
|
|
|
|
|
with reporter.step("[NEGATIVE] Put object with --grant-full-control id=mycanonicaluserid"):
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
s3_client.put_object(bucket, file_path, grant_full_control=f"id={second_wallet_public_key}")
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2024-06-05 10:07:07 +00:00
|
|
|
with reporter.step(
|
|
|
|
"[NEGATIVE] Put object with --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers"
|
|
|
|
):
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
s3_client.put_object(
|
|
|
|
bucket, file_path, grant_read="uri=http://acs.amazonaws.com/groups/global/AllUsers"
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object with lock-mode (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_object_lock_mode(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object with lock-mode GOVERNANCE lock-retain-until-date +1day, lock-legal-hold-status"):
|
2022-09-19 14:22:10 +00:00
|
|
|
date_obj = datetime.utcnow() + timedelta(days=1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="GOVERNANCE",
|
|
|
|
object_lock_retain_until_date=date_obj.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
object_lock_legal_hold_status="OFF",
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.assert_object_lock_mode(s3_client, bucket, file_name, "GOVERNANCE", date_obj, "OFF")
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(
|
2022-09-19 14:22:10 +00:00
|
|
|
"Put new version of object with [--object-lock-mode COMPLIANCE] и [--object-lock-retain-until-date +3days]"
|
|
|
|
):
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=2)
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.assert_object_lock_mode(s3_client, bucket, file_name, "COMPLIANCE", date_obj, "OFF")
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(
|
2022-09-19 14:22:10 +00:00
|
|
|
"Put new version of object with [--object-lock-mode COMPLIANCE] и [--object-lock-retain-until-date +2days]"
|
|
|
|
):
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=3)
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
|
|
|
object_lock_legal_hold_status="ON",
|
|
|
|
)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.assert_object_lock_mode(s3_client, bucket, file_name, "COMPLIANCE", date_obj, "ON")
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object with lock-mode"):
|
2022-10-03 13:03:55 +00:00
|
|
|
with pytest.raises(
|
|
|
|
Exception,
|
2022-10-11 08:18:08 +00:00
|
|
|
match=r".*must both be supplied*",
|
2022-10-03 13:03:55 +00:00
|
|
|
):
|
2022-10-11 08:18:08 +00:00
|
|
|
# x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1, object_lock_mode="COMPLIANCE")
|
2022-10-03 13:03:55 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object with lock-mode and past date"):
|
2022-10-11 08:18:08 +00:00
|
|
|
date_obj = datetime.utcnow() - timedelta(days=3)
|
|
|
|
with pytest.raises(
|
|
|
|
Exception,
|
|
|
|
match=r".*until date must be in the future*",
|
|
|
|
):
|
|
|
|
# The retain until date must be in the future
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-10-11 08:18:08 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
2022-10-11 08:18:08 +00:00
|
|
|
)
|
|
|
|
|
2024-06-24 23:27:54 +00:00
|
|
|
@allure.title("Delete object & delete objects (s3_client={s3_client})")
|
|
|
|
def test_s3_api_delete(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
two_buckets: list[str],
|
|
|
|
simple_object_size: ObjectSize,
|
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Check delete_object and delete_objects S3 API operation. From first bucket some objects deleted one by one.
|
|
|
|
From second bucket some objects deleted all at once.
|
|
|
|
"""
|
|
|
|
max_obj_count = 20
|
|
|
|
max_delete_objects = 17
|
|
|
|
put_objects = []
|
|
|
|
file_paths = []
|
|
|
|
obj_sizes = [simple_object_size, complex_object_size]
|
|
|
|
|
|
|
|
bucket_1, bucket_2 = two_buckets
|
|
|
|
|
|
|
|
with reporter.step(f"Generate {max_obj_count} files"):
|
|
|
|
for _ in range(max_obj_count):
|
|
|
|
test_file = generate_file(random.choice(obj_sizes).value)
|
|
|
|
file_paths.append(test_file)
|
|
|
|
put_objects.append(s3_helper.object_key_from_file_path(test_file.path))
|
|
|
|
|
|
|
|
for i, bucket in enumerate([bucket_1, bucket_2], 1):
|
|
|
|
with reporter.step(f"Put {max_obj_count} objects into bucket_{i}"):
|
|
|
|
for file_path in file_paths:
|
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
|
|
|
|
with reporter.step(f"Check all objects put in bucket_{i} successfully"):
|
|
|
|
bucket_objects = s3_client.list_objects_v2(bucket)
|
|
|
|
assert set(put_objects) == set(
|
|
|
|
bucket_objects
|
|
|
|
), f"Expected all objects {put_objects} in objects list {bucket_objects}"
|
|
|
|
|
|
|
|
with reporter.step("Delete some objects from bucket_1 one by one"):
|
|
|
|
objects_to_delete_b1 = random.sample(put_objects, k=max_delete_objects)
|
|
|
|
for obj in objects_to_delete_b1:
|
|
|
|
s3_client.delete_object(bucket_1, obj)
|
|
|
|
|
|
|
|
with reporter.step("Check deleted objects are not visible in bucket bucket_1"):
|
|
|
|
bucket_objects = s3_client.list_objects_v2(bucket_1)
|
|
|
|
assert set(put_objects).difference(set(objects_to_delete_b1)) == set(
|
|
|
|
bucket_objects
|
|
|
|
), f"Expected all objects {put_objects} in objects list {bucket_objects}"
|
|
|
|
for object_key in objects_to_delete_b1:
|
|
|
|
with pytest.raises(Exception, match="The specified key does not exist"):
|
|
|
|
s3_client.get_object(bucket_1, object_key)
|
|
|
|
|
|
|
|
with reporter.step("Delete some objects from bucket_2 at once"):
|
|
|
|
objects_to_delete_b2 = random.sample(put_objects, k=max_delete_objects)
|
|
|
|
s3_client.delete_objects(bucket_2, objects_to_delete_b2)
|
|
|
|
|
|
|
|
with reporter.step("Check deleted objects are not visible in bucket bucket_2"):
|
|
|
|
objects_list = s3_client.list_objects_v2(bucket_2)
|
|
|
|
assert set(put_objects).difference(set(objects_to_delete_b2)) == set(
|
|
|
|
objects_list
|
|
|
|
), f"Expected all objects {put_objects} in objects list {bucket_objects}"
|
|
|
|
for object_key in objects_to_delete_b2:
|
|
|
|
with pytest.raises(Exception, match="The specified key does not exist"):
|
|
|
|
s3_client.get_object(bucket_2, object_key)
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Sync directory (sync_type={sync_type}, s3_client={s3_client})")
|
2023-11-27 10:47:02 +00:00
|
|
|
@pytest.mark.parametrize("s3_client", [AwsCliClient], indirect=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("sync_type", ["sync", "cp"])
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_sync_dir(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
sync_type: Literal["sync", "cp"],
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2024-06-18 10:00:56 +00:00
|
|
|
test_file_1 = TestFile(os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_1"))
|
|
|
|
test_file_2 = TestFile(os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_2"))
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2024-06-18 10:00:56 +00:00
|
|
|
key_to_path = {"test_file_1": test_file_1.path, "test_file_2": test_file_2.path}
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2024-06-18 10:00:56 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, test_file_1)
|
|
|
|
generate_file_with_content(simple_object_size.value, test_file_2)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2024-06-05 10:07:07 +00:00
|
|
|
|
2022-09-19 14:22:10 +00:00
|
|
|
if sync_type == "sync":
|
2024-06-18 10:00:56 +00:00
|
|
|
s3_client.sync(bucket, os.path.dirname(test_file_1), metadata=object_metadata)
|
2022-09-19 14:22:10 +00:00
|
|
|
elif sync_type == "cp":
|
2024-06-18 10:00:56 +00:00
|
|
|
s3_client.cp(bucket, os.path.dirname(test_file_1), metadata=object_metadata)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check objects are synced"):
|
2023-05-15 09:59:33 +00:00
|
|
|
objects = s3_client.list_objects(bucket)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert set(key_to_path.keys()) == set(objects), f"Expected all abjects saved. Got {objects}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Check these are the same objects"):
|
2022-09-19 14:22:10 +00:00
|
|
|
for obj_key in objects:
|
2023-05-15 09:59:33 +00:00
|
|
|
got_object = s3_client.get_object(bucket, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(got_object) == get_file_hash(
|
|
|
|
key_to_path.get(obj_key)
|
|
|
|
), "Expected hashes are the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, obj_key)
|
2023-10-31 14:51:09 +00:00
|
|
|
assert obj_head.get("Metadata") == object_metadata, f"Metadata of object is {object_metadata}"
|
2024-06-05 10:07:07 +00:00
|
|
|
object_grants = s3_client.get_object_acl(bucket, obj_key)
|
|
|
|
s3_helper.verify_acl_permissions(object_grants, PRIVATE_GRANTS)
|
2022-12-01 08:58:05 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put 10 nested level object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_10_folder(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2024-06-28 12:15:25 +00:00
|
|
|
key_characters_sample = string.ascii_letters + string.digits + "._-"
|
2022-12-01 08:58:05 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object"):
|
2024-06-28 12:15:25 +00:00
|
|
|
test_file = generate_file(simple_object_size.value)
|
|
|
|
obj_key = (
|
|
|
|
"/"
|
|
|
|
+ "/".join(["".join(random.choices(key_characters_sample, k=5)) for _ in range(10)])
|
|
|
|
+ "/test_file_1"
|
|
|
|
)
|
|
|
|
s3_client.put_object(bucket, test_file, obj_key)
|
|
|
|
|
|
|
|
with reporter.step("Check object can be downloaded"):
|
|
|
|
s3_client.get_object(bucket, obj_key)
|
|
|
|
|
|
|
|
with reporter.step("Check object listing"):
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [obj_key])
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete non-existing object from empty bucket (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_delete_non_existing_object(self, s3_client: S3ClientWrapper, bucket: str):
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
|
|
|
obj_key = "fake_object_key"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete non-existing object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key)
|
2023-05-04 06:52:55 +00:00
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete the same object twice (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_delete_twice(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put object into one bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete the object from the bucket"):
|
2023-05-15 17:20:27 +00:00
|
|
|
delete_object = s3_client.delete_object(bucket, file_name)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-10-31 14:51:09 +00:00
|
|
|
obj_versions = {version.get("VersionId") for version in versions if version.get("Key") == file_name}
|
2024-06-24 23:27:54 +00:00
|
|
|
assert obj_versions, f"Object versions were not found {versions}"
|
2023-05-04 06:52:55 +00:00
|
|
|
assert "DeleteMarker" in delete_object.keys(), "Delete markers not found"
|
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete the object from the bucket again"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_object_2nd_attempt = s3_client.delete_object(bucket, file_name)
|
|
|
|
versions_2nd_attempt = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-10-31 14:51:09 +00:00
|
|
|
assert delete_object.keys() == delete_object_2nd_attempt.keys(), "Delete markers are not the same"
|
2023-05-04 06:52:55 +00:00
|
|
|
# check that nothing was changed
|
|
|
|
# checking here not VersionId only, but all data (for example LastModified)
|
|
|
|
assert versions == versions_2nd_attempt, "Versions are not the same"
|