Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate part of s3 tests to dynamic env #699

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions dynamic_env_pytest_tests/tests/services/s3_gate/test_s3_bucket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import allure
import pytest
from file_helper import generate_file
from s3_helper import (
assert_object_lock_mode,
check_objects_in_bucket,
object_key_from_file_path,
assert_bucket_s3_acl,
)

from datetime import datetime, timedelta
from pytest_tests.steps import s3_gate_bucket, s3_gate_object
from s3.s3_gate_base import TestNeofsS3GateBase


def pytest_generate_tests(metafunc):
if "s3_client" in metafunc.fixturenames:
metafunc.parametrize("s3_client", ["aws cli", "boto3"], indirect=True)


@pytest.mark.s3_gate
@pytest.mark.s3_gate_bucket
class TestS3GateBucket(TestNeofsS3GateBase):
@pytest.mark.acl
@pytest.mark.sanity
@allure.title("Test S3: Create Bucket with different ACL")
vvarg229 marked this conversation as resolved.
Show resolved Hide resolved
def test_s3_create_bucket_with_ACL(self):

with allure.step("Create bucket with ACL private"):
acl="private"
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, True, acl=acl, bucket_configuration="rep-1")
vvarg229 marked this conversation as resolved.
Show resolved Hide resolved
bucket_acl = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket)
assert_bucket_s3_acl(
acl_grants=bucket_acl, permitted_users="CanonicalUser", acl=acl
)

with allure.step("Create bucket with ACL = public-read"):
vvarg229 marked this conversation as resolved.
Show resolved Hide resolved
acl="public-read"
bucket_1 = s3_gate_bucket.create_bucket_s3(self.s3_client, True, acl=acl, bucket_configuration="rep-1")
bucket_acl_1 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_1)
assert_bucket_s3_acl(
acl_grants=bucket_acl_1, permitted_users="AllUsers", acl=acl
)

with allure.step("Create bucket with ACL public-read-write"):
acl="public-read-write"
bucket_2 = s3_gate_bucket.create_bucket_s3(
self.s3_client, True, acl=acl, bucket_configuration="rep-1"
)
bucket_acl_2 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_2)
assert_bucket_s3_acl(
acl_grants=bucket_acl_2, permitted_users="AllUsers", acl=acl
)

with allure.step("Create bucket with ACL = authenticated-read"):
acl="authenticated-read"
bucket_3 = s3_gate_bucket.create_bucket_s3(
self.s3_client, True, acl=acl, bucket_configuration="rep-1"
)
bucket_acl_3 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_3)
assert_bucket_s3_acl(
acl_grants=bucket_acl_3, permitted_users="AllUsers", acl=acl
)

@pytest.mark.acl
@allure.title("Test S3: Create Bucket with different ACL by grand")
def test_s3_create_bucket_with_grands(self):

with allure.step("Create bucket with --grant-read"):
vvarg229 marked this conversation as resolved.
Show resolved Hide resolved
bucket = s3_gate_bucket.create_bucket_s3(
self.s3_client,
True,
grant_read="uri=http://acs.amazonaws.com/groups/global/AllUsers",
bucket_configuration="rep-1",
)
bucket_acl = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket)
assert_bucket_s3_acl(
acl_grants=bucket_acl, permitted_users="AllUsers", acl="grant-read"
)

with allure.step("Create bucket with --grant-wtite"):
vvarg229 marked this conversation as resolved.
Show resolved Hide resolved
bucket_1 = s3_gate_bucket.create_bucket_s3(
self.s3_client,
True,
grant_write="uri=http://acs.amazonaws.com/groups/global/AllUsers",
bucket_configuration="rep-1",
)
bucket_acl_1 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_1)
assert_bucket_s3_acl(
acl_grants=bucket_acl_1, permitted_users="AllUsers", acl="grant-write"
)

with allure.step("Create bucket with --grant-full-control"):
bucket_2 = s3_gate_bucket.create_bucket_s3(
self.s3_client,
True,
grant_full_control="uri=http://acs.amazonaws.com/groups/global/AllUsers",
bucket_configuration="rep-1",
)
bucket_acl_2 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_2)
assert_bucket_s3_acl(
acl_grants=bucket_acl_2, permitted_users="AllUsers", acl="grant-full-control"
)

@allure.title("Test S3: create bucket with object lock")
def test_s3_bucket_object_lock(self, simple_object_size):
file_path = generate_file(simple_object_size)
file_name = object_key_from_file_path(file_path)

with allure.step("Create bucket with --no-object-lock-enabled-for-bucket"):
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, False, bucket_configuration="rep-1")
date_obj = datetime.utcnow() + timedelta(days=1)
with pytest.raises(
Exception, match=r".*Object Lock configuration does not exist for this bucket.*"
):
# An error occurred (ObjectLockConfigurationNotFoundError) when calling the PutObject operation (reached max retries: 0):
# Object Lock configuration does not exist for this bucket
s3_gate_object.put_object_s3(
self.s3_client,
bucket,
file_path,
ObjectLockMode="COMPLIANCE",
ObjectLockRetainUntilDate=date_obj.strftime("%Y-%m-%dT%H:%M:%S"),
)
with allure.step("Create bucket with --object-lock-enabled-for-bucket"):
bucket_1 = s3_gate_bucket.create_bucket_s3(self.s3_client, True, bucket_configuration="rep-1")
date_obj_1 = datetime.utcnow() + timedelta(days=1)
s3_gate_object.put_object_s3(
self.s3_client,
bucket_1,
file_path,
ObjectLockMode="COMPLIANCE",
ObjectLockRetainUntilDate=date_obj_1.strftime("%Y-%m-%dT%H:%M:%S"),
ObjectLockLegalHoldStatus="ON",
)
assert_object_lock_mode(
self.s3_client, bucket_1, file_name, "COMPLIANCE", date_obj_1, "ON"
)

@allure.title("Test S3: delete bucket")
def test_s3_delete_bucket(self, simple_object_size):
file_path_1 = generate_file(simple_object_size)
file_name_1 = object_key_from_file_path(file_path_1)
file_path_2 = generate_file(simple_object_size)
file_name_2 = object_key_from_file_path(file_path_2)
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, bucket_configuration="rep-1")

with allure.step("Put two objects into bucket"):
s3_gate_object.put_object_s3(self.s3_client, bucket, file_path_1)
s3_gate_object.put_object_s3(self.s3_client, bucket, file_path_2)
check_objects_in_bucket(self.s3_client, bucket, [file_name_1, file_name_2])

with allure.step("Try to delete not empty bucket and get error"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd say

Suggested change
with allure.step("Try to delete not empty bucket and get error"):
with allure.step("Try to delete not empty bucket and expect error"):

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with pytest.raises(Exception, match=r".*The bucket you tried to delete is not empty.*"):
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket)

with allure.step("Delete object in bucket"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with allure.step("Delete object in bucket"):
with allure.step("Delete all objects in bucket"):

for better textual coherence between previous and next steps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s3_gate_object.delete_object_s3(self.s3_client, bucket, file_name_1)
s3_gate_object.delete_object_s3(self.s3_client, bucket, file_name_2)
check_objects_in_bucket(self.s3_client, bucket, [])

with allure.step(f"Delete empty bucket"):
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket)
with pytest.raises(Exception, match=r".*Not Found.*"):
s3_gate_bucket.head_bucket(self.s3_client, bucket)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other reading ops behaving like HEAD for this case? I'd check all of them against Not Found. exception here

Loading
Loading