forked from TrueCloudLab/s3-tests
Merge pull request #345 from huangp0600/hp-dev
Fix: Bucket resource leak when cleanup
This commit is contained in:
commit
7f8a12423f
1 changed files with 9 additions and 4 deletions
|
@ -113,6 +113,7 @@ def nuke_prefixed_buckets(prefix, client=None):
|
||||||
|
|
||||||
buckets = get_buckets_list(client, prefix)
|
buckets = get_buckets_list(client, prefix)
|
||||||
|
|
||||||
|
err = None
|
||||||
if buckets != []:
|
if buckets != []:
|
||||||
for bucket_name in buckets:
|
for bucket_name in buckets:
|
||||||
objects_list = get_objects_list(bucket_name, client)
|
objects_list = get_objects_list(bucket_name, client)
|
||||||
|
@ -126,11 +127,15 @@ def nuke_prefixed_buckets(prefix, client=None):
|
||||||
response = client.delete_object(Bucket=bucket_name,Key=obj[0],VersionId=obj[1])
|
response = client.delete_object(Bucket=bucket_name,Key=obj[0],VersionId=obj[1])
|
||||||
try:
|
try:
|
||||||
response = client.delete_bucket(Bucket=bucket_name)
|
response = client.delete_bucket(Bucket=bucket_name)
|
||||||
except ClientError:
|
except ClientError as e:
|
||||||
# if DELETE times out, the retry may see NoSuchBucket
|
# The exception shouldn't be raised when doing cleanup. Pass and continue
|
||||||
if response['Error']['Code'] != 'NoSuchBucket':
|
# the bucket cleanup process. Otherwise left buckets wouldn't be cleared
|
||||||
raise ClientError
|
# resulting in some kind of resource leak. err is used to hint user some
|
||||||
|
# exception once occurred.
|
||||||
|
err = e
|
||||||
pass
|
pass
|
||||||
|
if err:
|
||||||
|
raise err
|
||||||
|
|
||||||
print('Done with cleanup of buckets in tests.')
|
print('Done with cleanup of buckets in tests.')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue