From 04a5f2445bfeb454f0b7c52c41fa9b14b20bcb6f Mon Sep 17 00:00:00 2001 From: yuliyang Date: Mon, 15 May 2017 16:49:13 +0800 Subject: [PATCH] rgw-multisite: fix the problem of rgw website configure request not redirect to metadata master Signed-off-by: yuliyang --- src/rgw/rgw_op.cc | 8 ++++++++ src/rgw/rgw_op.h | 1 + src/rgw/rgw_rest_s3.cc | 3 +++ src/test/rgw/rgw_multi/tests.py | 12 ++++++++++++ 4 files changed, 24 insertions(+) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 29adbc58aa4..57e3235c3b1 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1969,6 +1969,14 @@ void RGWSetBucketWebsite::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; + } + } + s->bucket_info.has_website = true; s->bucket_info.website_conf = website_conf; diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 3589fb48985..2d8dc4edd35 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -748,6 +748,7 @@ public: class RGWSetBucketWebsite : public RGWOp { protected: + bufferlist in_data; RGWBucketWebsiteConf website_conf; public: RGWSetBucketWebsite() {} diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 0b2550d704b..684e65a66ce 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -850,6 +850,9 @@ int RGWSetBucketWebsite_ObjStore_S3::get_params() } } + bufferptr in_ptr(data, len); + in_data.append(in_ptr); + RGWXMLDecoder::XMLParser parser; if (!parser.init()) { ldout(s->cct, 0) << "ERROR: failed to initialize parser" << dendl; diff --git a/src/test/rgw/rgw_multi/tests.py b/src/test/rgw/rgw_multi/tests.py index fff682d37e4..58426dfbfe1 100644 --- a/src/test/rgw/rgw_multi/tests.py +++ b/src/test/rgw/rgw_multi/tests.py @@ -13,6 +13,7 @@ from itertools import combinations import boto import boto.s3.connection +from boto.s3.website import WebsiteConfiguration from nose.tools import eq_ as eq from nose.plugins.attrib import attr @@ -791,3 +792,14 @@ def test_zonegroup_remove(): # validate the resulting period zonegroup.period.update(z1, commit=True) + +def test_set_bucket_website(): + buckets, zone_bucket = create_bucket_per_zone_in_realm() + for _, bucket in zone_bucket: + website_cfg = WebsiteConfiguration(suffix='index.html',error_key='error.html') + try: + bucket.set_website_configuration(website_cfg) + except boto.exception.S3ResponseError as e: + if e.error_code == 'MethodNotAllowed': + raise SkipTest("test_set_bucket_website skipped. Requires rgw_enable_static_website = 1.") + assert(bucket.get_website_configuration_with_xml()[1] == website_cfg.to_xml()) \ No newline at end of file