diff --git a/ocs_ci/ocs/resources/objectbucket.py b/ocs_ci/ocs/resources/objectbucket.py index 01205803734..8cd0facb9b1 100644 --- a/ocs_ci/ocs/resources/objectbucket.py +++ b/ocs_ci/ocs/resources/objectbucket.py @@ -144,6 +144,7 @@ def __init__( replication_policy=None, quota=None, versioning=False, + object_lock=False, *args, **kwargs, ): @@ -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}") @@ -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") diff --git a/tests/conftest.py b/tests/conftest.py index 1c6c0bffd23..0fa96f6bb2b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2757,6 +2757,7 @@ def _create_buckets( bucketclass=None, replication_policy=None, versioning=False, + object_lock=False, *args, **kwargs, ): @@ -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"] @@ -2804,6 +2812,7 @@ def _create_buckets( bucketclass=bucketclass, replication_policy=replication_policy, versioning=versioning, + object_lock=object_lock, *args, **kwargs, )