From 4a6fe93f5264b737cea55f664b5847df5c253a47 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Thu, 7 Mar 2024 14:27:13 -0500 Subject: [PATCH] add test test_lifecycle_expiration_newer_noncurrent() This verifies the new NewerNoncurrentVersions lifecycle filter operator. Signed-off-by: Matt Benjamin (cherry picked from commit a5aa59df04b4fe446962c7394a53084c10212b84) --- s3tests_boto3/functional/test_s3.py | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/s3tests_boto3/functional/test_s3.py b/s3tests_boto3/functional/test_s3.py index 4a188bf..47c9656 100644 --- a/s3tests_boto3/functional/test_s3.py +++ b/s3tests_boto3/functional/test_s3.py @@ -8433,6 +8433,63 @@ def test_lifecycle_expiration_noncur_tags1(): # at T+60, only the current object version should exist assert num_objs == 1 +def wait_interval_list_object_versions(client, bucket_name, secs): + time.sleep(secs) + try: + response = client.list_object_versions(Bucket=bucket_name) + objs_list = response['Versions'] + except: + objs_list = [] + return len(objs_list) + +@pytest.mark.lifecycle +@pytest.mark.lifecycle_expiration +@pytest.mark.fails_on_aws +@pytest.mark.fails_on_dbstore +def test_lifecycle_expiration_newer_noncurrent(): + bucket_name = get_new_bucket() + client = get_client() + + check_configure_versioning_retry(bucket_name, "Enabled", "Enabled") + + # create 10 object versions (9 noncurrent) + key = "myobject_" + + for ix in range(10): + body = "%s v%d" % (key, ix) + response = client.put_object(Bucket=bucket_name, Key=key, Body=body) + assert response['ResponseMetadata']['HTTPStatusCode'] == 200 + + # add a lifecycle rule which sets newer-noncurrent-versions to 5 + days = 1 + lifecycle_config = { + 'Rules': [ + { + 'NoncurrentVersionExpiration': { + 'NoncurrentDays': days, + 'NewerNoncurrentVersions': 5, + }, + 'ID': 'newer_noncurrent1', + 'Filter': { + 'Prefix': '', + }, + 'Status': 'Enabled', + }, + ] + } + + response = client.put_bucket_lifecycle_configuration( + Bucket=bucket_name, LifecycleConfiguration=lifecycle_config) + assert response['ResponseMetadata']['HTTPStatusCode'] == 200 + + lc_interval = get_lc_debug_interval() + + num_objs = wait_interval_list_object_versions( + client, bucket_name, 2*lc_interval) + + # at T+20, 6 objects should exist (1 current and (9 - 5) noncurrent) + assert num_objs == 6 + @pytest.mark.lifecycle def test_lifecycle_id_too_long(): bucket_name = get_new_bucket()