1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
import logging
from nose import SkipTest
from nose.tools import assert_not_equal, assert_equal
from boto.s3.deletemarker import DeleteMarker
from .tests import get_realm, \
ZonegroupConns, \
zonegroup_meta_checkpoint, \
zone_meta_checkpoint, \
zone_bucket_checkpoint, \
zone_data_checkpoint, \
zonegroup_bucket_checkpoint, \
check_bucket_eq, \
gen_bucket_name, \
get_user, \
get_tenant
from .zone_az import print_connection_info
# configure logging for the tests module
log = logging.getLogger(__name__)
##########################################
# utility functions for archive zone tests
##########################################
def check_az_configured():
"""check if at least one archive zone exist"""
realm = get_realm()
zonegroup = realm.master_zonegroup()
az_zones = zonegroup.zones_by_type.get("archive")
if az_zones is None or len(az_zones) != 1:
raise SkipTest("Requires one archive zone")
def is_az_zone(zone_conn):
"""check if a specific zone is archive zone"""
if not zone_conn:
return False
return zone_conn.zone.tier_type() == "archive"
def init_env():
"""initialize the environment"""
check_az_configured()
realm = get_realm()
zonegroup = realm.master_zonegroup()
zonegroup_conns = ZonegroupConns(zonegroup)
zonegroup_meta_checkpoint(zonegroup)
az_zones = []
zones = []
for conn in zonegroup_conns.zones:
if is_az_zone(conn):
zone_meta_checkpoint(conn.zone)
az_zones.append(conn)
elif not conn.zone.is_read_only():
zones.append(conn)
assert_not_equal(len(zones), 0)
assert_not_equal(len(az_zones), 0)
return zones, az_zones
def zone_full_checkpoint(target_zone, source_zone):
zone_meta_checkpoint(target_zone)
zone_data_checkpoint(target_zone, source_zone)
def check_bucket_exists_on_zone(zone, bucket_name):
try:
zone.conn.get_bucket(bucket_name)
except:
return False
return True
def check_key_exists(key):
try:
key.get_contents_as_string()
except:
return False
return True
def get_versioning_status(bucket):
res = bucket.get_versioning_status()
key = 'Versioning'
if not key in res:
return None
else:
return res[key]
def get_versioned_objs(bucket):
b = []
for b_entry in bucket.list_versions():
if isinstance(b_entry, DeleteMarker):
continue
d = {}
d['version_id'] = b_entry.version_id
d['size'] = b_entry.size
d['etag'] = b_entry.etag
d['is_latest'] = b_entry.is_latest
b.append({b_entry.key:d})
return b
def get_versioned_entries(bucket):
dm = []
ver = []
for b_entry in bucket.list_versions():
if isinstance(b_entry, DeleteMarker):
d = {}
d['version_id'] = b_entry.version_id
d['is_latest'] = b_entry.is_latest
dm.append({b_entry.name:d})
else:
d = {}
d['version_id'] = b_entry.version_id
d['size'] = b_entry.size
d['etag'] = b_entry.etag
d['is_latest'] = b_entry.is_latest
ver.append({b_entry.key:d})
return (dm, ver)
def get_number_buckets_by_zone(zone):
return len(zone.conn.get_all_buckets())
def get_bucket_names_by_zone(zone):
return [b.name for b in zone.conn.get_all_buckets()]
def get_full_bucket_name(partial_bucket_name, bucket_names_az):
full_bucket_name = None
for bucket_name in bucket_names_az:
if bucket_name.startswith(partial_bucket_name):
full_bucket_name = bucket_name
break
return full_bucket_name
####################
# archive zone tests
####################
def test_az_info():
""" log information for manual testing """
return SkipTest("only used in manual testing")
zones, az_zones = init_env()
realm = get_realm()
zonegroup = realm.master_zonegroup()
bucket_name = gen_bucket_name()
# create bucket on the first of the rados zones
bucket = zones[0].create_bucket(bucket_name)
# create objects in the bucket
number_of_objects = 3
for i in range(number_of_objects):
key = bucket.new_key(str(i))
key.set_contents_from_string('bar')
print('Zonegroup: ' + zonegroup.name)
print('user: ' + get_user())
print('tenant: ' + get_tenant())
print('Master Zone')
print_connection_info(zones[0].conn)
print('Archive Zone')
print_connection_info(az_zones[0].conn)
print('Bucket: ' + bucket_name)
def test_az_create_empty_bucket():
""" test empty bucket replication """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create bucket on the non archive zone
zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# bucket exist on the archive zone
p = check_bucket_exists_on_zone(az_zones[0], bucket_name)
assert_equal(p, True)
def test_az_check_empty_bucket_versioning():
""" test bucket vesioning with empty bucket """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create bucket on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# get bucket on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
# check for non bucket versioning
p1 = get_versioning_status(bucket) is None
assert_equal(p1, True)
p2 = get_versioning_status(bucket_az) is None
assert_equal(p2, True)
def test_az_object_replication():
""" test object replication """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create bucket on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
key = bucket.new_key("foo")
key.set_contents_from_string("bar")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check object on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
key_az = bucket_az.get_key("foo")
p1 = key_az.get_contents_as_string(encoding='ascii') == "bar"
assert_equal(p1, True)
def test_az_object_replication_versioning():
""" test object replication versioning """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create object on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
key = bucket.new_key("foo")
key.set_contents_from_string("bar")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check object content on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
key_az = bucket_az.get_key("foo")
p1 = key_az.get_contents_as_string(encoding='ascii') == "bar"
assert_equal(p1, True)
# grab object versioning and etag
for b_version in bucket.list_versions():
b_version_id = b_version.version_id
b_version_etag = b_version.etag
for b_az_version in bucket_az.list_versions():
b_az_version_id = b_az_version.version_id
b_az_version_etag = b_az_version.etag
# check
p2 = b_version_id == 'null'
assert_equal(p2, True)
p3 = b_az_version_id != 'null'
assert_equal(p3, True)
p4 = b_version_etag == b_az_version_etag
assert_equal(p4, True)
def test_az_lazy_activation_of_versioned_bucket():
""" test lazy activation of versioned bucket """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create object on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# get bucket on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
# check for non bucket versioning
p1 = get_versioning_status(bucket) is None
assert_equal(p1, True)
p2 = get_versioning_status(bucket_az) is None
assert_equal(p2, True)
# create object on non archive zone
key = bucket.new_key("foo")
key.set_contents_from_string("bar")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check lazy versioned buckets
p3 = get_versioning_status(bucket) is None
assert_equal(p3, True)
p4 = get_versioning_status(bucket_az) == 'Enabled'
assert_equal(p4, True)
def test_az_archive_zone_double_object_replication_versioning():
""" test archive zone double object replication versioning """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create object on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
key = bucket.new_key("foo")
key.set_contents_from_string("bar")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# get bucket on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
# check for non bucket versioning
p1 = get_versioning_status(bucket) is None
assert_equal(p1, True)
p2 = get_versioning_status(bucket_az) == 'Enabled'
assert_equal(p2, True)
# overwrite object on non archive zone
key = bucket.new_key("foo")
key.set_contents_from_string("ouch")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check lazy versioned buckets
p3 = get_versioning_status(bucket) is None
assert_equal(p3, True)
p4 = get_versioning_status(bucket_az) == 'Enabled'
assert_equal(p4, True)
# get versioned objects
objs = get_versioned_objs(bucket)
objs_az = get_versioned_objs(bucket_az)
# check version_id, size, and is_latest on non archive zone
p5 = objs[0]['foo']['version_id'] == 'null'
assert_equal(p5, True)
p6 = objs[0]['foo']['size'] == 4
assert_equal(p6, True)
p7 = objs[0]['foo']['is_latest'] == True
assert_equal(p7, True)
# check version_id, size, is_latest on archive zone
latest_obj_az_etag = None
for obj_az in objs_az:
current_obj_az = obj_az['foo']
if current_obj_az['is_latest'] == True:
p8 = current_obj_az['size'] == 4
assert_equal(p8, True)
latest_obj_az_etag = current_obj_az['etag']
else:
p9 = current_obj_az['size'] == 3
assert_equal(p9, True)
assert_not_equal(current_obj_az['version_id'], 'null')
# check last versions' etags
p10 = objs[0]['foo']['etag'] == latest_obj_az_etag
assert_equal(p10, True)
def test_az_deleted_object_replication():
""" test zone deleted object replication """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create object on the non archive zone
bucket = zones[0].create_bucket(bucket_name)
key = bucket.new_key("foo")
key.set_contents_from_string("bar")
p1 = key.get_contents_as_string(encoding='ascii') == "bar"
assert_equal(p1, True)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# update object on non archive zone
key.set_contents_from_string("soup")
p2 = key.get_contents_as_string(encoding='ascii') == "soup"
assert_equal(p2, True)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# delete object on non archive zone
key.delete()
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check object on non archive zone
p3 = check_key_exists(key) == False
assert_equal(p3, True)
# check objects on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
key_az = bucket_az.get_key("foo")
p4 = check_key_exists(key_az) == True
assert_equal(p4, True)
p5 = key_az.get_contents_as_string(encoding='ascii') == "soup"
assert_equal(p5, True)
b_ver_az = get_versioned_objs(bucket_az)
p6 = len(b_ver_az) == 2
assert_equal(p6, True)
def test_az_bucket_renaming_on_empty_bucket_deletion():
""" test bucket renaming on empty bucket deletion """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# grab number of buckets on non archive zone
num_buckets = get_number_buckets_by_zone(zones[0])
# grab number of buckets on archive zone
num_buckets_az = get_number_buckets_by_zone(az_zones[0])
# create bucket on non archive zone
bucket = zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# delete bucket in non archive zone
zones[0].delete_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check no new buckets on non archive zone
p1 = get_number_buckets_by_zone(zones[0]) == num_buckets
assert_equal(p1, True)
# check non deletion on bucket on archive zone
p2 = get_number_buckets_by_zone(az_zones[0]) == (num_buckets_az + 1)
assert_equal(p2, True)
# check bucket renaming
bucket_names_az = get_bucket_names_by_zone(az_zones[0])
new_bucket_name = bucket_name + '-deleted-'
p3 = any(bucket_name.startswith(new_bucket_name) for bucket_name in bucket_names_az)
assert_equal(p3, True)
def test_az_old_object_version_in_archive_zone():
""" test old object version in archive zone """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# grab number of buckets on non archive zone
num_buckets = get_number_buckets_by_zone(zones[0])
# grab number of buckets on archive zone
num_buckets_az = get_number_buckets_by_zone(az_zones[0])
# create bucket on non archive zone
bucket = zones[0].create_bucket(bucket_name)
# create object on non archive zone
key = bucket.new_key("foo")
key.set_contents_from_string("zero")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# save object version on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
b_ver_az = get_versioned_objs(bucket_az)
obj_az_version_id = b_ver_az[0]['foo']['version_id']
# update object on non archive zone
key.set_contents_from_string("one")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# delete object on non archive zone
key.delete()
# delete bucket on non archive zone
zones[0].delete_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check same buckets on non archive zone
p1 = get_number_buckets_by_zone(zones[0]) == num_buckets
assert_equal(p1, True)
# check for new bucket on archive zone
p2 = get_number_buckets_by_zone(az_zones[0]) == (num_buckets_az + 1)
assert_equal(p2, True)
# get new bucket name on archive zone
bucket_names_az = get_bucket_names_by_zone(az_zones[0])
new_bucket_name_az = get_full_bucket_name(bucket_name + '-deleted-', bucket_names_az)
p3 = new_bucket_name_az is not None
assert_equal(p3, True)
# check number of objects on archive zone
new_bucket_az = az_zones[0].conn.get_bucket(new_bucket_name_az)
new_b_ver_az = get_versioned_objs(new_bucket_az)
p4 = len(new_b_ver_az) == 2
assert_equal(p4, True)
# check versioned objects on archive zone
new_key_az = new_bucket_az.get_key("foo", version_id=obj_az_version_id)
p5 = new_key_az.get_contents_as_string(encoding='ascii') == "zero"
assert_equal(p5, True)
new_key_latest_az = new_bucket_az.get_key("foo")
p6 = new_key_latest_az.get_contents_as_string(encoding='ascii') == "one"
assert_equal(p6, True)
def test_az_force_bucket_renaming_if_same_bucket_name():
""" test force bucket renaming if same bucket name """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# grab number of buckets on non archive zone
num_buckets = get_number_buckets_by_zone(zones[0])
# grab number of buckets on archive zone
num_buckets_az = get_number_buckets_by_zone(az_zones[0])
# create bucket on non archive zone
bucket = zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check same buckets on non archive zone
p1 = get_number_buckets_by_zone(zones[0]) == (num_buckets + 1)
assert_equal(p1, True)
# check for new bucket on archive zone
p2 = get_number_buckets_by_zone(az_zones[0]) == (num_buckets_az + 1)
assert_equal(p2, True)
# delete bucket on non archive zone
zones[0].delete_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check number of buckets on non archive zone
p3 = get_number_buckets_by_zone(zones[0]) == num_buckets
assert_equal(p3, True)
# check number of buckets on archive zone
p4 = get_number_buckets_by_zone(az_zones[0]) == (num_buckets_az + 1)
assert_equal(p4, True)
# get new bucket name on archive zone
bucket_names_az = get_bucket_names_by_zone(az_zones[0])
new_bucket_name_az = get_full_bucket_name(bucket_name + '-deleted-', bucket_names_az)
p5 = new_bucket_name_az is not None
assert_equal(p5, True)
# create bucket on non archive zone
_ = zones[0].create_bucket(new_bucket_name_az)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check number of buckets on non archive zone
p6 = get_number_buckets_by_zone(zones[0]) == (num_buckets + 1)
assert_equal(p6, True)
# check number of buckets on archive zone
p7 = get_number_buckets_by_zone(az_zones[0]) == (num_buckets_az + 2)
assert_equal(p7, True)
def test_az_versioning_support_in_zones():
""" test versioning support on zones """
zones, az_zones = init_env()
bucket_name = gen_bucket_name()
# create bucket on non archive zone
bucket = zones[0].create_bucket(bucket_name)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# get bucket on archive zone
bucket_az = az_zones[0].conn.get_bucket(bucket_name)
# check non versioned buckets
p1 = get_versioning_status(bucket) is None
assert_equal(p1, True)
p2 = get_versioning_status(bucket_az) is None
assert_equal(p2, True)
# create object on non archive zone
key = bucket.new_key("foo")
key.set_contents_from_string("zero")
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check bucket versioning
p3 = get_versioning_status(bucket) is None
assert_equal(p3, True)
p4 = get_versioning_status(bucket_az) == 'Enabled'
assert_equal(p4, True)
# enable bucket versioning on non archive zone
bucket.configure_versioning(True)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check bucket versioning
p5 = get_versioning_status(bucket) == 'Enabled'
assert_equal(p5, True)
p6 = get_versioning_status(bucket_az) == 'Enabled'
assert_equal(p6, True)
# delete object on non archive zone
key.delete()
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check delete-markers and versions on non archive zone
(b_dm, b_ver) = get_versioned_entries(bucket)
p7 = len(b_dm) == 1
assert_equal(p7, True)
p8 = len(b_ver) == 1
assert_equal(p8, True)
# check delete-markers and versions on archive zone
(b_dm_az, b_ver_az) = get_versioned_entries(bucket_az)
p9 = len(b_dm_az) == 1
assert_equal(p9, True)
p10 = len(b_ver_az) == 1
assert_equal(p10, True)
# delete delete-marker on non archive zone
dm_version_id = b_dm[0]['foo']['version_id']
bucket.delete_key("foo", version_id=dm_version_id)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check delete-markers and versions on non archive zone
(b_dm, b_ver) = get_versioned_entries(bucket)
p11 = len(b_dm) == 0
assert_equal(p11, True)
p12 = len(b_ver) == 1
assert_equal(p12, True)
# check delete-markers and versions on archive zone
(b_dm_az, b_ver_az) = get_versioned_entries(bucket_az)
p13 = len(b_dm_az) == 1
assert_equal(p13, True)
p14 = len(b_ver_az) == 1
assert_equal(p14, True)
# delete delete-marker on archive zone
dm_az_version_id = b_dm_az[0]['foo']['version_id']
bucket_az.delete_key("foo", version_id=dm_az_version_id)
# sync
zone_full_checkpoint(az_zones[0].zone, zones[0].zone)
# check delete-markers and versions on non archive zone
(b_dm, b_ver) = get_versioned_entries(bucket)
p15 = len(b_dm) == 0
assert_equal(p15, True)
p16 = len(b_ver) == 1
assert_equal(p16, True)
# check delete-markers and versions on archive zone
(b_dm_az, b_ver_az) = get_versioned_entries(bucket_az)
p17 = len(b_dm_az) == 0
assert_equal(p17, True)
p17 = len(b_ver_az) == 1
assert_equal(p17, True)
# check body in zones
obj_version_id = b_ver[0]['foo']['version_id']
key = bucket.get_key("foo", version_id=obj_version_id)
p18 = key.get_contents_as_string(encoding='ascii') == "zero"
assert_equal(p18, True)
obj_az_version_id = b_ver_az[0]['foo']['version_id']
key_az = bucket_az.get_key("foo", version_id=obj_az_version_id)
p19 = key_az.get_contents_as_string(encoding='ascii') == "zero"
assert_equal(p19, True)
|