mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-21 23:29:47 +00:00
Rework nuke_buckets
Nuke all buckets on the master, sync, and then nuke any remaining buckets on non-master regions. Signed-off-by: Joe Buck <jbbuck@gmail.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
This commit is contained in:
parent
e54c700bbd
commit
15f7fcfc84
1 changed files with 43 additions and 23 deletions
|
@ -7,6 +7,8 @@ import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
from .utils import region_sync_meta
|
||||||
|
|
||||||
s3 = bunch.Bunch()
|
s3 = bunch.Bunch()
|
||||||
config = bunch.Bunch()
|
config = bunch.Bunch()
|
||||||
targets = bunch.Bunch()
|
targets = bunch.Bunch()
|
||||||
|
@ -49,31 +51,49 @@ def choose_bucket_prefix(template, max_len=30):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def nuke_prefixed_buckets_on_conn(prefix, name, conn):
|
||||||
|
print 'Cleaning buckets from connection {name} prefix {prefix!r}.'.format(
|
||||||
|
name=name,
|
||||||
|
prefix=prefix,
|
||||||
|
)
|
||||||
|
for bucket in conn.get_all_buckets():
|
||||||
|
if bucket.name.startswith(prefix):
|
||||||
|
print 'Cleaning bucket {bucket}'.format(bucket=bucket)
|
||||||
|
try:
|
||||||
|
bucket.set_canned_acl('private')
|
||||||
|
for key in bucket.list():
|
||||||
|
print 'Cleaning bucket {bucket} key {key}'.format(
|
||||||
|
bucket=bucket,
|
||||||
|
key=key,
|
||||||
|
)
|
||||||
|
key.set_canned_acl('private')
|
||||||
|
key.delete()
|
||||||
|
bucket.delete()
|
||||||
|
except boto.exception.S3ResponseError as e:
|
||||||
|
if e.error_code != 'AccessDenied':
|
||||||
|
print 'GOT UNWANTED ERROR', e.error_code
|
||||||
|
raise
|
||||||
|
# seems like we're not the owner of the bucket; ignore
|
||||||
|
pass
|
||||||
|
|
||||||
def nuke_prefixed_buckets(prefix):
|
def nuke_prefixed_buckets(prefix):
|
||||||
|
# First, delete all buckets on the master connection
|
||||||
for name, conn in s3.items():
|
for name, conn in s3.items():
|
||||||
print 'Cleaning buckets from connection {name} prefix {prefix!r}.'.format(
|
#if conn == s3[targets.main.master]:
|
||||||
name=name,
|
if conn == targets.main.master.connection:
|
||||||
prefix=prefix,
|
print 'Deleting buckets on {name} (master)'.format(name=name)
|
||||||
)
|
nuke_prefixed_buckets_on_conn(prefix, name, conn)
|
||||||
for bucket in conn.get_all_buckets():
|
|
||||||
if bucket.name.startswith(prefix):
|
# Then sync to propagate deletes to secondaries
|
||||||
print 'Cleaning bucket {bucket}'.format(bucket=bucket)
|
region_sync_meta(targets.main, targets.main.master.connection)
|
||||||
try:
|
print 'region-sync in nuke_prefixed_buckets'
|
||||||
bucket.set_canned_acl('private')
|
|
||||||
for key in bucket.list():
|
# Now delete remaining buckets on any other connection
|
||||||
print 'Cleaning bucket {bucket} key {key}'.format(
|
for name, conn in s3.items():
|
||||||
bucket=bucket,
|
#if conn != s3[targets.main.master]:
|
||||||
key=key,
|
if conn != targets.main.master.connection:
|
||||||
)
|
print 'Deleting buckets on {name} (non-master)'.format(name=name)
|
||||||
key.set_canned_acl('private')
|
nuke_prefixed_buckets_on_conn(prefix, name, conn)
|
||||||
key.delete()
|
|
||||||
bucket.delete()
|
|
||||||
except boto.exception.S3ResponseError as e:
|
|
||||||
if e.error_code != 'AccessDenied':
|
|
||||||
print 'GOT UNWANTED ERROR', e.error_code
|
|
||||||
raise
|
|
||||||
# seems like we're not the owner of the bucket; ignore
|
|
||||||
pass
|
|
||||||
|
|
||||||
print 'Done with cleanup of test buckets.'
|
print 'Done with cleanup of test buckets.'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue