Skip to content

Commit

Permalink
add object locking for mcg buckets
Browse files Browse the repository at this point in the history
Signed-off-by: fbalak <[email protected]>
  • Loading branch information
fbalak committed Nov 10, 2023
1 parent 2f2e6a9 commit 8a9ead8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ocs_ci/ocs/resources/objectbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(
replication_policy=None,
quota=None,
versioning=False,
object_lock=False,
*args,
**kwargs,
):
Expand All @@ -159,6 +160,7 @@ def __init__(

self.quota = quota
self.versioning = versioning
self.object_lock = object_lock
self.namespace = config.ENV_DATA["cluster_namespace"]
logger.info(f"Creating bucket: {self.name}")

Expand Down Expand Up @@ -425,7 +427,9 @@ def __init__(self, *args, **kwargs):
else:
self.s3resource = self.mcg.s3_resource
self.s3client = self.mcg.s3_client
self.s3resource.create_bucket(Bucket=self.name)
self.s3resource.create_bucket(
Bucket=self.name, ObjectLockEnabledForBucket=self.object_lock
)
if self.versioning:
self.set_versioning("Enabled")

Expand Down
11 changes: 10 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,7 @@ def _create_buckets(
bucketclass=None,
replication_policy=None,
versioning=False,
object_lock=False,
*args,
**kwargs,
):
Expand All @@ -2772,13 +2773,20 @@ def _create_buckets(
bucketclass (dict): A dictionary describing a new
bucketclass to be created.
When None, the default bucketclass is used.
versioning (bool): Enable or disable versining for the bucket
versioning (bool): Enable or disable versioning for the bucket
object_lock (bool): Enable or disable Object Lock for the bucket
Versioning needs to be enabled for the bucket if object_lock
is enabled.
Returns:
list: A list of s3.Bucket objects, containing all the created
buckets
"""
if object_lock and not versioning:
raise ValueError(
"Enabling object_lock for a bucket requires to enable versioning too"
)
if bucketclass:
interface = bucketclass["interface"]

Expand All @@ -2804,6 +2812,7 @@ def _create_buckets(
bucketclass=bucketclass,
replication_policy=replication_policy,
versioning=versioning,
object_lock=object_lock,
*args,
**kwargs,
)
Expand Down

0 comments on commit 8a9ead8

Please sign in to comment.