Skip to content

Commit c2d2357

Browse files
author
Shilpa Jagannath
committed
rgw/multisite: sync bucket obj_lock.
add json encoding/decoding to members Signed-off-by: Shilpa Jagannath <[email protected]>
1 parent 6c00155 commit c2d2357

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
lines changed

src/rgw/rgw_common.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,9 @@ void RGWBucketInfo::dump(Formatter *f) const
26032603
if (!empty_sync_policy()) {
26042604
encode_json("sync_policy", *sync_policy, f);
26052605
}
2606+
if (obj_lock_enabled()) {
2607+
encode_json("obj_lock", obj_lock, f);
2608+
}
26062609
}
26072610

26082611
void RGWBucketInfo::decode_json(JSONObj *obj) {
@@ -2646,6 +2649,9 @@ void RGWBucketInfo::decode_json(JSONObj *obj) {
26462649
if (!sp.empty()) {
26472650
set_sync_policy(std::move(sp));
26482651
}
2652+
if (obj_lock_enabled()) {
2653+
JSONDecoder::decode_json("obj_lock", obj_lock, obj);
2654+
}
26492655
}
26502656

26512657
void RGWUserInfo::generate_test_instances(list<RGWUserInfo*>& o)

src/rgw/rgw_object_lock.cc

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
using namespace std;
77

8+
void DefaultRetention::decode_json(JSONObj *obj) {
9+
JSONDecoder::decode_json("mode", mode, obj);
10+
JSONDecoder::decode_json("days", days, obj);
11+
JSONDecoder::decode_json("years", years, obj);
12+
}
13+
814
void DefaultRetention::decode_xml(XMLObj *obj) {
915
RGWXMLDecoder::decode_xml("Mode", mode, obj, true);
1016
if (mode.compare("GOVERNANCE") != 0 && mode.compare("COMPLIANCE") != 0) {
@@ -18,11 +24,11 @@ void DefaultRetention::decode_xml(XMLObj *obj) {
1824
}
1925

2026
void DefaultRetention::dump(Formatter *f) const {
21-
f->dump_string("mode", mode);
27+
encode_json("mode", mode, f);
2228
if (days > 0) {
23-
f->dump_int("days", days);
29+
encode_json("days", days, f);
2430
} else {
25-
f->dump_int("years", years);
31+
encode_json("years", years, f);
2632
}
2733
}
2834

@@ -35,6 +41,10 @@ void DefaultRetention::dump_xml(Formatter *f) const {
3541
}
3642
}
3743

44+
void ObjectLockRule::decode_json(JSONObj *obj) {
45+
JSONDecoder::decode_json("defaultRetention", defaultRetention, obj);
46+
}
47+
3848
void ObjectLockRule::decode_xml(XMLObj *obj) {
3949
RGWXMLDecoder::decode_xml("DefaultRetention", defaultRetention, obj, true);
4050
}
@@ -44,16 +54,22 @@ void ObjectLockRule::dump_xml(Formatter *f) const {
4454
}
4555

4656
void ObjectLockRule::dump(Formatter *f) const {
47-
f->open_object_section("default_retention");
48-
defaultRetention.dump(f);
49-
f->close_section();
57+
encode_json("defaultRetention", defaultRetention, f);
5058
}
5159

5260
void ObjectLockRule::generate_test_instances(std::list<ObjectLockRule*>& o) {
5361
ObjectLockRule *obj = new ObjectLockRule;
5462
o.push_back(obj);
5563
}
5664

65+
void RGWObjectLock::decode_json(JSONObj *obj) {
66+
JSONDecoder::decode_json("enabled", enabled, obj);
67+
JSONDecoder::decode_json("rule_exist", rule_exist, obj);
68+
if (rule_exist) {
69+
JSONDecoder::decode_json("rule", rule, obj);
70+
}
71+
}
72+
5773
void RGWObjectLock::decode_xml(XMLObj *obj) {
5874
string enabled_str;
5975
RGWXMLDecoder::decode_xml("ObjectLockEnabled", enabled_str, obj, true);
@@ -75,12 +91,12 @@ void RGWObjectLock::dump_xml(Formatter *f) const {
7591
}
7692

7793
void RGWObjectLock::dump(Formatter *f) const {
78-
f->dump_bool("enabled", enabled);
79-
f->dump_bool("rule_exist", rule_exist);
94+
if (enabled) {
95+
encode_json("enabled", enabled, f);
96+
}
97+
encode_json("rule_exist", rule_exist, f);
8098
if (rule_exist) {
81-
f->open_object_section("rule");
82-
rule.dump(f);
83-
f->close_section();
99+
encode_json("rule", rule, f);
84100
}
85101
}
86102

src/rgw/rgw_object_lock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77
#include "common/ceph_time.h"
88
#include "common/iso_8601.h"
9+
#include "common/ceph_json.h"
910
#include "rgw_xml.h"
1011

1112
class DefaultRetention
@@ -45,6 +46,8 @@ class DefaultRetention
4546
decode(years, bl);
4647
DECODE_FINISH(bl);
4748
}
49+
50+
void decode_json(JSONObj *obj);
4851
void dump(Formatter *f) const;
4952
void decode_xml(XMLObj *obj);
5053
void dump_xml(Formatter *f) const;
@@ -80,6 +83,7 @@ class ObjectLockRule
8083
DECODE_FINISH(bl);
8184
}
8285

86+
void decode_json(JSONObj *obj);
8387
void decode_xml(XMLObj *obj);
8488
void dump_xml(Formatter *f) const;
8589
void dump(Formatter *f) const;
@@ -140,6 +144,7 @@ class RGWObjectLock
140144
DECODE_FINISH(bl);
141145
}
142146

