Skip to content

Commit

Permalink
Merge pull request ceph#15260 from shashalu/fix-secondary-zonegroup-cors
Browse files Browse the repository at this point in the history
rgw: update bucket cors in secondary zonegroup should forward to master

Reviewed-by: Casey Bodley <[email protected]>
  • Loading branch information
cbodley authored Jun 20, 2017
2 parents 853a54a + 7dd0995 commit 2edd33c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/rgw/rgw_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4691,6 +4691,14 @@ void RGWPutCORS::execute()
if (op_ret < 0)
return;

if (!store->is_meta_master()) {
op_ret = forward_request_to_master(s, NULL, store, in_data, nullptr);
if (op_ret < 0) {
ldout(s->cct, 20) << __func__ << "forward_request_to_master returned ret=" << op_ret << dendl;
return;
}
}

map<string, bufferlist> attrs = s->bucket_attrs;
attrs[RGW_ATTR_CORS] = cors_bl;
op_ret = rgw_bucket_set_attrs(store, s->bucket_info, attrs, &s->bucket_info.objv_tracker);
Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ class RGWGetCORS : public RGWOp {
class RGWPutCORS : public RGWOp {
protected:
bufferlist cors_bl;
bufferlist in_data;

public:
RGWPutCORS() {}
Expand Down
6 changes: 6 additions & 0 deletions src/rgw/rgw_rest_s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,12 @@ int RGWPutCORS_ObjStore_S3::get_params()
return -EINVAL;
}

// forward bucket cors requests to meta master zone
if (!store->is_meta_master()) {
/* only need to keep this data around if we're not meta master */
in_data.append(data, len);
}

if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15)) {
ldout(s->cct, 15) << "CORSConfiguration";
cors_config->to_xml(*_dout);
Expand Down
9 changes: 9 additions & 0 deletions src/test/rgw/rgw_multi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import boto
import boto.s3.connection
from boto.s3.website import WebsiteConfiguration
from boto.s3.cors import CORSConfiguration

from nose.tools import eq_ as eq
from nose.plugins.attrib import attr
Expand Down Expand Up @@ -655,6 +656,14 @@ def test_bucket_acl():
bucket.set_acl('public-read')
assert(len(bucket.get_acl().acl.grants) == 2) # new grant on AllUsers

def test_bucket_cors():
buckets, zone_bucket = create_bucket_per_zone_in_realm()
for _, bucket in zone_bucket:
cors_cfg = CORSConfiguration()
cors_cfg.add_rule(['DELETE'], 'https://www.example.com', allowed_header='*', max_age_seconds=3000)
bucket.set_cors(cors_cfg)
assert(bucket.get_cors().to_xml() == cors_cfg.to_xml())

def test_bucket_delete_notempty():
zonegroup = realm.master_zonegroup()
zonegroup_conns = ZonegroupConns(zonegroup)
Expand Down

0 comments on commit 2edd33c

Please sign in to comment.