s3tests: lifecycle transitions: configurable storage classes

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
This commit is contained in:
Yehuda Sadeh 2019-01-03 17:32:34 -08:00
parent d024de76f8
commit 5522ac93fc
2 changed files with 55 additions and 26 deletions

View file

@ -319,6 +319,7 @@ def setup():
'port', 'port',
'is_secure', 'is_secure',
'kms_keyid', 'kms_keyid',
'storage_classes',
]: ]:
try: try:
config[name][var] = cfg.get(section, var) config[name][var] = cfg.get(section, var)

View file

@ -7654,6 +7654,18 @@ def set_lifecycle(rules = None):
bucket.configure_lifecycle(lifecycle) bucket.configure_lifecycle(lifecycle)
return bucket return bucket
def configured_storage_classes():
sc = [ 'STANDARD' ]
if 'storage_classes' in config['main']:
extra_sc = re.split('\W+', config['main']['storage_classes'])
for item in extra_sc:
if item != 'STANDARD':
sc.append(item)
return sc
def lc_transition(days=None, date=None, storage_class=None): def lc_transition(days=None, date=None, storage_class=None):
return boto.s3.lifecycle.Transition(days=days, date=date, storage_class=storage_class) return boto.s3.lifecycle.Transition(days=days, date=date, storage_class=storage_class)
@ -7766,8 +7778,12 @@ def list_bucket_storage_class(bucket):
@attr('lifecycle_transition') @attr('lifecycle_transition')
@attr('fails_on_aws') @attr('fails_on_aws')
def test_lifecycle_transition(): def test_lifecycle_transition():
bucket = set_lifecycle(rules=[{'id': 'rule1', 'transition': lc_transition(days=1, storage_class='FOOCLASS'), 'prefix': 'expire1/', 'status': 'Enabled'}, sc = configured_storage_classes()
{'id':'rule2', 'transition': lc_transition(days=4, storage_class='BARCLASS'), 'prefix': 'expire3/', 'status': 'Enabled'}]) if len(sc) < 3:
raise SkipTest
bucket = set_lifecycle(rules=[{'id': 'rule1', 'transition': lc_transition(days=1, storage_class=sc[1]), 'prefix': 'expire1/', 'status': 'Enabled'},
{'id':'rule2', 'transition': lc_transition(days=4, storage_class=sc[2]), 'prefix': 'expire3/', 'status': 'Enabled'}])
_create_keys(bucket=bucket, keys=['expire1/foo', 'expire1/bar', 'keep2/foo', _create_keys(bucket=bucket, keys=['expire1/foo', 'expire1/bar', 'keep2/foo',
'keep2/bar', 'expire3/foo', 'expire3/bar']) 'keep2/bar', 'expire3/foo', 'expire3/bar'])
# Get list of all keys # Get list of all keys
@ -7778,22 +7794,22 @@ def test_lifecycle_transition():
time.sleep(25) time.sleep(25)
expire1_keys = list_bucket_storage_class(bucket) expire1_keys = list_bucket_storage_class(bucket)
eq(len(expire1_keys['STANDARD']), 4) eq(len(expire1_keys['STANDARD']), 4)
eq(len(expire1_keys['FOOCLASS']), 2) eq(len(expire1_keys[sc[1]]), 2)
eq(len(expire1_keys['BARCLASS']), 0) eq(len(expire1_keys[sc[2]]), 0)
# Wait for next expiration cycle # Wait for next expiration cycle
time.sleep(10) time.sleep(10)
keep2_keys = list_bucket_storage_class(bucket) keep2_keys = list_bucket_storage_class(bucket)
eq(len(keep2_keys['STANDARD']), 4) eq(len(keep2_keys['STANDARD']), 4)
eq(len(keep2_keys['FOOCLASS']), 2) eq(len(keep2_keys[sc[1]]), 2)
eq(len(keep2_keys['BARCLASS']), 0) eq(len(keep2_keys[sc[2]]), 0)
# Wait for final expiration cycle # Wait for final expiration cycle
time.sleep(20) time.sleep(20)
expire3_keys = list_bucket_storage_class(bucket) expire3_keys = list_bucket_storage_class(bucket)
eq(len(expire3_keys['STANDARD']), 2) eq(len(expire3_keys['STANDARD']), 2)
eq(len(expire3_keys['FOOCLASS']), 2) eq(len(expire3_keys[sc[1]]), 2)
eq(len(expire3_keys['BARCLASS']), 2) eq(len(expire3_keys[sc[2]]), 2)
# The test harness for lifecycle is configured to treat days as 10 second intervals. # The test harness for lifecycle is configured to treat days as 10 second intervals.
@attr(resource='bucket') @attr(resource='bucket')
@ -7803,11 +7819,15 @@ def test_lifecycle_transition():
@attr('lifecycle_transition') @attr('lifecycle_transition')
@attr('fails_on_aws') @attr('fails_on_aws')
def test_lifecycle_transition_single_rule_multi_trans(): def test_lifecycle_transition_single_rule_multi_trans():
sc = configured_storage_classes()
if len(sc) < 3:
raise SkipTest
bucket = set_lifecycle(rules=[ bucket = set_lifecycle(rules=[
{'id': 'rule1', {'id': 'rule1',
'transition': lc_transitions([ 'transition': lc_transitions([
lc_transition(days=1, storage_class='FOOCLASS'), lc_transition(days=1, storage_class=sc[1]),
lc_transition(days=4, storage_class='BARCLASS')]), lc_transition(days=4, storage_class=sc[2])]),
'prefix': 'expire1/', 'prefix': 'expire1/',
'status': 'Enabled'}]) 'status': 'Enabled'}])
@ -7821,22 +7841,22 @@ def test_lifecycle_transition_single_rule_multi_trans():
time.sleep(25) time.sleep(25)
expire1_keys = list_bucket_storage_class(bucket) expire1_keys = list_bucket_storage_class(bucket)
eq(len(expire1_keys['STANDARD']), 4) eq(len(expire1_keys['STANDARD']), 4)
eq(len(expire1_keys['FOOCLASS']), 2) eq(len(expire1_keys[sc[1]]), 2)
eq(len(expire1_keys['BARCLASS']), 0) eq(len(expire1_keys[sc[2]]), 0)
# Wait for next expiration cycle # Wait for next expiration cycle
time.sleep(10) time.sleep(10)
keep2_keys = list_bucket_storage_class(bucket) keep2_keys = list_bucket_storage_class(bucket)
eq(len(keep2_keys['STANDARD']), 4) eq(len(keep2_keys['STANDARD']), 4)
eq(len(keep2_keys['FOOCLASS']), 2) eq(len(keep2_keys[sc[1]]), 2)
eq(len(keep2_keys['BARCLASS']), 0) eq(len(keep2_keys[sc[2]]), 0)
# Wait for final expiration cycle # Wait for final expiration cycle
time.sleep(20) time.sleep(20)
expire3_keys = list_bucket_storage_class(bucket) expire3_keys = list_bucket_storage_class(bucket)
eq(len(expire3_keys['STANDARD']), 4) eq(len(expire3_keys['STANDARD']), 4)
eq(len(expire3_keys['FOOCLASS']), 0) eq(len(expire3_keys[sc[1]]), 0)
eq(len(expire3_keys['BARCLASS']), 2) eq(len(expire3_keys[sc[2]]), 2)
@attr(resource='bucket') @attr(resource='bucket')
@attr(method='put') @attr(method='put')
@ -8060,6 +8080,10 @@ def test_lifecycle_noncur_expiration():
@attr('lifecycle') @attr('lifecycle')
@attr('lifecycle_transition') @attr('lifecycle_transition')
def test_lifecycle_set_noncurrent_transition(): def test_lifecycle_set_noncurrent_transition():
sc = configured_storage_classes()
if len(sc) < 3:
raise SkipTest
bucket = get_new_bucket() bucket = get_new_bucket()
rules = [ rules = [
{ {
@ -8069,11 +8093,11 @@ def test_lifecycle_set_noncurrent_transition():
'NoncurrentVersionTransition': [ 'NoncurrentVersionTransition': [
{ {
'NoncurrentDays': 2, 'NoncurrentDays': 2,
'StorageClass': 'FOOCLASS' 'StorageClass': sc[1]
}, },
{ {
'NoncurrentDays': 4, 'NoncurrentDays': 4,
'StorageClass': 'BARCLASS' 'StorageClass': sc[2]
} }
], ],
'NoncurrentVersionExpiration': { 'NoncurrentVersionExpiration': {
@ -8100,6 +8124,10 @@ def test_lifecycle_set_noncurrent_transition():
@attr('lifecycle_transition') @attr('lifecycle_transition')
@attr('fails_on_aws') @attr('fails_on_aws')
def test_lifecycle_noncur_transition(): def test_lifecycle_noncur_transition():
sc = configured_storage_classes()
if len(sc) < 3:
raise SkipTest
bucket = get_new_bucket() bucket = get_new_bucket()
check_configure_versioning_retry(bucket, True, "Enabled") check_configure_versioning_retry(bucket, True, "Enabled")
@ -8111,11 +8139,11 @@ def test_lifecycle_noncur_transition():
'NoncurrentVersionTransition': [ 'NoncurrentVersionTransition': [
{ {
'NoncurrentDays': 1, 'NoncurrentDays': 1,
'StorageClass': 'FOOCLASS' 'StorageClass': sc[1]
}, },
{ {
'NoncurrentDays': 3, 'NoncurrentDays': 3,
'StorageClass': 'BARCLASS' 'StorageClass': sc[2]
} }
], ],
'NoncurrentVersionExpiration': { 'NoncurrentVersionExpiration': {
@ -8138,21 +8166,21 @@ def test_lifecycle_noncur_transition():
time.sleep(25) time.sleep(25)
expire1_keys = list_bucket_storage_class(bucket) expire1_keys = list_bucket_storage_class(bucket)
eq(len(expire1_keys['STANDARD']), 2) eq(len(expire1_keys['STANDARD']), 2)
eq(len(expire1_keys['FOOCLASS']), 4) eq(len(expire1_keys[sc[1]]), 4)
eq(len(expire1_keys['BARCLASS']), 0) eq(len(expire1_keys[sc[2]]), 0)
time.sleep(20) time.sleep(20)
expire1_keys = list_bucket_storage_class(bucket) expire1_keys = list_bucket_storage_class(bucket)
eq(len(expire1_keys['STANDARD']), 2) eq(len(expire1_keys['STANDARD']), 2)
eq(len(expire1_keys['FOOCLASS']), 0) eq(len(expire1_keys[sc[1]]), 0)
eq(len(expire1_keys['BARCLASS']), 4) eq(len(expire1_keys[sc[2]]), 4)
time.sleep(20) time.sleep(20)
expire_keys = bucket.get_all_versions() expire_keys = bucket.get_all_versions()
expire1_keys = list_bucket_storage_class(bucket) expire1_keys = list_bucket_storage_class(bucket)
eq(len(expire1_keys['STANDARD']), 2) eq(len(expire1_keys['STANDARD']), 2)
eq(len(expire1_keys['FOOCLASS']), 0) eq(len(expire1_keys[sc[1]]), 0)
eq(len(expire1_keys['BARCLASS']), 0) eq(len(expire1_keys[sc[2]]), 0)
@attr(resource='bucket') @attr(resource='bucket')
@attr(method='put') @attr(method='put')