2022-09-26 08:25:49 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper, S3ClientWrapper, VersioningStatus
|
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
|
|
|
from frostfs_testlib.utils.file_utils import generate_file, generate_file_with_content
|
2022-10-11 08:18:08 +00:00
|
|
|
|
2022-09-26 08:25:49 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc):
|
2022-09-26 08:25:49 +00:00
|
|
|
if "s3_client" in metafunc.fixturenames:
|
2023-05-15 09:59:33 +00:00
|
|
|
metafunc.parametrize("s3_client", [AwsCliClient, Boto3ClientWrapper], indirect=True)
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
2022-09-26 08:25:49 +00:00
|
|
|
@pytest.mark.s3_gate
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.s3_gate_versioning
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestS3GateVersioning:
|
2022-09-26 08:25:49 +00:00
|
|
|
@allure.title("Test S3: try to disable versioning")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_version_off(self, s3_client: S3ClientWrapper):
|
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True)
|
2022-09-26 08:25:49 +00:00
|
|
|
with pytest.raises(Exception):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.SUSPENDED)
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
@allure.title("Test S3: Enable and disable versioning")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_version(self, s3_client: S3ClientWrapper, simple_object_size: int):
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path = generate_file(simple_object_size)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-26 08:25:49 +00:00
|
|
|
bucket_objects = [file_name]
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=False)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.SUSPENDED)
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
objects_list = s3_client.list_objects(bucket)
|
2022-09-26 08:25:49 +00:00
|
|
|
assert (
|
|
|
|
objects_list == bucket_objects
|
|
|
|
), f"Expected list with single objects in bucket, got {objects_list}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_version = s3_client.list_objects_versions(bucket)
|
2022-09-26 08:25:49 +00:00
|
|
|
actual_version = [
|
|
|
|
version.get("VersionId")
|
|
|
|
for version in object_version
|
|
|
|
if version.get("Key") == file_name
|
|
|
|
]
|
2022-10-16 16:29:09 +00:00
|
|
|
assert actual_version == [
|
|
|
|
"null"
|
|
|
|
], f"Expected version is null in list-object-versions, got {object_version}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_0 = s3_client.head_object(bucket, file_name)
|
2022-10-16 16:29:09 +00:00
|
|
|
assert (
|
|
|
|
object_0.get("VersionId") == "null"
|
|
|
|
), f"Expected version is null in head-object, got {object_0.get('VersionId')}"
|
2022-09-26 08:25:49 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-26 08:25:49 +00:00
|
|
|
|
|
|
|
with allure.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)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size, 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-26 08:25:49 +00:00
|
|
|
|
|
|
|
with allure.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-26 08:25:49 +00:00
|
|
|
obj_versions = [
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == file_name
|
|
|
|
]
|
|
|
|
assert (
|
|
|
|
obj_versions.sort() == [version_id_1, version_id_2, "null"].sort()
|
|
|
|
), f"Expected object has versions: {version_id_1, version_id_2, 'null'}"
|
|
|
|
|
|
|
|
with allure.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1 = s3_client.get_object(bucket, file_name, full_output=True)
|
2022-09-26 08:25:49 +00:00
|
|
|
assert (
|
|
|
|
object_1.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|
|
|
|
|
|
|
|
with allure.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2 = s3_client.get_object(bucket, file_name, version_id_1, full_output=True)
|
2022-09-26 08:25:49 +00:00
|
|
|
assert (
|
|
|
|
object_2.get("VersionId") == version_id_1
|
|
|
|
), f"Get object with version {version_id_1}"
|
|
|
|
|
|
|
|
with allure.step("Get second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, file_name, version_id_2, full_output=True)
|
2022-09-26 08:25:49 +00:00
|
|
|
assert (
|
|
|
|
object_3.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|