Skip to content

Commit

Permalink
[Tier-2]Configure sync to a different bucket in another zone
Browse files Browse the repository at this point in the history
Signed-off-by: Anuchaithra <[email protected]>
  • Loading branch information
anrao19 committed Mar 1, 2024
1 parent 7d0f766 commit 42f02ae
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Polarian TC : CEPH-83575141
# script: test_multisite_bucket_granular_sync_policy.py
config:
user_count: 1
bucket_count: 1
objects_count: 100
objects_size_range:
min: 5K
max: 2M
test_ops:
zonegroup_group: true
zonegroup_status: allowed
zonegroup_flow: true
zonegroup_flow_type: symmetrical
zonegroup_pipe: true
bucket_group: true
bucket_status: enabled
bucket_flow: false
bucket_pipe: true
bucket_pipe_count: 2
create_object: true
create_bucket: true
create_new_bucket: true
new_bucket_count: 2
sync_to_diff_bucket: true
bucket_policy_details: --dest-bucket <dest_bucket_name>
write_io_verify_another_site: true
write_io_verify_should_sync: false
zonegroup_group_remove: true
25 changes: 14 additions & 11 deletions rgw/v2/tests/s3_swift/reusable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,16 +1880,18 @@ def verify_bucket_sync_policy_on_other_site(rgw_ssh_con, bucket):
)


def verify_object_sync_on_other_site(rgw_ssh_con, bucket, config):
log.info(f"Verify object sync on other site for bucket {bucket.name}")
bucket_stats = json.loads(
utils.exec_shell_cmd(f"radosgw-admin bucket stats --bucket {bucket.name}")
)
bkt_objects = bucket_stats["usage"]["rgw.main"]["num_objects"]
if bkt_objects != config.objects_count:
raise TestExecError(
f"Did not find {config.objects_count} in bucket {bucket.name}, but found {bkt_objects}"
def verify_object_sync_on_other_site(rgw_ssh_con, bucket, config, diff_bucket=None, bkt_objects=None):
if diff_bucket is None:
bucket_stats = json.loads(
utils.exec_shell_cmd(f"radosgw-admin bucket stats --bucket {bucket.name}")
)
bucket_object = bucket_stats["usage"]["rgw.main"]["num_objects"]
if bucket_object == bkt_objects:
raise TestExecError(f"object synced to bucket {bucket.name}")
else:
log.info(f"object did not sync to bucket {bucket.name} on same site as expected")

log.info(f"Verify object sync on other site for bucket {bucket.name}")
_, stdout, _ = rgw_ssh_con.exec_command(
f"radosgw-admin bucket stats --bucket {bucket.name}"
)
Expand Down Expand Up @@ -1935,7 +1937,7 @@ def verify_object_sync_on_other_site(rgw_ssh_con, bucket, config):
f"object count mismatch found in another site for bucket {bucket.name} : {bucket_objects} expected {bkt_objects}"
)
cmd_output = command_output
log.info(f"object synced on anothe site for bucket {bucket.name} : {cmd_output}")
log.info(f"object synced on another site for bucket {bucket.name} : {cmd_output}")


def flow_operation(
Expand Down Expand Up @@ -1968,8 +1970,9 @@ def pipe_operation(
policy_detail=None,
source_zones=None,
dest_zones=None,
pipe_id=None,
):
pipe_id = group_id + "pipe"
pipe_id = pipe_id if pipe_id is not None else group_id + "pipe"
if zone_names is not None:
zone_name = zone_names.split(",")
zn = f" --source-zones='{zone_name[0]}','{zone_name[1]}' --dest-zones='{zone_name[0]}','{zone_name[1]}'"
Expand Down
126 changes: 109 additions & 17 deletions rgw/v2/tests/s3_swift/test_multisite_bucket_granular_sync_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
multisite_configs/test_multisite_granular_bucketsync_forbidden_enabled.yaml
multisite_configs/test_multisite_granular_bucketsync_forbidden_forbidden.yaml
multisite_configs/test_multisite_granular_bucketsync_forbidden_allowed.yaml
multisite_configs/test_multisite_granular_bucketsync_sync_to_diff_bucket.yaml
Operation:
Creates delete sync policy group bucket , zonegroupl level
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_exec(config, ssh_con):
if config.test_ops.get("create_bucket", False):
log.info(f"no of buckets to create: {config.bucket_count}")
buckets = []
new_buckets = []
for bc in range(config.bucket_count):
bucket_name_to_create = utils.gen_bucket_name_from_userid(
each_user["user_id"], rand_no=bc
Expand All @@ -80,6 +82,17 @@ def test_exec(config, ssh_con):
bucket = reusable.create_bucket(
bucket_name_to_create, rgw_conn, each_user
)

if config.test_ops.get("create_new_bucket", False):
bucket_count = config.test_ops.get("new_bucket_count", 1)
for i in range(bucket_count):
new_bucket_name = f"{bucket_name_to_create}-new-{i}"
log.info(f"creating new bucket with name: {new_bucket_name}")
new_bucket = reusable.create_bucket(
new_bucket_name, rgw_conn, each_user
)
new_buckets.append(new_bucket)

reusable.verify_bucket_sync_on_other_site(rgw_ssh_con, bucket)
buckets.append(bucket)

Expand Down Expand Up @@ -157,23 +170,31 @@ def test_exec(config, ssh_con):
bucket_dest_flow,
)
if config.test_ops.get("bucket_pipe", False):
bucket_details = config.test_ops.get(
"bucket_policy_details", None
)
bucket_source_pipe = config.test_ops.get(
"bucket_source_zones", None
)
bucket_dest_pipe = config.test_ops.get(
"bucket_dest_zones", None
)
pipe_id = reusable.pipe_operation(
bucket_group,
"create",
bucket_name=bkt.name,
policy_detail=bucket_details,
source_zones=bucket_source_pipe,
dest_zones=bucket_dest_pipe,
)
bucket_pipe_count = config.test_ops.get("bucket_pipe_count", 1)
for pipec in range(bucket_pipe_count):
bucket_details = config.test_ops.get(
"bucket_policy_details", None
)
pipe_id = None
if config.test_ops.get("sync_to_diff_bucket", False):
bucket_details = " " + bucket_details.replace("<dest_bucket_name>", f"{bkt.name}-new-{pipec}")
pipe_id = f"{bucket_group}pipe{pipec}"

bucket_source_pipe = config.test_ops.get(
"bucket_source_zones", None
)
bucket_dest_pipe = config.test_ops.get(
"bucket_dest_zones", None
)
pipe_id = reusable.pipe_operation(
bucket_group,
"create",
bucket_name=bkt.name,
policy_detail=bucket_details,
source_zones=bucket_source_pipe,
dest_zones=bucket_dest_pipe,
pipe_id=pipe_id,
)

for bkt in buckets:
if config.test_ops.get("bucket_group", False):
Expand Down Expand Up @@ -236,6 +257,29 @@ def test_exec(config, ssh_con):
f"object did not sync to another site for bucket {bkt.name} as expected"
)

