]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: update bucket cors in secondary zonegroup should forward to master 15260/head
authorlu.shasha <lu.shasha@eisoo.com>
Wed, 24 May 2017 08:06:07 +0000 (16:06 +0800)
committerlu.shasha <lu.shasha@eisoo.com>
Mon, 19 Jun 2017 01:15:49 +0000 (09:15 +0800)
pr#14082 is incomplete, cors should be redirect to master

Fixes: http://tracker.ceph.com/issues/16888
Signed-off-by: Shasha Lu <lu.shasha@eisoo.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_s3.cc
src/test/rgw/rgw_multi/tests.py

index 4a0fe93bc4b195b0ea1d61f438198f297fd1d402..560560f4b22a307ac51898f917902e88dc8c6bfa 100644 (file)
@@ -4678,6 +4678,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);
index 2d8dc4edd352bc630d205a0508d497919ed57281..de48abcd0d12decbe49c280b184a67bbb8adc5eb 100644 (file)
@@ -1423,6 +1423,7 @@ public:
 class RGWPutCORS : public RGWOp {
 protected:
   bufferlist cors_bl;
+  bufferlist in_data;
 
 public:
   RGWPutCORS() {}
index f6bbe9da59b62fbf67352d21798c1a97f64b64de..099a5d20285792ab993924d1df777523f7dc2a90 100644 (file)
@@ -2130,6 +2130,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);
index 90ddb83cd7665a267a169f10488f90768756c13c..d23fba3097f4025cb1500e576b2d08f89739f7ad 100644 (file)
@@ -14,6 +14,7 @@ from itertools import combinations
 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
@@ -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)