]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
Rework nuke_buckets
authorJoe Buck <jbbuck@gmail.com>
Thu, 29 Aug 2013 22:48:09 +0000 (15:48 -0700)
committerJoe Buck <jbbuck@gmail.com>
Sat, 31 Aug 2013 05:13:34 +0000 (22:13 -0700)
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>
s3tests/functional/__init__.py

index ce609a89f44591ee493cfcb14075129903c37650..a845e1c546484f9ac739889cf7a9683fb8ea7c49 100644 (file)
@@ -7,6 +7,8 @@ import os
 import random
 import string
 
+from .utils import region_sync_meta
+
 s3 = bunch.Bunch()
 config = 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):
+    # First, delete all buckets on the master connection 
     for name, conn in s3.items():
-        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
+        #if conn == s3[targets.main.master]:
+        if conn == targets.main.master.connection:
+            print 'Deleting buckets on {name} (master)'.format(name=name)
+            nuke_prefixed_buckets_on_conn(prefix, name, conn)
+
+    # Then sync to propagate deletes to secondaries
+    region_sync_meta(targets.main, targets.main.master.connection)
+    print 'region-sync in nuke_prefixed_buckets'
+
+    # Now delete remaining buckets on any other connection 
+    for name, conn in s3.items():
+        #if conn != s3[targets.main.master]:
+        if conn != targets.main.master.connection:
+            print 'Deleting buckets on {name} (non-master)'.format(name=name)
+            nuke_prefixed_buckets_on_conn(prefix, name, conn)
 
     print 'Done with cleanup of test buckets.'