147+
void decode_json(JSONObj *obj);
143148
void decode_xml(XMLObj *obj);
144149
void dump_xml(Formatter *f) const;
145150
ceph::real_time get_lock_until_date(const ceph::real_time& mtime) const;

src/test/rgw/rgw_multi/tests.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5934,4 +5934,43 @@ def test_copy_obj_perm_check_between_zonegroups(zonegroup):
59345934
Bucket=dest_bucket.name,
59355935
CopySource={'Bucket': source_bucket.name, 'Key': objname},
59365936
Key=objname)
5937-
assert e.response['Error']['Code'] == 'AccessDenied'
5937+
assert e.response['Error']['Code'] == 'AccessDenied'
5938+
5939+
5940+
def test_object_lock_sync():
5941+
5942+
zonegroup = realm.master_zonegroup()
5943+
zonegroup_conns = ZonegroupConns(zonegroup)
5944+
primary = zonegroup_conns.rw_zones[0]
5945+
secondary = zonegroup_conns.rw_zones[1]
5946+
5947+
bucket = primary.create_bucket(gen_bucket_name())
5948+
log.debug('created bucket=%s', bucket.name)
5949+
5950+
# enable versioning
5951+
bucket.configure_versioning(True)
5952+
zonegroup_meta_checkpoint(zonegroup)
5953+
5954+
lock_config = {
5955+
'ObjectLockEnabled': 'Enabled',
5956+
'Rule': {
5957+
'DefaultRetention': {
5958+
'Mode': 'COMPLIANCE',
5959+
'Days': 1
5960+
}
5961+
}
5962+
}
5963+
5964+
# enable object lock on bucket
5965+
primary.s3_client.put_object_lock_configuration(
5966+
Bucket=bucket.name,
5967+
ObjectLockConfiguration = lock_config)
5968+
5969+
zonegroup_meta_checkpoint(zonegroup)
5970+
zone_data_checkpoint(secondary.zone, primary.zone)
5971+
5972+
response = secondary.s3_client.get_object_lock_configuration(Bucket=bucket.name)
5973+
assert(response['ObjectLockConfiguration'] == lock_config)
5974+
5975+
5976+

0 commit comments

Comments
 (0)