]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test_multi: add more bucket related tests
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 18 Dec 2015 22:07:58 +0000 (14:07 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:46 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/test/rgw/test_multi.py

index 85ecafd02eef57027702f10a52ead817d261af26..1b7118d50f5bddf5b93c1faa7ebda0ed4bc65d5c 100644 (file)
@@ -16,8 +16,8 @@ import inspect
 
 from nose.tools import eq_ as eq
 
-def lineno():
-    return inspect.currentframe().f_back.f_lineno
+num_buckets = 0
+run_prefix=''.join(random.SystemRandom().choice(string.ascii_lowercase) for _ in range(6))
 
 mstart_path = os.getenv('MSTART_PATH')
 if mstart_path is None:
@@ -25,6 +25,9 @@ if mstart_path is None:
 
 test_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__))) + '/'
 
+def lineno():
+    return inspect.currentframe().f_back.f_lineno
+
 def log(*params):
     s = '>>> '
     for p in params:
@@ -291,6 +294,12 @@ def gen_access_key():
 def gen_secret():
      return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(32))
 
+def gen_bucket_name():
+    global num_buckets
+
+    num_buckets += 1
+    return run_prefix + '-' + str(num_buckets)
+
 class RGWMulti:
     def __init__(self, num_clusters):
         self.num_clusters = num_clusters
@@ -340,22 +349,78 @@ def check_all_buckets_exist(zone, buckets):
 
     return True
 
-def test_create_bucket():
-    i = 0
+def check_all_buckets_dont_exist(zone, buckets):
+    conn = zone.get_connection(user)
+
+    for b in buckets:
+        try:
+            conn.get_bucket(b)
+        except:
+            continue
+
+        log('zone ', zone.zone_name, ' contains bucket ', b)
+        return False
+
+    return True
+
+def create_bucket_per_zone():
     buckets = []
+    zone_bucket = {}
     for zone in realm.get_zones():
         conn = zone.get_connection(user)
-        log('create bucket')
-        bucket_name = 'buck-{i}'.format(i=i)
+        bucket_name = gen_bucket_name()
+        log('create bucket zone=', zone.zone_name, ' name=', bucket_name)
         bucket = conn.create_bucket(bucket_name)
         buckets.append(bucket_name)
-        i += 1
+        zone_bucket[zone] = bucket
+
+    return buckets, zone_bucket
+
+def test_create_bucket():
+    buckets, _ = create_bucket_per_zone()
+    realm.meta_checkpoint()
+
+    for zone in realm.get_zones():
+        assert check_all_buckets_exist(zone, buckets)
+
+def test_recreate_bucket():
+    buckets, _ = create_bucket_per_zone()
+    realm.meta_checkpoint()
+
+    for zone in realm.get_zones():
+        assert check_all_buckets_exist(zone, buckets)
+
+    # recreate buckets on all zones, make sure they weren't removed
+    for zone in realm.get_zones():
+        for bucket_name in buckets:
+            conn = zone.get_connection(user)
+            bucket = conn.create_bucket(bucket_name)
+
+    for zone in realm.get_zones():
+        assert check_all_buckets_exist(zone, buckets)
+
+    realm.meta_checkpoint()
+
+    for zone in realm.get_zones():
+        assert check_all_buckets_exist(zone, buckets)
 
+def test_remove_bucket():
+    buckets, zone_bucket = create_bucket_per_zone()
     realm.meta_checkpoint()
 
     for zone in realm.get_zones():
         assert check_all_buckets_exist(zone, buckets)
 
+    for zone, bucket_name in zone_bucket.iteritems():
+        conn = zone.get_connection(user)
+        conn.delete_bucket(bucket_name)
+
+    realm.meta_checkpoint()
+
+    for zone in realm.get_zones():
+        assert check_all_buckets_dont_exist(zone, buckets)
+
+
 def init(parse_args):
     cfg = ConfigParser.RawConfigParser({
                                          'num_zones': 2,
@@ -394,6 +459,7 @@ def init(parse_args):
 
     rgw_multi.setup(not args.no_bootstrap)
 
+
 def setup_module():
     init(False)