From: Shilpa Jagannath Date: Thu, 1 May 2025 16:46:35 +0000 (-0400) Subject: rgw/multisite: sync bucket obj_lock. X-Git-Tag: testing/wip-vshankar-testing-20250917.131748-debug~7^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c2d235788c4e6ea0d3c7990cbc93af1ef2d31692;p=ceph-ci.git rgw/multisite: sync bucket obj_lock. add json encoding/decoding to members Signed-off-by: Shilpa Jagannath --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 6303e6e3e93..d4da8fc7fc6 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -2603,6 +2603,9 @@ void RGWBucketInfo::dump(Formatter *f) const if (!empty_sync_policy()) { encode_json("sync_policy", *sync_policy, f); } + if (obj_lock_enabled()) { + encode_json("obj_lock", obj_lock, f); + } } void RGWBucketInfo::decode_json(JSONObj *obj) { @@ -2646,6 +2649,9 @@ void RGWBucketInfo::decode_json(JSONObj *obj) { if (!sp.empty()) { set_sync_policy(std::move(sp)); } + if (obj_lock_enabled()) { + JSONDecoder::decode_json("obj_lock", obj_lock, obj); + } } void RGWUserInfo::generate_test_instances(list& o) diff --git a/src/rgw/rgw_object_lock.cc b/src/rgw/rgw_object_lock.cc index fdd6608af15..1853d84ccef 100644 --- a/src/rgw/rgw_object_lock.cc +++ b/src/rgw/rgw_object_lock.cc @@ -5,6 +5,12 @@ using namespace std; +void DefaultRetention::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("mode", mode, obj); + JSONDecoder::decode_json("days", days, obj); + JSONDecoder::decode_json("years", years, obj); +} + void DefaultRetention::decode_xml(XMLObj *obj) { RGWXMLDecoder::decode_xml("Mode", mode, obj, true); if (mode.compare("GOVERNANCE") != 0 && mode.compare("COMPLIANCE") != 0) { @@ -18,11 +24,11 @@ void DefaultRetention::decode_xml(XMLObj *obj) { } void DefaultRetention::dump(Formatter *f) const { - f->dump_string("mode", mode); + encode_json("mode", mode, f); if (days > 0) { - f->dump_int("days", days); + encode_json("days", days, f); } else { - f->dump_int("years", years); + encode_json("years", years, f); } } @@ -35,6 +41,10 @@ void DefaultRetention::dump_xml(Formatter *f) const { } } +void ObjectLockRule::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("defaultRetention", defaultRetention, obj); +} + void ObjectLockRule::decode_xml(XMLObj *obj) { RGWXMLDecoder::decode_xml("DefaultRetention", defaultRetention, obj, true); } @@ -44,9 +54,7 @@ void ObjectLockRule::dump_xml(Formatter *f) const { } void ObjectLockRule::dump(Formatter *f) const { - f->open_object_section("default_retention"); - defaultRetention.dump(f); - f->close_section(); + encode_json("defaultRetention", defaultRetention, f); } void ObjectLockRule::generate_test_instances(std::list& o) { @@ -54,6 +62,14 @@ void ObjectLockRule::generate_test_instances(std::list& o) { o.push_back(obj); } +void RGWObjectLock::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("enabled", enabled, obj); + JSONDecoder::decode_json("rule_exist", rule_exist, obj); + if (rule_exist) { + JSONDecoder::decode_json("rule", rule, obj); + } +} + void RGWObjectLock::decode_xml(XMLObj *obj) { string enabled_str; RGWXMLDecoder::decode_xml("ObjectLockEnabled", enabled_str, obj, true); @@ -75,12 +91,12 @@ void RGWObjectLock::dump_xml(Formatter *f) const { } void RGWObjectLock::dump(Formatter *f) const { - f->dump_bool("enabled", enabled); - f->dump_bool("rule_exist", rule_exist); + if (enabled) { + encode_json("enabled", enabled, f); + } + encode_json("rule_exist", rule_exist, f); if (rule_exist) { - f->open_object_section("rule"); - rule.dump(f); - f->close_section(); + encode_json("rule", rule, f); } } diff --git a/src/rgw/rgw_object_lock.h b/src/rgw/rgw_object_lock.h index 7c6b9cf612b..cdfdbc7681c 100644 --- a/src/rgw/rgw_object_lock.h +++ b/src/rgw/rgw_object_lock.h @@ -6,6 +6,7 @@ #include #include "common/ceph_time.h" #include "common/iso_8601.h" +#include "common/ceph_json.h" #include "rgw_xml.h" class DefaultRetention @@ -45,6 +46,8 @@ public: decode(years, bl); DECODE_FINISH(bl); } + + void decode_json(JSONObj *obj); void dump(Formatter *f) const; void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; @@ -80,6 +83,7 @@ public: DECODE_FINISH(bl); } + void decode_json(JSONObj *obj); void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; void dump(Formatter *f) const; @@ -140,6 +144,7 @@ public: DECODE_FINISH(bl); } + void decode_json(JSONObj *obj); void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; ceph::real_time get_lock_until_date(const ceph::real_time& mtime) const; diff --git a/src/test/rgw/rgw_multi/tests.py b/src/test/rgw/rgw_multi/tests.py index c457fc3ca9c..8a0716eb4b3 100644 --- a/src/test/rgw/rgw_multi/tests.py +++ b/src/test/rgw/rgw_multi/tests.py @@ -5934,4 +5934,43 @@ def test_copy_obj_perm_check_between_zonegroups(zonegroup): Bucket=dest_bucket.name, CopySource={'Bucket': source_bucket.name, 'Key': objname}, Key=objname) - assert e.response['Error']['Code'] == 'AccessDenied' \ No newline at end of file + assert e.response['Error']['Code'] == 'AccessDenied' + + +def test_object_lock_sync(): + + zonegroup = realm.master_zonegroup() + zonegroup_conns = ZonegroupConns(zonegroup) + primary = zonegroup_conns.rw_zones[0] + secondary = zonegroup_conns.rw_zones[1] + + bucket = primary.create_bucket(gen_bucket_name()) + log.debug('created bucket=%s', bucket.name) + + # enable versioning + bucket.configure_versioning(True) + zonegroup_meta_checkpoint(zonegroup) + + lock_config = { + 'ObjectLockEnabled': 'Enabled', + 'Rule': { + 'DefaultRetention': { + 'Mode': 'COMPLIANCE', + 'Days': 1 + } + } + } + + # enable object lock on bucket + primary.s3_client.put_object_lock_configuration( + Bucket=bucket.name, + ObjectLockConfiguration = lock_config) + + zonegroup_meta_checkpoint(zonegroup) + zone_data_checkpoint(secondary.zone, primary.zone) + + response = secondary.s3_client.get_object_lock_configuration(Bucket=bucket.name) + assert(response['ObjectLockConfiguration'] == lock_config) + + +