if config.test_ops.get("sync_to_diff_bucket", False):
log.info(f"Verify object sync on same site for bucket {bkt.name}")
bucket_stats = json.loads(
utils.exec_shell_cmd(f"radosgw-admin bucket stats --bucket {bkt.name}")
)
bkt_objects = bucket_stats["usage"]["rgw.main"]["num_objects"]
if bkt_objects != config.objects_count:
raise TestExecError(
f"Did not find {config.objects_count} in bucket {bkt.name}, but found {bkt_objects}"
)

log.info(
f"object did not sync to same site for bucket {bkt.name} as expected"
)
bucket_count = config.test_ops.get("new_bucket_count", 1)
for i in range(bucket_count):
new_bucket = f"{bucket_name_to_create}-new-{i}"
for new_bkt in new_buckets:
if new_bkt.name == new_bucket:
reusable.verify_object_sync_on_other_site(
rgw_ssh_con, new_bkt, config, diff_bucket=True, bkt_objects=bkt_objects
)

if config.test_ops.get("bucket_sync", False):
bucket_group = "bgroup-" + bkt.name
reusable.group_operation(
Expand Down Expand Up @@ -282,6 +326,14 @@ def test_exec(config, ssh_con):
)

if config.test_ops.get("write_io_verify_another_site", False):
if config.test_ops.get("sync_to_diff_bucket", False):
cmd_output = json.loads(utils.exec_shell_cmd(f"radosgw-admin bucket stats --bucket {bkt.name}"))
sync_num_obj = (
cmd_output["usage"]["rgw.main"]["num_objects"]
if "rgw.main" in cmd_output["usage"].keys()
else 0
)

_, stdout, _ = rgw_ssh_con.exec_command(
f"radosgw-admin bucket stats --bucket {bkt.name}"
)
Expand Down Expand Up @@ -355,6 +407,46 @@ def test_exec(config, ssh_con):
log.info(
f"Object synced for bucket {bkt.name}, on another site as expected"
)

elif config.test_ops.get("sync_to_diff_bucket", False):
if bkt_objects != sync_num_obj:
raise TestExecError(
f"Object should not sync in bucket {bkt.name}, but found {bkt_objects}"
)

bucket_count = config.test_ops.get("new_bucket_count", 1)
for i in range(bucket_count):
new_bkt = f"{bucket_name_to_create}-new-{i}"
_, stats_stdout, _ = rgw_ssh_con.exec_command(
f"radosgw-admin bucket stats --bucket {new_bkt}"
)
re_cmd_output = json.loads(stats_stdout.read().decode())
log.info(f"re_cmd_output for {new_bkt} : {re_cmd_output}")
if (
re_cmd_output["usage"]["rgw.main"]["num_objects"]
!= config.objects_count
):
raise TestExecError(
f"IO performed for {bkt.name} should not sync to {new_bkt} in same site as of IO"
)
log.info(f"IO did not sync to {new_bkt} as expected in same site as of IO")
log.info(f"verify IO sync on {new_bkt} in another site")
new_bucket_stats = json.loads(
utils.exec_shell_cmd(
f"radosgw-admin bucket stats --bucket {new_bkt}"
)
)
new_bkt_objects = new_bucket_stats["usage"]["rgw.main"][
"num_objects"
]
if new_bkt_objects != config.objects_count:
raise TestExecError(
f"Object did not sync in bucket {new_bkt}, but found {new_bkt_objects}"
)
log.info(
f"Object synced for bucket {new_bkt}, on another site as expected"
)

else:
if bkt_objects != config.objects_count:
raise TestExecError(
Expand Down

0 comments on commit 42f02ae

Please sign in to comment.